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;
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;
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;
dialogExecutor.shutdownNow();
}
closeAll_actionPerformed(null);
+
+ if (groovyConsole != null)
+ {
+ groovyConsole.exit();
+ }
System.exit(0);
}
*/
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);
}
/**