From: BobHanson Date: Tue, 16 Jun 2020 03:05:44 +0000 (-0500) Subject: JAL-3446 CTRL-DOWN check for headless operation X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8bf712c3c126fee93cf20e09da289158422eb6de;p=jalview.git JAL-3446 CTRL-DOWN check for headless operation --- diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java index ac84846..c8f2fc4 100644 --- a/src/jalview/util/Platform.java +++ b/src/jalview/util/Platform.java @@ -116,48 +116,50 @@ public class Platform static { - // Using non-deprecated Extended key mask modifiers, but Java 8 has no - // getMenuShortcutKeyMaskEx method - Toolkit tk = Toolkit.getDefaultToolkit(); - Method method = null; - try - { - method = tk.getClass().getMethod("getMenuShortcutKeyMaskEx"); - } catch (NoSuchMethodException e) - { - System.err.println( - "Could not find Toolkit method getMenuShortcutKeyMaskEx. Trying getMenuShortcutKeyMask."); - } - if (method == null) + if (!Jalview.isHeadlessMode()) { + // Using non-deprecated Extended key mask modifiers, but Java 8 has no + // getMenuShortcutKeyMaskEx method + Toolkit tk = Toolkit.getDefaultToolkit(); + Method method = null; try { - method = tk.getClass().getMethod("getMenuShortcutKeyMask"); - } catch (NoSuchMethodException e) + method = tk.getClass().getMethod("getMenuShortcutKeyMaskEx"); + } catch (Exception e) { System.err.println( - "Could not find Toolkit method getMenuShortcutKeyMaskEx or getMenuShortcutKeyMask."); - e.printStackTrace(); + "Could not find Toolkit method getMenuShortcutKeyMaskEx. Trying getMenuShortcutKeyMask."); } - } - if (method != null) - { - try + if (method == null) { - method.setAccessible(true); - SHORTCUT_KEY_MASK = ((int) method.invoke(tk, new Object[0])); - } catch (Exception e) + try + { + method = tk.getClass().getMethod("getMenuShortcutKeyMask"); + } catch (Exception e) + { + System.err.println( + "Could not find Toolkit method getMenuShortcutKeyMaskEx or getMenuShortcutKeyMask."); + e.printStackTrace(); + } + } + 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; } - } - if (SHORTCUT_KEY_MASK <= 0xF) - { - // shift this into the extended region (was Java 8) - SHORTCUT_KEY_MASK = SHORTCUT_KEY_MASK << 6; } } - /** * added to group mouse events into Windows and nonWindows (mac, unix, linux) *