JAL-3130 Helper classes to take Class Exceptions when run in java 1.8 JRE out of...
authorBen Soares <bsoares@dundee.ac.uk>
Mon, 15 Apr 2019 16:24:38 +0000 (17:24 +0100)
committerBen Soares <bsoares@dundee.ac.uk>
Mon, 15 Apr 2019 16:24:38 +0000 (17:24 +0100)
src/jalview/bin/Jalview.java
src/jalview/bin/JalviewTaskbar.java [new file with mode: 0644]
src/jalview/gui/APQHandlers.java [new file with mode: 0644]
src/jalview/gui/Desktop.java
src/jalview/gui/SplitFrame.java
src/jalview/jbgui/GAlignFrame.java
src/jalview/jbgui/GCutAndPasteHtmlTransfer.java
src/jalview/jbgui/GCutAndPasteTransfer.java
src/jalview/jbgui/GDesktop.java
src/jalview/util/Platform.java
src/jalview/util/ShortcutKeyMaskExWrapper.java [new file with mode: 0644]

index cda02fc..60cce46 100755 (executable)
@@ -41,8 +41,6 @@ import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.jws2.Jws2Discoverer;
 
-import java.awt.Image;
-import java.awt.Taskbar;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
@@ -338,26 +336,15 @@ public class Jalview
       desktop = new Desktop();
       desktop.setInBatchMode(true); // indicate we are starting up
 
-      if (Taskbar.isTaskbarSupported())
+      try
       {
-        Taskbar tb = Taskbar.getTaskbar();
-        if (tb.isSupported(Taskbar.Feature.ICON_IMAGE))
-        {
-          try
-          {
-            java.net.URL url = getClass()
-                    .getResource("/images/JalviewLogo_Huge.png");
-            if (url != null)
-            {
-              Image image = java.awt.Toolkit.getDefaultToolkit()
-                      .createImage(url);
-              tb.setIconImage(image);
-            }
-          } catch (Exception e)
-          {
-            e.printStackTrace();
-          }
-        }
+        JalviewTaskbar.setTaskbar(this);
+      } catch (Exception e)
+      {
+        e.printStackTrace();
+      } catch (Throwable t)
+      {
+        t.printStackTrace();
       }
 
       desktop.setVisible(true);
