From 4b1c969e87feaefd4fb9c49ba3d6b828b3ce1a9c Mon Sep 17 00:00:00 2001 From: BobHanson Date: Thu, 9 Apr 2020 10:36:05 -0500 Subject: [PATCH] reconciled with develop --- src/jalview/util/ShortcutKeyMaskExWrapper.java | 74 ++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/jalview/util/ShortcutKeyMaskExWrapper.java diff --git a/src/jalview/util/ShortcutKeyMaskExWrapper.java b/src/jalview/util/ShortcutKeyMaskExWrapper.java new file mode 100644 index 0000000..3162f24 --- /dev/null +++ b/src/jalview/util/ShortcutKeyMaskExWrapper.java @@ -0,0 +1,74 @@ +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(); + } + +} -- 1.7.10.2