+ if (getBinding() == null)
+ {
+ return null;
+ }
+ File session = getBinding().saveSession();
+ long l = session.length();
+ int wait = 50;
+ do
+ {
+ try
+ {
+ Thread.sleep(5);
+ } catch (InterruptedException e)
+ {
+ }
+ long nextl = session.length();
+ if (nextl != l)
+ {
+ wait = 50;
+ l = nextl;
+ }
+ } while (--wait > 0);
+ return session;
+ }
+
+ private static boolean quitClose = false;
+
+ public static void setQuitClose(boolean b)
+ {
+ quitClose = b;
+ }
+
+ @Override
+ public boolean stillRunning()
+ {
+ AAStructureBindingModel binding = getBinding();
+ return binding != null && binding.isViewerRunning();
+ }
+
+ /**
+ * Close down this instance of Jalview's Chimera viewer, giving the user the
+ * 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 forceClose
+ * if true, close any linked Chimera process; if false, prompt first
+ */
+ @Override
+ public void closeViewer(boolean forceClose)
+ {
+ AAStructureBindingModel binding = getBinding();
+ if (stillRunning())
+ {
+ if (!forceClose)
+ {
+ String viewerName = getViewerName();
+
+ int confirm = JvOptionPane.CANCEL_OPTION;
+ if (QuitHandler.quitting())
+ {
+ // already asked about closing external windows
+ confirm = quitClose ? JvOptionPane.YES_OPTION
+ : JvOptionPane.NO_OPTION;
+ }
+ else
+ {
+ String prompt = MessageManager
+ .formatMessage("label.confirm_close_viewer", new Object[]
+ { binding.getViewerTitle(viewerName, false),
+ viewerName });
+ prompt = JvSwingUtils.wrapTooltip(true, prompt);
+ String title = MessageManager.getString("label.close_viewer");
+ confirm = showCloseDialog(title, prompt);
+ }
+
+ /*
+ * abort closure if user hits escape or Cancel
+ */
+ if (confirm == JvOptionPane.CANCEL_OPTION
+ || confirm == JvOptionPane.CLOSED_OPTION)
+ {
+ // abort possible quit handling if CANCEL chosen
+ if (confirm == JvOptionPane.CANCEL_OPTION)
+ {
+ try
+ {
+ // this is a bit futile
+ this.setClosed(false);
+ } catch (PropertyVetoException e)
+ {
+ }
+ QuitHandler.abortQuit();
+ }
+ return;
+ }
+ forceClose = confirm == JvOptionPane.YES_OPTION;
+ }
+ }
+ if (binding != null)
+ {
+ binding.closeViewer(forceClose);
+ }
+ setAlignmentPanel(null);
+ _aps.clear();
+ _alignwith.clear();
+ _colourwith.clear();
+ // TODO: check for memory leaks where instance isn't finalised because jmb
+ // holds a reference to the window
+ // jmb = null;
+
+ try
+ {
+ svbs.remove(this);
+ } catch (Throwable t)
+ {
+ Console.info(
+ "Unexpected exception when deregistering structure viewer",
+ t);
+ }
+ dispose();
+ }
+
+ private int showCloseDialog(final String title, final String prompt)
+ {
+ int confirmResponse = JvOptionPane.CANCEL_OPTION;
+ confirmResponse = JvOptionPane.showConfirmDialog(this, prompt,
+ MessageManager.getString("label.close_viewer"),
+ JvOptionPane.YES_NO_CANCEL_OPTION,
+ JvOptionPane.WARNING_MESSAGE);
+ return confirmResponse;
+ }
+
+ @Override
+ public void showHelp_actionPerformed()
+ {
+ /*
+ try
+ {
+ */
+ String url = getBinding().getHelpURL();
+ if (url != null)
+ {
+ BrowserLauncher.openURL(url);
+ }
+ /*
+ }
+ catch (IOException ex)
+ {
+ System.err
+ .println("Show " + getViewerName() + " failed with: "
+ + ex.getMessage());
+ }
+ */
+ }
+
+ @Override
+ public boolean hasViewerActionsMenu()
+ {
+ return viewerActionMenu != null && viewerActionMenu.isEnabled()
+ && viewerActionMenu.getItemCount() > 0
+ && viewerActionMenu.isVisible();