diff --git a/src/jalview/bin/JalviewTaskbar.java b/src/jalview/bin/JalviewTaskbar.java
new file mode 100644 (file)
index 0000000..5747263
--- /dev/null
@@ -0,0 +1,39 @@
+package jalview.bin;
+
+import java.awt.Image;
+import java.awt.Taskbar;
+
+public class JalviewTaskbar
+{
+  public JalviewTaskbar()
+  {
+  }
+
+  protected static void setTaskbar(Jalview jalview)
+  {
+    
+    if (Taskbar.isTaskbarSupported())
+    {
+      Taskbar tb = Taskbar.getTaskbar();
+      if (tb.isSupported(Taskbar.Feature.ICON_IMAGE))
+      {
+        try
+        {
+          java.net.URL url = jalview.getClass()
+                  .getResource("/images/JalviewLogo_Huge.png");
+          if (url != null)
+          {
+            Image image = java.awt.Toolkit.getDefaultToolkit()
+                    .createImage(url);
+            tb.setIconImage(image);
+          }
+        } catch (Exception e)
+        {
+          e.printStackTrace();
+        }
+      }
+    }
+
+  }
+
+}
diff --git a/src/jalview/gui/APQHandlers.java b/src/jalview/gui/APQHandlers.java
new file mode 100644 (file)
index 0000000..31f7a6d
--- /dev/null
@@ -0,0 +1,150 @@
+package jalview.gui;
+
+import jalview.util.MessageManager;
+import jalview.util.Platform;
+
+import java.awt.Desktop;
+import java.awt.desktop.AboutEvent;
+import java.awt.desktop.AboutHandler;
+import java.awt.desktop.PreferencesEvent;
+import java.awt.desktop.PreferencesHandler;
+import java.awt.desktop.QuitEvent;
+import java.awt.desktop.QuitHandler;
+import java.awt.desktop.QuitResponse;
+import java.awt.desktop.QuitStrategy;
+
+import javax.swing.JOptionPane;
+
+public class APQHandlers
+{
+  private static boolean setAPQHandlers = false;
+
+  public APQHandlers() {
+  }
+
+  protected static boolean setAPQHandlers(jalview.gui.Desktop jalviewDesktop)
+  {
+    // flagging this test to avoid unnecessary reflection
+    if (!setAPQHandlers)
+    {
+      // see if the Quit, About and Preferences handlers are available
+      Class desktopClass = Desktop.class;
+      Desktop hdesktop = Desktop.getDesktop();
+
+      try
+      {
+        Float specversion = Float.parseFloat(
+                System.getProperty("java.specification.version"));
+
+        if (specversion >= 9)
+        {
+          if (Platform.isAMac())
+          {
+            if (desktopClass.getDeclaredMethod("setAboutHandler",
+                    new Class[]
+                    { AboutHandler.class }) != null)
+            {
+
+              hdesktop.setAboutHandler(new AboutHandler()
+              {
+                @Override
+                public void handleAbout(AboutEvent e)
+                {
+                  jalviewDesktop.aboutMenuItem_actionPerformed(null);
+                }
+              });
+
+            }
+
+            if (desktopClass.getDeclaredMethod("setPreferencesHandler",
+                    new Class[]
+                    { PreferencesHandler.class }) != null)
+            {
+
+              hdesktop.setPreferencesHandler(
+                      new PreferencesHandler()
+              {
+                        @Override
+                        public void handlePreferences(
+                                PreferencesEvent e)
+                        {
+                          jalviewDesktop.preferences_actionPerformed(null);
+                        }
+                      });
+
+            }
+
+            if (desktopClass.getDeclaredMethod("setQuitHandler",
+                    new Class[]
+                    { QuitHandler.class }) != null)
+            {
+
+              hdesktop.setQuitHandler(new QuitHandler()
+              {
+                @Override
+                public void handleQuitRequestWith(
+                        QuitEvent e, QuitResponse r)
+                {
+                  boolean confirmQuit = jalview.bin.Cache
+                          .getDefault(jalviewDesktop.CONFIRM_KEYBOARD_QUIT,
+                                  true);
+                  int n;
+                  if (confirmQuit)
+                  {
+                    n = JOptionPane.showConfirmDialog(null,
+                            MessageManager.getString("label.quit_jalview"),
+                            MessageManager.getString("action.quit"),
+                            JOptionPane.OK_CANCEL_OPTION,
+                            JOptionPane.PLAIN_MESSAGE, null);
+                  }
+                  else
+                  {
+                    n = JOptionPane.OK_OPTION;
+                  }
+                  if (n == JOptionPane.OK_OPTION)
+                  {
+                    System.out.println("Shortcut Quit confirmed by user");
+                    jalviewDesktop.quit();
+                    r.performQuit(); // probably won't reach this line, but just
+                                     // in
+                                     // case
+                  }
+                  else
+                  {
+                    r.cancelQuit();
+                    System.out.println("Shortcut Quit cancelled by user");
+                  }
+                }
+              });
+              hdesktop.setQuitStrategy(
+                      QuitStrategy.CLOSE_ALL_WINDOWS);
+
+            }
+          }
+          setAPQHandlers = true;
+        }
+        else
+        {
+          System.out.println(
+                  "Not going to try setting APQ Handlers as java.spec.version is "
+                          + specversion);
+        }
+
+      } catch (Exception e)
+      {
+        System.out.println(
+                "Exception when looking for About, Preferences, Quit Handlers");
+        e.printStackTrace();
+      } catch (Throwable t)
+      {
+        System.out.println(
+                "Throwable when looking for About, Preferences, Quit Handlers");
+        t.printStackTrace();
+      }
+
+    }
+    
+    return setAPQHandlers;
+  }
+
+}
index 1fed71e..41cbad8 100644 (file)
@@ -62,16 +62,6 @@ import java.awt.datatransfer.Clipboard;
 import java.awt.datatransfer.ClipboardOwner;
 import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.Transferable;
