JAL-3518 pull up closeViewer() and external viewer process monitor
[jalview.git] / src / jalview / ext / rbvi / chimera / JalviewChimeraBinding.java
index 460b156..bc4eef4 100644 (file)
@@ -37,7 +37,6 @@ import ext.edu.ucsf.rbvi.strucviz2.ChimeraModel;
 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
 import ext.edu.ucsf.rbvi.strucviz2.StructureManager.ModelType;
 import jalview.api.AlignmentViewPanel;
-import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.bin.Cache;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.PDBEntry;
@@ -78,8 +77,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
 
   String lastHighlightCommand;
 
-  private Thread chimeraMonitor;
-
   /**
    * Open a PDB structure file in Chimera and set up mappings from Jalview.
    * 
@@ -186,37 +183,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   }
 
   /**
-   * Starts a thread that waits for the Chimera process to finish, so that we can
-   * then close the associated resources. This avoids leaving orphaned Chimera
-   * viewer panels in Jalview if the user closes Chimera.
-   */
-  protected void startChimeraProcessMonitor()
-  {
-    final Process p = chimeraManager.getChimeraProcess();
-    chimeraMonitor = new Thread(new Runnable()
-    {
-
-      @Override
-      public void run()
-      {
-        try
-        {
-          p.waitFor();
-          JalviewStructureDisplayI display = getViewer();
-          if (display != null)
-          {
-            display.closeViewer(false);
-          }
-        } catch (InterruptedException e)
-        {
-          // exit thread if Chimera Viewer is closed in Jalview
-        }
-      }
-    });
-    chimeraMonitor.start();
-  }
-
-  /**
    * Start a dedicated HttpServer to listen for Chimera notifications, and tell it
    * to start listening
    */
@@ -241,21 +207,13 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   public void closeViewer(boolean closeChimera)
   {
     super.closeViewer(closeChimera);
-    if (closeChimera)
-    {
-      chimeraManager.exitChimera();
-    }
     if (this.chimeraListener != null)
     {
       chimeraListener.shutdown();
       chimeraListener = null;
     }
+    chimeraManager.clearOnChimeraExit();
     chimeraManager = null;
-
-    if (chimeraMonitor != null)
-    {
-      chimeraMonitor.interrupt();
-    }
   }
 
   /**
@@ -306,7 +264,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
     boolean launched = chimeraManager.launchChimera(getChimeraPaths());
     if (launched)
     {
-      startChimeraProcessMonitor();
+      startExternalViewerMonitor(chimeraManager.getChimeraProcess());
     }
     else
     {
@@ -500,7 +458,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
         atomSpecs.add(spec);
       } catch (IllegalArgumentException e)
       {
-        System.err.println("Failed to parse atomspec: " + atomSpec);
+        Cache.log.error("Failed to parse atomspec: " + atomSpec);
       }
     }
     return atomSpecs;