JAL-3210 Improvements to eclipse detection. New src tree and SwingJS updated from...
[jalview.git] / src / jalview / gui / AlignViewport.java
index 7d01222..fb3ec3a 100644 (file)
@@ -206,24 +206,26 @@ public class AlignViewport extends AlignmentViewport
    */
   private void applyViewProperties()
   {
-    antiAlias = Cache.getDefault("ANTI_ALIAS", false);
-
-    viewStyle.setShowJVSuffix(Cache.getDefault("SHOW_JVSUFFIX", true));
-    setShowAnnotation(Cache.getDefault("SHOW_ANNOTATIONS", true));
-
-    setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false));
-    setCentreColumnLabels(Cache.getDefault("CENTRE_COLUMN_LABELS", false));
-    autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
-
-    setPadGaps(Cache.getDefault("PAD_GAPS", true));
-    setShowNPFeats(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
-    setShowDBRefs(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
-    viewStyle.setSeqNameItalics(Cache.getDefault("ID_ITALICS", true));
-    viewStyle.setWrapAlignment(Cache.getDefault("WRAP_ALIGNMENT", false));
+    antiAlias = Cache.getDefault(Preferences.ANTI_ALIAS, false);
+
+    viewStyle.setShowJVSuffix(
+            Cache.getDefault(Preferences.SHOW_JVSUFFIX, true));
+    setShowAnnotation(Cache.getDefault(Preferences.SHOW_ANNOTATIONS, true));
+
+    setRightAlignIds(Cache.getDefault(Preferences.RIGHT_ALIGN_IDS, false));
+    setCentreColumnLabels(Cache.getDefault(Preferences.CENTRE_COLUMN_LABELS, false));
+    autoCalculateConsensusAndConservation = Cache.getDefault(Preferences.AUTO_CALC_CONSENSUS, true);
+
+    setPadGaps(Cache.getDefault(Preferences.PAD_GAPS, true));
+    setShowNPFeats(Cache.getDefault(Preferences.SHOW_NPFEATS_TOOLTIP, true));
+    setShowDBRefs(Cache.getDefault(Preferences.SHOW_DBREFS_TOOLTIP, true));
+    viewStyle.setSeqNameItalics(Cache.getDefault(Preferences.ID_ITALICS, true));
+    viewStyle.setWrapAlignment(
+            Cache.getDefault(Preferences.WRAP_ALIGNMENT, false));
     viewStyle.setShowUnconserved(
-            Cache.getDefault("SHOW_UNCONSERVED", false));
-    sortByTree = Cache.getDefault("SORT_BY_TREE", false);
-    followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
+            Cache.getDefault(Preferences.SHOW_UNCONSERVED, false));
+    sortByTree = Cache.getDefault(Preferences.SORT_BY_TREE, false);
+    followSelection = Cache.getDefault(Preferences.FOLLOW_SELECTIONS, true);
     sortAnnotationsBy = SequenceAnnotationOrder
             .valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS,
                     SequenceAnnotationOrder.NONE.name()));
@@ -237,9 +239,10 @@ public class AlignViewport extends AlignmentViewport
   {
     applyViewProperties();
 
-    String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
-    String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
-    String fontSize = Cache.getDefault("FONT_SIZE", "10");
+    String fontName = Cache.getDefault(Preferences.FONT_NAME, "SansSerif");
+    String fontStyle = Cache.getDefault(Preferences.FONT_STYLE,
+            Font.PLAIN + "");
+    String fontSize = Cache.getDefault(Preferences.FONT_SIZE, "10");
 
     int style = 0;
 
@@ -255,7 +258,8 @@ public class AlignViewport extends AlignmentViewport
     setFont(new Font(fontName, style, Integer.parseInt(fontSize)), true);
 
     alignment
-            .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
+            .setGapCharacter(Cache.getDefault(Preferences.GAP_SYMBOL, "-")
+                    .charAt(0));
 
     // We must set conservation and consensus before setting colour,
     // as Blosum and Clustal require this to be done
@@ -263,18 +267,22 @@ public class AlignViewport extends AlignmentViewport
     {
       if (!alignment.isNucleotide())
       {
-        showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
-        showQuality = Cache.getDefault("SHOW_QUALITY", true);
-        showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
-                false);
+        showConservation = Cache.getDefault(Preferences.SHOW_CONSERVATION,
+                true);
+        showQuality = Cache.getDefault(Preferences.SHOW_QUALITY, true);
+        showGroupConservation = Cache
+                .getDefault(Preferences.SHOW_GROUP_CONSERVATION, false);
       }
-      showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
-              true);
-      showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
-      normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
+      showConsensusHistogram = Cache
+              .getDefault(Preferences.SHOW_CONSENSUS_HISTOGRAM, true);
+      showSequenceLogo = Cache.getDefault(Preferences.SHOW_CONSENSUS_LOGO,
               false);
