+ // callInitCallback();
+ }
+
+ private Hashtable<String, long[]> jshashes = new Hashtable<String, long[]>();
+
+ private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<String, Hashtable<String, String[]>>();
+
+ public void setJsMessageSet(String messageclass, String viewId,
+ String[] colcommands)
+ {
+ Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
+ if (msgset == null)
+ {
+ msgset = new Hashtable<String, String[]>();
+ jsmessages.put(messageclass, msgset);
+ }
+ msgset.put(viewId, colcommands);
+ long[] l = new long[colcommands.length];
+ for (int i = 0; i < colcommands.length; i++)
+ {
+ l[i] = colcommands[i].hashCode();
+ }
+ jshashes.put(messageclass + "|" + viewId, l);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String,
+ * java.lang.String)
+ */
+ public String getJsMessage(String messageclass, String viewId)
+ {
+ Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
+ if (msgset != null)
+ {
+ String[] msgs = msgset.get(viewId);
+ if (msgs != null)
+ {
+ for (int i = 0; i < msgs.length; i++)
+ {
+ if (msgs[i] != null)
+ {
+ String m = msgs[i];
+ msgs[i] = null;
+ return m;
+ }
+ }
+ }
+ }
+ return "";
+ }
+
+ public boolean isJsMessageSetChanged(String string, String string2,
+ String[] colcommands)
+ {
+ long[] l = jshashes.get(string + "|" + string2);
+ if (l == null && colcommands != null)
+ {
+ return true;
+ }
+ for (int i = 0; i < colcommands.length; i++)
+ {
+ if (l[i] != colcommands[i].hashCode())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private Vector jsExecQueue = new Vector();
+
+ public Vector getJsExecQueue()
+ {
+ return jsExecQueue;
+ }
+
+ public void setExecutor(JSFunctionExec jsFunctionExec2)
+ {
+ jsFunctionExec = jsFunctionExec2;
+ }
+
+ /**
+ * return the given colour value parameter or the given default if parameter
+ * not given
+ *
+ * @param colparam
+ * @param defcolour
+ * @return
+ */
+ public Color getDefaultColourParameter(String colparam, Color defcolour)
+ {
+ String colprop = getParameter(colparam);
+ if (colprop == null || colprop.trim().length() == 0)
+ {
+ return defcolour;
+ }
+ Color col = jalview.schemes.ColourSchemeProperty
+ .getAWTColorFromName(colprop);
+ if (col == null)
+ {
+ try
+ {
+ col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
+ } catch (Exception ex)
+ {
+ System.err.println("Couldn't parse '" + colprop
+ + "' as a colour for " + colparam);
+ col = null;
+ }
+ }
+ return (col == null) ? defcolour : col;
+
+ }
+
+ public void openJalviewHelpUrl()
+ {
+ String helpUrl = getParameter("jalviewhelpurl");
+ if (helpUrl == null || helpUrl.trim().length() < 5)
+ {
+ helpUrl = "http://www.jalview.org/help.html";
+ }
+ showURL(helpUrl, "HELP");
+ }
+
+ /**
+ * form a complete URL given a path to a resource and a reference location on
+ * the same server
+ *
+ * @param url
+ * - an absolute path on the same server as localref or a document
+ * located relative to localref
+ * @param localref
+ * - a URL on the same server as url
+ * @return a complete URL for the resource located by url
+ */
+ private String resolveUrlForLocalOrAbsolute(String url, URL localref)
+ {
+ String codebase = localref.toString();
+ if (url.indexOf("/") == 0)
+ {
+ url = codebase.substring(0, codebase.length()
+ - localref.getFile().length())
+ + url;
+ }
+ else
+ {
+ url = localref + url;
+ }
+ return url;
+ }
+
+ /**
+ * open a URL in the browser - resolving it according to relative refs and
+ * coping with javascript: protocol if necessary.
+ *
+ * @param url
+ * @param target
+ */
+ public void showURL(String url, String target)
+ {
+ try
+ {
+ if (url.indexOf(":") == -1)
+ {
+ // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
+ // form valid URL
+ // Should really use docbase, not codebase.
+ URL prepend;
+ url = resolveUrlForLocalOrAbsolute(
+ url,
+ prepend = getDefaultParameter("resolvetocodebase", false) ? getDocumentBase()
+ : getCodeBase());
+ if (debug)
+ {
+ System.err
+ .println("Show url (prepended "
+ + prepend
+ + " - toggle resolvetocodebase if code/docbase resolution is wrong): "
+ + url);
+ }
+ }
+ else
+ {
+ if (debug)
+ {
+ System.err.println("Show url: " + url);
+ }
+ }
+ if (url.indexOf("javascript:") == 0)
+ {
+ // no target for the javascript context
+ getAppletContext().showDocument(new java.net.URL(url));
+ }
+ else
+ {
+ getAppletContext().showDocument(new java.net.URL(url), target);
+ }
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }