package jalview.bin; import java.util.HashMap; import java.util.Map; /** * Collection of all known applet tags from JalviewLite * * @author hansonr * */ @SuppressWarnings("serial") public class AppletParams extends HashMap { private final static String[] params = { "alignpdbfiles", "ANNOTATIONCOLOUR_MAX", "ANNOTATIONCOLOUR_MIN", "annotations", "APPLICATION_URL", "automaticScrolling", "centrecolumnlabels", "debug", "defaultColour", "defaultColourNuc", "defaultColourProt", "embedded", "enableSplitFrame", "externalstructureviewer", "features", "file", "file2", "format", "heightScale", "hidefeaturegroups", "jalviewhelpurl", "jnetfile", "jpredfile", "label", "linkLabel_", "linkLabel_1", "linkURL_", "nojmol", "normaliseLogo", "normaliseSequenceLogo", "oninit", "PDBFILE", "PDBSEQ", "relaxedidmatch", "resolvetocodebase", "RGB", "scaleProteinAsCdna", "scoreFile", "separator", "sequence", "showAnnotation", "showbutton", "showConsensus", "showConsensusHistogram", "showConservation", "showfeaturegroups", "showFeatureSettings", "showFullId", "showGroupConsensus", "showGroupConservation", "showOccupancy", "showQuality", "showSequenceLogo", "showTreeBootstraps", "showTreeDistances", "showUnconserved", "showUnlinkedTreeNodes", "sortBy", "sortByTree", "tree", "treeFile", "upperCase", "userDefinedColour", "widthScale", "windowHeight", "windowWidth", "wrap", }; public AppletParams(Map info) { for (int i = params.length; --i >= 0;) { put(params[i], info.get(params[i])); } } public String getParam(String param, String def) { String val = get(param); return (val != null ? val : def); } // // // // // // // // // // // // // // // // public AppletParams(String outerHTML) { String[] tokens = outerHTML.split(" 0;) { String param = tokens[i]; String key = getAttr(param, "name"); if (key != null) { String value = getAttr(param, "value"); System.out.println("AppletParams " + key + " = \"" + value + "\""); put(key, value); } } put("_width", getAttr(outerHTML, "width")); put("_height", getAttr(outerHTML, "height")); put("_id", getAttr(outerHTML, "id")); put("_name", getAttr(outerHTML, "name")); put("_archive", getAttr(outerHTML, "archive")); put("_code", code); } /** * Crude applet innerHTML parser * * @param tag * @param attr * @return */ private String getAttr(String tag, String attr) { int pt = tag.indexOf(attr + "=\""); if (pt < 0) { System.out .println("AppletParams did not read " + attr + " in " + tag); return null; } // int pt1 = pt + attr.length() + 2; int pt2 = tag.indexOf("\"", pt1); return (pt < 0 ? null : tag.substring(pt1, pt2)); } public static void main(String[] args) { new AppletParams(" \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " "); } }