JAL-1452 nucleotide/protein default colour; JAL-845 SplitFrame refactor
[jalview.git] / src / jalview / gui / AlignViewport.java
index 8fc10d7..93d8c19 100644 (file)
@@ -46,6 +46,7 @@ import jalview.api.AlignViewportI;
 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;
@@ -107,6 +108,13 @@ public class AlignViewport extends AlignmentViewport implements
 
   String viewName;
 
+  /*
+   * Flag set true on the view that should 'gather' multiple views of the same
+   * sequence set id when a project is reloaded. Set false on all views when
+   * they are 'exploded' into separate windows. Set true on the current view
+   * when 'Gather' is performed, and also on the first tab when the first new
+   * view is created.
+   */
   private boolean gatherViewsHere = false;
 
   private AnnotationColumnChooser annotationColumnSelectionState;
@@ -293,10 +301,18 @@ public class AlignViewport extends AlignmentViewport implements
       showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
     }
     initAutoAnnotation();
-    if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
+    String colourProperty = alignment.isNucleotide() ? Preferences.DEFAULT_COLOUR_NUC
+            : Preferences.DEFAULT_COLOUR_PROT;
+    String propertyValue = Cache.getProperty(colourProperty);
+    if (propertyValue == null)
+    {
+      // fall back on this property for backwards compatibility
+      propertyValue = Cache.getProperty(Preferences.DEFAULT_COLOUR);
+    }
+    if (propertyValue != null)
     {
       globalColourScheme = ColourSchemeProperty.getColour(alignment,
-              jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
+              propertyValue);
 
       if (globalColourScheme instanceof UserColourScheme)
       {
@@ -977,9 +993,9 @@ public class AlignViewport extends AlignmentViewport implements
         MessageManager.getString("label.split_window"),
         MessageManager.getString("label.new_window"), };
     final String question = JvSwingUtils.wrapTooltip(true,
-            MessageManager.getString("label.open_linked_alignment?"));
+            MessageManager.getString("label.open_split_window?"));
     int response = JOptionPane.showOptionDialog(Desktop.desktop, question,
-            MessageManager.getString("label.open_linked_alignment"),
+            MessageManager.getString("label.open_split_window"),
             JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null,
             options, options[0]);
 
@@ -1053,7 +1069,8 @@ public class AlignViewport extends AlignmentViewport implements
 
     if (openSplitPane)
     {
-      protein = openSplitFrame(newAlignFrame, thisAlignment);
+      protein = openSplitFrame(newAlignFrame,
+              thisAlignment.getSequencesArray(), protein.getCodonFrames());
     }
 
     /*
@@ -1073,18 +1090,20 @@ public class AlignViewport extends AlignmentViewport implements
    * 
    * @param newAlignFrame
    *          containing a new alignment to be shown
-   * @param existingAlignment
-   *          an existing alignment to be copied for display in the split frame
+   * @param seqs
+   *          'complementary' sequences to show in the other split half
+   * @param mappings
    * @return the protein alignment in the split frame
    */
   protected AlignmentI openSplitFrame(AlignFrame newAlignFrame,
-          AlignmentI existingAlignment)
+          SequenceI[] seqs, Set<AlignedCodonFrame> mappings)
   {
+    AlignmentI complementAlignment = new Alignment(seqs);
     // TODO: move this to a factory/controller method ?
     /*
      * Open in split pane. DNA sequence above, protein below.
      */
-    AlignFrame copyMe = new AlignFrame(existingAlignment,
+    AlignFrame copyMe = new AlignFrame(complementAlignment,
             AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
     copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
 
@@ -1094,6 +1113,7 @@ public class AlignViewport extends AlignmentViewport implements
     final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame
             : copyMe;
     AlignmentI protein = proteinFrame.viewport.getAlignment();
+    protein.setCodonFrames(mappings);
 
     cdnaFrame.setVisible(true);
     proteinFrame.setVisible(true);
@@ -1102,20 +1122,6 @@ public class AlignViewport extends AlignmentViewport implements
     JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
     Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
 
-    /*
-     * Set the frames to listen for each other's edit and sort commands.
-     */
-    final StructureSelectionManager ssm = StructureSelectionManager
-            .getStructureSelectionManager(Desktop.instance);
-    ssm.addCommandListener(cdnaFrame.getViewport());
-    ssm.addCommandListener(proteinFrame.getViewport());
-
-    /*
-     * 'Coding complement' (dna/protein) views will mirror each others' edits,
-     * selections, sorting etc as decided from time to time by the relevant
-     * authorities.
-     */
-    proteinFrame.getViewport().setCodingComplement(cdnaFrame.getViewport());
     return protein;
   }