+
+ 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 sel_listeners = new Vector();
+
+ 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);
+ }
+ ;
+ }
+ }
+ }