JAL-2358 ensure mappings removed on close Chimera; pull up method;
[jalview.git] / src / jalview / gui / ChimeraViewFrame.java
index ab23e62..7cf3bfc 100644 (file)
@@ -66,7 +66,6 @@ import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JColorChooser;
 import javax.swing.JInternalFrame;
 import javax.swing.JMenu;
-import javax.swing.JOptionPane;
 import javax.swing.event.InternalFrameAdapter;
 import javax.swing.event.InternalFrameEvent;
 import javax.swing.event.MenuEvent;
@@ -341,28 +340,6 @@ public class ChimeraViewFrame extends StructureViewerBase
     setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
   }
 
-  /**
-   * Returns a list of any Chimera viewers in the desktop. The list is
-   * restricted to those linked to the given alignment panel if it is not null.
-   */
-  @Override
-  protected List<StructureViewerBase> getViewersFor(AlignmentPanel ap)
-  {
-    List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
-    JInternalFrame[] frames = Desktop.instance.getAllFrames();
-
-    for (JInternalFrame frame : frames)
-    {
-      if (frame instanceof ChimeraViewFrame)
-      {
-        if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap))
-        {
-          result.add((StructureViewerBase) frame);
-        }
-      }
-    }
-    return result;
-  }
 
   /**
    * Launch Chimera. If we have a chimera session file name, send Chimera the
@@ -377,10 +354,10 @@ public class ChimeraViewFrame extends StructureViewerBase
 
     if (!jmb.launchChimera())
     {
-      JOptionPane.showMessageDialog(Desktop.desktop,
+      JvOptionPane.showMessageDialog(Desktop.desktop,
               MessageManager.getString("label.chimera_failed"),
               MessageManager.getString("label.error_loading_file"),
-              JOptionPane.ERROR_MESSAGE);
+              JvOptionPane.ERROR_MESSAGE);
       this.dispose();
       return;
     }
@@ -427,35 +404,47 @@ public class ChimeraViewFrame extends StructureViewerBase
    * option to close the associated Chimera window (process). They may wish to
    * keep it open until they have had an opportunity to save any work.
    * 
-   * @param closeChimera
+   * @param forceCloseChimera
    *          if true, close any linked Chimera process; if false, prompt first
    */
   @Override
-  public void closeViewer(boolean closeChimera)
+  public void closeViewer(boolean forceCloseChimera)
   {
-    if (jmb != null && jmb.isChimeraRunning())
+    if (jmb != null)
     {
-      if (!closeChimera)
+      if (jmb.isChimeraRunning())
       {
-        String prompt = MessageManager.formatMessage(
-                "label.confirm_close_chimera",
-                new Object[] { jmb.getViewerTitle("Chimera", false) });
-        prompt = JvSwingUtils.wrapTooltip(true, prompt);
-        int confirm = JOptionPane.showConfirmDialog(this, prompt,
-                MessageManager.getString("label.close_viewer"),
-                JOptionPane.YES_NO_CANCEL_OPTION);
         /*
-         * abort closure if user hits escape or Cancel
+         * force close, or prompt to close, Chimera
          */
-        if (confirm == JOptionPane.CANCEL_OPTION
-                || confirm == JOptionPane.CLOSED_OPTION)
+        if (!forceCloseChimera)
         {
-          return;
+          String prompt = MessageManager.formatMessage(
+                  "label.confirm_close_chimera",
+                  new Object[] { jmb.getViewerTitle("Chimera", false) });
+          prompt = JvSwingUtils.wrapTooltip(true, prompt);
+          int confirm = JvOptionPane.showConfirmDialog(this, prompt,
+                  MessageManager.getString("label.close_viewer"),
+                  JvOptionPane.YES_NO_CANCEL_OPTION);
+          /*
+           * abort closure if user hits escape or Cancel
+           */
+          if (confirm == JvOptionPane.CANCEL_OPTION
+                  || confirm == JvOptionPane.CLOSED_OPTION)
+          {
+            return;
+          }
+          forceCloseChimera = confirm == JvOptionPane.YES_OPTION;
         }
-        closeChimera = confirm == JOptionPane.YES_OPTION;
       }
-      jmb.closeViewer(closeChimera);
+
+      /*
+       * close the viewer plus any side-effects e.g. remove mappings
+       * note we do this also if closing Chimera triggered this method
+       */
+      jmb.closeViewer(forceCloseChimera);
     }
+
     setAlignmentPanel(null);
     _aps.clear();
     _alignwith.clear();
@@ -541,11 +530,11 @@ public class ChimeraViewFrame extends StructureViewerBase
     if (errormsgs.length() > 0)
     {
 
-      JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
+      JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
               .formatMessage("label.pdb_entries_couldnt_be_retrieved",
                       new Object[] { errormsgs.toString() }),
               MessageManager.getString("label.couldnt_load_file"),
-              JOptionPane.ERROR_MESSAGE);
+              JvOptionPane.ERROR_MESSAGE);
     }
 
     if (files.length() > 0)