+
+ private int[] seqmappingrefs = null; // refcount for seqmappings elements
+
+ private synchronized void modifySeqMappingList(boolean add,
+ AlignedCodonFrame[] codonFrames)
+ {
+ if (!add && (seqmappings == null || seqmappings.size() == 0))
+ {
+ return;
+ }
+ if (seqmappings == null)
+ {
+ seqmappings = new Vector();
+ }
+ if (codonFrames != null && codonFrames.length > 0)
+ {
+ for (int cf = 0; cf < codonFrames.length; cf++)
+ {
+ if (seqmappings.contains(codonFrames[cf]))
+ {
+ if (add)
+ {
+ seqmappingrefs[seqmappings.indexOf(codonFrames[cf])]++;
+ }
+ else
+ {
+ if (--seqmappingrefs[seqmappings.indexOf(codonFrames[cf])] <= 0)
+ {
+ int pos = seqmappings.indexOf(codonFrames[cf]);
+ int[] nr = new int[seqmappingrefs.length - 1];
+ if (pos > 0)
+ {
+ System.arraycopy(seqmappingrefs, 0, nr, 0, pos);
+ }
+ if (pos < seqmappingrefs.length - 1)
+ {
+ System.arraycopy(seqmappingrefs, pos + 1, nr, 0,
+ seqmappingrefs.length - pos - 2);
+ }
+ }
+ }
+ }
+ else
+ {
+ if (add)
+ {
+ seqmappings.addElement(codonFrames[cf]);
+
+ int[] nsr = new int[(seqmappingrefs == null) ? 1
+ : seqmappingrefs.length + 1];
+ if (seqmappingrefs != null && seqmappingrefs.length > 0)
+ {
+ System.arraycopy(seqmappingrefs, 0, nsr, 0,
+ seqmappingrefs.length);
+ }
+ nsr[(seqmappingrefs == null) ? 0 : seqmappingrefs.length] = 1;
+ seqmappingrefs = nsr;
+ }
+ }
+ }
+ }
+ }
+
+ public void removeMappings(AlignedCodonFrame[] codonFrames)
+ {
+ modifySeqMappingList(false, codonFrames);
+ }
+
+ public void addMappings(AlignedCodonFrame[] codonFrames)
+ {
+ modifySeqMappingList(true, codonFrames);
+ }
+
+ Vector<SelectionListener> sel_listeners = new Vector<SelectionListener>();
+
+ public void addSelectionListener(SelectionListener selecter)
+ {
+ if (!sel_listeners.contains(selecter))
+ {
+ sel_listeners.addElement(selecter);
+ }
+ }
+
+ public void removeSelectionListener(SelectionListener toremove)
+ {
+ if (sel_listeners.contains(toremove))
+ {
+ sel_listeners.removeElement(toremove);
+ }
+ }
+
+ public synchronized void sendSelection(
+ jalview.datamodel.SequenceGroup selection,
+ jalview.datamodel.ColumnSelection colsel, SelectionSource source)
+ {
+ if (sel_listeners != null && sel_listeners.size() > 0)
+ {
+ Enumeration listeners = sel_listeners.elements();
+ while (listeners.hasMoreElements())
+ {
+ SelectionListener slis = ((SelectionListener) listeners
+ .nextElement());
+ if (slis != source)
+ {
+ slis.selection(selection, colsel, source);
+ }
+ ;
+ }
+ }
+ }
+
+ Vector<AlignmentViewPanelListener> view_listeners = new Vector<AlignmentViewPanelListener>();
+
+ public synchronized void sendViewPosition(
+ jalview.api.AlignmentViewPanel source, int startRes, int endRes,
+ int startSeq, int endSeq)
+ {
+
+ if (view_listeners != null && view_listeners.size() > 0)
+ {
+ Enumeration<AlignmentViewPanelListener> listeners = view_listeners
+ .elements();
+ while (listeners.hasMoreElements())
+ {
+ AlignmentViewPanelListener slis = listeners.nextElement();
+ if (slis != source)
+ {
+ slis.viewPosition(startRes, endRes, startSeq, endSeq, source);
+ }
+ ;
+ }
+ }
+ }
+
+ public void finalize() throws Throwable
+ {
+ if (listeners != null)
+ {
+ listeners.clear();
+ listeners = null;
+ }
+ if (pdbIdFileName != null)
+ {
+ pdbIdFileName.clear();
+ pdbIdFileName = null;
+ }
+ if (sel_listeners != null)
+ {
+ sel_listeners.clear();
+ sel_listeners = null;
+ }
+ if (view_listeners != null)
+ {
+ view_listeners.clear();
+ view_listeners = null;
+ }
+ mappings = null;
+ seqmappingrefs = null;
+ }
+
+ /**
+ * release all references associated with this manager provider
+ *
+ * @param jalviewLite
+ */
+ public static void release(StructureSelectionManagerProvider jalviewLite)
+ {
+ // synchronized (instances)
+ {
+ if (instances == null)
+ {
+ return;
+ }
+ StructureSelectionManager mnger = (instances.get(jalviewLite));
+ if (mnger != null)
+ {
+ instances.remove(jalviewLite);
+ try
+ {
+ mnger.finalize();
+ } catch (Throwable x)
+ {
+ }
+ ;
+ }
+ }
+ }
+
+ public void registerPDBEntry(PDBEntry pdbentry)
+ {
+ if (pdbentry.getFile() != null
+ && pdbentry.getFile().trim().length() > 0)
+ {
+ registerPDBFile(pdbentry.getId(), pdbentry.getFile());
+ }
+ }
+