Jalview-JS/JAL-3253-applet more argument parsing
authorhansonr <hansonr@STO24954W.ad.stolaf.edu>
Fri, 17 May 2019 18:45:28 +0000 (13:45 -0500)
committerhansonr <hansonr@STO24954W.ad.stolaf.edu>
Fri, 17 May 2019 18:45:28 +0000 (13:45 -0500)
trying to simplify the sourcing of parametric data:

applet origin: <applet><param>
application origin: Info.args
preference file origin: Info.XXXX_YYYY

Close to full implementation of all three.

Next: Moving Jalview API to a jointly accessible class for Jalview(JS) and JalviewLite (deprecated, but still there).

src/jalview/bin/AppletParams.java
src/jalview/bin/ArgsParser.java
src/jalview/bin/Jalview.java
src/jalview/bin/JalviewAppLoader.java
src/jalview/bin/JalviewLite.java
src/jalview/fts/core/FTSRestRequest.java
src/jalview/fts/service/uniprot/UniProtFTSRestClient.java
src/jalview/ws/dbsources/Uniprot.java

index 86546a6..6a23c39 100644 (file)
@@ -128,9 +128,10 @@ public class AppletParams extends HashMap<String, String>
       String arg = args[i].trim();
       if (arg.startsWith("name="))
       {
-        String appName = getAttr(arg, "name");
+        String prefName = getAttr(arg, "name");
+        String appletName = prefName.toLowerCase();
+        String argName = prefName;
         String value = getAttr(arg, "value");
-        String appletName = appName.toLowerCase();
 
         // note that Application arguments ARE case-sensitive, but
         // Applet.getParameter() is not.
@@ -138,160 +139,144 @@ public class AppletParams extends HashMap<String, String>
         switch (appletName)
         {
 
-        // tested, working:
-
         case "file":
-          appName = "open";
-          value = resourcePath + value;
+          argName = "open";
           appletName = null;
+          value = resourcePath + value;
           break;
         case "file2":
+          argName = "open2";
+          prefName = null;
           value = resourcePath + value;
-          appName = null;
           break;
+        case "features":
         case "jnetfile":
-          value = resourcePath + value;
-          appName = null;
-          break;
         case "jpredfile":
-          value = resourcePath + value;
-          appName = null;
-          break;
-        case "features":
-          value = resourcePath + value;
-          appName = null;
-          break;
         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;
-          appName = null;
           break;
         case "tree":
         case "treefile":
-          appName = "tree";
+          // 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;
-          appletName = null; // taken care of by Jalview
           break;
+
+        // non-loading preferences
+
         case "defaultcolour":
-          appName = Preferences.DEFAULT_COLOUR;
+          prefName = Preferences.DEFAULT_COLOUR;
           break;
         case "defaultcolournuc":
-          appName = Preferences.DEFAULT_COLOUR_NUC;
+          prefName = Preferences.DEFAULT_COLOUR_NUC;
           break;
         case "defaultcolourprot":
-          appName = Preferences.DEFAULT_COLOUR_PROT;
+          prefName = Preferences.DEFAULT_COLOUR_PROT;
+          break;
+        case "annotationcolour_max":
+          prefName = Preferences.ANNOTATIONCOLOUR_MAX;
+          break;
+        case "annotationcolour_min":
+          prefName = Preferences.ANNOTATIONCOLOUR_MIN;
+          break;
+        case "enablesplitframe":
+          prefName = Preferences.ENABLE_SPLIT_FRAME;
+          break;
+        case "centrecolumnlabels":
+          prefName = Preferences.CENTRE_COLUMN_LABELS;
+          break;
+        case "sortby":
+          prefName = Preferences.SORT_ALIGNMENT; // id, etc.
+          break;
+        case "normalisesequencelogo":
+          prefName = Preferences.NORMALISE_CONSENSUS_LOGO;
+          break;
+        case "relaxedidmatch":
+          prefName = Preferences.RELAXEDSEQIDMATCHING;
+          break;
+        case "scaleproteinascdna":
+          prefName = Preferences.SCALE_PROTEIN_TO_CDNA;
+          break;
+        case "userdefinedcolour":
+          argName = "colour";
+          prefName = Preferences.USER_DEFINED_COLOURS;
+          break;
+        case "wrap":
+          prefName = Preferences.WRAP_ALIGNMENT;
           break;
 
         // implemented; not tested:
 
         case "oninit":
-          appName = null;
+          prefName = null;
           break;
         case "annotations":
           value = resourcePath + value;
-          appName = null;
-          break;
-        case "annotationcolour_max":
-          appName = Preferences.ANNOTATIONCOLOUR_MAX;
-          break;
-        case "annotationcolour_min":
-          appName = Preferences.ANNOTATIONCOLOUR_MIN;
-          break;
-        case "enablesplitframe":
-          appName = Preferences.ENABLE_SPLIT_FRAME;
+          argName = null;
           break;
         case "hidefeaturegroups":
-          break;
-        case "centrecolumnlabels":
-          appName = null;
+          // TODO
           break;
         case "pdbseq":
-          appName = null;
-          break;
-        case "sortby":
-          appName = Preferences.SORT_ALIGNMENT; // id, etc.
+          argName = prefName = null;
           break;
         case "sortbytree":
-          appName = Preferences.SORT_BY_TREE;
+          prefName = Preferences.SORT_BY_TREE;
           value = checkTF(value);
           appletName = null; // taken care of by Jalview
           break;
         case "format":
           break;
+        case "alignpdbfiles":
+          argName = prefName = null;
+          break;
+        case "separator":
+          break;
 
-        // probably not relevant:
+        // TODO: probably not relevant?
 
-        case "externalstructureviewer":
+        case "rgb":
+          prefName = null; // TODO no background for application?
           break;
-        case "alignpdbfiles":
+        case "externalstructureviewer":
           break;
         case "application_url":
-          appName = "APPLICATION_URL";
           break;
         case "automaticscrolling":
-          appName = "automaticScrolling";
           break;
         case "heightscale":
-          appName = "heightScale";
           break;
         case "jalviewhelpurl":
           break;
         case "label":
           break;
         case "linklabel_":
-          appName = "linkLabel_";
+          prefName = "linkLabel_";
           break;
         case "linklabel_1":
-          appName = "linkLabel_1";
+          prefName = "linkLabel_1";
           break;
         case "linkurl_":
-          appName = "linkURL_";
-          break;
-        case "rgb":
-          appName = null; // no background for application
+          prefName = "linkURL_";
           break;
 
         // unknown:
 
         case "nojmol":
-          break;
         case "normaliselogo":
-          appName = Preferences.NORMALISE_LOGO;
-          break;
-        case "normalisesequencelogo":
-          appName = Preferences.NORMALISE_CONSENSUS_LOGO;
-          break;
-        case "relaxedidmatch":
-          break;
         case "resolvetocodebase":
-          break;
-        case "scaleproteinascdna":
-          appName = "scaleProteinAsCdna";
-          break;
-        case "separator":
-          break;
-        case "sequence":
-          break;
         case "uppercase":
-          appName = "upperCase";
-          break;
-        case "userdefinedcolour":
-          appName = "colour";
-          break;
         case "widthscale":
-          appName = "widthScale";
-          break;
         case "windowheight":
-          appName = "windowHeight";
-          break;
         case "windowwidth":
-          appName = "windowWidth";
-          break;
-        case "wrap":
-          appName = Preferences.WRAP_ALIGNMENT;
-          break;
-        case "scorefile":
-          appName = "scoreFile";
-          value = resourcePath + value;
+          argName = prefName = null;
           break;
 
         // TRUE/FALSE
@@ -306,76 +291,80 @@ public class AppletParams extends HashMap<String, String>
           value = checkTF(value);
           break;
         case "showannotation":
-          appName = Preferences.SHOW_ANNOTATIONS;
+          prefName = Preferences.SHOW_ANNOTATIONS;
           value = checkTF(value);
           break;
         case "showconsensus":
-          appName = Preferences.SHOW_CONSENSUS_LOGO;
+          prefName = Preferences.SHOW_CONSENSUS_LOGO;
           value = checkTF(value);
           break;
         case "showconsensushistogram":
-          appName = Preferences.SHOW_CONSENSUS_HISTOGRAM;
+          prefName = Preferences.SHOW_CONSENSUS_HISTOGRAM;
           value = checkTF(value);
           break;
         case "showconservation":
-          appName = Preferences.SHOW_CONSERVATION;
+          prefName = Preferences.SHOW_CONSERVATION;
           value = checkTF(value);
           break;
         case "showgroupconsensus":
-          appName = Preferences.SHOW_GROUP_CONSENSUS;
+          prefName = Preferences.SHOW_GROUP_CONSENSUS;
           value = checkTF(value);
           break;
         case "showgroupconservation":
-          appName = Preferences.SHOW_GROUP_CONSERVATION;
+          prefName = Preferences.SHOW_GROUP_CONSERVATION;
           value = checkTF(value);
           break;
         case "showoccupancy":
-          appName = Preferences.SHOW_OCCUPANCY;
+          prefName = Preferences.SHOW_OCCUPANCY;
           value = checkTF(value);
           break;
         case "showquality":
-          appName = Preferences.SHOW_QUALITY;
+          prefName = Preferences.SHOW_QUALITY;
           value = checkTF(value);
           break;
         case "showsequencelogo":
-          appName = Preferences.SHOW_CONSENSUS_LOGO;
+          prefName = Preferences.SHOW_CONSENSUS_LOGO;
           value = checkTF(value);
           break;
         case "showfeaturegroups":
           value = checkTF(value);
           break;
         case "showfeaturesettings":
-          appName = "showFeatureSettings";
           value = checkTF(value);
           break;
         case "showfullid":
-          appName = "showFullId";
           value = checkTF(value);
           break;
         case "showtreebootstraps":
-          appName = "showTreeBootstraps";
           value = checkTF(value);
           break;
         case "showtreedistances":
-          appName = "showTreeDistances";
           value = checkTF(value);
           break;
         case "showunconserved":
-          appName = Preferences.SHOW_UNCONSERVED;
+          prefName = Preferences.SHOW_UNCONSERVED;
           value = checkTF(value);
           break;
         case "showunlinkedtreenodes":
-          appName = "showUnlinkedTreeNodes";
           value = checkTF(value);
           break;
         default:
-          // could be pdbFile2, for example
+          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(appName);
+          vargs.add(argName);
           if (value != "true")
           {
             vargs.add(value);
@@ -385,13 +374,17 @@ public class AppletParams extends HashMap<String, String>
         {
           value = "false";
         }
-        System.out.println("AppletParams appName=" + appName + "appletName="
+        System.out.println("AppletParams propName=" + prefName + " argName="
+                + argName + " appletName="
                 + appletName + " value=" + value);
-        Cache.setPropertyNoSave(appName, value);
         if (appletName != null)
         {
           appletParams.put(appletName, value);
         }
+        if (prefName != null)
+        {
+          Cache.setPropertyNoSave(prefName, value);
+        }
       }
     }
     return appletParams;
index 2780e25..45ea206 100644 (file)
@@ -67,6 +67,10 @@ public class ArgsParser
 
   public static final String OPEN = "open";
 
+  public static final String OPEN2 = "open2"; // BH added -- for applet
+                                              // compatibility; not fully
+                                              // implemented
+
   public static final String PROPS = "props";
 
   public static final String QUESTIONNAIRE = "questionnaire";
index b39f0e2..c27d7af 100755 (executable)
@@ -510,18 +510,18 @@ public class Jalview implements ApplicationSingletonI
       }
     }
 
