jalview.bin.AppletParams
authorhansonr <hansonr@STO24954W.ad.stolaf.edu>
Mon, 13 May 2019 02:14:04 +0000 (21:14 -0500)
committerhansonr <hansonr@STO24954W.ad.stolaf.edu>
Mon, 13 May 2019 02:14:04 +0000 (21:14 -0500)
doc/parameters.xlsx
src/jalview/bin/AppletParams.java
src/jalview/bin/ArgsParser.java

index fcbd0fd..b04aba1 100644 (file)
Binary files a/doc/parameters.xlsx and b/doc/parameters.xlsx differ
index 8beee03..01c910d 100644 (file)
@@ -2,6 +2,7 @@ package jalview.bin;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Vector;
 
 /**
  * Collection of all known applet tags from JalviewLite
@@ -97,6 +98,282 @@ public class AppletParams extends HashMap<String, String>
     put("_code", code);
   }
 
+  public AppletParams()
+  {
+    // TODO Auto-generated constructor stub
+  }
+
+  public static AppletParams getAppletParams(String[] args,
+          Vector<String> vargs)
+  {
+    AppletParams appletParams = new AppletParams();
+    String resourcePath = null;
+    for (int i = args.length; --i > 0;) // > 0 is correct, not >=0
+    {
+      if (args[i].startsWith("name=\"Info.resourcePath\""))
+      {
+        resourcePath = getAttr(args[i], "value");
+        if (resourcePath.length() > 0 && !resourcePath.endsWith("/"))
+        {
+          resourcePath += "/";
+        }
+        break;
+      }
+    }
+    for (int i = 1; i < args.length; i++)
+    {
+      String arg = args[i].trim();
+      if (arg.startsWith("name="))
+      {
+        String key = getAttr(arg, "name");
+        String value = getAttr(arg, "value");
+        String name = key;
+        switch (name)
+        {
+        case "alignpdbfiles":
+          break;
+        case "annotationcolour_max":
+          name = "ANNOTATIONCOLOUR_MAX";
+          break;
+        case "annotationcolour_min":
+          name = "ANNOTATIONCOLOUR_MIN";
+          break;
+        case "annotations":
+          value = checkTF(value);
+          break;
+        case "application_url":
+          name = "APPLICATION_URL";
+          break;
+        case "automaticscrolling":
+          name = "automaticScrolling";
+          break;
+        case "centrecolumnlabels":
+          break;
+        case "defaultcolour":
+          name = "defaultColour";
+          break;
+        case "defaultcolournuc":
+          name = "defaultColourNuc";
+          break;
+        case "defaultcolourprot":
+          name = "defaultColourProt";
+          break;
+        case "enablesplitframe":
+          name = "enableSplitFrame";
+          break;
+        case "externalstructureviewer":
+          break;
+        case "features":
+          value = resourcePath + value;
+          break;
+        case "format":
+          break;
+        case "heightscale":
+          name = "heightScale";
+          break;
+        case "hidefeaturegroups":
+          break;
+        case "jalviewhelpurl":
+          break;
+        case "jnetfile":
+          value = resourcePath + value;
+          break;
+        case "jpredfile":
+          value = resourcePath + value;
+          break;
+        case "label":
+          break;
+        case "linklabel_":
+          name = "linkLabel_";
+          break;
+        case "linklabel_1":
+          name = "linkLabel_1";
+          break;
+        case "linkurl_":
+          name = "linkURL_";
+          break;
+        case "nojmol":
+          break;
+        case "normaliselogo":
+          name = "normaliseLogo";
+          break;
+        case "normalisesequencelogo":
+          name = "normaliseSequenceLogo";
+          break;
+        case "oninit":
+          break;
+        case "pdbfile":
+          name = "PDBFILE";
+          break;
+        case "pdbseq":
+          name = "PDBSEQ";
+          break;
+        case "relaxedidmatch":
+          break;
+        case "resolvetocodebase":
+          break;
+        case "rgb":
+          name = "RGB";
+          break;
+        case "scaleproteinascdna":
+          name = "scaleProteinAsCdna";
+          break;
+        case "scorefile":
+          name = "scoreFile";
+          value = resourcePath + value;
+          break;
+        case "separator":
+          break;
+        case "sequence":
+          break;
+        case "sortby":
+          name = "sortBy";
+          break;
+        case "sortbytree":
+          value = checkTF(value);
+          key = null; // taken care of by Jalview
+          break;
+        case "tree":
+        case "treefile":
+          name = "tree";
+          value = resourcePath + value;
+          key = null; // taken care of by Jalview
+          break;
+        case "uppercase":
+          name = "upperCase";
+          break;
+        case "userdefinedcolour":
+          name = "userDefinedColour";
+          break;
+        case "widthscale":
+          name = "widthScale";
+          break;
+        case "windowheight":
+          name = "windowHeight";
+          break;
+        case "windowwidth":
+          name = "windowWidth";
+          break;
+        case "wrap":
+          break;
+
+        // cases not handled in doc/parameters.xlsx
+        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";
+          value = checkTF(value);
+          break;
+        case "showbutton":
+          value = checkTF(value);
+          break;
+        case "showconsensus":
+          name = "SHOW_CONSENSUS_LOGO";
+          value = checkTF(value);
+          break;
+        case "showconsensushistogram":
+          name = "SHOW_CONSENSUS_HISTOGRAM";
+          value = checkTF(value);
+          break;
+        case "showconservation":
+          name = "SHOW_CONSERVATION";
+          value = checkTF(value);
+          break;
+        case "showfeaturegroups":
+          value = checkTF(value);
+          break;
+        case "showfeaturesettings":
+          name = "showFeatureSettings";
+          value = checkTF(value);
+          break;
+        case "showfullid":
+          name = "showFullId";
+          value = checkTF(value);
+          break;
+        case "showgroupconsensus":
+          name = "SHOW_GROUP_CONSENSUS";
+          value = checkTF(value);
+          break;
+        case "showgroupconservation":
+          name = "SHOW_GROUP_CONSERVATION";
+          value = checkTF(value);
+          break;
+        case "showoccupancy":
+          name = "SHOW_OCCUPANCY";
+          value = checkTF(value);
+          break;
+        case "showquality":
+          name = "SHOW_QUALITY";
+          value = checkTF(value);
+          break;
+        case "showsequencelogo":
+          name = "showSequenceLogo";
+          value = checkTF(value);
+          break;
+        case "showtreebootstraps":
+          name = "showTreeBootstraps";
+          value = checkTF(value);
+          break;
+        case "showtreedistances":
+          name = "showTreeDistances";
+          value = checkTF(value);
+          break;
+        case "showunconserved":
+          name = "showUnconserved";
+          value = checkTF(value);
+          break;
+        case "showunlinkedtreenodes":
+          name = "showUnlinkedTreeNodes";
+          value = checkTF(value);
+          break;
+        default:
+          break;
+        }
+        if (value != null)
+        {
+          vargs.add(name);
+          if (value != "true")
+          {
+            vargs.add(value);
+          }
+        }
+        if (value == null)
+        {
+          value = "false";
+        }
+        System.out.println("AppletParams name=" + name + " value=" + value);
+        Cache.setPropertyNoSave(name, value);
+        if (key != null)
+        {
+          appletParams.put(key, value);
+        }
+      }
+    }
+    return appletParams;
+  }
+
+  /**
+   * Check for a single-argument option.
+   * 
+   * @param value
+   * @return "true" or null
+   */
+  private static String checkTF(String value)
+  {
+    return (value.toLowerCase() == "true" ? "true" : null);
+  }
+
   /**
    * Crude applet innerHTML parser
    * 
@@ -104,7 +381,7 @@ public class AppletParams extends HashMap<String, String>
    * @param attr
    * @return
    */
