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 appName = getAttr(arg, "name");
132 String value = getAttr(arg, "value");
133 String appletName = appName.toLowerCase();
135 // note that Application arguments ARE case-sensitive, but
136 // Applet.getParameter() is not.
145 value = resourcePath + value;
149 value = resourcePath + value;
153 value = resourcePath + value;
157 value = resourcePath + value;
161 value = resourcePath + value;
165 value = resourcePath + value;
171 value = resourcePath + value;
172 appletName = null; // taken care of by Jalview
174 case "defaultcolour":
175 appName = Preferences.DEFAULT_COLOUR;
177 case "defaultcolournuc":
178 appName = Preferences.DEFAULT_COLOUR_NUC;
180 case "defaultcolourprot":
181 appName = Preferences.DEFAULT_COLOUR_PROT;
184 // implemented; not tested:
190 value = resourcePath + value;
193 case "annotationcolour_max":
194 appName = Preferences.ANNOTATIONCOLOUR_MAX;
196 case "annotationcolour_min":
197 appName = Preferences.ANNOTATIONCOLOUR_MIN;
199 case "enablesplitframe":
200 appName = Preferences.ENABLE_SPLIT_FRAME;
202 case "hidefeaturegroups":
204 case "centrecolumnlabels":
211 appName = Preferences.SORT_ALIGNMENT; // id, etc.
214 appName = Preferences.SORT_BY_TREE;
215 value = checkTF(value);
216 appletName = null; // taken care of by Jalview
221 // probably not relevant:
223 case "externalstructureviewer":
225 case "alignpdbfiles":
227 case "application_url":
228 appName = "APPLICATION_URL";
230 case "automaticscrolling":
231 appName = "automaticScrolling";
234 appName = "heightScale";
236 case "jalviewhelpurl":
241 appName = "linkLabel_";
244 appName = "linkLabel_1";
247 appName = "linkURL_";
250 appName = null; // no background for application
257 case "normaliselogo":
258 appName = Preferences.NORMALISE_LOGO;
260 case "normalisesequencelogo":
261 appName = Preferences.NORMALISE_CONSENSUS_LOGO;
263 case "relaxedidmatch":
265 case "resolvetocodebase":
267 case "scaleproteinascdna":
268 appName = "scaleProteinAsCdna";
275 appName = "upperCase";
277 case "userdefinedcolour":
281 appName = "widthScale";
284 appName = "windowHeight";
287 appName = "windowWidth";
290 appName = Preferences.WRAP_ALIGNMENT;
293 appName = "scoreFile";
294 value = resourcePath + value;
300 value = checkTF(value);
303 value = checkTF(value);
306 value = checkTF(value);
308 case "showannotation":
309 appName = Preferences.SHOW_ANNOTATIONS;
310 value = checkTF(value);
312 case "showconsensus":
313 appName = Preferences.SHOW_CONSENSUS_LOGO;
314 value = checkTF(value);
316 case "showconsensushistogram":
317 appName = Preferences.SHOW_CONSENSUS_HISTOGRAM;
318 value = checkTF(value);
320 case "showconservation":
321 appName = Preferences.SHOW_CONSERVATION;
322 value = checkTF(value);
324 case "showgroupconsensus":
325 appName = Preferences.SHOW_GROUP_CONSENSUS;
326 value = checkTF(value);
328 case "showgroupconservation":
329 appName = Preferences.SHOW_GROUP_CONSERVATION;
330 value = checkTF(value);
332 case "showoccupancy":
333 appName = Preferences.SHOW_OCCUPANCY;
334 value = checkTF(value);
337 appName = Preferences.SHOW_QUALITY;
338 value = checkTF(value);
340 case "showsequencelogo":
341 appName = Preferences.SHOW_CONSENSUS_LOGO;
342 value = checkTF(value);
344 case "showfeaturegroups":
345 value = checkTF(value);
347 case "showfeaturesettings":
348 appName = "showFeatureSettings";
349 value = checkTF(value);
352 appName = "showFullId";
353 value = checkTF(value);
355 case "showtreebootstraps":
356 appName = "showTreeBootstraps";
357 value = checkTF(value);
359 case "showtreedistances":
360 appName = "showTreeDistances";
361 value = checkTF(value);
363 case "showunconserved":
364 appName = Preferences.SHOW_UNCONSERVED;
365 value = checkTF(value);
367 case "showunlinkedtreenodes":
368 appName = "showUnlinkedTreeNodes";
369 value = checkTF(value);
372 // could be pdbFile2, for example
373 // or one of the app preference names
388 System.out.println("AppletParams appName=" + appName + "appletName="
389 + appletName + " value=" + value);
390 Cache.setPropertyNoSave(appName, value);
391 if (appletName != null)
393 appletParams.put(appletName, value);
401 * Check for a single-argument option.
404 * @return "true" or null
406 private static String checkTF(String value)
408 return (value.toLowerCase() == "true" ? "true" : null);
412 * Crude applet innerHTML parser
418 private static String getAttr(String tag, String attr)
420 int pt = tag.indexOf(attr + "=\"");
424 .println("AppletParams did not read " + attr + " in " + tag);
427 // <param name="sortByTree" value="True"/>
428 int pt1 = pt + attr.length() + 2;
429 int pt2 = tag.indexOf("\"", pt1);
430 return (pt < 0 ? null : tag.substring(pt1, pt2));
433 public static void main(String[] args)
435 new AppletParams("<applet\r\n"
436 + " code=\"jalview.bin.JalviewLite\" width=\"140\" height=\"35\"\r\n"
437 + " archive=\"jalviewApplet.jar,JmolApplet-14.6.4_2016.10.26.jar,java-json.jar,json_simple-1.1.jar\"> \r\n"
438 + " <param name=\"permissions\" value=\"sandbox\"/>\r\n"
439 + " <param name=\"file\" value=\"uniref50.fa\"/>\r\n"
440 + " <param name=\"treeFile\" value=\"ferredoxin.nw\"/>\r\n"
441 + " <param name=\"userDefinedColour\" value=\"C=yellow; R,K,H=FF5555; D,E=5555FF\"/>\r\n"
442 + " <param name=\"sortByTree\" value=\"True\"/>\r\n"
443 + " <param name=\"showSequenceLogo\" value=\"true\"/>\r\n"
444 + " <param name=\"showGroupConsensus\" value=\"true\"/>\r\n"
445 + " <param name=\"showFullId\" value=\"false\"/>\r\n"
446 + " <param name=\"linkLabel_1\" value=\"Uniprot\"/>\r\n"
447 + " <param name=\"linkUrl_1\" value=\"http://www.uniprot.org/uniprot/$SEQUENCE_ID$\"/>\r\n"
448 + " <param name=\"linkLabel_2\" value=\"EMBL-EBI Search\"/>\r\n"
449 + " <param name=\"linkUrl_2\" value=\"http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$\"/>\r\n"
450 + " <param name=\"APPLICATION_URL\" value=\"http://www.jalview.org/services/launchApp\"/>\r\n"