-
     // script to execute after all loading is
     // completed one way or another
     // extract groovy argument and execute if necessary
     String groovyscript = (isJS ? null
             : aparser.getValue(ArgsParser.GROOVY, true));
     String file = aparser.getValue(ArgsParser.OPEN, true);
-    String file2 = (isJavaAppletTag ? aparser.getAppletValue("file2", null)
-            : null);
+    // BH this here to allow split frame; not working as of 5/17/2019
+    String file2 = aparser.getValue(ArgsParser.OPEN2, true);
     String fileFormat = (isJavaAppletTag
             ? aparser.getAppletValue("format", null)
             : null);
+
     FileFormatI format = null;
     DataSourceType protocol = null;
 
@@ -533,6 +533,22 @@ public class Jalview implements ApplicationSingletonI
     boolean haveImport = checkStartVamas(aparser);
     // Finally, deal with the remaining input data.
     long progress = -1;
+    if (file == null && isJavaAppletTag)
+    {
+      // Maybe the sequences are added as parameters
+      StringBuffer data = new StringBuffer("PASTE");
+      int i = 1;
+      while ((file = aparser.getAppletValue("sequence" + i, null)) != null)
+      {
+        data.append(file.toString() + "\n");
+        i++;
+      }
+      if (data.length() > 5)
+      {
+        file = data.toString();
+      }
+    }
+
     if (file != null)
     {
       if (!headless)
@@ -582,8 +598,7 @@ public class Jalview implements ApplicationSingletonI
       }
 
       AlignFrame af = new FileLoader(!headless).loadFileWaitTillLoaded(file,
-              protocol,
-              format);
+              protocol, format);
       if (af == null)
       {
         System.out.println("error");
@@ -602,9 +617,8 @@ public class Jalview implements ApplicationSingletonI
           {
             // TODO ?
           }
-          AlignFrame af2 = new FileLoader(!headless).loadFileWaitTillLoaded(
-                  file2,
-                  protocol, format);
+          AlignFrame af2 = new FileLoader(!headless)
+                  .loadFileWaitTillLoaded(file2, protocol, format);
           if (af2 == null)
           {
             System.out.println("error");
@@ -615,6 +629,8 @@ public class Jalview implements ApplicationSingletonI
                     af.getViewport().getAlignment(),
                     af2.getViewport().getAlignment(), "",
                     AlignViewport.SPLIT_FRAME);
+            System.out.println(
+                    "CMD [-open2 " + file2 + "] executed successfully!");
           }
         }
 