-      showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
-      showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
+
+      normaliseSequenceLogo = Cache
+              .getDefault(Preferences.NORMALISE_CONSENSUS_LOGO, false);
+      showGroupConsensus = Cache
+              .getDefault(Preferences.SHOW_GROUP_CONSENSUS, false);
+      showConsensus = Cache.getDefault(Preferences.SHOW_IDENTITY, true);
 
       showOccupancy = Cache.getDefault(Preferences.SHOW_OCCUPANCY, true);
     }
@@ -289,8 +297,8 @@ public class AlignViewport extends AlignmentViewport
       schemeName = Cache.getDefault(Preferences.DEFAULT_COLOUR,
               ResidueColourScheme.NONE);
     }
-    ColourSchemeI colourScheme = ColourSchemeProperty
-            .getColourScheme(this, alignment, schemeName);
+    ColourSchemeI colourScheme = ColourSchemeProperty.getColourScheme(this,
+            alignment, schemeName);
     residueShading = new ResidueShader(colourScheme);
 
     if (colourScheme instanceof UserColourScheme)
@@ -383,9 +391,8 @@ public class AlignViewport extends AlignmentViewport
      */
     if (align != null)
     {
-      StructureSelectionManager ssm = StructureSelectionManager
-              .getStructureSelectionManager(Desktop.instance);
-      ssm.registerMappings(align.getCodonFrames());
+      Desktop.getStructureSelectionManager()
+              .registerMappings(align.getCodonFrames());
     }
 
     /*
@@ -405,8 +412,8 @@ public class AlignViewport extends AlignmentViewport
       List<AlignedCodonFrame> mappings = al.getCodonFrames();
       if (mappings != null)
       {
-        StructureSelectionManager ssm = StructureSelectionManager
-                .getStructureSelectionManager(Desktop.instance);
+        StructureSelectionManager ssm = Desktop
+                .getStructureSelectionManager();
         for (AlignedCodonFrame acf : mappings)
         {
           if (noReferencesTo(acf))
@@ -531,12 +538,10 @@ public class AlignViewport extends AlignmentViewport
   @Override
   public void sendSelection()
   {
-    jalview.structure.StructureSelectionManager
-            .getStructureSelectionManager(Desktop.instance)
-            .sendSelection(new SequenceGroup(getSelectionGroup()),
-                    new ColumnSelection(getColumnSelection()),
-                    new HiddenColumns(getAlignment().getHiddenColumns()),
-                    this);
+    Desktop.getStructureSelectionManager().sendSelection(
+            new SequenceGroup(getSelectionGroup()),
+            new ColumnSelection(getColumnSelection()),
+            new HiddenColumns(getAlignment().getHiddenColumns()), this);
   }
 
   /**
@@ -577,8 +582,7 @@ public class AlignViewport extends AlignmentViewport
   @Override
   public StructureSelectionManager getStructureSelectionManager()
   {
-    return StructureSelectionManager
-            .getStructureSelectionManager(Desktop.instance);
+    return Desktop.getStructureSelectionManager();
   }
 
   @Override
@@ -747,6 +751,12 @@ public class AlignViewport extends AlignmentViewport
     firePropertyChange("alignment", null, getAlignment().getSequences());
   }
 
+  public final static int NO_SPLIT = 0;
+
+  public final static int SPLIT_FRAME = 1;
+
+  public final static int NEW_WINDOW = 2;
+
   /**
    * Show a dialog with the option to open and link (cDNA <-> protein) as a new
    * alignment, either as a standalone alignment or in a split frame. Returns
@@ -763,54 +773,62 @@ public class AlignViewport extends AlignmentViewport
         MessageManager.getString("label.new_window"), };
     final String question = JvSwingUtils.wrapTooltip(true,
             MessageManager.getString("label.open_split_window?"));
-    final AlignViewport us = this;
-    
+
     /*
      * options No, Split Window, New Window correspond to
      * dialog responses 0, 1, 2 (even though JOptionPane shows them
      * in reverse order)
      */
