import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
import jalview.analysis.NJTree;
import jalview.api.AlignViewportI;
+import jalview.api.AlignmentViewPanel;
import jalview.api.ViewStyleI;
import jalview.bin.Cache;
import jalview.commands.CommandI;
+import jalview.datamodel.AlignedCodonFrame;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.ColumnSelection;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
+import java.util.Set;
import java.util.Vector;
import javax.swing.JInternalFrame;
*/
public void replaceMappings(AlignmentI align)
{
- StructureSelectionManager ssm = StructureSelectionManager
- .getStructureSelectionManager(Desktop.instance);
/*
* Deregister current mappings (if any)
*/
- if (alignment != null)
- {
- ssm.deregisterMappings(alignment.getCodonFrames());
- }
+ deregisterMappings();
/*
* Register new mappings (if any)
*/
if (align != null)
{
+ StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(Desktop.instance);
ssm.registerMappings(align.getCodonFrames());
}
}
}
+ protected void deregisterMappings()
+ {
+ AlignmentI al = getAlignment();
+ if (al != null)
+ {
+ Set<AlignedCodonFrame> mappings = al.getCodonFrames();
+ if (mappings != null)
+ {
+ StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(Desktop.instance);
+ for (AlignedCodonFrame acf : mappings)
+ {
+ if (noReferencesTo(acf))
+ {
+ ssm.deregisterMapping(acf);
+ }
+ }
+ }
+ }
+ }
+
/**
* DOCUMENT ME!
*
}
}
+ /**
+ * Answers true if no alignment holds a reference to the given mapping
+ *
+ * @param acf
+ * @return
+ */
+ protected boolean noReferencesTo(AlignedCodonFrame acf)
+ {
+ AlignFrame[] frames = Desktop.getAlignFrames();
+ if (frames == null)
+ {
+ return true;
+ }
+ for (AlignFrame af : frames)
+ {
+ if (!af.isClosed())
+ {
+ for (AlignmentViewPanel ap : af.getAlignPanels())
+ {
+ AlignmentI al = ap.getAlignment();
+ if (al != null && al.getCodonFrames().contains(acf))
+ {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
}