@@ -792,8 +808,7 @@ public class Jalview implements ApplicationSingletonI
       }
 
       startUpAlframe = new FileLoader(!headless)
-              .loadFileWaitTillLoaded(file, protocol,
-              format);
+              .loadFileWaitTillLoaded(file, protocol, format);
       // extract groovy arguments before anything else.
     }
 
index dbb3611..2b6503a 100644 (file)
@@ -665,4 +665,25 @@ public class JalviewAppLoader
     }
   }
 
+  /**
+   * read sequence1...sequenceN as a raw alignment
+   * 
+   * @param jalviewApp
+   * @return
+   */
+  public String getPastedSequence(JalviewApp jalviewApp) {
+    StringBuffer data = new StringBuffer("PASTE");
+    int i = 1;
+    String file = null;
+    while ((file = app.getParameter("sequence" + i)) != null)
+    {
+      data.append(file.toString() + "\n");
+      i++;
+    }
+    if (data.length() > 5)
+    {
+      file = data.toString();
+    }
+    return file;
+  }
 }
index e12b24d..aec0a5e 100644 (file)
@@ -1510,56 +1510,21 @@ public class JalviewLite extends Applet
 
     if (file == null)
     {
-      // Maybe the sequences are added as parameters
-      StringBuffer data = new StringBuffer("PASTE");
-      int i = 1;
-      while ((file = getParameter("sequence" + i)) != null)
-      {
-        data.append(file.toString() + "\n");
-        i++;
-      }
-      if (data.length() > 5)
-      {
-        file = data.toString();
-      }
+      file = appLoader.getPastedSequence(this);
     }
     if (getDefaultParameter("enableSplitFrame", true))
     {
       file2 = getParameter("file2");
     }
 