-import java.awt.desktop.QuitStrategy;
-/* not importing directly. Calling classes with full name in try block to allow Java 1.8 runtime
-import java.awt.desktop.AboutHandler;
-import java.awt.desktop.PreferencesEvent;
-import java.awt.desktop.PreferencesHandler;
-import java.awt.desktop.QuitEvent;
-import java.awt.desktop.QuitHandler;
-import java.awt.desktop.QuitResponse;
-import java.awt.desktop.QuitStrategy;
-*/
 import java.awt.dnd.DnDConstants;
 import java.awt.dnd.DropTargetDragEvent;
 import java.awt.dnd.DropTargetDropEvent;
@@ -120,7 +110,6 @@ import javax.swing.JDesktopPane;
 import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
 import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.JProgressBar;
@@ -156,7 +145,7 @@ public class Desktop extends jalview.jbgui.GDesktop
 
   private static final String EXPERIMENTAL_FEATURES = "EXPERIMENTAL_FEATURES";
 
-  private static final String CONFIRM_KEYBOARD_QUIT = "CONFIRM_KEYBOARD_QUIT";
+  protected static final String CONFIRM_KEYBOARD_QUIT = "CONFIRM_KEYBOARD_QUIT";
 
   public static HashMap<String, FileWriter> savingFiles = new HashMap<>();
 
@@ -169,8 +158,6 @@ public class Desktop extends jalview.jbgui.GDesktop
 
   private File projectFile;
 
-  private static boolean setAPQHandlers = false;
-
   /**
    * @param listener
    * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.beans.PropertyChangeListener)
@@ -374,125 +361,20 @@ public class Desktop extends jalview.jbgui.GDesktop
     }
     */
 
-    // flagging this test to avoid unnecessary reflection
-    if (!setAPQHandlers)
+    try
     {
-      // see if the Quit, About and Preferences handlers are available
-      Class desktopClass = java.awt.Desktop.class;
-      java.awt.Desktop hdesktop = java.awt.Desktop.getDesktop();
-
-      try
-      {
-        Float specversion = Float.parseFloat(
-                System.getProperty("java.specification.version"));
-
-        if (specversion >= 9)
-        {
-          if (Platform.isAMac())
-          {
-            if (desktopClass.getDeclaredMethod("setAboutHandler",
-                    new Class[]
-                    { java.awt.desktop.AboutHandler.class }) != null)
-            {
-
-              hdesktop.setAboutHandler(new java.awt.desktop.AboutHandler()
-              {
-                @Override
-                public void handleAbout(java.awt.desktop.AboutEvent e)
-                {
-                  aboutMenuItem_actionPerformed(null);
-                }
-              });
-
-            }
-
-            if (desktopClass.getDeclaredMethod("setPreferencesHandler",
-                    new Class[]
-                    { java.awt.desktop.PreferencesHandler.class }) != null)
-            {
-
-              hdesktop.setPreferencesHandler(
-                      new java.awt.desktop.PreferencesHandler()
-              {
-                        @Override
-                        public void handlePreferences(
-                                java.awt.desktop.PreferencesEvent e)
-                        {
-                          preferences_actionPerformed(null);
-                        }
-                      });
-
-            }
-
-            if (desktopClass.getDeclaredMethod("setQuitHandler",
-                    new Class[]
-                    { java.awt.desktop.QuitHandler.class }) != null)
-            {
-
-              hdesktop.setQuitHandler(new java.awt.desktop.QuitHandler()
-              {
-                @Override
-                public void handleQuitRequestWith(
-                        java.awt.desktop.QuitEvent e,
-                        java.awt.desktop.QuitResponse r)
-                {
-                  boolean confirmQuit = jalview.bin.Cache
-                          .getDefault(CONFIRM_KEYBOARD_QUIT, true);
-                  int n;
-                  if (confirmQuit)
-                  {
-                    n = JOptionPane.showConfirmDialog(null,
-                            MessageManager.getString("label.quit_jalview"),
-                            MessageManager.getString("action.quit"),
-                            JOptionPane.OK_CANCEL_OPTION,
-                            JOptionPane.PLAIN_MESSAGE, null);
-                  }
-                  else
-                  {
-                    n = JOptionPane.OK_OPTION;
-                  }
-                  if (n == JOptionPane.OK_OPTION)
-                  {
-                    System.out.println("Shortcut Quit confirmed by user");
-                    quit();
-                    r.performQuit(); // probably won't reach this line, but just
-                                     // in
-                                     // case
-                  }
-                  else
-                  {
-                    r.cancelQuit();
-                    System.out.println("Shortcut Quit cancelled by user");
-                  }
-                }
-              });
-              hdesktop.setQuitStrategy(QuitStrategy.CLOSE_ALL_WINDOWS);
-
-            }
-          }
-        }
-        else
-        {
-          System.out.println(
-                  "Not going to try setting APQ Handlers as java.spec.version is "
-                          + specversion);
-        }
-
-      } catch (Exception e)
-      {
-        System.out.println(
-                "Exception when looking for About, Preferences, Quit Handlers");
-        e.printStackTrace();
-      } catch (Throwable t)
-      {
-        System.out.println(
-                "Throwable when looking for About, Preferences, Quit Handlers");
-        t.printStackTrace();
-      }
-
-      setAPQHandlers = true;
+      APQHandlers.setAPQHandlers(this);
+    } catch (Exception e)
+    {
+      System.out.println("Exception when trying to set APQHandlers");
+      e.printStackTrace();
+    } catch (Throwable t)
+    {
+      System.out.println("Throwable when trying to set APQHandlers");
+      t.printStackTrace();
     }
 
