Merge branch 'develop' of http://source.jalview.org/git/jalview into develop
authorJim Procter <jprocter@issues.jalview.org>
Tue, 21 Jun 2016 14:58:43 +0000 (15:58 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Tue, 21 Jun 2016 14:58:43 +0000 (15:58 +0100)
src/jalview/gui/Desktop.java
test/jalview/ext/so/SequenceOntologyTest.java
test/jalview/ws/jabaws/RNAStructExportImport.java

index e56c42f..d54e553 100644 (file)
@@ -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;
@@ -1178,6 +1181,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);
   }
 
@@ -2465,39 +2475,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);
   }
 
   /**
index 1ebc42c..ea92e3c 100644 (file)
@@ -3,10 +3,8 @@ package jalview.ext.so;
 import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertTrue;
 
-import jalview.io.gff.SequenceOntologyFactory;
 import jalview.io.gff.SequenceOntologyI;
 
-import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
@@ -17,17 +15,17 @@ public class SequenceOntologyTest
   @BeforeClass(alwaysRun = true)
   public void setUp() {
     long now = System.currentTimeMillis();
-    SequenceOntologyFactory.setInstance(new SequenceOntology());
+    try
+    {
+      so = new SequenceOntology();
+    } catch (Throwable t)
+    {
+      System.out.println("SOTest error ");
+      t.printStackTrace(System.err);
+    }
     long elapsed = System.currentTimeMillis() - now;
     System.out.println("Load and cache of Sequence Ontology took "
             + elapsed + "ms");
-    so = SequenceOntologyFactory.getInstance();
-  }
-
-  @AfterClass(alwaysRun = true)
-  public void tearDown()
-  {
-    SequenceOntologyFactory.setInstance(null);
   }
 
   @Test(groups = "Functional")
index 24578f1..fe96e07 100644 (file)
@@ -36,6 +36,7 @@ import jalview.ws.jws2.jabaws2.Jws2Instance;
 import jalview.ws.params.AutoCalcSetting;
 
 import java.awt.Component;
+import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -51,6 +52,8 @@ import compbio.metadata.WrongParameterException;
 
 public class RNAStructExportImport
 {
+  private static final String JAR_FILE_NAME = "testRnalifold_param.jar";
+
   public static String testseqs = "examples/RF00031_folded.stk";
 
   public static Jws2Discoverer disc;
@@ -115,6 +118,11 @@ public class RNAStructExportImport
     {
       af.setVisible(false);
       af.dispose();
+      File f = new File(JAR_FILE_NAME);
+      if (f.exists())
+      {
+        f.delete();
+      }
     }
   }
 
@@ -267,10 +275,10 @@ public class RNAStructExportImport
     // write out parameters
     jalview.gui.AlignFrame nalf = null;
     assertTrue("Couldn't write out the Jar file",
-            new Jalview2XML(false).saveAlignment(af,
-                    "testRnalifold_param.jar", "trial parameter writeout"));
+            new Jalview2XML(false).saveAlignment(af, JAR_FILE_NAME,
+                    "trial parameter writeout"));
     assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
-            false).loadJalviewAlign("testRnalifold_param.jar")) != null);
+            false).loadJalviewAlign(JAR_FILE_NAME)) != null);
     if (nalf != null)
     {
       AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(