X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FDesktop.java;h=3cc2c1439369bead240cfe297864b14909f56513;hb=c708b0d5bed26752c34e62960f0acdeada8742df;hp=e56c42f2752426bd4aff16730c6042e1a6e7a333;hpb=8c7fd90d480e2671e0fa251ada3c89fa1d18862a;p=jalview.git diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index e56c42f..3cc2c14 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -61,6 +61,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; +import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -82,6 +83,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Semaphore; +import javax.swing.AbstractAction; import javax.swing.DefaultDesktopManager; import javax.swing.DesktopManager; import javax.swing.JButton; @@ -96,6 +98,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JProgressBar; +import javax.swing.KeyStroke; import javax.swing.SwingUtilities; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkEvent.EventType; @@ -822,7 +825,15 @@ public class Desktop extends jalview.jbgui.GDesktop implements javax.swing.event.InternalFrameEvent evt) { PaintRefresher.RemoveComponent(frame); - openFrameCount--; + + /* + * defensive check to prevent frames being + * added half off the window + */ + if (openFrameCount > 0) + { + openFrameCount--; + } windowMenu.remove(menuItem); JInternalFrame itf = desktop.getSelectedFrame(); if (itf != null) @@ -1178,6 +1189,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements dialogExecutor.shutdownNow(); } closeAll_actionPerformed(null); + + if (groovyConsole != null) + { + // suppress a possible repeat prompt to save script + groovyConsole.setDirty(false); + groovyConsole.exit(); + } System.exit(0); } @@ -1796,7 +1814,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements * * @param af */ - public void explodeViews(AlignFrame af) + public static void explodeViews(AlignFrame af) { int size = af.alignPanels.size(); if (size < 2) @@ -2465,39 +2483,63 @@ public class Desktop extends jalview.jbgui.GDesktop implements */ void openGroovyConsole() { - groovyConsole = new groovy.ui.Console(); + if (groovyConsole == null) + { + groovyConsole = new groovy.ui.Console(); + groovyConsole.setVariable("Jalview", this); + groovyConsole.run(); - /* - * bind groovy variable 'Jalview' to the Desktop object - */ - groovyConsole.setVariable("Jalview", this); + /* + * We allow only one console at a time, so that AlignFrame menu option + * 'Calculate | Run Groovy script' is unambiguous. + * Disable 'Groovy Console', and enable 'Run script', when the console is + * opened, and the reverse when it is closed + */ + Window window = (Window) groovyConsole.getFrame(); + window.addWindowListener(new WindowAdapter() + { + @Override + public void windowClosed(WindowEvent e) + { + /* + * rebind CMD-Q from Groovy Console to Jalview Quit + */ + addQuitHandler(); + enableExecuteGroovy(false); + } + }); + } /* - * start the console + * show Groovy console window (after close and reopen) */ - groovyConsole.run(); + ((Window) groovyConsole.getFrame()).setVisible(true); /* - * Allow only one console at a time, so that the AlignFrame menu option - * 'Calculate | Run Groovy script' is unambiguous. - * Disable 'new console', and enable 'Run script', when the console is - * opened, and the reverse when it is closed + * if we got this far, enable 'Run Groovy' in AlignFrame menus + * and disable opening a second console */ - Window window = (Window) groovyConsole.getFrame(); - window.addWindowListener(new WindowAdapter() + enableExecuteGroovy(true); + } + + /** + * Bind Ctrl/Cmd-Q to Quit - for reset as Groovy Console takes over this + * binding when opened + */ + protected void addQuitHandler() + { + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( + KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit + .getDefaultToolkit().getMenuShortcutKeyMask()), + "Quit"); + getRootPane().getActionMap().put("Quit", new AbstractAction() { @Override - public void windowClosed(WindowEvent e) + public void actionPerformed(ActionEvent e) { - enableExecuteGroovy(false); + quit(); } }); - - /* - * if we got this far, enable 'Run Groovy' in AlignFrame menus - * and disable opening a second console - */ - enableExecuteGroovy(true); } /**