-    embedded = TRUE.equalsIgnoreCase(getParameter("embedded"));
+    embedded = (TRUE.equalsIgnoreCase(getParameter("embedded"))
+            || file != null
+                    && FALSE.equalsIgnoreCase(getParameter("showbutton")));
     if (embedded)
     {
-      LoadingThread loader = new LoadingThread(file, file2, this);
-      loader.start();
-    }
-    else if (file != null)
-    {
-      /*
-       * Start the applet immediately or show a button to start it
-       */
-      if (FALSE.equalsIgnoreCase(getParameter("showbutton")))
-      {
-        LoadingThread loader = new LoadingThread(file, file2, this);
-        loader.start();
-      }
-      else
-      {
-        add(launcher);
-        launcher.addActionListener(new java.awt.event.ActionListener()
-        {
-          @Override
-          public void actionPerformed(ActionEvent e)
-          {
-            LoadingThread loader = new LoadingThread(file, file2,
-                    JalviewLite.this);
-            loader.start();
-          }
-        });
-      }
+      startLoading();
     }
-    else
+    else if (file == null)
     {
       // jalview initialisation with no alignment. loadAlignment() method can
       // still be called to open new alignments.
@@ -1567,6 +1532,24 @@ public class JalviewLite extends Applet
       fileFound = false;
       callInitCallback();
     }
+    else
+    {
+      add(launcher);
+      launcher.addActionListener(new java.awt.event.ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          startLoading();
+        }
+      });
+    }
+  }
+
+  protected void startLoading()
+  {
+    LoadingThread loader = new LoadingThread(file, file2, this);
+    loader.start();
   }
 
   private void initLiveConnect()
index b09fcc0..52c48a1 100644 (file)
@@ -24,6 +24,7 @@ package jalview.fts.core;
 import jalview.bin.Cache;
 import jalview.datamodel.SequenceI;
 import jalview.fts.api.FTSDataColumnI;
+import jalview.gui.Preferences;
 
 import java.util.Collection;
 
index d56bcbf..094052b 100644 (file)
@@ -30,6 +30,7 @@ import jalview.fts.api.FTSRestClientI;
 import jalview.fts.core.FTSRestClient;
 import jalview.fts.core.FTSRestRequest;
 import jalview.fts.core.FTSRestResponse;
+import jalview.gui.Preferences;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 
index a3d6dbf..d199963 100644 (file)
@@ -29,10 +29,10 @@ import jalview.datamodel.PDBEntry;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.gui.Preferences;
 import jalview.schemes.ResidueProperties;
 import jalview.util.StringUtils;
 import jalview.ws.seqfetcher.DbSourceProxyImpl;
-import jalview.xml.binding.embl.ROOT;
 import jalview.xml.binding.uniprot.DbReferenceType;
 import jalview.xml.binding.uniprot.Entry;
 import jalview.xml.binding.uniprot.FeatureType;