Jalview-JS/JAL-3253-applet adding more applet parameters and setting
authorhansonr <hansonr@STO24954W.ad.stolaf.edu>
Fri, 17 May 2019 04:59:29 +0000 (23:59 -0500)
committerhansonr <hansonr@STO24954W.ad.stolaf.edu>
Fri, 17 May 2019 04:59:29 +0000 (23:59 -0500)
more static final constants

Three types of parameters are being read:

1. Property file values, from Info.Jalview_XXX_XXXX:

  Info.Jalview_ENABLE_SPLIT_FRAME = true;

2. Applet parameters:

<applet><param name="enableSplitPane" value="true">...</applet>

3. Jalview Command-line parameters:

  Info.args='open "xxxxx.fa" ....'

15 files changed:
site-resources/swingjs/JalviewApplet.js
src/jalview/appletgui/AnnotationColourChooser.java
src/jalview/bin/AppletParams.java
src/jalview/bin/Jalview.java
src/jalview/bin/JalviewAppLoader.java
src/jalview/bin/JalviewLite.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignViewport.java
src/jalview/gui/AnnotationColourChooser.java
src/jalview/gui/Desktop.java
src/jalview/gui/Preferences.java
src/jalview/io/FileLoader.java
test/jalview/ext/jmol/JmolViewerTest.java
test/jalview/io/FileLoaderTest.java
test/jalview/structure/Mapping.java

