JAL-3210 Barebones gradle/buildship/eclipse. See README
[jalview.git] / src / jalview / javascript / JSFunctionExec.java
index ad7a379..29f3fa9 100644 (file)
  */
 package jalview.javascript;
 
-import jalview.api.JalviewApp;
+import jalview.bin.JalviewLite;
 
 import java.net.URL;
-import java.util.Hashtable;
 import java.util.Vector;
 
 import netscape.javascript.JSObject;
 
 public class JSFunctionExec implements Runnable
 {
-  public JalviewApp jvlite;
+  public JalviewLite jvlite;
 
-  protected boolean debug;
-
-  public JSFunctionExec(JalviewApp applet, boolean debug)
+  public JSFunctionExec(JalviewLite applet)
   {
     jvlite = applet;
-    this.debug = debug;
-    jsExecQueue = jvlite.getJsExecQueue(this);
+
+    jsExecQueue = jvlite.getJsExecQueue();
+    jvlite.setExecutor(this);
   }
 
-  private Vector<Runnable> jsExecQueue;
+  private Vector jsExecQueue;
 
   private Thread executor = null;
 
@@ -49,7 +47,7 @@ public class JSFunctionExec implements Runnable
   {
     if (jsExecQueue != null)
     {
-      Vector<Runnable> q = null;
+      Vector<JSFunctionExec> q = null;
       synchronized (jsExecQueue)
       {
         q = jsExecQueue;
@@ -57,9 +55,9 @@ public class JSFunctionExec implements Runnable
       }
       if (q != null)
       {
-        for (Runnable jx : q)
+        for (JSFunctionExec jx : q)
         {
-          ((JSFunctionExec) jx).jvlite = null;
+          jx.jvlite = null;
 
         }
         q.removeAllElements();
@@ -80,7 +78,7 @@ public class JSFunctionExec implements Runnable
     {
       if (jsExecQueue.size() > 0)
       {
-        Runnable r = jsExecQueue.elementAt(0);
+        Runnable r = (Runnable) jsExecQueue.elementAt(0);
         jsExecQueue.removeElementAt(0);
         try
         {
@@ -164,14 +162,14 @@ public class JSFunctionExec implements Runnable
           JSObject scriptObject = null;
           try
           {
-            scriptObject = jvlite.getJSObject();
+            scriptObject = JSObject.getWindow(jvlite);
           } catch (Exception ex)
           {
           }
           ;
           if (scriptObject != null)
           {
-            if (debug && dbgMsg != null)
+            if (jvlite.debug && dbgMsg != null)
             {
               System.err.println(dbgMsg);
             }
@@ -182,15 +180,15 @@ public class JSFunctionExec implements Runnable
           // squash any malformedURLExceptions thrown by windows/safari
           if (!(jex instanceof java.net.MalformedURLException))
           {
-            if (debug)
+            if (jvlite.debug)
             {
               System.err.println(jex);
             }
             if (jex instanceof netscape.javascript.JSException
-                    && jvlite.isJsfallbackEnabled())
+                    && jvlite.jsfallbackEnabled)
             {
               jsex[0] = jex;
-              if (debug)
+              if (jvlite.debug)
               {
                 System.err.println("Falling back to javascript: url call");
               }
@@ -213,7 +211,7 @@ public class JSFunctionExec implements Runnable
                 sb.append("\"");
               }
               sb.append(")");
-              if (debug)
+              if (jvlite.debug)
               {
                 System.err.println(sb.toString());
               }
@@ -250,7 +248,7 @@ public class JSFunctionExec implements Runnable
     {
       if (executor == null)
       {
-        executor = new Thread(new JSFunctionExec(jvlite, debug));
+        executor = new Thread(new JSFunctionExec(jvlite));
         executor.start();
       }
       synchronized (jsExecQueue)
@@ -270,80 +268,4 @@ public class JSFunctionExec implements Runnable
     }
   }
 
-  public static void setJsMessageSet(String messageclass, String viewId,
-          String[] colcommands, JalviewApp app)
-  {
-    Hashtable<String, Hashtable<String, String[]>> jsmessages = app
-            .getJSMessages();
-    Hashtable<String, int[]> jshashes = app.getJSHashes();
-
-    Hashtable<String, String[]> 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<String, String[]> 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;
-  }
-
 }