3 import java.util.HashMap;
5 import java.util.Vector;
8 * Collection of all known applet tags from JalviewLite
13 @SuppressWarnings("serial")
14 public class AppletParams extends HashMap<String, String>
17 private final static String[] params = { "alignpdbfiles",
18 "ANNOTATIONCOLOUR_MAX", "ANNOTATIONCOLOUR_MIN", "annotations",
19 "APPLICATION_URL", "automaticScrolling", "centrecolumnlabels",
20 "debug", "defaultColour", "defaultColourNuc", "defaultColourProt",
21 "embedded", "enableSplitFrame", "externalstructureviewer", "features",
22 "file", "file2", "format", "heightScale", "hidefeaturegroups",
23 "jalviewhelpurl", "jnetfile", "jpredfile", "label", "linkLabel_",
24 "linkLabel_1", "linkURL_", "nojmol", "normaliseLogo",
25 "normaliseSequenceLogo", "oninit", "PDBFILE", "PDBSEQ",
26 "relaxedidmatch", "resolvetocodebase", "RGB", "scaleProteinAsCdna",
27 "scoreFile", "separator", "sequence", "showAnnotation", "showbutton",
28 "showConsensus", "showConsensusHistogram", "showConservation",
29 "showfeaturegroups", "showFeatureSettings", "showFullId",
30 "showGroupConsensus", "showGroupConservation", "showOccupancy",
31 "showQuality", "showSequenceLogo", "showTreeBootstraps",
32 "showTreeDistances", "showUnconserved", "showUnlinkedTreeNodes",
33 "sortBy", "sortByTree", "tree", "treeFile", "upperCase",
34 "userDefinedColour", "widthScale", "windowHeight", "windowWidth",
37 public AppletParams(Map<String, String> info)
39 for (int i = params.length; --i >= 0;)
41 put(params[i], info.get(params[i]));
45 public String getParam(String param, String def)
47 String val = get(param);
48 return (val != null ? val : def);
52 // code="jalview.bin.JalviewLite" width="140" height="35"
53 // archive="jalviewApplet.jar,JmolApplet-14.6.4_2016.10.26.jar,java-json.jar,json_simple-1.1.jar">
54 // <param name="permissions" value="sandbox"/>
55 // <param name="file" value="uniref50.fa"/>
56 // <param name="treeFile" value="ferredoxin.nw"/>
57 // <param name="userDefinedColour" value="C=yellow; R,K,H=FF5555;
59 // <param name="sortByTree" value="True"/>
60 // <param name="showSequenceLogo" value="true"/>
61 // <param name="showGroupConsensus" value="true"/>
62 // <param name="showFullId" value="false"/>
63 // <param name="linkLabel_1" value="Uniprot"/>
64 // <param name="linkUrl_1"
65 // value="http://www.uniprot.org/uniprot/$SEQUENCE_ID$"/>
66 // <param name="linkLabel_2" value="EMBL-EBI Search"/>
67 // <param name="linkUrl_2"
68 // value="http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$"/>
69 // <param name="APPLICATION_URL"
70 // value="http://www.jalview.org/services/launchApp"/>
73 public AppletParams(String outerHTML)
75 String[] tokens = outerHTML.split("<param");
76 outerHTML = tokens[0];
77 String code = getAttr(outerHTML, "code");
78 if (!code.equals("jalview.bin.JalviewLite"))
82 for (int i = tokens.length; --i > 0;)
84 String param = tokens[i];
85 String key = getAttr(param, "name");
88 String value = getAttr(param, "value");
89 System.out.println("AppletParams " + key + " = \"" + value + "\"");
93 put("_width", getAttr(outerHTML, "width"));
94 put("_height", getAttr(outerHTML, "height"));
95 put("_id", getAttr(outerHTML, "id"));
96 put("_name", getAttr(outerHTML, "name"));
97 put("_archive", getAttr(outerHTML, "archive"));
101 public AppletParams()
103 // TODO Auto-generated constructor stub
106 public static AppletParams getAppletParams(String[] args,
107 Vector<String> vargs)
109 AppletParams appletParams = new AppletParams();
110 String resourcePath = null;
111 for (int i = args.length; --i > 0;) // > 0 is correct, not >=0
113 if (args[i].startsWith("name=\"Info.resourcePath\""))
115 resourcePath = getAttr(args[i], "value");
116 if (resourcePath.length() > 0 && !resourcePath.endsWith("/"))
123 for (int i = 1; i < args.length; i++)
125 String arg = args[i].trim();
126 if (arg.startsWith("name="))
128 String key = getAttr(arg, "name");
129 String value = getAttr(arg, "value");
131 switch (name.toLowerCase())
133 case "alignpdbfiles":
135 case "annotationcolour_max":
136 name = "ANNOTATIONCOLOUR_MAX";
138 case "annotationcolour_min":
139 name = "ANNOTATIONCOLOUR_MIN";
142 value = checkTF(value);
144 case "application_url":
145 name = "APPLICATION_URL";
147 case "automaticscrolling":
148 name = "automaticScrolling";
150 case "centrecolumnlabels":
152 case "defaultcolour":
153 name = "DEFAULT_COLOUR"; // defaultColour
155 case "defaultcolournuc":
156 name = "DEFAULT_COLOUR_NUC";// defaultColourNuc
158 case "defaultcolourprot":
159 name = "DEFAULT_COLOUR_PROT";// defaultColourProt";
161 case "enablesplitframe":
162 name = "enableSplitFrame";
164 case "externalstructureviewer":
167 value = resourcePath + value;
172 name = "heightScale";
174 case "hidefeaturegroups":
176 case "jalviewhelpurl":
179 value = resourcePath + value;
182 value = resourcePath + value;
190 name = "linkLabel_1";
197 case "normaliselogo":
198 name = "normaliseLogo";
200 case "normalisesequencelogo":
201 name = "normaliseSequenceLogo";
211 case "relaxedidmatch":
213 case "resolvetocodebase":
218 case "scaleproteinascdna":
219 name = "scaleProteinAsCdna";
223 value = resourcePath + value;
233 value = checkTF(value);
234 key = null; // taken care of by Jalview
239 value = resourcePath + value;
240 key = null; // taken care of by Jalview
245 case "userdefinedcolour":
252 name = "windowHeight";
255 name = "windowWidth";
260 // cases not handled in doc/parameters.xlsx
262 value = checkTF(value);
266 value = resourcePath + value;
269 value = resourcePath + value;
272 value = checkTF(value);
274 case "showannotation":
275 name = "SHOW_ANNOTATIONS";
276 value = checkTF(value);
279 value = checkTF(value);
281 case "showconsensus":
282 name = "SHOW_CONSENSUS_LOGO";
283 value = checkTF(value);
285 case "showconsensushistogram":
286 name = "SHOW_CONSENSUS_HISTOGRAM";
287 value = checkTF(value);
289 case "showconservation":
290 name = "SHOW_CONSERVATION";
291 value = checkTF(value);
293 case "showfeaturegroups":
294 value = checkTF(value);
296 case "showfeaturesettings":
297 name = "showFeatureSettings";
298 value = checkTF(value);
302 value = checkTF(value);
304 case "showgroupconsensus":
305 name = "SHOW_GROUP_CONSENSUS";
306 value = checkTF(value);
308 case "showgroupconservation":
309 name = "SHOW_GROUP_CONSERVATION";
310 value = checkTF(value);
312 case "showoccupancy":
313 name = "SHOW_OCCUPANCY";
314 value = checkTF(value);
317 name = "SHOW_QUALITY";
318 value = checkTF(value);
320 case "showsequencelogo":
321 name = "showSequenceLogo";
322 value = checkTF(value);
324 case "showtreebootstraps":
325 name = "showTreeBootstraps";
326 value = checkTF(value);
328 case "showtreedistances":
329 name = "showTreeDistances";
330 value = checkTF(value);
332 case "showunconserved":
333 name = "showUnconserved";
334 value = checkTF(value);
336 case "showunlinkedtreenodes":
337 name = "showUnlinkedTreeNodes";
338 value = checkTF(value);
355 System.out.println("AppletParams name=" + name + " value=" + value);
356 Cache.setPropertyNoSave(name, value);
359 appletParams.put(key, value);
367 * Check for a single-argument option.
370 * @return "true" or null
372 private static String checkTF(String value)
374 return (value.toLowerCase() == "true" ? "true" : null);
378 * Crude applet innerHTML parser
384 private static String getAttr(String tag, String attr)
386 int pt = tag.indexOf(attr + "=\"");
390 .println("AppletParams did not read " + attr + " in " + tag);
393 // <param name="sortByTree" value="True"/>
394 int pt1 = pt + attr.length() + 2;
395 int pt2 = tag.indexOf("\"", pt1);
396 return (pt < 0 ? null : tag.substring(pt1, pt2));
399 public static void main(String[] args)
401 new AppletParams("<applet\r\n"
402 + " code=\"jalview.bin.JalviewLite\" width=\"140\" height=\"35\"\r\n"
403 + " archive=\"jalviewApplet.jar,JmolApplet-14.6.4_2016.10.26.jar,java-json.jar,json_simple-1.1.jar\"> \r\n"
404 + " <param name=\"permissions\" value=\"sandbox\"/>\r\n"
405 + " <param name=\"file\" value=\"uniref50.fa\"/>\r\n"
406 + " <param name=\"treeFile\" value=\"ferredoxin.nw\"/>\r\n"
407 + " <param name=\"userDefinedColour\" value=\"C=yellow; R,K,H=FF5555; D,E=5555FF\"/>\r\n"
408 + " <param name=\"sortByTree\" value=\"True\"/>\r\n"
409 + " <param name=\"showSequenceLogo\" value=\"true\"/>\r\n"
410 + " <param name=\"showGroupConsensus\" value=\"true\"/>\r\n"
411 + " <param name=\"showFullId\" value=\"false\"/>\r\n"
412 + " <param name=\"linkLabel_1\" value=\"Uniprot\"/>\r\n"
413 + " <param name=\"linkUrl_1\" value=\"http://www.uniprot.org/uniprot/$SEQUENCE_ID$\"/>\r\n"
414 + " <param name=\"linkLabel_2\" value=\"EMBL-EBI Search\"/>\r\n"
415 + " <param name=\"linkUrl_2\" value=\"http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$\"/>\r\n"
416 + " <param name=\"APPLICATION_URL\" value=\"http://www.jalview.org/services/launchApp\"/>\r\n"