+
     addWindowListener(new WindowAdapter()
     {
 
@@ -1138,7 +1020,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     KeyStroke ctrlWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W,
             InputEvent.CTRL_DOWN_MASK);
     KeyStroke cmdWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx());
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx());
 
     InputMap inputMap = frame
             .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
@@ -2886,7 +2768,7 @@ public class Desktop extends jalview.jbgui.GDesktop
   {
     getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
             .put(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
-                    Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()),
+                    jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx()),
                     "Quit");
     getRootPane().getActionMap().put("Quit", new AbstractAction()
     {
index 98a8251..4a4c10c 100644 (file)
@@ -412,7 +412,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI
      * Ctrl-W / Cmd-W - close view or window
      */
     KeyStroke key_cmdW = KeyStroke.getKeyStroke(KeyEvent.VK_W,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     action = new AbstractAction()
     {
       @Override
@@ -433,7 +433,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI
      * Ctrl-T / Cmd-T open new view
      */
     KeyStroke key_cmdT = KeyStroke.getKeyStroke(KeyEvent.VK_T,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     AbstractAction action = new AbstractAction()
     {
       @Override
@@ -773,7 +773,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI
      * Ctrl-F / Cmd-F open Finder dialog, 'focused' on the right alignment
      */
     KeyStroke key_cmdF = KeyStroke.getKeyStroke(KeyEvent.VK_F,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     AbstractAction action = new AbstractAction()
     {
       @Override
index ff15070..075b490 100755 (executable)
@@ -35,7 +35,6 @@ import jalview.util.Platform;
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.GridLayout;
-import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.FocusAdapter;
@@ -266,14 +265,14 @@ public class GAlignFrame extends JInternalFrame
 
     // FIXME getDefaultToolkit throws an exception in Headless mode
     KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_S,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()
-                    | KeyEvent.SHIFT_DOWN_MASK,
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx()
+                    | jalview.util.ShortcutKeyMaskExWrapper.SHIFT_DOWN_MASK,
             false);
     addMenuActionAndAccelerator(keyStroke, saveAs, al);
 
     closeMenuItem.setText(MessageManager.getString("action.close"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_W,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     al = new ActionListener()
     {
       @Override
@@ -296,7 +295,7 @@ public class GAlignFrame extends JInternalFrame
     JMenuItem selectAllSequenceMenuItem = new JMenuItem(
             MessageManager.getString("action.select_all"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_A,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     al = new ActionListener()
     {
       @Override
@@ -323,7 +322,7 @@ public class GAlignFrame extends JInternalFrame
     JMenuItem invertSequenceMenuItem = new JMenuItem(
             MessageManager.getString("action.invert_sequence_selection"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_I,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     al = new ActionListener()
     {
       @Override
@@ -359,7 +358,7 @@ public class GAlignFrame extends JInternalFrame
     JMenuItem remove2LeftMenuItem = new JMenuItem(
             MessageManager.getString("action.remove_left"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_L,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     al = new ActionListener()
     {
       @Override
@@ -373,7 +372,7 @@ public class GAlignFrame extends JInternalFrame
     JMenuItem remove2RightMenuItem = new JMenuItem(
             MessageManager.getString("action.remove_right"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_R,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     al = new ActionListener()
     {
       @Override
@@ -387,7 +386,7 @@ public class GAlignFrame extends JInternalFrame
     JMenuItem removeGappedColumnMenuItem = new JMenuItem(
             MessageManager.getString("action.remove_empty_columns"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_E,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     al = new ActionListener()
     {
       @Override
@@ -401,8 +400,8 @@ public class GAlignFrame extends JInternalFrame
     JMenuItem removeAllGapsMenuItem = new JMenuItem(
             MessageManager.getString("action.remove_all_gaps"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_E,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()
-                    | KeyEvent.SHIFT_DOWN_MASK,
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx()
+                    | jalview.util.ShortcutKeyMaskExWrapper.SHIFT_DOWN_MASK,
             false);
     al = new ActionListener()
     {
@@ -509,7 +508,7 @@ public class GAlignFrame extends JInternalFrame
     JMenuItem removeRedundancyMenuItem = new JMenuItem(
             MessageManager.getString("action.remove_redundancy"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_D,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     al = new ActionListener()
     {
       @Override
@@ -684,7 +683,7 @@ public class GAlignFrame extends JInternalFrame
     undoMenuItem.setEnabled(false);
     undoMenuItem.setText(MessageManager.getString("action.undo"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_Z,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     al = new ActionListener()
     {
       @Override
@@ -698,7 +697,7 @@ public class GAlignFrame extends JInternalFrame
     redoMenuItem.setEnabled(false);
     redoMenuItem.setText(MessageManager.getString("action.redo"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_Y,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     al = new ActionListener()
     {
       @Override
@@ -722,7 +721,7 @@ public class GAlignFrame extends JInternalFrame
     JMenuItem printMenuItem = new JMenuItem(
             MessageManager.getString("action.print"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_P,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     al = new ActionListener()
     {
       @Override
@@ -748,7 +747,7 @@ public class GAlignFrame extends JInternalFrame
     JMenuItem findMenuItem = new JMenuItem(
             MessageManager.getString("action.find"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     findMenuItem.setToolTipText(JvSwingUtils.wrapTooltip(true,
             MessageManager.getString("label.find_tip")));
     al = new ActionListener()
@@ -909,7 +908,7 @@ public class GAlignFrame extends JInternalFrame
     JMenuItem deleteGroups = new JMenuItem(
             MessageManager.getString("action.undefine_groups"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_U,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     al = new ActionListener()
     {
       @Override
@@ -934,7 +933,7 @@ public class GAlignFrame extends JInternalFrame
     JMenuItem createGroup = new JMenuItem(
             MessageManager.getString("action.create_group"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_G,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     al = new ActionListener()
     {
       @Override
@@ -948,8 +947,8 @@ public class GAlignFrame extends JInternalFrame
     JMenuItem unGroup = new JMenuItem(
             MessageManager.getString("action.remove_group"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_G,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()
-                    | KeyEvent.SHIFT_DOWN_MASK,
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx()
+                    | jalview.util.ShortcutKeyMaskExWrapper.SHIFT_DOWN_MASK,
             false);
     al = new ActionListener()
     {
@@ -963,7 +962,7 @@ public class GAlignFrame extends JInternalFrame
 
     copy.setText(MessageManager.getString("action.copy"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_C,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
 
     al = new ActionListener()
     {
@@ -977,7 +976,7 @@ public class GAlignFrame extends JInternalFrame
 
     cut.setText(MessageManager.getString("action.cut"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_X,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     al = new ActionListener()
     {
       @Override
@@ -1003,8 +1002,8 @@ public class GAlignFrame extends JInternalFrame
     JMenuItem pasteNew = new JMenuItem(
             MessageManager.getString("label.to_new_alignment"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_V,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()
-                    | KeyEvent.SHIFT_DOWN_MASK,
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx()
+                    | jalview.util.ShortcutKeyMaskExWrapper.SHIFT_DOWN_MASK,
             false);
     al = new ActionListener()
     {
@@ -1019,7 +1018,7 @@ public class GAlignFrame extends JInternalFrame
     JMenuItem pasteThis = new JMenuItem(
             MessageManager.getString("label.to_this_alignment"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_V,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     al = new ActionListener()
     {
       @Override
@@ -1531,8 +1530,8 @@ public class GAlignFrame extends JInternalFrame
     JMenuItem invertColSel = new JMenuItem(
             MessageManager.getString("action.invert_column_selection"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_I,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()
-                    | KeyEvent.ALT_DOWN_MASK,
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx()
+                    | jalview.util.ShortcutKeyMaskExWrapper.ALT_DOWN_MASK,
             false);
     al = new ActionListener()
     {
@@ -1595,7 +1594,7 @@ public class GAlignFrame extends JInternalFrame
 
     JMenuItem save = new JMenuItem(MessageManager.getString("action.save"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_S,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     al = new ActionListener()
     {
       @Override
@@ -1620,7 +1619,7 @@ public class GAlignFrame extends JInternalFrame
     JMenuItem newView = new JMenuItem(
             MessageManager.getString("action.new_view"));
     keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_T,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false);
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
     al = new ActionListener()
     {
       @Override
index 389a030..3f0df21 100644 (file)
@@ -22,10 +22,10 @@ package jalview.jbgui;
 
 import jalview.gui.JvSwingUtils;
 import jalview.util.MessageManager;
+import jalview.util.ShortcutKeyMaskExWrapper;
 
 import java.awt.BorderLayout;
 import java.awt.Font;
-import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseEvent;
@@ -136,11 +136,11 @@ public class GCutAndPasteHtmlTransfer extends JInternalFrame
     });
     close.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
             java.awt.event.KeyEvent.VK_W,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false));
+            ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false));
     selectAll.setText(MessageManager.getString("action.select_all"));
     selectAll.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
             java.awt.event.KeyEvent.VK_A,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false));
+            ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false));
     selectAll.addActionListener(new ActionListener()
     {
       @Override
@@ -153,7 +153,7 @@ public class GCutAndPasteHtmlTransfer extends JInternalFrame
     save.setText(MessageManager.getString("action.save"));
     save.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
             java.awt.event.KeyEvent.VK_S,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false));
+            ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false));
     save.addActionListener(new ActionListener()
     {
       @Override
@@ -164,7 +164,7 @@ public class GCutAndPasteHtmlTransfer extends JInternalFrame
     });
     copyItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
             java.awt.event.KeyEvent.VK_C,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false));
+            ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false));
 
     editMenubar.add(jMenu1);
     editMenubar.add(editMenu);
index 2e4d733..94a4677 100755 (executable)
@@ -123,7 +123,7 @@ public class GCutAndPasteTransfer extends JInternalFrame
     selectAll.setText(MessageManager.getString("action.select_all"));
     selectAll.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
             java.awt.event.KeyEvent.VK_A,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false));
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false));
     selectAll.addActionListener(new ActionListener()
     {
       @Override
@@ -136,7 +136,7 @@ public class GCutAndPasteTransfer extends JInternalFrame
     save.setText(MessageManager.getString("action.save"));
     save.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
             java.awt.event.KeyEvent.VK_S,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false));
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false));
     save.addActionListener(new ActionListener()
     {
       @Override
@@ -147,10 +147,10 @@ public class GCutAndPasteTransfer extends JInternalFrame
     });
     copyItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
             java.awt.event.KeyEvent.VK_C,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false));
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false));
     pasteMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
             java.awt.event.KeyEvent.VK_V,
-            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(), false));
+            jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false));
     editMenubar.add(jMenu1);
     editMenubar.add(editMenu);
     textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 12));
index 0d075cf..fe85043 100755 (executable)
@@ -26,7 +26,6 @@ import jalview.util.MessageManager;
 import jalview.util.Platform;
 
 import java.awt.FlowLayout;
-import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 
@@ -161,7 +160,7 @@ public class GDesktop extends JFrame
             .setText(MessageManager.getString("label.load_tree_from_file"));
     inputLocalFileMenuItem.setAccelerator(
             javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O,
-                    Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx(),
+                    jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(),
                     false));
     inputLocalFileMenuItem
             .addActionListener(new java.awt.event.ActionListener()
@@ -425,6 +424,8 @@ public class GDesktop extends JFrame
       }
     });
 
+    Float specversion = Float.parseFloat(System.getProperty("java.specification.version"));
+    
     desktopMenubar.add(FileMenu);
     desktopMenubar.add(toolsMenu);
     VamsasMenu.setVisible(false);
@@ -447,7 +448,7 @@ public class GDesktop extends JFrame
     VamsasMenu.add(vamsasImport);
     VamsasMenu.add(vamsasSave);
     VamsasMenu.add(vamsasStop);
-    if (!Platform.isAMac())
+    if (!Platform.isAMac() || specversion < 11)
     {
       toolsMenu.add(preferences);
     }
index 1be6086..22032b5 100644 (file)
@@ -140,7 +140,7 @@ public class Platform
       {
         return false;
       }
-      return (Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx() // .getMenuShortcutKeyMaskEx()
+      return (jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx() // .getMenuShortcutKeyMaskEx()
               & e.getModifiersEx()) != 0; // getModifiers()) != 0;
     }
     return e.isControlDown();
diff --git a/src/jalview/util/ShortcutKeyMaskExWrapper.java b/src/jalview/util/ShortcutKeyMaskExWrapper.java
new file mode 100644 (file)
index 0000000..7292c80
--- /dev/null
@@ -0,0 +1,57 @@
+package jalview.util;
+
+import java.awt.Toolkit;
+import java.awt.event.KeyEvent;
+
+public class ShortcutKeyMaskExWrapper
+{
+
+  private static boolean init = false;
+
+  private static final Float specversion = Float
+          .parseFloat(System.getProperty("java.specification.version"));
+
+  private static final float modern = 11;
+
+  public static int SHIFT_DOWN_MASK = KeyEvent.SHIFT_DOWN_MASK;
+
+  public static int ALT_DOWN_MASK = KeyEvent.ALT_DOWN_MASK;
+
+  public ShortcutKeyMaskExWrapper()
+  {
+  }
+
+  private static void init()
+  {
+    if (init)
+    {
+      return;
+    }
+    if (specversion < modern)
+    {
+      SHIFT_DOWN_MASK = KeyEvent.SHIFT_MASK;
+      ALT_DOWN_MASK = KeyEvent.ALT_MASK;
+    }
+    else
+    {
+      SHIFT_DOWN_MASK = KeyEvent.SHIFT_DOWN_MASK;
+      ALT_DOWN_MASK = KeyEvent.ALT_DOWN_MASK;
+    }
+
+    init = true;
+  }
+
+  public static int getMenuShortcutKeyMaskEx()
+  {
+    init();
+    if (specversion < modern)
+    {
+      return Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
+    }
+    else
+    {
+      return Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx();
+    }
+  }
+
+}