JAL-1725 first version of Jetty server / chimera selection listener
[jalview.git] / src / ext / edu / ucsf / rbvi / strucviz2 / ChimeraManager.java
index b74e65a..3ed27a3 100644 (file)
@@ -1,7 +1,5 @@
 package ext.edu.ucsf.rbvi.strucviz2;
 
-import jalview.ws.HttpClientUtils;
-
 import java.awt.Color;
 import java.io.BufferedReader;
 import java.io.File;
@@ -22,6 +20,8 @@ import org.slf4j.LoggerFactory;
 import ext.edu.ucsf.rbvi.strucviz2.StructureManager.ModelType;
 import ext.edu.ucsf.rbvi.strucviz2.port.ListenerThreads;
 
+import jalview.ws.HttpClientUtils;
+
 /**
  * This object maintains the Chimera communication information.
  */
@@ -177,7 +177,7 @@ public class ChimeraManager
           ModelType type)
   {
     logger.info("chimera open " + modelPath);
-    stopListening();
+    // stopListening();
     List<String> response = null;
     // TODO: [Optional] Handle modbase models
     if (type == ModelType.MODBASE_MODEL)
@@ -281,7 +281,7 @@ public class ChimeraManager
     }
 
     sendChimeraCommand("focus", false);
-    startListening();
+    // startListening(); // see ChimeraListener
     return models;
   }
 
@@ -339,12 +339,35 @@ public class ChimeraManager
 
   public void startListening()
   {
-    sendChimeraCommand("listen start models; listen start select", false);
+    sendChimeraCommand("listen start models; listen start selection", false);
   }
 
   public void stopListening()
   {
-    sendChimeraCommand("listen stop models; listen stop select", false);
+    sendChimeraCommand("listen stop models; listen stop selection", false);
+  }
+
+  /**
+   * Tell Chimera we are listening on the given URI
+   * 
+   * @param uri
+   */
+  public void startListening(String uri)
+  {
+    sendChimeraCommand("listen start models url " + uri, false);
+    sendChimeraCommand("listen start select prefix SelectionChanged url "
+            + uri, false);
+  }
+
+  /**
+   * Tell Chimera we have stopped listening on the given URI
+   * 
+   * @param uri
+   */
+  public void stopListening(String uri)
+  {
+    sendChimeraCommand("listen stop models url " + uri, false);
+    sendChimeraCommand("listen stop selection url " + uri, false);
   }
 
   /**
@@ -355,8 +378,8 @@ public class ChimeraManager
    */
   public void select(String command)
   {
-    sendChimeraCommand("listen stop select; " + command
-            + "; listen start select", false);
+    sendChimeraCommand("listen stop selection; " + command
+            + "; listen start selection", false);
   }
 
   public void focus()
@@ -407,6 +430,12 @@ public class ChimeraManager
     return selectedModelsMap;
   }
 
+  /**
+   * Sends a 'list selection level residue' command to Chimera and returns the
+   * list of selected atomspecs
+   * 
+   * @return
+   */
   public List<String> getSelectedResidueSpecs()
   {
     List<String> selectedResidues = new ArrayList<String>();
@@ -561,7 +590,7 @@ public class ChimeraManager
       structureManager.setChimeraPathProperty(workingPath);
       // TODO: [Optional] Check Chimera version and show a warning if below 1.8
       // Ask Chimera to give us updates
-      startListening();
+      // startListening(); // later - see ChimeraListener
       return true;
     }
 
@@ -775,6 +804,7 @@ public class ChimeraManager
    */
   protected List<String> sendRestCommand(String command)
   {
+    // System.out.println("Rest: " + command);
     // TODO start a separate thread to do this so we don't block?
     String restUrl = "http://127.0.0.1:" + this.chimeraRestPort + "/run";
     List<NameValuePair> commands = new ArrayList<NameValuePair>(1);
@@ -850,5 +880,4 @@ public class ChimeraManager
   {
     return busy;
   }
-
 }