--- /dev/null
+package jalview.util;
+
+import java.awt.Toolkit;
+import java.awt.event.MouseEvent;
+
+/**
+ * retrieve KeyEvent masks for Java 8 or Java 11+
+ *
+ * @author hansonr
+ *
+ */
+public class ShortcutKeyMaskExWrapper
+{
+ public static final int SHIFT_DOWN_MASK;
+
+ public static final int ALT_DOWN_MASK;
+
+ public static final int SHORTCUT_MASK;
+
+ static
+ {
+ float specversion = 1.8f;
+ try
+ {
+ specversion = Float
+ .parseFloat(System.getProperty("java.specification.version"));
+ } catch (Exception e)
+ {
+ System.out.println("Shortcut exception: " + e);
+ }
+
+ String method;
+ // BH technically, these are not masks; they are bits.
+ if (specversion >= 11)
+ {
+ SHIFT_DOWN_MASK = 0x040; // KeyEvent.SHIFT_DOWN_MASK;
+ ALT_DOWN_MASK = 0x200; // KeyEvent.ALT_DOWN_MASK;
+ method = "getMenuShortcutKeyMaskEx";
+ }
+ else
+ {
+ SHIFT_DOWN_MASK = 0x01; // KeyEvent.SHIFT_MASK;
+ ALT_DOWN_MASK = 0x08; // KeyEvent.ALT_MASK;
+ method = "getMenuShortcutKeyMask";
+ }
+
+ int mask = 0;
+ try
+ {
+ // Just use reflection -- doesn't matter what version is running.
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ mask = (int) (tk.getClass().getMethod(method, new Class<?>[0])
+ .invoke(tk, new Object[0]));
+ } catch (Exception e)
+ {
+ System.out.println("Shortcut exception: " + e);
+ }
+
+ SHORTCUT_MASK = mask;
+ }
+
+ // BH Q: Why not just use the public static field?
+ public static int getMenuShortcutKeyMaskEx()
+ {
+ return SHORTCUT_MASK;
+ }
+
+ // BH Q: Why is this here?
+ public static int getModifiersEx(MouseEvent e)
+ {
+ return e.getModifiersEx();
+ }
+
+}