index 99b1617..601b1c4 100644 (file)
@@ -12,8 +12,11 @@ $(document).ready(function() {
 
  
 Jalview.processAllAppletElements = function(PageInfo) {
-       var apps = document.getElementsByTagName("applet");
-       for (var i = apps.length; --i >= 0;) {
+       var applets = document.getElementsByTagName("applet");
+       var apps=[];
+       for (var i = 0; i < applets.length; i++)
+               apps[i] = applets[i];
+       for (var i = 0; i < apps.length; i++) {
                Jalview.processAppletElement(apps[i], PageInfo);
        }
 }
@@ -55,15 +58,15 @@ for (var i in UserInfo) {
 
 // generate name/value pairs for parameters in Applet tag
 
-       if (!Info.j2sAppletID) {
-       Info.j2sAppletID = Info.idPrefix.replace(/%ID%/g, "jalview" + Jalview.jvid++);
-}
-
-
-Info.jalview_SCREEN_X= 10,Info.jalview_SCREEN_Y= 10;
-Info.jalview_EMBEDDED= true;
-Info.jalview_SCREEN_WIDTH = 400;
-Info.jalview_SCREEN_HEIGHT = 100;
+       Info.j2sAppletID = Info.j2sAppletID 
+               || element.getAttribute("name") 
+               || element.getAttribute("id") 
+               || Info.idPrefix.replace(/%ID%/g, "jalview" + ++Jalview.jvid);
+       
+//Info.jalview_SCREEN_X= 10,Info.jalview_SCREEN_Y= 10;
+//Info.jalview_EMBEDDED= true;
+//Info.jalview_SCREEN_WIDTH = 400;
+//Info.jalview_SCREEN_HEIGHT = 100;
 
        
 var addParam = function(key,value) {
index 533226e..6eca05e 100644 (file)
@@ -22,6 +22,7 @@ package jalview.appletgui;
 
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.SequenceGroup;
+import jalview.gui.Preferences;
 import jalview.schemes.AnnotationColourGradient;
 import jalview.schemes.ColourSchemeI;
 import jalview.util.MessageManager;
@@ -217,9 +218,9 @@ public class AnnotationColourChooser extends Panel implements
   private void setDefaultMinMax()
   {
     minColour.setBackground(av.applet.getDefaultColourParameter(
-            "ANNOTATIONCOLOUR_MIN", Color.orange));
+            Preferences.ANNOTATIONCOLOUR_MIN, Color.orange));
     maxColour.setBackground(av.applet
-            .getDefaultColourParameter("ANNOTATIONCOLOUR_MAX", Color.red));
+            .getDefaultColourParameter(Preferences.ANNOTATIONCOLOUR_MAX, Color.red));
 
   }
 
index 290ae01..86546a6 100644 (file)
@@ -1,5 +1,7 @@
 package jalview.bin;
 
+import jalview.gui.Preferences;
+
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Vector;
@@ -15,7 +17,8 @@ public class AppletParams extends HashMap<String, String>
 {
 
   private final static String[] params = { "alignpdbfiles",
-      "ANNOTATIONCOLOUR_MAX", "ANNOTATIONCOLOUR_MIN", "annotations",
+      Preferences.ANNOTATIONCOLOUR_MAX, Preferences.ANNOTATIONCOLOUR_MIN,
+      "annotations",
       "APPLICATION_URL", "automaticScrolling", "centrecolumnlabels",
       "debug", "defaultColour", "defaultColourNuc", "defaultColourProt",
       "embedded", "enableSplitFrame", "externalstructureviewer", "features",
@@ -134,7 +137,18 @@ public class AppletParams extends HashMap<String, String>
 
         switch (appletName)
         {
+
         // tested, working:
+
+        case "file":
+          appName = "open";
+          value = resourcePath + value;
+          appletName = null;
+          break;
+        case "file2":
+          value = resourcePath + value;
+          appName = null;
+          break;
         case "jnetfile":
           value = resourcePath + value;
           appName = null;
@@ -148,7 +162,6 @@ public class AppletParams extends HashMap<String, String>
           appName = null;
           break;
         case "pdbfile":
-          appName = "PDBFILE";
           value = resourcePath + value;
           appName = null;
           break;
@@ -158,32 +171,55 @@ public class AppletParams extends HashMap<String, String>
           value = resourcePath + value;
           appletName = null; // taken care of by Jalview
           break;
-        // implemented; not tested:
-        case "annotations":
-          value = resourcePath + value;
-          appName = null;
-          break;
         case "defaultcolour":
-          appName = "DEFAULT_COLOUR"; // defaultColour
+          appName = Preferences.DEFAULT_COLOUR;
           break;
         case "defaultcolournuc":
-          appName = "DEFAULT_COLOUR_NUC";// defaultColourNuc
+          appName = Preferences.DEFAULT_COLOUR_NUC;
           break;
         case "defaultcolourprot":
-          appName = "DEFAULT_COLOUR_PROT";// defaultColourProt";
+          appName = Preferences.DEFAULT_COLOUR_PROT;
+          break;
+
+        // implemented; not tested:
+
+        case "oninit":
+          appName = null;
+          break;
+        case "annotations":
+          value = resourcePath + value;
+          appName = null;
           break;
         case "annotationcolour_max":
-          appName = "ANNOTATIONCOLOUR_MAX";
+          appName = Preferences.ANNOTATIONCOLOUR_MAX;
           break;
         case "annotationcolour_min":
-          appName = "ANNOTATIONCOLOUR_MIN";
+          appName = Preferences.ANNOTATIONCOLOUR_MIN;
+          break;
+        case "enablesplitframe":
+          appName = Preferences.ENABLE_SPLIT_FRAME;
+          break;
+        case "hidefeaturegroups":
           break;
         case "centrecolumnlabels":
           appName = null;
           break;
-        case "enablesplitframe":
-          appName = "enableSplitFrame";
+        case "pdbseq":
+          appName = null;
+          break;
+        case "sortby":
+          appName = Preferences.SORT_ALIGNMENT; // id, etc.
+          break;
+        case "sortbytree":
+          appName = Preferences.SORT_BY_TREE;
+          value = checkTF(value);
+          appletName = null; // taken care of by Jalview
           break;
+        case "format":
+          break;
+
+        // probably not relevant:
+
         case "externalstructureviewer":
           break;
         case "alignpdbfiles":
@@ -197,8 +233,6 @@ public class AppletParams extends HashMap<String, String>
         case "heightscale":
           appName = "heightScale";
           break;
-        case "hidefeaturegroups":
-          break;
         case "jalviewhelpurl":
           break;
         case "label":
@@ -212,26 +246,24 @@ public class AppletParams extends HashMap<String, String>
         case "linkurl_":
           appName = "linkURL_";
           break;
+        case "rgb":
+          appName = null; // no background for application
+          break;
+
+        // unknown:
+
         case "nojmol":
           break;
         case "normaliselogo":
-          appName = "normaliseLogo";
+          appName = Preferences.NORMALISE_LOGO;
           break;
         case "normalisesequencelogo":
-          appName = "normaliseSequenceLogo";
-          break;
-        case "oninit":
-          break;
-        case "pdbseq":
-          appName = "PDBSEQ";
+          appName = Preferences.NORMALISE_CONSENSUS_LOGO;
           break;
         case "relaxedidmatch":
           break;
         case "resolvetocodebase":
           break;
-        case "rgb":
-          appName = "RGB";
-          break;
         case "scaleproteinascdna":
           appName = "scaleProteinAsCdna";
           break;
@@ -239,18 +271,6 @@ public class AppletParams extends HashMap<String, String>
           break;
         case "sequence":
           break;
-        case "sortby":
-          break;
-        case "sortbytree":
-          value = checkTF(value);
-          appletName = null; // taken care of by Jalview
-          break;
-        case "format":
-          break;
-        case "scorefile":
-          appName = "scoreFile";
-          value = resourcePath + value;
-          break;
         case "uppercase":
           appName = "upperCase";
           break;
@@ -267,70 +287,69 @@ public class AppletParams extends HashMap<String, String>
           appName = "windowWidth";
           break;
         case "wrap":
+          appName = Preferences.WRAP_ALIGNMENT;
           break;
+        case "scorefile":
+          appName = "scoreFile";
+          value = resourcePath + value;
+          break;
+
+        // TRUE/FALSE
 
-        // cases not handled in doc/parameters.xlsx
         case "debug":
           value = checkTF(value);
           break;
-        case "file":
-          appName = "open";
-          value = resourcePath + value;
-          break;
-        case "file2":
-          value = resourcePath + value;
-          break;
         case "embedded":
           value = checkTF(value);
           break;
-        case "showannotation":
-          appName = "SHOW_ANNOTATIONS";
+        case "showbutton":
           value = checkTF(value);
           break;
-        case "showbutton":
+        case "showannotation":
+          appName = Preferences.SHOW_ANNOTATIONS;
           value = checkTF(value);
           break;
         case "showconsensus":
-          appName = "SHOW_CONSENSUS_LOGO";
+          appName = Preferences.SHOW_CONSENSUS_LOGO;
           value = checkTF(value);
           break;
         case "showconsensushistogram":
-          appName = "SHOW_CONSENSUS_HISTOGRAM";
+          appName = Preferences.SHOW_CONSENSUS_HISTOGRAM;
           value = checkTF(value);
           break;
         case "showconservation":
-          appName = "SHOW_CONSERVATION";
+          appName = Preferences.SHOW_CONSERVATION;
           value = checkTF(value);
           break;
-        case "showfeaturegroups":
+        case "showgroupconsensus":
+          appName = Preferences.SHOW_GROUP_CONSENSUS;
           value = checkTF(value);
           break;
-        case "showfeaturesettings":
-          appName = "showFeatureSettings";
+        case "showgroupconservation":
+          appName = Preferences.SHOW_GROUP_CONSERVATION;
           value = checkTF(value);
           break;
-        case "showfullid":
-          appName = "showFullId";
+        case "showoccupancy":
+          appName = Preferences.SHOW_OCCUPANCY;
           value = checkTF(value);
           break;
-        case "showgroupconsensus":
-          appName = "SHOW_GROUP_CONSENSUS";
+        case "showquality":
+          appName = Preferences.SHOW_QUALITY;
           value = checkTF(value);
           break;
-        case "showgroupconservation":
-          appName = "SHOW_GROUP_CONSERVATION";
+        case "showsequencelogo":
+          appName = Preferences.SHOW_CONSENSUS_LOGO;
           value = checkTF(value);
           break;
-        case "showoccupancy":
-          appName = "SHOW_OCCUPANCY";
+        case "showfeaturegroups":
           value = checkTF(value);
           break;
-        case "showquality":
-          appName = "SHOW_QUALITY";
+        case "showfeaturesettings":
+          appName = "showFeatureSettings";
           value = checkTF(value);
           break;
-        case "showsequencelogo":
-          appName = "showSequenceLogo";
+        case "showfullid":
+          appName = "showFullId";
           value = checkTF(value);
           break;
         case "showtreebootstraps":
@@ -342,7 +361,7 @@ public class AppletParams extends HashMap<String, String>
           value = checkTF(value);
           break;
         case "showunconserved":
-          appName = "showUnconserved";
+          appName = Preferences.SHOW_UNCONSERVED;
           value = checkTF(value);
           break;
         case "showunlinkedtreenodes":
@@ -350,6 +369,8 @@ public class AppletParams extends HashMap<String, String>
           value = checkTF(value);
           break;
         default:
+          // could be pdbFile2, for example
+          // or one of the app preference names
           break;
         }
         if (value != null)
index 808acc4..d716c25 100755 (executable)
@@ -27,6 +27,7 @@ import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.ext.so.SequenceOntology;
 import jalview.gui.AlignFrame;
+import jalview.gui.AlignViewport;
 import jalview.gui.Desktop;
 import jalview.gui.Preferences;
 import jalview.gui.PromptUserConfig;
@@ -509,8 +510,6 @@ public class Jalview implements ApplicationSingletonI
       }
     }
 
-    String data = null;
-    FileLoader fileLoader = new FileLoader(!headless);
 
     // script to execute after all loading is
     // completed one way or another
@@ -543,7 +542,6 @@ public class Jalview implements ApplicationSingletonI
                         .getString("status.processing_commandline_args"),
                 progress = System.currentTimeMillis());
       }
