3 import jalview.gui.Preferences;
5 import java.util.HashMap;
7 import java.util.Vector;
10 * Collection of all known applet tags from JalviewLite
15 @SuppressWarnings("serial")
16 public class AppletParams extends HashMap<String, String>
19 private final static String[] params = { "alignpdbfiles",
20 Preferences.ANNOTATIONCOLOUR_MAX, Preferences.ANNOTATIONCOLOUR_MIN,
22 "APPLICATION_URL", "automaticScrolling", "centrecolumnlabels",
23 "debug", "defaultColour", "defaultColourNuc", "defaultColourProt",
24 "embedded", "enableSplitFrame", "externalstructureviewer", "features",
25 "file", "file2", "format", "heightScale", "hidefeaturegroups",
26 "jalviewhelpurl", "jnetfile", "jpredfile", "label", "linkLabel_",
27 "linkLabel_1", "linkURL_", "nojmol", "normaliseLogo",
28 "normaliseSequenceLogo", "oninit", "PDBFILE", "PDBSEQ",
29 "relaxedidmatch", "resolvetocodebase", "RGB", "scaleProteinAsCdna",
30 "scoreFile", "separator", "sequence", "showAnnotation", "showbutton",
31 "showConsensus", "showConsensusHistogram", "showConservation",
32 "showfeaturegroups", "showFeatureSettings", "showFullId",
33 "showGroupConsensus", "showGroupConservation", "showOccupancy",
34 "showQuality", "showSequenceLogo", "showTreeBootstraps",
35 "showTreeDistances", "showUnconserved", "showUnlinkedTreeNodes",
36 "sortBy", "sortByTree", "tree", "treeFile", "upperCase",
37 "userDefinedColour", "widthScale", "windowHeight", "windowWidth",
40 public AppletParams(Map<String, String> info)
42 for (int i = params.length; --i >= 0;)
44 put(params[i], info.get(params[i]));
48 public String getParam(String param, String def)
50 String val = get(param);
51 return (val != null ? val : def);
55 // code="jalview.bin.JalviewLite" width="140" height="35"
56 // archive="jalviewApplet.jar,JmolApplet-14.6.4_2016.10.26.jar,java-json.jar,json_simple-1.1.jar">
57 // <param name="permissions" value="sandbox"/>
58 // <param name="file" value="uniref50.fa"/>
59 // <param name="treeFile" value="ferredoxin.nw"/>
60 // <param name="userDefinedColour" value="C=yellow; R,K,H=FF5555;
62 // <param name="sortByTree" value="True"/>
63 // <param name="showSequenceLogo" value="true"/>
64 // <param name="showGroupConsensus" value="true"/>
65 // <param name="showFullId" value="false"/>
66 // <param name="linkLabel_1" value="Uniprot"/>
67 // <param name="linkUrl_1"
68 // value="http://www.uniprot.org/uniprot/$SEQUENCE_ID$"/>
69 // <param name="linkLabel_2" value="EMBL-EBI Search"/>
70 // <param name="linkUrl_2"
71 // value="http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$"/>
72 // <param name="APPLICATION_URL"
73 // value="http://www.jalview.org/services/launchApp"/>
76 public AppletParams(String outerHTML)
78 String[] tokens = outerHTML.split("<param");
79 outerHTML = tokens[0];
80 String code = getAttr(outerHTML, "code");
81 if (!code.equals("jalview.bin.JalviewLite"))
85 for (int i = tokens.length; --i > 0;)
87 String param = tokens[i];
88 String key = getAttr(param, "name");
91 String value = getAttr(param, "value");
92 System.out.println("AppletParams " + key + " = \"" + value + "\"");
96 put("_width", getAttr(outerHTML, "width"));
97 put("_height", getAttr(outerHTML, "height"));
98 put("_id", getAttr(outerHTML, "id"));
99 put("_name", getAttr(outerHTML, "name"));
100 put("_archive", getAttr(outerHTML, "archive"));
104 public AppletParams()
106 // TODO Auto-generated constructor stub
109 public static AppletParams getAppletParams(String[] args,
110 Vector<String> vargs)
112 AppletParams appletParams = new AppletParams();
113 String resourcePath = null;
114 for (int i = args.length; --i > 0;) // > 0 is correct, not >=0
116 if (args[i].startsWith("name=\"Info.resourcePath\""))
118 resourcePath = getAttr(args[i], "value");
119 if (resourcePath.length() > 0 && !resourcePath.endsWith("/"))
126 for (int i = 1; i < args.length; i++)
128 String arg = args[i].trim();
129 if (arg.startsWith("name="))
131 String prefName = getAttr(arg, "name");
132 String appletName = prefName.toLowerCase();
133 String argName = prefName;
134 String value = getAttr(arg, "value");
136 // note that Application arguments ARE case-sensitive, but
137 // Applet.getParameter() is not.
145 value = resourcePath + value;
150 value = resourcePath + value;
158 // setting argName to null indicates that we want
159 // JalviewAppLoader to take care of this.
160 prefName = argName = null;
161 value = resourcePath + value;
165 // setting appletName to null indicates that we want
166 // Jalview.doMain to taken care of this as Jalview args
169 value = resourcePath + value;
172 // non-loading preferences
174 case "defaultcolour":
175 prefName = Preferences.DEFAULT_COLOUR;
177 case "defaultcolournuc":
178 prefName = Preferences.DEFAULT_COLOUR_NUC;
180 case "defaultcolourprot":
181 prefName = Preferences.DEFAULT_COLOUR_PROT;
183 case "annotationcolour_max":
184 prefName = Preferences.ANNOTATIONCOLOUR_MAX;
186 case "annotationcolour_min":
187 prefName = Preferences.ANNOTATIONCOLOUR_MIN;
189 case "enablesplitframe":
190 prefName = Preferences.ENABLE_SPLIT_FRAME;
192 case "centrecolumnlabels":
193 prefName = Preferences.CENTRE_COLUMN_LABELS;
196 prefName = Preferences.SORT_ALIGNMENT; // id, etc.
198 case "normalisesequencelogo":
199 prefName = Preferences.NORMALISE_CONSENSUS_LOGO;
201 case "relaxedidmatch":
202 prefName = Preferences.RELAXEDSEQIDMATCHING;
204 case "scaleproteinascdna":
205 prefName = Preferences.SCALE_PROTEIN_TO_CDNA;
207 case "userdefinedcolour":
209 prefName = Preferences.USER_DEFINED_COLOURS;
212 prefName = Preferences.WRAP_ALIGNMENT;
215 // implemented; not tested:
221 value = resourcePath + value;
224 case "hidefeaturegroups":
228 argName = prefName = null;
231 prefName = Preferences.SORT_BY_TREE;
232 value = checkTF(value);
233 appletName = null; // taken care of by Jalview
237 case "alignpdbfiles":
238 argName = prefName = null;
243 // TODO: probably not relevant?
246 prefName = null; // TODO no background for application?
248 case "externalstructureviewer":
250 case "application_url":
252 case "automaticscrolling":
256 case "jalviewhelpurl":
261 prefName = "linkLabel_";
264 prefName = "linkLabel_1";
267 prefName = "linkURL_";
273 case "normaliselogo":
274 case "resolvetocodebase":
279 argName = prefName = null;
285 value = checkTF(value);
288 value = checkTF(value);
291 value = checkTF(value);
293 case "showannotation":
294 prefName = Preferences.SHOW_ANNOTATIONS;
295 value = checkTF(value);
297 case "showconsensus":
298 prefName = Preferences.SHOW_CONSENSUS_LOGO;
299 value = checkTF(value);
301 case "showconsensushistogram":
302 prefName = Preferences.SHOW_CONSENSUS_HISTOGRAM;
303 value = checkTF(value);
305 case "showconservation":
306 prefName = Preferences.SHOW_CONSERVATION;
307 value = checkTF(value);
309 case "showgroupconsensus":
310 prefName = Preferences.SHOW_GROUP_CONSENSUS;
311 value = checkTF(value);
313 case "showgroupconservation":
314 prefName = Preferences.SHOW_GROUP_CONSERVATION;
315 value = checkTF(value);
317 case "showoccupancy":
318 prefName = Preferences.SHOW_OCCUPANCY;
319 value = checkTF(value);
322 prefName = Preferences.SHOW_QUALITY;
323 value = checkTF(value);
325 case "showsequencelogo":
326 prefName = Preferences.SHOW_CONSENSUS_LOGO;
327 value = checkTF(value);
329 case "showfeaturegroups":
330 value = checkTF(value);
332 case "showfeaturesettings":
333 value = checkTF(value);
336 value = checkTF(value);
338 case "showtreebootstraps":
339 value = checkTF(value);
341 case "showtreedistances":
342 value = checkTF(value);
344 case "showunconserved":
345 prefName = Preferences.SHOW_UNCONSERVED;
346 value = checkTF(value);
348 case "showunlinkedtreenodes":
349 value = checkTF(value);
352 if (appletName.startsWith("pdbfile")
353 || appletName.startsWith("sequence") && Character.isDigit(
354 appletName.charAt(appletName.length() - 1)))
356 // could be pdbFile2, for example
357 prefName = argName = null;
358 value = resourcePath + value;
361 // or one of the app preference names
364 // put name and value into application args
365 if (value != null && argName != null)
377 System.out.println("AppletParams propName=" + prefName + " argName="
378 + argName + " appletName="
379 + appletName + " value=" + value);
380 if (appletName != null)
382 appletParams.put(appletName, value);
384 if (prefName != null)
386 Cache.setPropertyNoSave(prefName, value);
394 * Check for a single-argument option.
397 * @return "true" or null
399 private static String checkTF(String value)
401 return (value.toLowerCase() == "true" ? "true" : null);
405 * Crude applet innerHTML parser
411 private static String getAttr(String tag, String attr)
413 int pt = tag.indexOf(attr + "=\"");
417 .println("AppletParams did not read " + attr + " in " + tag);
420 // <param name="sortByTree" value="True"/>
421 int pt1 = pt + attr.length() + 2;
422 int pt2 = tag.indexOf("\"", pt1);
423 return (pt < 0 ? null : tag.substring(pt1, pt2));
426 public static void main(String[] args)
428 new AppletParams("<applet\r\n"
429 + " code=\"jalview.bin.JalviewLite\" width=\"140\" height=\"35\"\r\n"
430 + " archive=\"jalviewApplet.jar,JmolApplet-14.6.4_2016.10.26.jar,java-json.jar,json_simple-1.1.jar\"> \r\n"
431 + " <param name=\"permissions\" value=\"sandbox\"/>\r\n"
432 + " <param name=\"file\" value=\"uniref50.fa\"/>\r\n"
433 + " <param name=\"treeFile\" value=\"ferredoxin.nw\"/>\r\n"
434 + " <param name=\"userDefinedColour\" value=\"C=yellow; R,K,H=FF5555; D,E=5555FF\"/>\r\n"
435 + " <param name=\"sortByTree\" value=\"True\"/>\r\n"
436 + " <param name=\"showSequenceLogo\" value=\"true\"/>\r\n"
437 + " <param name=\"showGroupConsensus\" value=\"true\"/>\r\n"
438 + " <param name=\"showFullId\" value=\"false\"/>\r\n"
439 + " <param name=\"linkLabel_1\" value=\"Uniprot\"/>\r\n"
440 + " <param name=\"linkUrl_1\" value=\"http://www.uniprot.org/uniprot/$SEQUENCE_ID$\"/>\r\n"
441 + " <param name=\"linkLabel_2\" value=\"EMBL-EBI Search\"/>\r\n"
442 + " <param name=\"linkUrl_2\" value=\"http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$\"/>\r\n"
443 + " <param name=\"APPLICATION_URL\" value=\"http://www.jalview.org/services/launchApp\"/>\r\n"