-  private String getAttr(String tag, String attr)
+  private static String getAttr(String tag, String attr)
   {
     int pt = tag.indexOf(attr + "=\"");
     if (pt < 0)
index 2c6cea7..4c2a6c0 100644 (file)
@@ -83,17 +83,34 @@ public class ArgsParser
 
   private Vector<String> vargs = null;
 
+  private boolean isApplet;
+
+  private AppletParams appletParams;
+
+  public boolean isApplet()
+  {
+    return isApplet;
+  }
+
   public ArgsParser(String[] args)
   {
     vargs = new Vector<>();
-    for (int i = 0; i < args.length; i++)
+    isApplet = (args.length > 0 && args[0].startsWith("<applet"));
+    if (isApplet)
     {
-      String arg = args[i].trim();
-      if (arg.charAt(0) == '-')
+      appletParams = AppletParams.getAppletParams(args, vargs);
+    }
+    else
+    {
+      for (int i = 0; i < args.length; i++)
       {
-        arg = arg.substring(1);
+        String arg = args[i].trim();
+        if (arg.charAt(0) == '-')
+        {
+          arg = arg.substring(1);
+        }
+        vargs.addElement(arg);
       }
-      vargs.addElement(arg);
     }
   }
 
@@ -161,4 +178,11 @@ public class ArgsParser
     return vargs.size();
   }
 
+  public String getAppletValue(String key, String def)
+  {
+    String value;
+    return (appletParams == null ? null
+            : (value = appletParams.get(key)) != null ? value : def);
+  }
+
 }