JAL-1528 Chimera tidy errors, focus after align, close option
[jalview.git] / src / jalview / ext / rbvi / chimera / JalviewChimeraBinding.java
index 3f2d5e4..7033ba7 100644 (file)
@@ -254,12 +254,13 @@ public abstract class JalviewChimeraBinding extends
   }
 
   /**
-   * construct a title string for the viewer window based on the data jalview
+   * Construct a title string for the viewer window based on the data Jalview
    * knows about
    * 
+   * @param verbose
    * @return
    */
-  public String getViewerTitle()
+  public String getViewerTitle(boolean verbose)
   {
     if (sequence == null || pdbentry == null || sequence.length < 1
             || pdbentry.length < 1 || sequence[0].length < 1)
@@ -268,20 +269,24 @@ public abstract class JalviewChimeraBinding extends
     }
     // TODO: give a more informative title when multiple structures are
     // displayed.
-    StringBuffer title = new StringBuffer("Chimera view for "
-            + sequence[0][0].getName() + ":" + pdbentry[0].getId());
+    StringBuilder title = new StringBuilder(64);
+    title.append("Chimera view for " + sequence[0][0].getName() + ":"
+            + pdbentry[0].getId());
 
-    if (pdbentry[0].getProperty() != null)
+    if (verbose)
     {
-      if (pdbentry[0].getProperty().get("method") != null)
+      if (pdbentry[0].getProperty() != null)
       {
-        title.append(" Method: ");
-        title.append(pdbentry[0].getProperty().get("method"));
-      }
-      if (pdbentry[0].getProperty().get("chains") != null)
-      {
-        title.append(" Chain:");
-        title.append(pdbentry[0].getProperty().get("chains"));
+        if (pdbentry[0].getProperty().get("method") != null)
+        {
+          title.append(" Method: ");
+          title.append(pdbentry[0].getProperty().get("method"));
+        }
+        if (pdbentry[0].getProperty().get("chains") != null)
+        {
+          title.append(" Chain:");
+          title.append(pdbentry[0].getProperty().get("chains"));
+        }
       }
     }
     return title.toString();
@@ -319,11 +324,17 @@ public abstract class JalviewChimeraBinding extends
             + ";focus " + cmdstring, false);
   }
 
-  public void closeViewer()
+  /**
+   * Close down the Jalview viewer, and (optionally) the associate Chimera
+   * window.
+   */
+  public void closeViewer(boolean closeChimera)
   {
     ssm.removeStructureViewerListener(this, this.getPdbFile());
-    // and shut down Chimera
-    viewer.exitChimera();
+    if (closeChimera)
+    {
+      viewer.exitChimera();
+    }
     // viewer.evalStringQuiet("zap");
     // viewer.setJmolStatusListener(null);
     lastCommand = null;
@@ -670,7 +681,7 @@ public abstract class JalviewChimeraBinding extends
       }
       System.out.println("Select regions:\n" + selectioncom.toString());
       allComs.append("; ~display all; chain @CA|P; ribbon "
-              + selectioncom.toString() + "");
+              + selectioncom.toString() + "; focus");
       // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString());
       evalStateCommand(allComs.toString(), true /* false */);
     }
@@ -689,7 +700,24 @@ public abstract class JalviewChimeraBinding extends
     }
   }
 
-  public void evalStateCommand(final String command, boolean resp)
+  /**
+   * Answers true if the Chimera process is still running, false if ended or not
+   * started.
+   * 
+   * @return
+   */
+  public boolean isChimeraRunning()
+  {
+    return viewer.isChimeraLaunched();
+  }
+
+  /**
+   * Send a command to Chimera, and optionally log any responses.
+   * 
+   * @param command
+   * @param logResponse
+   */
+  public void evalStateCommand(final String command, boolean logResponse)
   {
     viewerCommandHistory(false);
     checkLaunched();
@@ -701,8 +729,8 @@ public abstract class JalviewChimeraBinding extends
 //        public void run()
 //        {
       // trim command or it may never find a match in the replyLog!!
-      lastReply = viewer.sendChimeraCommand(command.trim(), resp);
-      if (debug && resp)
+      lastReply = viewer.sendChimeraCommand(command.trim(), logResponse);
+      if (debug && logResponse)
           {
             log("Response from command ('" + command + "') was:\n"
                     + lastReply);