JAL-629 Change all stdout and stderr output to use Console.outPrintln and Console...
[jalview.git] / src / jalview / ext / jmol / JalviewJmolBinding.java
index 895db9a..870db65 100644 (file)
@@ -122,8 +122,21 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
 
   private String jmolScript(String script)
   {
+    return jmolScript(script, false);
+  }
+
+  private String jmolScript(String script, boolean useScriptWait)
+  {
     Console.debug(">>Jmol>> " + script);
-    String s = jmolViewer.evalStringQuiet(script); // scriptWait(script); BH
+    String s;
+    if (useScriptWait)
+    {
+      s = jmolViewer.scriptWait(script);
+    }
+    else
+    {
+      s = jmolViewer.evalStringQuiet(script); // scriptWait(script); BH
+    }
     Console.debug("<<Jmol<< " + s);
 
     return s;
@@ -150,21 +163,21 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
 
   public void createImage(String file, String type, int quality)
   {
-    System.out.println("JMOL CREATE IMAGE");
+    jalview.bin.Console.outPrintln("JMOL CREATE IMAGE");
   }
 
   @Override
   public String createImage(String fileName, String type,
           Object textOrBytes, int quality)
   {
-    System.out.println("JMOL CREATE IMAGE");
+    jalview.bin.Console.outPrintln("JMOL CREATE IMAGE");
     return null;
   }
 
   @Override
   public String eval(String strEval)
   {
-    // System.out.println(strEval);
+    // jalview.bin.Console.outPrintln(strEval);
     // "# 'eval' is implemented only for the applet.";
     return null;
   }
@@ -254,22 +267,47 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
   {
     if (atoms != null)
     {
+      boolean useScriptWait = atoms.size() > 1;
       if (resetLastRes.length() > 0)
       {
-        jmolScript(resetLastRes.toString());
+        jmolScript(resetLastRes.toString(), useScriptWait);
         resetLastRes.setLength(0);
       }
       for (AtomSpec atom : atoms)
       {
         highlightAtom(atom.getAtomIndex(), atom.getPdbResNum(),
-                atom.getChain(), atom.getPdbFile());
+                atom.getChain(), atom.getPdbFile(), useScriptWait);
       }
+      // Highlight distances between atoms with a 'measure' command - not yet
+      // working
+      // if (atoms.size() >= 2)
+      // {
+      // StringBuilder sb = new StringBuilder();
+      // for (int a = 0; a < atoms.size(); a++)
+      // {
+      // AtomSpec speca = atoms.get(a);
+      // String a_model = getModelIdForFile(speca.getPdbFile());
+      // for (int b = a + 1; b < atoms.size(); b++)
+      // {
+      // AtomSpec specb = atoms.get(b);
+      // String b_model = getModelIdForFile(speca.getPdbFile());
+      // sb.append("measure ALL (" + speca.getAtomIndex() + " and */"
+      // + a_model + ") (" + specb.getAtomIndex() + " and */"
+      // + b_model + ");");
+      // }
+      // }
+      // jmolHistory(false, useScriptWait);
+      // jmolScript(sb.toString(), useScriptWait);
+      // jmolHistory(true, useScriptWait);
+      // }
+
     }
+
   }
 
   // jmol/ssm only
   public void highlightAtom(int atomIndex, int pdbResNum, String chain,
-          String pdbfile)
+          String pdbfile, boolean useScriptWait)
   {
     String modelId = getModelIdForFile(pdbfile);
     if (modelId.isEmpty())
@@ -277,7 +315,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
       return;
     }
 
-    jmolHistory(false);
+    jmolHistory(false, useScriptWait);
 
     StringBuilder selection = new StringBuilder(32);
     StringBuilder cmd = new StringBuilder(64);
@@ -295,15 +333,21 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
     resetLastRes.append(selection).append(";wireframe 0;").append(selection)
             .append(" and not hetero; spacefill 0;");
 
-    jmolScript(cmd.toString());
-    jmolHistory(true);
+    jmolScript(cmd.toString(), useScriptWait);
+    jmolHistory(true, useScriptWait);
   }
 
   private boolean debug = true;
 
   private void jmolHistory(boolean enable)
   {
-    jmolScript("History " + ((debug || enable) ? "on" : "off"));
+    jmolHistory(enable, false);
+  }
+
+  private void jmolHistory(boolean enable, boolean useScriptWait)
+  {
+    jmolScript("History " + ((debug || enable) ? "on" : "off"),
+            useScriptWait);
   }
 
   public void loadInline(String string)
@@ -432,7 +476,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
     lastMessage = strInfo;
     if (data != null)
     {
-      System.err.println("Ignoring additional hover info: " + data
+      jalview.bin.Console.errPrintln("Ignoring additional hover info: " + data
               + " (other info: '" + strInfo + "' pos " + atomIndex + ")");
     }
     mouseOverStructure(atomIndex, strInfo);
@@ -453,7 +497,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
      */
     if (strData != null)
     {
-      System.err.println("Ignoring additional pick data string " + strData);
+      jalview.bin.Console.errPrintln("Ignoring additional pick data string " + strData);
     }
     int chainSeparator = strInfo.indexOf(":");
     int p = 0;
@@ -555,7 +599,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
                 (data == null) ? ((String) null) : (String) data[1]);
         break;
       case ERROR:
-        // System.err.println("Ignoring error callback.");
+        // jalview.bin.Console.errPrintln("Ignoring error callback.");
         break;
       case SYNC:
       case RESIZE:
@@ -565,13 +609,13 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
 
       case CLICK:
       default:
-        System.err.println(
+        jalview.bin.Console.errPrintln(
                 "Unhandled callback " + type + " " + data[1].toString());
         break;
       }
     } catch (Exception e)
     {
-      System.err.println("Squashed Jmol callback handler error:");
+      jalview.bin.Console.errPrintln("Squashed Jmol callback handler error:");
       e.printStackTrace();
     }
   }
@@ -820,7 +864,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
   public void setCallbackFunction(String callbackType,
           String callbackFunction)
   {
-    System.err.println("Ignoring set-callback request to associate "
+    jalview.bin.Console.errPrintln("Ignoring set-callback request to associate "
             + callbackType + " with function " + callbackFunction);
 
   }
@@ -894,7 +938,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
           String buttonsToShow)
   {
 
-    System.err.println("Allocating Jmol Viewer: " + commandOptions);
+    jalview.bin.Console.errPrintln("Allocating Jmol Viewer: " + commandOptions);
 
     if (commandOptions == null)
     {
@@ -912,7 +956,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
       console = createJmolConsole(consolePanel, buttonsToShow);
     } catch (Throwable e)
     {
-      System.err.println("Could not create Jmol application console. "
+      jalview.bin.Console.errPrintln("Could not create Jmol application console. "
               + e.getMessage());
       e.printStackTrace();
     }