4 import java.util.HashMap;
8 import jalview.gui.Preferences;
11 * Collection of all known applet tags from JalviewLite
16 @SuppressWarnings("serial")
17 public class AppletParams extends HashMap<String, Object>
20 private final static String[] params = { "alignpdbfiles",
21 Preferences.ANNOTATIONCOLOUR_MAX, Preferences.ANNOTATIONCOLOUR_MIN,
23 "APPLICATION_URL", "automaticScrolling", "centrecolumnlabels",
24 "debug", "defaultColour", "defaultColourNuc", "defaultColourProt",
25 "embedded", "enableSplitFrame", "externalstructureviewer", "features",
26 "file", "file2", "format", "heightScale", "hidefeaturegroups",
27 "jalviewhelpurl", "jnetfile", "jpredfile", "label", "linkLabel_",
28 "linkLabel_1", "linkURL_", "nojmol", "normaliseLogo",
29 "normaliseSequenceLogo", "oninit", "PDBFILE", "PDBSEQ",
30 "relaxedidmatch", "resolvetocodebase", "RGB", "scaleProteinAsCdna",
31 "scoreFile", "separator", "sequence", "showAnnotation", "showbutton",
32 "showConsensus", "showConsensusHistogram", "showConservation",
33 "showfeaturegroups", "showFeatureSettings", "showFullId",
34 "showGroupConsensus", "showGroupConservation", "showOccupancy",
35 "showQuality", "showSequenceLogo", "showTreeBootstraps",
36 "showTreeDistances", "showUnconserved", "showUnlinkedTreeNodes",
37 "sortBy", "sortByTree", "tree", "treeFile", "upperCase",
38 "userDefinedColour", "widthScale", "windowHeight", "windowWidth",
41 public String getParam(String param, String def)
43 Object val = get(param);
44 return (val != null ? val.toString() : def);
48 // code="jalview.bin.JalviewLite" width="140" height="35"
49 // archive="jalviewApplet.jar,JmolApplet-14.6.4_2016.10.26.jar,java-json.jar,json_simple-1.1.jar">
50 // <param name="permissions" value="sandbox"/>
51 // <param name="file" value="uniref50.fa"/>
52 // <param name="treeFile" value="ferredoxin.nw"/>
53 // <param name="userDefinedColour" value="C=yellow; R,K,H=FF5555;
55 // <param name="sortByTree" value="True"/>
56 // <param name="showSequenceLogo" value="true"/>
57 // <param name="showGroupConsensus" value="true"/>
58 // <param name="showFullId" value="false"/>
59 // <param name="linkLabel_1" value="Uniprot"/>
60 // <param name="linkUrl_1"
61 // value="http://www.uniprot.org/uniprot/$SEQUENCE_ID$"/>
62 // <param name="linkLabel_2" value="EMBL-EBI Search"/>
63 // <param name="linkUrl_2"
64 // value="http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$"/>
65 // <param name="APPLICATION_URL"
66 // value="http://www.jalview.org/services/launchApp"/>
69 public AppletParams(String outerHTML)
71 String[] tokens = outerHTML.split("<param");
72 outerHTML = tokens[0];
73 String code = getAttr(outerHTML, "code");
74 if (!code.equals("jalview.bin.JalviewLite"))
78 for (int i = tokens.length; --i > 0;)
80 String param = tokens[i];
81 String key = getAttr(param, "name");
84 String value = getAttr(param, "value");
85 System.out.println("AppletParams " + key + " = \"" + value + "\"");
89 put("_width", getAttr(outerHTML, "width"));
90 put("_height", getAttr(outerHTML, "height"));
91 put("_id", getAttr(outerHTML, "id"));
92 put("_name", getAttr(outerHTML, "name"));
93 put("_archive", getAttr(outerHTML, "archive"));
101 public static AppletParams getAppletParams(Map<String, Object> map,
104 AppletParams appletParams = new AppletParams();
105 String resourcePath = getString(map, "resourcePath");
106 if (resourcePath == null)
108 if (resourcePath.length() > 0 && !resourcePath.endsWith("/"))
112 for (int i = params.length; --i >= 0;)
114 String prefName = params[i];
115 Object value = map.get(prefName);
117 addParam(vargs, prefName, value, appletParams, resourcePath);
122 private static String getString(Map<String, Object> map, String key)
124 Object o = map.get(key);
125 return (o == null ? null : o.toString());
128 public static AppletParams getAppletParams(String[] args,
131 AppletParams appletParams = new AppletParams();
132 String resourcePath = "";
133 for (int i = args.length; --i > 0;) // > 0 is correct, not >=0
135 if (args[i].startsWith("name=\"Info.resourcePath\""))
137 resourcePath = getAttr(args[i], "value");
138 if (resourcePath.length() > 0 && !resourcePath.endsWith("/"))
145 for (int i = 1; i < args.length; i++)
147 String arg = args[i].trim();
148 if (arg.startsWith("name="))
150 String prefName = getAttr(arg, "name");
151 String value = getAttr(arg, "value");
152 addParam(vargs, prefName, value, appletParams, resourcePath);
158 private static void addParam(List<String> vargs, String prefName,
159 Object value, AppletParams appletParams, String resourcePath)
162 // note that Application arguments ARE case-sensitive, but
163 // Applet.getParameter() is not.
165 String appletName = prefName.toLowerCase();
166 String argName = prefName;
173 value = resourcePath + value;
178 value = resourcePath + value;
186 // setting argName to null indicates that we want
187 // JalviewAppLoader to take care of this.
188 prefName = argName = null;
189 value = resourcePath + value;
193 // setting appletName to null indicates that we want
194 // Jalview.doMain to taken care of this as Jalview args
197 value = resourcePath + value;
200 // non-loading preferences
202 case "defaultcolour":
203 prefName = Preferences.DEFAULT_COLOUR;
205 case "defaultcolournuc":
206 prefName = Preferences.DEFAULT_COLOUR_NUC;
208 case "defaultcolourprot":
209 prefName = Preferences.DEFAULT_COLOUR_PROT;
211 case "annotationcolour_max":
212 prefName = Preferences.ANNOTATIONCOLOUR_MAX;
214 case "annotationcolour_min":
215 prefName = Preferences.ANNOTATIONCOLOUR_MIN;
217 case "enablesplitframe":
218 prefName = Preferences.ENABLE_SPLIT_FRAME;
220 case "centrecolumnlabels":
221 prefName = Preferences.CENTRE_COLUMN_LABELS;
224 prefName = Preferences.SORT_ALIGNMENT; // id, etc.
226 case "normalisesequencelogo":
227 prefName = Preferences.NORMALISE_CONSENSUS_LOGO;
229 case "relaxedidmatch":
230 prefName = Preferences.RELAXEDSEQIDMATCHING;
232 case "scaleproteinascdna":
233 prefName = Preferences.SCALE_PROTEIN_TO_CDNA;
235 case "userdefinedcolour":
237 prefName = Preferences.USER_DEFINED_COLOURS;
240 prefName = Preferences.WRAP_ALIGNMENT;
243 // implemented; not tested:
249 value = resourcePath + value;
252 case "hidefeaturegroups":
256 argName = prefName = null;
259 prefName = Preferences.SORT_BY_TREE;
260 value = checkTF(value);
261 appletName = null; // taken care of by Jalview
265 case "alignpdbfiles":
266 argName = prefName = null;
271 // TODO: probably not relevant?
274 prefName = null; // TODO no background for application?
276 case "externalstructureviewer":
278 case "application_url":
280 case "automaticscrolling":
284 case "jalviewhelpurl":
289 prefName = "linkLabel_";
292 prefName = "linkLabel_1";
295 prefName = "linkURL_";
301 case "normaliselogo":
302 case "resolvetocodebase":
307 argName = prefName = null;
313 value = checkTF(value);
316 value = checkTF(value);
319 value = checkTF(value);
321 case "showannotation":
322 prefName = Preferences.SHOW_ANNOTATIONS;
323 value = checkTF(value);
325 case "showconsensus":
326 prefName = Preferences.SHOW_CONSENSUS_LOGO;
327 value = checkTF(value);
329 case "showconsensushistogram":
330 prefName = Preferences.SHOW_CONSENSUS_HISTOGRAM;
331 value = checkTF(value);
333 case "showconservation":
334 prefName = Preferences.SHOW_CONSERVATION;
335 value = checkTF(value);
337 case "showgroupconsensus":
338 prefName = Preferences.SHOW_GROUP_CONSENSUS;
339 value = checkTF(value);
341 case "showgroupconservation":
342 prefName = Preferences.SHOW_GROUP_CONSERVATION;
343 value = checkTF(value);
345 case "showoccupancy":
346 prefName = Preferences.SHOW_OCCUPANCY;
347 value = checkTF(value);
350 prefName = Preferences.SHOW_QUALITY;
351 value = checkTF(value);
353 case "showsequencelogo":
354 prefName = Preferences.SHOW_CONSENSUS_LOGO;
355 value = checkTF(value);
357 case "showfeaturegroups":
358 value = checkTF(value);
360 case "showfeaturesettings":
361 value = checkTF(value);
364 value = checkTF(value);
366 case "showtreebootstraps":
367 value = checkTF(value);
369 case "showtreedistances":
370 value = checkTF(value);
372 case "showunconserved":
373 prefName = Preferences.SHOW_UNCONSERVED;
374 value = checkTF(value);
376 case "showunlinkedtreenodes":
377 value = checkTF(value);
380 if (appletName.startsWith("pdbfile")
381 || appletName.startsWith("sequence") && Character
382 .isDigit(appletName.charAt(appletName.length() - 1)))
384 // could be pdbFile2, for example
385 prefName = argName = null;
386 value = resourcePath + value;
389 // or one of the app preference names
393 // put name and value into application args
394 if (value != null && argName != null)
399 vargs.add(value.toString());
406 System.out.println("AppletParams propName=" + prefName + " argName="
407 + argName + " appletName=" + appletName + " value=" + value);
408 if (appletName != null)
410 appletParams.put(appletName, value);
412 if (prefName != null)
414 Cache.setPropertyNoSave(prefName, value.toString());
419 * Check for a single-argument option.
422 * @return "true" or null
424 private static String checkTF(Object value)
426 return (("" + value).toLowerCase() == "true" ? "true" : null);
430 * Crude applet innerHTML parser
436 private static String getAttr(String tag, String attr)
438 int pt = tag.indexOf(attr + "=\"");
442 .println("AppletParams did not read " + attr + " in " + tag);
445 // <param name="sortByTree" value="True"/>
446 int pt1 = pt + attr.length() + 2;
447 int pt2 = tag.indexOf("\"", pt1);
448 return (pt < 0 ? null : tag.substring(pt1, pt2));
451 public static void main(String[] args)
453 new AppletParams("<applet\r\n"
454 + " code=\"jalview.bin.JalviewLite\" width=\"140\" height=\"35\"\r\n"
455 + " archive=\"jalviewApplet.jar,JmolApplet-14.6.4_2016.10.26.jar,java-json.jar,json_simple-1.1.jar\"> \r\n"
456 + " <param name=\"permissions\" value=\"sandbox\"/>\r\n"
457 + " <param name=\"file\" value=\"uniref50.fa\"/>\r\n"
458 + " <param name=\"treeFile\" value=\"ferredoxin.nw\"/>\r\n"
459 + " <param name=\"userDefinedColour\" value=\"C=yellow; R,K,H=FF5555; D,E=5555FF\"/>\r\n"
460 + " <param name=\"sortByTree\" value=\"True\"/>\r\n"
461 + " <param name=\"showSequenceLogo\" value=\"true\"/>\r\n"
462 + " <param name=\"showGroupConsensus\" value=\"true\"/>\r\n"
463 + " <param name=\"showFullId\" value=\"false\"/>\r\n"
464 + " <param name=\"linkLabel_1\" value=\"Uniprot\"/>\r\n"
465 + " <param name=\"linkUrl_1\" value=\"http://www.uniprot.org/uniprot/$SEQUENCE_ID$\"/>\r\n"
466 + " <param name=\"linkLabel_2\" value=\"EMBL-EBI Search\"/>\r\n"
467 + " <param name=\"linkUrl_2\" value=\"http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$\"/>\r\n"
468 + " <param name=\"APPLICATION_URL\" value=\"http://www.jalview.org/services/launchApp\"/>\r\n"