-      System.out.println("CMD [-open " + file + "] executed successfully!");
 
       if (!isJS)
       /**
@@ -583,7 +581,8 @@ public class Jalview implements ApplicationSingletonI
         // TODO ?
       }
 
-      AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
+      AlignFrame af = new FileLoader(!headless).loadFileWaitTillLoaded(file,
+              protocol,
               format);
       if (af == null)
       {
@@ -591,11 +590,39 @@ public class Jalview implements ApplicationSingletonI
       }
       else
       {
+        System.out
+                .println("CMD [-open " + file + "] executed successfully!");
+        if (file2 != null)
+        {
+          protocol = AppletFormatAdapter.checkProtocol(file2);
+          try
+          {
+            format = new IdentifyFile().identify(file2, protocol);
+          } catch (FileFormatException e1)
+          {
+            // TODO ?
+          }
+          AlignFrame af2 = new FileLoader(!headless).loadFileWaitTillLoaded(
+                  file2,
+                  protocol, format);
+          if (af2 == null)
+          {
+            System.out.println("error");
+          }
+          else
+          {
+            AlignViewport.openLinkedAlignmentAs(af,
+                    af.getViewport().getAlignment(),
+                    af2.getViewport().getAlignment(), "",
+                    AlignViewport.SPLIT_FRAME);
+          }
+        }
+
         setCurrentAlignFrame(af);
 
         // TODO: file2 How to implement file2 for the applet spit screen?
 
-        data = aparser.getValue(ArgsParser.COLOUR, true);
+        String data = aparser.getValue(ArgsParser.COLOUR, true);
         if (data != null)
         {
           data.replaceAll("%20", " ");
@@ -691,15 +718,16 @@ public class Jalview implements ApplicationSingletonI
           loadAppletParams(aparser, af);
         }
         else if (!isJS)
-          /**
-           * Java only
-           * 
-           * @j2sIgnore
-           */
+        /**
+         * Java only
+         * 
+         * @j2sIgnore
+         */
         {
           if (groovyscript != null)
           {
-            // Execute the groovy script after we've done all the rendering stuff
+            // Execute the groovy script after we've done all the rendering
+            // stuff
             // and before any images or figures are generated.
             System.out.println("Executing script " + groovyscript);
             executeGroovyScript(groovyscript, af);
@@ -763,7 +791,8 @@ public class Jalview implements ApplicationSingletonI
         }
       }
 
