X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FPlatform.java;h=daaab3a7a908d9cb361bdb4824677396b51dd375;hb=772f645f8a2cb3c5d25eab36d875f2e09ceca48f;hp=371cd3212fbd7e0122757ab1e1f9999841e525c5;hpb=ae737f35e5185aa421563e4c061340a3c4152514;p=jalview.git diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java index 371cd32..daaab3a 100644 --- a/src/jalview/util/Platform.java +++ b/src/jalview/util/Platform.java @@ -22,7 +22,9 @@ package jalview.util; import java.awt.Component; import java.awt.Dimension; +import java.awt.GraphicsEnvironment; import java.awt.Toolkit; +import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.io.BufferedReader; import java.io.File; @@ -32,6 +34,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.lang.reflect.Method; import java.net.URL; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; @@ -73,8 +76,6 @@ public class Platform private static Boolean isNoJSMac = null, isNoJSWin = null, isMac = null, isWin = null; - private static Boolean isHeadless = null; - private static swingjs.api.JSUtilI jsutil; static @@ -94,7 +95,6 @@ public class Platform } } } - // private static Boolean isHeadless = null; /** * added to group mouse events into Windows and nonWindows (mac, unix, linux) @@ -108,36 +108,56 @@ public class Platform : isMac); } - public static int SHIFT_DOWN_MASK = KeyEvent.SHIFT_DOWN_MASK; - - 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 (Exception 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 (Exception 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; } } } - /** * added to group mouse events into Windows and nonWindows (mac, unix, linux) * @@ -172,7 +192,7 @@ public class Platform } /** - * Check if we are on a Microsoft plaform... + * Check if we are on a Microsoft platform... * * @return true if we have to cope with another platform variation */ @@ -181,18 +201,6 @@ public class Platform return (isNoJSWin == null ? (isNoJSWin = !isJS && isWin()) : isNoJSWin); } - /** - * - * @return true if we are running in non-interactive no UI mode - */ - public static boolean isHeadless() - { - if (isHeadless == null) - { - isHeadless = "true".equals(System.getProperty("java.awt.headless")); - } - return isHeadless; - } /** * @@ -239,12 +247,13 @@ public class Platform */ 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()); } @@ -654,20 +663,22 @@ public class Platform public static void getURLCommandArguments() { - try { - /** - * Retrieve the first query field as command arguments to Jalview. Include - * only if prior to "?j2s" or "&j2s" or "#". Assign the applet's __Info.args - * element to this value. - * - * @j2sNative var a = - * decodeURI((document.location.href.replace("&","?").split("?j2s")[0] - * + "?").split("?")[1].split("#")[0]); a && - * (J2S.thisApplet.__Info.args = a.split(" ")); - * - * System.out.println("URL arguments: " + a); - */ - } catch (Throwable t) { + try + { + /** + * Retrieve the first query field as command arguments to Jalview. Include + * only if prior to "?j2s" or "&j2s" or "#". Assign the applet's + * __Info.args element to this value. + * + * @j2sNative var a = + * decodeURI((document.location.href.replace("&","?").split("?j2s")[0] + * + "?").split("?")[1].split("#")[0]); a && + * (J2S.thisApplet.__Info.args = a.split(" ")); + * + * System.out.println("URL arguments: " + a); + */ + } catch (Throwable t) + { } } @@ -831,7 +842,8 @@ public class Platform * * @param frame * a JFrame or JInternalFrame - * @param type "name", "node", "init", "dim", or any DOM attribute, such as "id" + * @param type + * "name", "node", "init", "dim", or any DOM attribute, such as "id" * @return null if frame is not embedded. */ public static Object getEmbeddedAttribute(Component frame, String type) @@ -947,17 +959,17 @@ public class Platform */ public static String getAppID(String frameType) { - + String id = Jalview.getInstance().j2sAppletID; if (id == null) { - Jalview.getInstance().j2sAppletID = id = (isJS ? (String) jsutil - .getAppletAttribute("_id") : "jalview"); + Jalview.getInstance().j2sAppletID = id = (isJS + ? (String) jsutil.getAppletAttribute("_id") + : "jalview"); } return id + (frameType == null ? "" : "-" + frameType); } - /** * Option to avoid unnecessary seeking of nonexistent resources in JavaScript. * Works in Java as well.