Merge branch 'Jalview-JS/jim/JAL-3253-JAL-3418' into Jalview-JS/JAL-3253-applet
[jalview.git] / src / jalview / bin / AppletParams.java
index 01c910d..6a23c39 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",
@@ -125,224 +128,243 @@ public class AppletParams extends HashMap<String, String>
       String arg = args[i].trim();
       if (arg.startsWith("name="))
       {
-        String key = getAttr(arg, "name");
+        String prefName = getAttr(arg, "name");
+        String appletName = prefName.toLowerCase();
+        String argName = prefName;
         String value = getAttr(arg, "value");
-        String name = key;
-        switch (name)
+
+        // note that Application arguments ARE case-sensitive, but
+        // Applet.getParameter() is not.
+
+        switch (appletName)
         {
-        case "alignpdbfiles":
-          break;
-        case "annotationcolour_max":
-          name = "ANNOTATIONCOLOUR_MAX";
-          break;
-        case "annotationcolour_min":
-          name = "ANNOTATIONCOLOUR_MIN";
-          break;
-        case "annotations":
-          value = checkTF(value);
+
+        case "file":
+          argName = "open";
+          appletName = null;
+          value = resourcePath + value;
           break;
-        case "application_url":
-          name = "APPLICATION_URL";
+        case "file2":
+          argName = "open2";
+          prefName = null;
+          value = resourcePath + value;
           break;
-        case "automaticscrolling":
-          name = "automaticScrolling";
+        case "features":
+        case "jnetfile":
+        case "jpredfile":
+        case "pdbfile":
+        case "scorefile":
+        case "sequence":
+          // setting argName to null indicates that we want
+          // JalviewAppLoader to take care of this.
+          prefName = argName = null;
+          value = resourcePath + value;
           break;
-        case "centrecolumnlabels":
+        case "tree":
+        case "treefile":
+          // setting appletName to null indicates that we want
+          // Jalview.doMain to taken care of this as Jalview args
+          argName = "tree";
+          appletName = null;
+          value = resourcePath + value;
           break;
+
+        // non-loading preferences
+
         case "defaultcolour":
-          name = "defaultColour";
+          prefName = Preferences.DEFAULT_COLOUR;
           break;
         case "defaultcolournuc":
-          name = "defaultColourNuc";
+          prefName = Preferences.DEFAULT_COLOUR_NUC;
           break;
         case "defaultcolourprot":
-          name = "defaultColourProt";
-          break;
-        case "enablesplitframe":
-          name = "enableSplitFrame";
+          prefName = Preferences.DEFAULT_COLOUR_PROT;
           break;
-        case "externalstructureviewer":
-          break;
-        case "features":
-          value = resourcePath + value;
-          break;
-        case "format":
+        case "annotationcolour_max":
+          prefName = Preferences.ANNOTATIONCOLOUR_MAX;
           break;
-        case "heightscale":
-          name = "heightScale";
+        case "annotationcolour_min":
+          prefName = Preferences.ANNOTATIONCOLOUR_MIN;
           break;
-        case "hidefeaturegroups":
+        case "enablesplitframe":
+          prefName = Preferences.ENABLE_SPLIT_FRAME;
           break;
-        case "jalviewhelpurl":
+        case "centrecolumnlabels":
+          prefName = Preferences.CENTRE_COLUMN_LABELS;
           break;
-        case "jnetfile":
-          value = resourcePath + value;
+        case "sortby":
+          prefName = Preferences.SORT_ALIGNMENT; // id, etc.
           break;
-        case "jpredfile":
-          value = resourcePath + value;
+        case "normalisesequencelogo":
+          prefName = Preferences.NORMALISE_CONSENSUS_LOGO;
           break;
-        case "label":
+        case "relaxedidmatch":
+          prefName = Preferences.RELAXEDSEQIDMATCHING;
           break;
-        case "linklabel_":
-          name = "linkLabel_";
+        case "scaleproteinascdna":
+          prefName = Preferences.SCALE_PROTEIN_TO_CDNA;
           break;
-        case "linklabel_1":
-          name = "linkLabel_1";
+        case "userdefinedcolour":
+          argName = "colour";
+          prefName = Preferences.USER_DEFINED_COLOURS;
           break;
-        case "linkurl_":
-          name = "linkURL_";
+        case "wrap":
+          prefName = Preferences.WRAP_ALIGNMENT;
           break;
-        case "nojmol":
+
+        // implemented; not tested:
+
+        case "oninit":
+          prefName = null;
           break;
-        case "normaliselogo":
-          name = "normaliseLogo";
+        case "annotations":
+          value = resourcePath + value;
+          argName = null;
           break;
-        case "normalisesequencelogo":
-          name = "normaliseSequenceLogo";
+        case "hidefeaturegroups":
+          // TODO
           break;
-        case "oninit":
+        case "pdbseq":
+          argName = prefName = null;
           break;
-        case "pdbfile":
-          name = "PDBFILE";
+        case "sortbytree":
+          prefName = Preferences.SORT_BY_TREE;
+          value = checkTF(value);
+          appletName = null; // taken care of by Jalview
           break;
-        case "pdbseq":
-          name = "PDBSEQ";
+        case "format":
           break;
-        case "relaxedidmatch":
+        case "alignpdbfiles":
+          argName = prefName = null;
           break;
-        case "resolvetocodebase":
+        case "separator":
           break;
+
+        // TODO: probably not relevant?
+
         case "rgb":
-          name = "RGB";
+          prefName = null; // TODO no background for application?
           break;
-        case "scaleproteinascdna":
-          name = "scaleProteinAsCdna";
+        case "externalstructureviewer":
           break;
-        case "scorefile":
-          name = "scoreFile";
-          value = resourcePath + value;
+        case "application_url":
           break;
-        case "separator":
+        case "automaticscrolling":
           break;
-        case "sequence":
+        case "heightscale":
           break;
-        case "sortby":
-          name = "sortBy";
+        case "jalviewhelpurl":
           break;
-        case "sortbytree":
-          value = checkTF(value);
-          key = null; // taken care of by Jalview
+        case "label":
           break;
-        case "tree":
-        case "treefile":
-          name = "tree";
-          value = resourcePath + value;
-          key = null; // taken care of by Jalview
+        case "linklabel_":
+          prefName = "linkLabel_";
           break;
-        case "uppercase":
-          name = "upperCase";
+        case "linklabel_1":
+          prefName = "linkLabel_1";
           break;
-        case "userdefinedcolour":
-          name = "userDefinedColour";
+        case "linkurl_":
+          prefName = "linkURL_";
           break;
+
+        // unknown:
+
+        case "nojmol":
+        case "normaliselogo":
+        case "resolvetocodebase":
+        case "uppercase":
         case "widthscale":
-          name = "widthScale";
-          break;
         case "windowheight":
-          name = "windowHeight";
-          break;
         case "windowwidth":
-          name = "windowWidth";
-          break;
-        case "wrap":
+          argName = prefName = null;
           break;
 
-        // cases not handled in doc/parameters.xlsx
+        // TRUE/FALSE
+
         case "debug":
           value = checkTF(value);
           break;
-        case "file":
-          name = "open";
-          value = resourcePath + value;
-          break;
-        case "file2":
-          value = resourcePath + value;
-          break;
         case "embedded":
           value = checkTF(value);
           break;
-        case "showannotation":
-          name = "SHOW_ANNOTATIONS";
+        case "showbutton":
           value = checkTF(value);
           break;
-        case "showbutton":
+        case "showannotation":
+          prefName = Preferences.SHOW_ANNOTATIONS;
           value = checkTF(value);
           break;
         case "showconsensus":
-          name = "SHOW_CONSENSUS_LOGO";
+          prefName = Preferences.SHOW_CONSENSUS_LOGO;
           value = checkTF(value);
           break;
         case "showconsensushistogram":
-          name = "SHOW_CONSENSUS_HISTOGRAM";
+          prefName = Preferences.SHOW_CONSENSUS_HISTOGRAM;
           value = checkTF(value);
           break;
         case "showconservation":
-          name = "SHOW_CONSERVATION";
+          prefName = Preferences.SHOW_CONSERVATION;
           value = checkTF(value);
           break;
-        case "showfeaturegroups":
+        case "showgroupconsensus":
+          prefName = Preferences.SHOW_GROUP_CONSENSUS;
           value = checkTF(value);
           break;
-        case "showfeaturesettings":
-          name = "showFeatureSettings";
+        case "showgroupconservation":
+          prefName = Preferences.SHOW_GROUP_CONSERVATION;
           value = checkTF(value);
           break;
-        case "showfullid":
-          name = "showFullId";
+        case "showoccupancy":
+          prefName = Preferences.SHOW_OCCUPANCY;
           value = checkTF(value);
           break;
-        case "showgroupconsensus":
-          name = "SHOW_GROUP_CONSENSUS";
+        case "showquality":
+          prefName = Preferences.SHOW_QUALITY;
           value = checkTF(value);
           break;
-        case "showgroupconservation":
-          name = "SHOW_GROUP_CONSERVATION";
+        case "showsequencelogo":
+          prefName = Preferences.SHOW_CONSENSUS_LOGO;
           value = checkTF(value);
           break;
-        case "showoccupancy":
-          name = "SHOW_OCCUPANCY";
+        case "showfeaturegroups":
           value = checkTF(value);
           break;
-        case "showquality":
-          name = "SHOW_QUALITY";
+        case "showfeaturesettings":
           value = checkTF(value);
           break;
-        case "showsequencelogo":
-          name = "showSequenceLogo";
+        case "showfullid":
           value = checkTF(value);
           break;
         case "showtreebootstraps":
-          name = "showTreeBootstraps";
           value = checkTF(value);
           break;
         case "showtreedistances":
-          name = "showTreeDistances";
           value = checkTF(value);
           break;
         case "showunconserved":
-          name = "showUnconserved";
+          prefName = Preferences.SHOW_UNCONSERVED;
           value = checkTF(value);
           break;
         case "showunlinkedtreenodes":
-          name = "showUnlinkedTreeNodes";
           value = checkTF(value);
           break;
         default:
+          if (appletName.startsWith("pdbfile")
+                  || appletName.startsWith("sequence") && Character.isDigit(
+                          appletName.charAt(appletName.length() - 1)))
+          {
+            // could be pdbFile2, for example
+            prefName = argName = null;
+            value = resourcePath + value;
+            break;
+          }
+          // or one of the app preference names
           break;
         }
-        if (value != null)
+        // put name and value into application args
+        if (value != null && argName != null)
         {
-          vargs.add(name);
+          vargs.add(argName);
           if (value != "true")
           {
             vargs.add(value);
@@ -352,11 +374,16 @@ public class AppletParams extends HashMap<String, String>
         {
           value = "false";
         }
-        System.out.println("AppletParams name=" + name + " value=" + value);
-        Cache.setPropertyNoSave(name, value);
-        if (key != null)
+        System.out.println("AppletParams propName=" + prefName + " argName="
+                + argName + " appletName="
+                + appletName + " value=" + value);
+        if (appletName != null)
+        {
+          appletParams.put(appletName, value);
+        }
+        if (prefName != null)
         {
-          appletParams.put(key, value);
+          Cache.setPropertyNoSave(prefName, value);
         }
       }
     }