private static Boolean isHeadless = null;
private static swingjs.api.JSUtilI jsutil;
-
static
{
public static int ALT_DOWN_MASK = KeyEvent.ALT_DOWN_MASK;
- public static int SHORTCUT_KEY_MASK = (Platform.isMac() ? KeyEvent.META_DOWN_MASK : KeyEvent.CTRL_DOWN_MASK);
-
+ public static int SHORTCUT_KEY_MASK = (Platform.isMac()
+ ? KeyEvent.META_DOWN_MASK
+ : KeyEvent.CTRL_DOWN_MASK);
+
static
{
if (!GraphicsEnvironment.isHeadless())
{
+ // Using non-deprecated Extended key mask modifiers, but Java 8 has no
+ // getMenuShortcutKeyMaskEx method
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ Method method = null;
try
{
-
- Toolkit tk = Toolkit.getDefaultToolkit();
- Method method = tk.getClass().getMethod("getMenuShortcutKeyMaskEx");
- if (method == null)
+ method = tk.getClass().getMethod("getMenuShortcutKeyMaskEx");
+ } catch (NoSuchMethodException e)
+ {
+ System.err.println(
+ "Could not find Toolkit method getMenuShortcutKeyMaskEx. Trying getMenuShortcutKeyMask.");
+ }
+ if (method == null)
+ {
+ try
+ {
method = tk.getClass().getMethod("getMenuShortcutKeyMask");
- SHORTCUT_KEY_MASK = ((int) method.invoke(tk, new Object[0]));
- if (SHORTCUT_KEY_MASK <= 0xF)
+ } catch (NoSuchMethodException e)
{
- // shift this into the extended region (was Java 8)
- SHORTCUT_KEY_MASK = SHORTCUT_KEY_MASK << 6;
+ System.err.println(
+ "Could not find Toolkit method getMenuShortcutKeyMaskEx or getMenuShortcutKeyMask.");
+ e.printStackTrace();
}
- } catch (Exception e)
+ }
+ if (method != null)
{
- e.printStackTrace();
+ try
+ {
+ method.setAccessible(true);
+ SHORTCUT_KEY_MASK = ((int) method.invoke(tk, new Object[0]));
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ if (SHORTCUT_KEY_MASK <= 0xF)
+ {
+ // shift this into the extended region (was Java 8)
+ SHORTCUT_KEY_MASK = SHORTCUT_KEY_MASK << 6;
}
}
}
*/
protected static boolean isControlDown(MouseEvent e, boolean aMac)
{
-
- System.out.println(e.isPopupTrigger()
- + " " + ((SHORTCUT_KEY_MASK & e.getModifiersEx()) != 0)
- + " " + e.isControlDown());
- return (aMac ? !e.isPopupTrigger()
- && (SHORTCUT_KEY_MASK & e.getModifiersEx()) != 0
+
+ System.out.println(e.isPopupTrigger() + " "
+ + ((SHORTCUT_KEY_MASK & e.getModifiersEx()) != 0) + " "
+ + e.isControlDown());
+ return (aMac
+ ? !e.isPopupTrigger()
+ && (SHORTCUT_KEY_MASK & e.getModifiersEx()) != 0
: e.isControlDown());
- }
+ }
// BH: I don't know about that previous method. Here is what SwingJS uses.
// Notice the distinction in mouse events. (BUTTON3_MASK == META)