JAL-3210 Barebones gradle/buildship/eclipse. See README
[jalview.git] / src / jalview / gui / AlignViewport.java
index eb9c180..7d01222 100644 (file)
@@ -206,26 +206,24 @@ public class AlignViewport extends AlignmentViewport
    */
   private void applyViewProperties()
   {
-    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));
+    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));
     viewStyle.setShowUnconserved(
-            Cache.getDefault(Preferences.SHOW_UNCONSERVED, false));
-    sortByTree = Cache.getDefault(Preferences.SORT_BY_TREE, false);
-    followSelection = Cache.getDefault(Preferences.FOLLOW_SELECTIONS, true);
+            Cache.getDefault("SHOW_UNCONSERVED", false));
+    sortByTree = Cache.getDefault("SORT_BY_TREE", false);
+    followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
     sortAnnotationsBy = SequenceAnnotationOrder
             .valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS,
                     SequenceAnnotationOrder.NONE.name()));
@@ -239,10 +237,9 @@ public class AlignViewport extends AlignmentViewport
   {
     applyViewProperties();
 
-    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");
+    String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
+    String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
+    String fontSize = Cache.getDefault("FONT_SIZE", "10");
 
     int style = 0;
 
@@ -258,8 +255,7 @@ public class AlignViewport extends AlignmentViewport
     setFont(new Font(fontName, style, Integer.parseInt(fontSize)), true);
 
     alignment
-            .setGapCharacter(Cache.getDefault(Preferences.GAP_SYMBOL, "-")
-                    .charAt(0));
+            .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
 
     // We must set conservation and consensus before setting colour,
     // as Blosum and Clustal require this to be done
@@ -267,22 +263,18 @@ public class AlignViewport extends AlignmentViewport
     {
       if (!alignment.isNucleotide())
       {
-        showConservation = Cache.getDefault(Preferences.SHOW_CONSERVATION,
-                true);
-        showQuality = Cache.getDefault(Preferences.SHOW_QUALITY, true);
-        showGroupConservation = Cache
-                .getDefault(Preferences.SHOW_GROUP_CONSERVATION, false);
+        showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
+        showQuality = Cache.getDefault("SHOW_QUALITY", true);
+        showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
+                false);
       }
-      showConsensusHistogram = Cache
-              .getDefault(Preferences.SHOW_CONSENSUS_HISTOGRAM, true);
-      showSequenceLogo = Cache.getDefault(Preferences.SHOW_CONSENSUS_LOGO,
+      showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
+              true);
+      showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
+      normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
               false);
-
-      normaliseSequenceLogo = Cache
-              .getDefault(Preferences.NORMALISE_CONSENSUS_LOGO, false);
-      showGroupConsensus = Cache
-              .getDefault(Preferences.SHOW_GROUP_CONSENSUS, false);
-      showConsensus = Cache.getDefault(Preferences.SHOW_IDENTITY, true);
+      showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
+      showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
 
       showOccupancy = Cache.getDefault(Preferences.SHOW_OCCUPANCY, true);
     }
