+ // callInitCallback();
+ }
+
+ private Hashtable<String, long[]> jshashes = new Hashtable<>();
+
+ private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<>();
+
+ public void setJsMessageSet(String messageclass, String viewId,
+ String[] colcommands)
+ {
+ Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
+ if (msgset == null)
+ {
+ msgset = new Hashtable<>();
+ 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)
+ */
+ @Override
+ 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 = ColorUtils.parseColourString(colprop);
+ if (col == null)
+ {
+ System.err.println("Couldn't parse '" + colprop + "' as a colour for "
+ + colparam);
+ }
+ 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 targetPath
+ * - 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 targetPath,
+ URL localref)
+ {
+ String resolvedPath = "";
+ if (targetPath.startsWith("/"))
+ {
+ String codebase = localref.toString();
+ String localfile = localref.getFile();
+ resolvedPath = codebase.substring(0,
+ codebase.length() - localfile.length()) + targetPath;
+ return resolvedPath;
+ }
+
+ /*
+ * get URL path and strip off any trailing file e.g.
+ * www.jalview.org/examples/index.html#applets?a=b is trimmed to
+ * www.jalview.org/examples/
+ */
+ String urlPath = localref.toString();
+ String directoryPath = urlPath;
+ int lastSeparator = directoryPath.lastIndexOf("/");
+ if (lastSeparator > 0)
+ {
+ directoryPath = directoryPath.substring(0, lastSeparator + 1);
+ }
+
+ if (targetPath.startsWith("/"))
+ {
+ /*
+ * construct absolute URL to a file on the server - this is not allowed?
+ */
+ // String localfile = localref.getFile();
+ // resolvedPath = urlPath.substring(0,
+ // urlPath.length() - localfile.length())
+ // + targetPath;
+ resolvedPath = directoryPath + targetPath.substring(1);
+ }
+ else
+ {
+ resolvedPath = directoryPath + targetPath;
+ }
+ if (debug)
+ {
+ System.err.println(
+ "resolveUrlForLocalOrAbsolute returning " + resolvedPath);
+ }
+ return resolvedPath;
+ }
+
+ /**
+ * 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)
+ ? getCodeBase()
+ : getDocumentBase());
+ 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();
+ }