X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fjavascript%2FJSFunctionExec.java;h=ad7a379abe914be407689ddff8312fe8cb5f4c5e;hb=a83adb45bdf9554e270921b4baad94defd314b36;hp=29f3fa939f7ff60c1ccebdd615c99ded63118d9c;hpb=d4ec118f86b5c9dee801e743c46aaacc7bb521d1;p=jalview.git diff --git a/src/jalview/javascript/JSFunctionExec.java b/src/jalview/javascript/JSFunctionExec.java index 29f3fa9..ad7a379 100644 --- a/src/jalview/javascript/JSFunctionExec.java +++ b/src/jalview/javascript/JSFunctionExec.java @@ -20,26 +20,28 @@ */ package jalview.javascript; -import jalview.bin.JalviewLite; +import jalview.api.JalviewApp; import java.net.URL; +import java.util.Hashtable; import java.util.Vector; import netscape.javascript.JSObject; public class JSFunctionExec implements Runnable { - public JalviewLite jvlite; + public JalviewApp jvlite; - public JSFunctionExec(JalviewLite applet) + protected boolean debug; + + public JSFunctionExec(JalviewApp applet, boolean debug) { jvlite = applet; - - jsExecQueue = jvlite.getJsExecQueue(); - jvlite.setExecutor(this); + this.debug = debug; + jsExecQueue = jvlite.getJsExecQueue(this); } - private Vector jsExecQueue; + private Vector jsExecQueue; private Thread executor = null; @@ -47,7 +49,7 @@ public class JSFunctionExec implements Runnable { if (jsExecQueue != null) { - Vector q = null; + Vector q = null; synchronized (jsExecQueue) { q = jsExecQueue; @@ -55,9 +57,9 @@ public class JSFunctionExec implements Runnable } if (q != null) { - for (JSFunctionExec jx : q) + for (Runnable jx : q) { - jx.jvlite = null; + ((JSFunctionExec) jx).jvlite = null; } q.removeAllElements(); @@ -78,7 +80,7 @@ public class JSFunctionExec implements Runnable { if (jsExecQueue.size() > 0) { - Runnable r = (Runnable) jsExecQueue.elementAt(0); + Runnable r = jsExecQueue.elementAt(0); jsExecQueue.removeElementAt(0); try { @@ -162,14 +164,14 @@ public class JSFunctionExec implements Runnable JSObject scriptObject = null; try { - scriptObject = JSObject.getWindow(jvlite); + scriptObject = jvlite.getJSObject(); } catch (Exception ex) { } ; if (scriptObject != null) { - if (jvlite.debug && dbgMsg != null) + if (debug && dbgMsg != null) { System.err.println(dbgMsg); } @@ -180,15 +182,15 @@ public class JSFunctionExec implements Runnable // squash any malformedURLExceptions thrown by windows/safari if (!(jex instanceof java.net.MalformedURLException)) { - if (jvlite.debug) + if (debug) { System.err.println(jex); } if (jex instanceof netscape.javascript.JSException - && jvlite.jsfallbackEnabled) + && jvlite.isJsfallbackEnabled()) { jsex[0] = jex; - if (jvlite.debug) + if (debug) { System.err.println("Falling back to javascript: url call"); } @@ -211,7 +213,7 @@ public class JSFunctionExec implements Runnable sb.append("\""); } sb.append(")"); - if (jvlite.debug) + if (debug) { System.err.println(sb.toString()); } @@ -248,7 +250,7 @@ public class JSFunctionExec implements Runnable { if (executor == null) { - executor = new Thread(new JSFunctionExec(jvlite)); + executor = new Thread(new JSFunctionExec(jvlite, debug)); executor.start(); } synchronized (jsExecQueue) @@ -268,4 +270,80 @@ public class JSFunctionExec implements Runnable } } + public static void setJsMessageSet(String messageclass, String viewId, + String[] colcommands, JalviewApp app) + { + Hashtable> jsmessages = app + .getJSMessages(); + Hashtable jshashes = app.getJSHashes(); + + Hashtable msgset = jsmessages.get(messageclass); + if (msgset == null) + { + msgset = new Hashtable<>(); + jsmessages.put(messageclass, msgset); + } + msgset.put(viewId, colcommands); + int[] l = new int[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 static String getJsMessage(String messageclass, String viewId, + JalviewApp app) + { + Hashtable msgset = app.getJSMessages() + .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 static boolean isJsMessageSetChanged(String string, String string2, + String[] colcommands, JalviewApp app) + { + int[] l = app.getJSHashes().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; + } + + public void tidyUp() + { + stopQueue(); + jvlite = null; + } + }