-    JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop)
-            .setResponseHandler(0, new Runnable()
+    JvOptionPane dialog = JvOptionPane
+            .newOptionDialog(Desktop.getDesktopPane())
+            .setResponseHandler(NO_SPLIT, new Runnable()
             {
               @Override
               public void run()
               {
-                  addDataToAlignment(al);
+                addDataToAlignment(al);
               }
-            }).setResponseHandler(1, new Runnable()
+            }).setResponseHandler(SPLIT_FRAME, new Runnable()
             {
               @Override
               public void run()
               {
-                us.openLinkedAlignmentAs(al, title, true);
+                openLinkedAlignmentAs(getAlignPanel().alignFrame,
+                        new Alignment(getAlignment()), al, title,
+                        SPLIT_FRAME);
               }
-            }).setResponseHandler(2, new Runnable()
+            }).setResponseHandler(NEW_WINDOW, new Runnable()
             {
               @Override
               public void run()
               {
-                us.openLinkedAlignmentAs(al, title, false);
+                openLinkedAlignmentAs(null, getAlignment(), al, title,
+                        NEW_WINDOW);
               }
             });
-       dialog.showDialog(question,
+    dialog.showDialog(question,
             MessageManager.getString("label.open_split_window"),
             JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
             options, options[0]);
   }
 
-  protected void openLinkedAlignmentAs(AlignmentI al, String title,
-          boolean newWindowOrSplitPane)
-    {
+  /**
+   * Open a split frame or a new window
+   * 
+   * @param al
+   * @param title
+   * @param mode
+   *          SPLIT_FRAME or NEW_WINDOW
+   */
+  public static void openLinkedAlignmentAs(AlignFrame thisFrame,
+          AlignmentI thisAlignment, AlignmentI al, String title, int mode)
+  {
     /*
      * Identify protein and dna alignments. Make a copy of this one if opening
      * in a new split pane.
      */
-    AlignmentI thisAlignment = newWindowOrSplitPane
-            ? new Alignment(getAlignment())
-            : getAlignment();
     AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
-    final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
+    AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
 
     /*
      * Map sequences. At least one should get mapped as we have already passed
@@ -839,7 +857,7 @@ public class AlignViewport extends AlignmentViewport
     // alignFrame.setFileName(file, format);
     // }
 
-    if (!newWindowOrSplitPane)
+    if (mode == NEW_WINDOW)
     {
       Desktop.addInternalFrame(newAlignFrame, title,
               AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
@@ -847,16 +865,16 @@ public class AlignViewport extends AlignmentViewport
 
     try
     {
-      newAlignFrame.setMaximum(
-              jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false));
+      newAlignFrame.setMaximum(jalview.bin.Cache
+              .getDefault(Preferences.SHOW_FULLSCREEN, false));
     } catch (java.beans.PropertyVetoException ex)
     {
     }
 
-    if (newWindowOrSplitPane)
+    if (mode == SPLIT_FRAME)
     {
       al.alignAs(thisAlignment);
-      protein = openSplitFrame(newAlignFrame, thisAlignment);
+      openSplitFrame(thisFrame, newAlignFrame, thisAlignment);
     }
   }
 
@@ -870,8 +888,8 @@ public class AlignViewport extends AlignmentViewport
    *          cdna/protein complement alignment to show in the other split half
    * @return the protein alignment in the split frame
    */
-  protected AlignmentI openSplitFrame(AlignFrame newAlignFrame,
-          AlignmentI complement)
+  static protected AlignmentI openSplitFrame(AlignFrame thisFrame,
+          AlignFrame newAlignFrame, AlignmentI complement)
   {
     /*
      * Make a new frame with a copy of the alignment we are adding to. If this
@@ -880,7 +898,7 @@ public class AlignViewport extends AlignmentViewport
      */
     AlignFrame copyMe = new AlignFrame(complement, AlignFrame.DEFAULT_WIDTH,
             AlignFrame.DEFAULT_HEIGHT);
-    copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
+    copyMe.setTitle(thisFrame.getTitle());
 
     AlignmentI al = newAlignFrame.viewport.getAlignment();
     final AlignFrame proteinFrame = al.isNucleotide() ? copyMe