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 = {
22 "ANNOTATIONCOLOUR_MAX", "ANNOTATIONCOLOUR_MIN",
24 "APPLICATION_URL", "automaticScrolling", "centrecolumnlabels",
25 "debug", "defaultColour", "defaultColourNuc", "defaultColourProt",
26 "embedded", "enableSplitFrame", "externalstructureviewer", "features",
27 "file", "file2", "format", "heightScale", "hidefeaturegroups",
28 "jalviewhelpurl", "jnetfile", "jpredfile", "label", "linkLabel_",
29 "linkLabel_1", "linkURL_", "nojmol", "normaliseLogo",
30 "normaliseSequenceLogo", "oninit", "PDBFILE", "PDBSEQ",
31 "relaxedidmatch", "resolvetocodebase", "RGB", "scaleProteinAsCdna",
32 "scoreFile", "separator", "sequence", "showAnnotation", "showbutton",
33 "showConsensus", "showConsensusHistogram", "showConservation",
34 "showfeaturegroups", "showFeatureSettings", "showFullId",
35 "showGroupConsensus", "showGroupConservation", "showOccupancy",
36 "showQuality", "showSequenceLogo", "showTreeBootstraps",
37 "showTreeDistances", "showUnconserved", "showUnlinkedTreeNodes",
38 "sortBy", "sortByTree", "tree", "treeFile", "upperCase",
39 "userDefinedColour", "widthScale", "windowHeight", "windowWidth",
42 public String getParam(String param, String def)
44 Object val = get(param);
45 return (val != null ? val.toString() : def);
49 // code="jalview.bin.JalviewLite" width="140" height="35"
50 // archive="jalviewApplet.jar,JmolApplet-14.6.4_2016.10.26.jar,java-json.jar,json_simple-1.1.jar">
51 // <param name="permissions" value="sandbox"/>
52 // <param name="file" value="uniref50.fa"/>
53 // <param name="treeFile" value="ferredoxin.nw"/>
54 // <param name="userDefinedColour" value="C=yellow; R,K,H=FF5555;
56 // <param name="sortByTree" value="True"/>
57 // <param name="showSequenceLogo" value="true"/>
58 // <param name="showGroupConsensus" value="true"/>
59 // <param name="showFullId" value="false"/>
60 // <param name="linkLabel_1" value="Uniprot"/>
61 // <param name="linkUrl_1"
62 // value="http://www.uniprot.org/uniprot/$SEQUENCE_ID$"/>
63 // <param name="linkLabel_2" value="EMBL-EBI Search"/>
64 // <param name="linkUrl_2"
65 // value="http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$"/>
66 // <param name="APPLICATION_URL"
67 // value="http://www.jalview.org/services/launchApp"/>
70 public AppletParams(String outerHTML)
72 String[] tokens = outerHTML.split("<param");
73 outerHTML = tokens[0];
74 String code = getAttr(outerHTML, "code");
75 if (!code.equals("jalview.bin.JalviewLite"))
79 for (int i = tokens.length; --i > 0;)
81 String param = tokens[i];
82 String key = getAttr(param, "name");
85 String value = getAttr(param, "value");
86 System.out.println("AppletParams " + key + " = \"" + value + "\"");
90 put("_width", getAttr(outerHTML, "width"));
91 put("_height", getAttr(outerHTML, "height"));
92 put("_id", getAttr(outerHTML, "id"));
93 put("_name", getAttr(outerHTML, "name"));
94 put("_archive", getAttr(outerHTML, "archive"));
102 public static AppletParams getAppletParams(Map<String, Object> map,
105 AppletParams appletParams = new AppletParams();
106 String resourcePath = getString(map, "resourcePath");
107 if (resourcePath == null)
109 if (resourcePath.length() > 0 && !resourcePath.endsWith("/"))
113 for (int i = params.length; --i >= 0;)
115 String prefName = params[i];
116 Object value = map.get(prefName);
118 addParam(vargs, prefName, value, appletParams, resourcePath);
123 private static String getString(Map<String, Object> map, String key)
125 Object o = map.get(key);
126 return (o == null ? null : o.toString());
129 public static AppletParams getAppletParams(String[] args,
132 AppletParams appletParams = new AppletParams();
133 String resourcePath = "";
134 for (int i = args.length; --i > 0;) // > 0 is correct, not >=0
136 if (args[i].startsWith("name=\"Info.resourcePath\""))
138 resourcePath = getAttr(args[i], "value");
139 if (resourcePath.length() > 0 && !resourcePath.endsWith("/"))
146 for (int i = 1; i < args.length; i++)
148 String arg = args[i].trim();
149 if (arg.startsWith("name="))
151 String prefName = getAttr(arg, "name");
152 String value = getAttr(arg, "value");
153 addParam(vargs, prefName, value, appletParams, resourcePath);
159 private static void addParam(List<String> vargs, String prefName,
160 Object value, AppletParams appletParams, String resourcePath)
163 // note that Application arguments ARE case-sensitive, but
164 // Applet.getParameter() is not.
166 String appletName = prefName.toLowerCase();
167 String argName = prefName;
174 value = resourcePath + value;
179 value = resourcePath + value;
187 // setting argName to null indicates that we want
188 // JalviewJSApp to take care of this using getParameter or getParameterAsObject
189 prefName = argName = null;
190 value = resourcePath + value;
194 // setting appletName to null indicates that we want
195 // Jalview.doMain to taken care of this as Jalview args
198 value = resourcePath + value;
201 // non-loading preferences
203 case "defaultcolour":
204 prefName = Preferences.DEFAULT_COLOUR;
206 case "defaultcolournuc":
207 prefName = Preferences.DEFAULT_COLOUR_NUC;
209 case "defaultcolourprot":
210 prefName = Preferences.DEFAULT_COLOUR_PROT;
212 case "annotationcolour_max":
213 prefName = Preferences.ANNOTATIONCOLOUR_MAX;
215 case "annotationcolour_min":
216 prefName = Preferences.ANNOTATIONCOLOUR_MIN;
218 case "enablesplitframe":
219 prefName = Preferences.ENABLE_SPLIT_FRAME;
221 case "centrecolumnlabels":
222 prefName = Preferences.CENTRE_COLUMN_LABELS;
225 prefName = Preferences.SORT_ALIGNMENT; // id, etc.
227 case "normalisesequencelogo":
228 prefName = Preferences.NORMALISE_CONSENSUS_LOGO;
230 case "relaxedidmatch":
231 prefName = Preferences.RELAXEDSEQIDMATCHING;
233 case "scaleproteinascdna":
234 prefName = Preferences.SCALE_PROTEIN_TO_CDNA;
236 case "userdefinedcolour":
238 prefName = Preferences.USER_DEFINED_COLOURS;
241 prefName = Preferences.WRAP_ALIGNMENT;
244 // implemented; not tested:
250 value = resourcePath + value;
253 case "hidefeaturegroups":
257 argName = prefName = null;
260 prefName = Preferences.SORT_BY_TREE;
261 value = checkTF(value);
262 appletName = null; // taken care of by Jalview
266 case "alignpdbfiles":
267 argName = prefName = null;
272 // TODO: probably not relevant?
275 prefName = null; // TODO no background for application?
277 case "externalstructureviewer":
279 case "application_url":
281 case "automaticscrolling":
285 case "jalviewhelpurl":
290 prefName = "linkLabel_";
293 prefName = "linkLabel_1";
296 prefName = "linkURL_";
302 case "normaliselogo":
303 case "resolvetocodebase":
308 argName = prefName = null;
314 value = checkTF(value);
317 value = checkTF(value);
320 value = checkTF(value);
322 case "showannotation":
323 prefName = Preferences.SHOW_ANNOTATIONS;
324 value = checkTF(value);
326 case "showconsensus":
327 prefName = Preferences.SHOW_CONSENSUS_LOGO;
328 value = checkTF(value);
330 case "showconsensushistogram":
331 prefName = Preferences.SHOW_CONSENSUS_HISTOGRAM;
332 value = checkTF(value);
334 case "showconservation":
335 prefName = Preferences.SHOW_CONSERVATION;
336 value = checkTF(value);
338 case "showgroupconsensus":
339 prefName = Preferences.SHOW_GROUP_CONSENSUS;
340 value = checkTF(value);
342 case "showgroupconservation":
343 prefName = Preferences.SHOW_GROUP_CONSERVATION;
344 value = checkTF(value);
346 case "showoccupancy":
347 prefName = Preferences.SHOW_OCCUPANCY;
348 value = checkTF(value);
351 prefName = Preferences.SHOW_QUALITY;
352 value = checkTF(value);
354 case "showsequencelogo":
355 prefName = Preferences.SHOW_CONSENSUS_LOGO;
356 value = checkTF(value);
358 case "showfeaturegroups":
359 value = checkTF(value);
361 case "showfeaturesettings":
362 value = checkTF(value);
365 value = checkTF(value);
367 case "showtreebootstraps":
368 value = checkTF(value);
370 case "showtreedistances":
371 value = checkTF(value);
373 case "showunconserved":
374 prefName = Preferences.SHOW_UNCONSERVED;
375 value = checkTF(value);
377 case "showunlinkedtreenodes":
378 value = checkTF(value);
381 if (appletName.startsWith("pdbfile")
382 || appletName.startsWith("sequence") && Character
383 .isDigit(appletName.charAt(appletName.length() - 1)))
385 // could be pdbFile2, for example
386 prefName = argName = null;
387 value = resourcePath + value;
390 // or one of the app preference names
394 // put name and value into application args
395 if (value != null && argName != null)
400 vargs.add(value.toString());
407 System.out.println("AppletParams propName=" + prefName + " argName="
408 + argName + " appletName=" + appletName + " value=" + value);
409 if (appletName != null)
411 appletParams.put(appletName, value);
413 if (prefName != null)
415 Cache.setPropertyNoSave(prefName, value.toString());
420 * Check for a single-argument option.
423 * @return "true" or null
425 private static String checkTF(Object value)
427 return (("" + value).toLowerCase() == "true" ? "true" : null);
431 * Crude applet innerHTML parser
437 private static String getAttr(String tag, String attr)
439 int pt = tag.indexOf(attr + "=\"");
443 .println("AppletParams did not read " + attr + " in " + tag);
446 // <param name="sortByTree" value="True"/>
447 int pt1 = pt + attr.length() + 2;
448 int pt2 = tag.indexOf("\"", pt1);
449 return (pt < 0 ? null : tag.substring(pt1, pt2));
452 public static void main(String[] args)
454 new AppletParams("<applet\r\n"
455 + " code=\"jalview.bin.JalviewLite\" width=\"140\" height=\"35\"\r\n"
456 + " archive=\"jalviewApplet.jar,JmolApplet-14.6.4_2016.10.26.jar,java-json.jar,json_simple-1.1.jar\"> \r\n"
457 + " <param name=\"permissions\" value=\"sandbox\"/>\r\n"
458 + " <param name=\"file\" value=\"uniref50.fa\"/>\r\n"
459 + " <param name=\"treeFile\" value=\"ferredoxin.nw\"/>\r\n"
460 + " <param name=\"userDefinedColour\" value=\"C=yellow; R,K,H=FF5555; D,E=5555FF\"/>\r\n"
461 + " <param name=\"sortByTree\" value=\"True\"/>\r\n"
462 + " <param name=\"showSequenceLogo\" value=\"true\"/>\r\n"
463 + " <param name=\"showGroupConsensus\" value=\"true\"/>\r\n"
464 + " <param name=\"showFullId\" value=\"false\"/>\r\n"
465 + " <param name=\"linkLabel_1\" value=\"Uniprot\"/>\r\n"
466 + " <param name=\"linkUrl_1\" value=\"http://www.uniprot.org/uniprot/$SEQUENCE_ID$\"/>\r\n"
467 + " <param name=\"linkLabel_2\" value=\"EMBL-EBI Search\"/>\r\n"
468 + " <param name=\"linkUrl_2\" value=\"http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$\"/>\r\n"
469 + " <param name=\"APPLICATION_URL\" value=\"http://www.jalview.org/services/launchApp\"/>\r\n"