-      startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
+      startUpAlframe = new FileLoader(!headless)
+              .loadFileWaitTillLoaded(file, protocol,
               format);
       // extract groovy arguments before anything else.
     }
@@ -1277,8 +1306,7 @@ public class Jalview implements ApplicationSingletonI
       @Override
       public boolean loadScoreFile(String sScoreFile) throws IOException
       {
-        af.loadJalviewDataFile(sScoreFile, null,
-                null, null);
+        af.loadJalviewDataFile(sScoreFile, null, null, null);
         return true;
       }
 
@@ -1336,7 +1364,6 @@ public class Jalview implements ApplicationSingletonI
     };
 
     new JalviewAppLoader(true).load(app);
-
   }
 
 }
index 0bf922c..dbb3611 100644 (file)
@@ -29,7 +29,7 @@ import java.util.Vector;
 public class JalviewAppLoader
 {
 
-  private JalviewApp app;
+  private JalviewApp app; // Jalview or JalviewJS or JalviewLite
 
   private boolean debug;
 
index ba4f460..e12b24d 100644 (file)
@@ -1476,6 +1476,9 @@ public class JalviewLite extends Applet
                 .getString("error.invalid_separator_parameter"));
       }
     }
+
+    // Background color
+
     int r = 255;
     int g = 255;
     int b = 255;
@@ -1495,14 +1498,14 @@ public class JalviewLite extends Applet
         b = 255;
       }
     }
+    setBackground(new Color(r, g, b));
+
     param = getParameter("label");
     if (param != null)
     {
       launcher.setLabel(param);
     }
 
-    setBackground(new Color(r, g, b));
-
     file = getParameter("file");
 
     if (file == null)
index ecd9155..bc08c4f 100644 (file)
@@ -364,7 +364,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       // modifyPID.setEnabled(false);
     }
 
-    String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
+    String sortby = jalview.bin.Cache.getDefault(Preferences.SORT_ALIGNMENT,
             "No sort");
 
     if (sortby.equals("Id"))
@@ -1064,7 +1064,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         DataSourceType protocol = fileName.startsWith("http:")
                 ? DataSourceType.URL
                 : DataSourceType.FILE;
-        loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
+        loader.loadFile(viewport, fileName, protocol, currentFileFormat);
       }
       else
       {
@@ -1080,12 +1080,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           DataSourceType protocol = (fileName.startsWith("http:")
                   ? DataSourceType.URL
                   : DataSourceType.FILE);
-          newframe = loader.LoadFileWaitTillLoaded(fileName, protocol,
+          newframe = loader.loadFileWaitTillLoaded(fileName, protocol,
                   currentFileFormat);
         }
         else
         {
-          newframe = loader.LoadFileWaitTillLoaded(fileObject,
+          newframe = loader.loadFileWaitTillLoaded(fileObject,
                   DataSourceType.FILE, currentFileFormat);
         }
 
@@ -4428,7 +4428,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
       {
         final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
-        viewport.openSplitFrame(af, new Alignment(seqs));
+        AlignViewport.openSplitFrame(this, af, new Alignment(seqs));
       }
       else
       {
@@ -4799,7 +4799,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           }
           else
           {
-            new FileLoader().LoadFile(viewport, file, sourceType, format);
+            new FileLoader().loadFile(viewport, file, sourceType, format);
           }
         }
       }
index 1ebf584..4edb580 100644 (file)
@@ -209,7 +209,7 @@ public class AlignViewport extends AlignmentViewport
     antiAlias = Cache.getDefault("ANTI_ALIAS", false);
 
     viewStyle.setShowJVSuffix(Cache.getDefault("SHOW_JVSUFFIX", true));
-    setShowAnnotation(Cache.getDefault("SHOW_ANNOTATIONS", true));
+    setShowAnnotation(Cache.getDefault(Preferences.SHOW_ANNOTATIONS, true));
 
     setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false));
     setCentreColumnLabels(Cache.getDefault("CENTRE_COLUMN_LABELS", false));
