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;
static final int yOffset = 30;
- private static AlignFrame currentAlignFrame;
-
public static jalview.ws.jws1.Discoverer discoverer;
public static Object[] jalviewClipboard;
dialogExecutor.shutdownNow();
}
closeAll_actionPerformed(null);
+
+ if (groovyConsole != null)
+ {
+ // suppress a possible repeat prompt to save script
+ groovyConsole.setDirty(false);
+ groovyConsole.exit();
+ }
System.exit(0);
}
*
* @param af
*/
- public void explodeViews(AlignFrame af)
+ public static void explodeViews(AlignFrame af)
{
int size = af.alignPanels.size();
if (size < 2)
if (Jalview.isHeadlessMode())
{
// Desktop.desktop is null in headless mode
- return new AlignFrame[] { currentAlignFrame };
+ return new AlignFrame[] { Jalview.currentAlignFrame };
}
JInternalFrame[] frames = Desktop.desktop.getAllFrames();
*/
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)
{
- groovyShell.setEnabled(true);
- enableExecuteGroovy(false);
+ quit();
}
});
-
- /*
- * if we got this far, enable 'Run Groovy' in AlignFrame menus
- * and disable opening a second console
- */
- groovyShell.setEnabled(false);
- enableExecuteGroovy(true);
}
/**
* Enable or disable 'Run Groovy script' in AlignFrame calculate menus
*
* @param enabled
+ * true if Groovy console is open
*/
public void enableExecuteGroovy(boolean enabled)
{
+ /*
+ * disable opening a second Groovy console
+ * (or re-enable when the console is closed)
+ */
+ groovyShell.setEnabled(!enabled);
+
AlignFrame[] alignFrames = getAlignFrames();
if (alignFrames != null)
{
* The dust settles...give focus to the tab we did this from.
*/
myTopFrame.setDisplayedView(myTopFrame.alignPanel);
-
- }
-
- public static AlignFrame getCurrentAlignFrame()
- {
- return currentAlignFrame;
- }
-
- public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
- {
- Desktop.currentAlignFrame = currentAlignFrame;
}
public static groovy.ui.Console getGroovyConsole()
// Works on Windows and MacOSX
Cache.log.debug("Drop handled as javaFileListFlavor");
evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
- files.addAll((java.util.List<String>) t
- .getTransferData(DataFlavor.javaFileListFlavor));
+ for (Object file : (List) t
+ .getTransferData(DataFlavor.javaFileListFlavor))
+ {
+ files.add(((File)file).toString());
+ protocols.add(FormatAdapter.FILE);
+ }
}
else
{