@@ -297,8 +289,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)
@@ -391,8 +383,9 @@ public class AlignViewport extends AlignmentViewport
      */
     if (align != null)
     {
-      Desktop.getInstance().getStructureSelectionManager()
-              .registerMappings(align.getCodonFrames());
+      StructureSelectionManager ssm = StructureSelectionManager
+              .getStructureSelectionManager(Desktop.instance);
+      ssm.registerMappings(align.getCodonFrames());
     }
 
     /*
@@ -412,8 +405,8 @@ public class AlignViewport extends AlignmentViewport
       List<AlignedCodonFrame> mappings = al.getCodonFrames();
       if (mappings != null)
       {
-        StructureSelectionManager ssm = Desktop.getInstance()
-                .getStructureSelectionManager();
+        StructureSelectionManager ssm = StructureSelectionManager
+                .getStructureSelectionManager(Desktop.instance);
         for (AlignedCodonFrame acf : mappings)
         {
           if (noReferencesTo(acf))
@@ -538,10 +531,12 @@ public class AlignViewport extends AlignmentViewport
   @Override
   public void sendSelection()
   {
-    Desktop.getInstance().getStructureSelectionManager().sendSelection(
-            new SequenceGroup(getSelectionGroup()),
-            new ColumnSelection(getColumnSelection()),
-            new HiddenColumns(getAlignment().getHiddenColumns()), this);
+    jalview.structure.StructureSelectionManager
+            .getStructureSelectionManager(Desktop.instance)
+            .sendSelection(new SequenceGroup(getSelectionGroup()),
+                    new ColumnSelection(getColumnSelection()),
+                    new HiddenColumns(getAlignment().getHiddenColumns()),
+                    this);
   }
 
   /**
@@ -582,7 +577,8 @@ public class AlignViewport extends AlignmentViewport
   @Override
   public StructureSelectionManager getStructureSelectionManager()
   {
-    return Desktop.getInstance().getStructureSelectionManager();
+    return StructureSelectionManager
+            .getStructureSelectionManager(Desktop.instance);
   }
 
   @Override
@@ -751,12 +747,6 @@ 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
@@ -773,62 +763,54 @@ 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.getDesktopPane())
-            .setResponseHandler(NO_SPLIT, new Runnable()
+    JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop)
+            .setResponseHandler(0, new Runnable()
             {
               @Override
               public void run()
               {
-                addDataToAlignment(al);
+                  addDataToAlignment(al);
               }
-            }).setResponseHandler(SPLIT_FRAME, new Runnable()
+            }).setResponseHandler(1, new Runnable()
             {
               @Override
               public void run()
               {
-                openLinkedAlignmentAs(getAlignPanel().alignFrame,
-                        new Alignment(getAlignment()), al, title,
-                        SPLIT_FRAME);
+                us.openLinkedAlignmentAs(al, title, true);
               }
-            }).setResponseHandler(NEW_WINDOW, new Runnable()
+            }).setResponseHandler(2, new Runnable()
             {
               @Override
               public void run()
               {
-                openLinkedAlignmentAs(null, getAlignment(), al, title,
-                        NEW_WINDOW);
+                us.openLinkedAlignmentAs(al, title, false);
               }
             });
-    dialog.showDialog(question,
+       dialog.showDialog(question,
             MessageManager.getString("label.open_split_window"),
             JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
             options, options[0]);
   }
 
-  /**
-   * 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)
-  {
+  protected void openLinkedAlignmentAs(AlignmentI al, String title,
+          boolean newWindowOrSplitPane)
+    {
     /*
      * 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;
-    AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
+    final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
 
     /*
      * Map sequences. At least one should get mapped as we have already passed
@@ -857,7 +839,7 @@ public class AlignViewport extends AlignmentViewport
     // alignFrame.setFileName(file, format);
     // }
 
-    if (mode == NEW_WINDOW)
+    if (!newWindowOrSplitPane)
     {
       Desktop.addInternalFrame(newAlignFrame, title,
               AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
@@ -865,16 +847,16 @@ public class AlignViewport extends AlignmentViewport
 
     try
     {
-      newAlignFrame.setMaximum(jalview.bin.Cache
-              .getDefault(Preferences.SHOW_FULLSCREEN, false));
+      newAlignFrame.setMaximum(
+              jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false));
     } catch (java.beans.PropertyVetoException ex)
     {
     }
 
-    if (mode == SPLIT_FRAME)
+    if (newWindowOrSplitPane)
     {
       al.alignAs(thisAlignment);
-      openSplitFrame(thisFrame, newAlignFrame, thisAlignment);
+      protein = openSplitFrame(newAlignFrame, thisAlignment);
     }
   }
 
@@ -888,8 +870,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
    */
-  static protected AlignmentI openSplitFrame(AlignFrame thisFrame,
-          AlignFrame newAlignFrame, AlignmentI complement)
+  protected AlignmentI openSplitFrame(AlignFrame newAlignFrame,
+          AlignmentI complement)
   {
     /*
      * Make a new frame with a copy of the alignment we are adding to. If this
@@ -898,7 +880,7 @@ public class AlignViewport extends AlignmentViewport
      */
     AlignFrame copyMe = new AlignFrame(complement, AlignFrame.DEFAULT_WIDTH,
             AlignFrame.DEFAULT_HEIGHT);
-    copyMe.setTitle(thisFrame.getTitle());
+    copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
 
     AlignmentI al = newAlignFrame.viewport.getAlignment();
     final AlignFrame proteinFrame = al.isNucleotide() ? copyMe