@@ -219,10 +219,11 @@ public class AlignViewport extends AlignmentViewport
     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.setWrapAlignment(
+            Cache.getDefault(Preferences.WRAP_ALIGNMENT, false));
     viewStyle.setShowUnconserved(
-            Cache.getDefault("SHOW_UNCONSERVED", false));
-    sortByTree = Cache.getDefault("SORT_BY_TREE", false);
+            Cache.getDefault(Preferences.SHOW_UNCONSERVED, false));
+    sortByTree = Cache.getDefault(Preferences.SORT_BY_TREE, false);
     followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
     sortAnnotationsBy = SequenceAnnotationOrder
             .valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS,
@@ -263,17 +264,20 @@ public class AlignViewport extends AlignmentViewport
     {
       if (!alignment.isNucleotide())
       {
-        showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
-        showQuality = Cache.getDefault("SHOW_QUALITY", true);
+        showConservation = Cache.getDefault(Preferences.SHOW_CONSERVATION, true);
+        showQuality = Cache.getDefault(Preferences.SHOW_QUALITY, true);
         showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
                 false);
       }
       showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
               true);
-      showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
-      normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
+      showSequenceLogo = Cache.getDefault(Preferences.SHOW_CONSENSUS_LOGO, false);
+
+      normaliseSequenceLogo = Cache.getDefault(
+              Preferences.NORMALISE_CONSENSUS_LOGO,
               false);
-      showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
+      showGroupConsensus = Cache
+              .getDefault(Preferences.SHOW_GROUP_CONSENSUS, false);
       showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
 
       showOccupancy = Cache.getDefault(Preferences.SHOW_OCCUPANCY, true);
@@ -743,6 +747,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
@@ -759,54 +769,63 @@ 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(0, new Runnable()
+            .setResponseHandler(NO_SPLIT, new Runnable()
             {
               @Override
               public void run()
               {
                   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
@@ -835,7 +854,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);
@@ -849,10 +868,10 @@ public class AlignViewport extends AlignmentViewport
     {
     }
 
-    if (newWindowOrSplitPane)
+    if (mode == SPLIT_FRAME)
     {
       al.alignAs(thisAlignment);
-      protein = openSplitFrame(newAlignFrame, thisAlignment);
+      openSplitFrame(thisFrame, newAlignFrame, thisAlignment);
     }
   }
 
@@ -866,7 +885,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,
+  static protected AlignmentI openSplitFrame(AlignFrame thisFrame,
+          AlignFrame newAlignFrame,
           AlignmentI complement)
   {
     /*
@@ -876,7 +896,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
index bd05be1..a48553e 100644 (file)
@@ -283,9 +283,9 @@ public class AnnotationColourChooser extends AnnotationRowFilter
   private void setDefaultMinMax()
   {
     minColour.setBackground(
-            Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
+            Cache.getDefaultColour(Preferences.ANNOTATIONCOLOUR_MIN, Color.orange));
     maxColour.setBackground(
-            Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
+            Cache.getDefaultColour(Preferences.ANNOTATIONCOLOUR_MAX, Color.red));
   }
 
   protected void showColourChooser(JPanel colourPanel, String titleKey)
index c3640a9..bc892cf 100644 (file)
@@ -785,7 +785,7 @@ public class Desktop extends GDesktop
         FileFormatI format = new IdentifyFile().identify(file,
                 DataSourceType.PASTE);
 
-        new FileLoader().LoadFile(file, DataSourceType.PASTE, format);
+        new FileLoader().loadFile(file, DataSourceType.PASTE, format);
 
       }
     } catch (Exception ex)
@@ -1132,7 +1132,7 @@ public class Desktop extends GDesktop
           {
             Platform.cacheFileData((File) file);
           }
-          new FileLoader().LoadFile(null, file, protocol, format);
+          new FileLoader().loadFile(null, file, protocol, format);
 
         }
       } catch (Exception ex)
@@ -1189,7 +1189,7 @@ public class Desktop extends GDesktop
           }
         }
 
-        new FileLoader().LoadFile(viewport, selectedFile,
+        new FileLoader().loadFile(viewport, selectedFile,
                 DataSourceType.FILE, format);
       }
     });
@@ -1263,12 +1263,12 @@ public class Desktop extends GDesktop
         {
           if (viewport != null)
           {
-            new FileLoader().LoadFile(viewport, url, DataSourceType.URL,
+            new FileLoader().loadFile(viewport, url, DataSourceType.URL,
                     FileFormat.Jalview);
           }
           else
           {
-            new FileLoader().LoadFile(url, DataSourceType.URL,
+            new FileLoader().loadFile(url, DataSourceType.URL,
                     FileFormat.Jalview);
           }
         }
@@ -1298,12 +1298,12 @@ public class Desktop extends GDesktop
 
           if (viewport != null)
           {
-            new FileLoader().LoadFile(viewport, url, DataSourceType.URL,
+            new FileLoader().loadFile(viewport, url, DataSourceType.URL,
                     format);
           }
           else
           {
-            new FileLoader().LoadFile(url, DataSourceType.URL, format);
+            new FileLoader().loadFile(url, DataSourceType.URL, format);
           }
         }
       }
index 359eabe..62c1239 100755 (executable)
@@ -84,6 +84,10 @@ import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
 @SuppressWarnings("serial")
 public class Preferences extends GPreferences
 {
+  public static final String ANNOTATIONCOLOUR_MAX = "ANNOTATIONCOLOUR_MAX";
+
+  public static final String ANNOTATIONCOLOUR_MIN = "ANNOTATIONCOLOUR_MIN";
+
   public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
 
   public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
@@ -106,12 +110,42 @@ public class Preferences extends GPreferences
 
   public static final String CHIMERA_PATH = "CHIMERA_PATH";
 
+  public static final String SORT_ALIGNMENT = "SORT_ALIGNMENT";
+
+  public static final String WRAP_ALIGNMENT = "WRAP_ALIGNMENT";
+
   public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
 
+  public static final String SORT_BY_TREE = "SORT_BY_TREE";
+
+  public static final String SHOW_ANNOTATIONS = "SHOW_ANNOTATIONS";
+
   public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
 
+  public static final String SHOW_CONSERVATION = "SHOW_CONSERVATION";
+
+  public static final String SHOW_QUALITY = "SHOW_QUALITY";
+
+  public static final String SHOW_CONSENSUS_HISTOGRAM = "SHOW_CONSENSUS_HISTOGRAM";
+
+  public static final String SHOW_CONSENSUS = "SHOW_CONSENSUS";
+
+  public static final String SHOW_CONSENSUS_LOGO = "SHOW_CONSENSUS_LOGO";
+
+  public static final String SHOW_GROUP_CONSENSUS = "SHOW_GROUP_CONSENSUS";
+
+  public static final String SHOW_GROUP_CONSERVATION = "SHOW_GROUP_CONSERVATION";
+
+  public static final String NORMALISE_CONSENSUS_LOGO = "NORMALISE_CONSENSUS_LOGO";
+
+  public static final String NORMALISE_LOGO = "NORMALISE_LOGO";
+
   public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
 
+  public static final String SHOW_OVERVIEW = "SHOW_OVERVIEW";
+
+  public static final String SHOW_UNCONSERVED = "SHOW_UNCONSERVED";
+
   public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
 
   public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
@@ -221,21 +255,21 @@ public class Preferences extends GPreferences
     fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
     annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
 
-    conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
-    quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
+    conservation.setSelected(Cache.getDefault(SHOW_CONSERVATION, true));
+    quality.setSelected(Cache.getDefault(SHOW_QUALITY, true));
     identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
-    openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
+    openoverv.setSelected(Cache.getDefault(SHOW_OVERVIEW, false));
     showUnconserved
-            .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
+            .setSelected(Cache.getDefault(SHOW_UNCONSERVED, false));
     showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
     showGroupConsensus
-            .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
+            .setSelected(Cache.getDefault(SHOW_GROUP_CONSENSUS, false));
     showGroupConservation.setSelected(
-            Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
+            Cache.getDefault(SHOW_GROUP_CONSERVATION, false));
     showConsensHistogram.setSelected(
-            Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
+            Cache.getDefault(SHOW_CONSENSUS_HISTOGRAM, true));
     showConsensLogo
-            .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
+            .setSelected(Cache.getDefault(SHOW_CONSENSUS_LOGO, false));
     showNpTooltip
             .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
     showDbRefTooltip
@@ -278,7 +312,7 @@ public class Preferences extends GPreferences
     sortby.addItem("No sort");
     sortby.addItem("Id");
     sortby.addItem("Pairwise Identity");
-    sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
+    sortby.setSelectedItem(Cache.getDefault(SORT_ALIGNMENT, "No sort"));
 
     sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
     sortAnnBy
@@ -319,9 +353,9 @@ public class Preferences extends GPreferences
     newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
     nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
     minColour.setBackground(
-            Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
+            Cache.getDefaultColour(ANNOTATIONCOLOUR_MIN, Color.orange));
     maxColour.setBackground(
-            Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
+            Cache.getDefaultColour(ANNOTATIONCOLOUR_MAX, Color.red));
 
     /*
      * Set overview panel defaults
@@ -540,7 +574,7 @@ public class Preferences extends GPreferences
     autoCalculateConsCheck
             .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
     padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
-    sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
+    sortByTree.setSelected(Cache.getDefault(SORT_BY_TREE, false));
 
     annotations_actionPerformed(null); // update the display of the annotation
                                        // settings
@@ -612,9 +646,9 @@ public class Preferences extends GPreferences
             Boolean.toString(openoverv.isSelected()));
     Cache.setPropertyNoSave("SHOW_ANNOTATIONS",
             Boolean.toString(annotations.isSelected()));
-    Cache.setPropertyNoSave("SHOW_CONSERVATION",
+    Cache.setPropertyNoSave(SHOW_CONSERVATION,
             Boolean.toString(conservation.isSelected()));
-    Cache.setPropertyNoSave("SHOW_QUALITY",
+    Cache.setPropertyNoSave(SHOW_QUALITY,
             Boolean.toString(quality.isSelected()));
     Cache.setPropertyNoSave("SHOW_IDENTITY",
             Boolean.toString(identity.isSelected()));
@@ -635,13 +669,13 @@ public class Preferences extends GPreferences
             Boolean.toString(showUnconserved.isSelected()));
     Cache.setPropertyNoSave(SHOW_OCCUPANCY,
             Boolean.toString(showOccupancy.isSelected()));
-    Cache.setPropertyNoSave("SHOW_GROUP_CONSENSUS",
+    Cache.setPropertyNoSave(SHOW_GROUP_CONSENSUS,
             Boolean.toString(showGroupConsensus.isSelected()));
-    Cache.setPropertyNoSave("SHOW_GROUP_CONSERVATION",
+    Cache.setPropertyNoSave(SHOW_GROUP_CONSERVATION,
             Boolean.toString(showGroupConservation.isSelected()));
-    Cache.setPropertyNoSave("SHOW_CONSENSUS_HISTOGRAM",
+    Cache.setPropertyNoSave(SHOW_CONSENSUS_HISTOGRAM,
             Boolean.toString(showConsensHistogram.isSelected()));
-    Cache.setPropertyNoSave("SHOW_CONSENSUS_LOGO",
+    Cache.setPropertyNoSave(SHOW_CONSENSUS_LOGO,
             Boolean.toString(showConsensLogo.isSelected()));
     Cache.setPropertyNoSave("ANTI_ALIAS",
             Boolean.toString(smoothFont.isSelected()));
@@ -660,7 +694,7 @@ public class Preferences extends GPreferences
     Cache.setPropertyNoSave("SHOW_STARTUP_FILE",
             Boolean.toString(startupCheckbox.isSelected()));
 
-    Cache.setPropertyNoSave("SORT_ALIGNMENT",
+    Cache.setPropertyNoSave(SORT_ALIGNMENT,
             sortby.getSelectedItem().toString());
 
     // convert description of sort order to enum name for save
@@ -683,9 +717,9 @@ public class Preferences extends GPreferences
             protColour.getSelectedItem().toString());
     Cache.setPropertyNoSave(DEFAULT_COLOUR_NUC,
             nucColour.getSelectedItem().toString());
-    Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
+    Cache.setColourProperty(ANNOTATIONCOLOUR_MIN,
             minColour.getBackground());
-    Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
+    Cache.setColourProperty(ANNOTATIONCOLOUR_MAX,
             maxColour.getBackground());
 
     /*
@@ -898,9 +932,9 @@ public class Preferences extends GPreferences
     // showSequenceLogo true of false (default is false) When true, shows a
     // sequence logo above the consensus sequence (overlaid above the Consensus
 
-    Cache.setPropertyNoSave("SHOW_CONSERVATION", "true");
-    Cache.setPropertyNoSave("SHOW_QUALITY", "false");
-    Cache.setPropertyNoSave("SHOW_CONCENSUS", "true");
+    Cache.setPropertyNoSave(SHOW_CONSERVATION, "true");
+    Cache.setPropertyNoSave(SHOW_QUALITY, "false");
+    Cache.setPropertyNoSave(SHOW_CONSENSUS, "true");
     Cache.setPropertyNoSave("SHOW_UNCONSERVED", "false");
     Cache.setPropertyNoSave("SHOW_GROUP_CONSERVATION", "false");
     Cache.setPropertyNoSave("SHOW_GROUP_CONCENSUS", "false");
index f8283c3..6cbace4 100755 (executable)
@@ -55,16 +55,35 @@ import javax.swing.SwingUtilities;
 
 public class FileLoader implements Runnable
 {
+  private File selectedFile;
+
   String file;
 
   DataSourceType protocol;
 
   FileFormatI format;
 
-  AlignmentFileReaderI source = null; // alternative specification of where data
-                                      // comes
+  AlignmentFileReaderI source; // alternative specification of where data
+                               // comes from
 
-  // from
+  /**
+   * It is critical that all these fields are set, as this instance is reused.
+   * 
+   * @param source
+   * @param file
+   * @param inFile
+   * @param dataSourceType
+   * @param format
+   */
+  private void setFileFields(AlignmentFileReaderI source, File file,
+          String inFile, DataSourceType dataSourceType, FileFormatI format)
+  {
+    this.source = source;
+    this.file = inFile;
+    this.selectedFile = file;
+    this.protocol = dataSourceType;
+    this.format = format;
+  }
 
   AlignViewport viewport;
 
@@ -76,8 +95,6 @@ public class FileLoader implements Runnable
 
   boolean raiseGUI = true;
 
-  private File selectedFile;
-
   /**
    * default constructor always raised errors in GUI dialog boxes
    */
@@ -97,7 +114,7 @@ public class FileLoader implements Runnable
     this.raiseGUI = raiseGUI;
   }
 
-  public void LoadFile(AlignViewport viewport, Object file,
+  public void loadFile(AlignViewport viewport, Object file,
           DataSourceType protocol, FileFormatI format)
   {
     this.viewport = viewport;
@@ -105,10 +122,10 @@ public class FileLoader implements Runnable
       this.selectedFile = (File) file;
       file = selectedFile.getPath();
     }
-    LoadFile(file.toString(), protocol, format);
+    loadFile(file.toString(), protocol, format);
   }
 
-  public void LoadFile(String file, DataSourceType protocol,
+  public void loadFile(String file, DataSourceType protocol,
           FileFormatI format)
   {
     this.file = file;
@@ -135,7 +152,7 @@ public class FileLoader implements Runnable
    */
   public void LoadFile(String file, DataSourceType protocol)
   {
-    LoadFile(file, protocol, null);
+    loadFile(file, protocol, null);
   }
 
   /**
@@ -148,7 +165,7 @@ public class FileLoader implements Runnable
   public AlignFrame LoadFileWaitTillLoaded(String file,
           DataSourceType sourceType)
   {
-    return LoadFileWaitTillLoaded(file, sourceType, null);
+    return loadFileWaitTillLoaded(file, sourceType, null);
   }
 
   /**
@@ -159,13 +176,11 @@ public class FileLoader implements Runnable
    * @param format
    * @return alignFrame constructed from file contents
    */
-  public AlignFrame LoadFileWaitTillLoaded(String file,
+  public AlignFrame loadFileWaitTillLoaded(String file,
           DataSourceType sourceType, FileFormatI format)
   {
-    this.file = file;
-    this.protocol = sourceType;
-    this.format = format;
-    return _LoadFileWaitTillLoaded();
+    setFileFields(null, null, file, sourceType, format);
+    return _loadFileWaitTillLoaded();
   }
 
   /**
@@ -176,14 +191,11 @@ public class FileLoader implements Runnable
    * @param format
    * @return alignFrame constructed from file contents
    */
-  public AlignFrame LoadFileWaitTillLoaded(File file,
+  public AlignFrame loadFileWaitTillLoaded(File file,
           DataSourceType sourceType, FileFormatI format)
   {
-    this.selectedFile = file;
-    this.file = file.getPath();
-    this.protocol = sourceType;
-    this.format = format;
-    return _LoadFileWaitTillLoaded();
+    setFileFields(null, file, null, sourceType, format);
+    return _loadFileWaitTillLoaded();
   }
 
   /**
@@ -193,15 +205,12 @@ public class FileLoader implements Runnable
    * @param format
    * @return alignFrame constructed from file contents
    */
-  public AlignFrame LoadFileWaitTillLoaded(AlignmentFileReaderI source,
+  public AlignFrame loadFileWaitTillLoaded(AlignmentFileReaderI source,
           FileFormatI format)
   {
-    this.source = source;
-
-    file = source.getInFile();
-    protocol = source.getDataSourceType();
-    this.format = format;
-    return _LoadFileWaitTillLoaded();
+    setFileFields(source, null, source.getInFile(),
+            source.getDataSourceType(), format);
+    return _loadFileWaitTillLoaded();
   }
 
   /**
@@ -210,7 +219,7 @@ public class FileLoader implements Runnable
    * 
    * @return
    */
-  protected AlignFrame _LoadFileWaitTillLoaded()
+  private AlignFrame _loadFileWaitTillLoaded()
   {
     this.run();
     return alignFrame;
index 7ef0d16..d43f257 100644 (file)
@@ -165,7 +165,7 @@ public class JmolViewerTest
     final String _inFile = "examples/3W5V.pdb";
     inFile = _inFile;
     FileLoader fl = new FileLoader();
-    fl.LoadFile(af.getCurrentView(), _inFile, DataSourceType.FILE,
+    fl.loadFile(af.getCurrentView(), _inFile, DataSourceType.FILE,
             FileFormat.PDB);
     try
     {
index 968901f..983207a 100644 (file)
@@ -11,7 +11,7 @@ public class FileLoaderTest
   {
     String urlFile = "http://www.jalview.org/builds/develop/examples/3W5V.pdb";
     FileLoader fileLoader = new FileLoader();
-    fileLoader.LoadFileWaitTillLoaded(urlFile, DataSourceType.URL,
+    fileLoader.loadFileWaitTillLoaded(urlFile, DataSourceType.URL,
             FileFormat.PDB);
     Assert.assertNotNull(fileLoader.file);
     // The FileLoader's file is expected to be same as the original URL.
index 1970ff2..f8461f8 100644 (file)
@@ -247,7 +247,7 @@ public class Mapping
   public void mapFer1From3W5V() throws Exception
   {
     AlignFrame seqf = new FileLoader(false)
-            .LoadFileWaitTillLoaded(
+            .loadFileWaitTillLoaded(
                     ">FER1_MAIZE/1-150 Ferredoxin-1, chloroplast precursor\nMATVLGSPRAPAFFFSSSSLRAAPAPTAVALPAAKVGIMGRSASSRRRLRAQATYNVKLITPEGEVELQVPD\nDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADGWVLTCHAYPTSDVVIETHKE\nEELTGA",
                     DataSourceType.PASTE, FileFormat.Fasta);
     SequenceI newseq = seqf.getViewport().getAlignment().getSequenceAt(0);