X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FPlatform.java;h=f34849ec56c8dfdf5e515bc15601b11f66e2756f;hb=96026e673c3629afa54a0d03be4b0022c7b42869;hp=6c32ad4eff66752e426dc4a42658366dda0a0575;hpb=839552f2a09d84238d202f8c4f7b9bc630d48e6e;p=jalview.git diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java index 6c32ad4..f34849e 100644 --- a/src/jalview/util/Platform.java +++ b/src/jalview/util/Platform.java @@ -34,11 +34,29 @@ import javax.swing.SwingUtilities; public class Platform { - private static Boolean isNoJSMac = null, isNoJSWindows = null; + private static Boolean isNoJSMac = null, isNoJSWin = null, isMac = null, isWin = null; private static Boolean isHeadless = null; /** + * added to group mouse events into Windows and nonWindows (mac, unix, linux) + * @return + */ + public static boolean isMac() + { + return (isMac == null ? (isMac = (System.getProperty("os.name").indexOf("Mac") >= 0)) : isMac); + } + + /** + * added to group mouse events into Windows and nonWindows (mac, unix, linux) + * @return + */ + public static boolean isWin() + { + return (isWin == null ? (isWin = (System.getProperty("os.name").indexOf("Win") >= 0)) : isWin); + } + + /** * sorry folks - Macs really are different * * BH: disabled for SwingJS -- will need to check key-press issues @@ -47,61 +65,18 @@ public class Platform */ public static boolean isAMacAndNotJS() { - if (isNoJSMac == null) - { - isNoJSMac = /** @j2sNative false && */ - System.getProperty("os.name").indexOf("Mac") > -1; - } - - return isNoJSMac.booleanValue(); - + return (isNoJSMac == null ? (isNoJSMac = /** @j2sNative false && */isMac()) : isNoJSMac); } - /** +/** * Check if we are on a Microsoft plaform... * * @return true if we have to cope with another platform variation */ public static boolean isWindowsAndNotJS() { - if (isNoJSWindows == null) - { - isNoJSWindows = /** @j2sNative false && */ - System.getProperty("os.name").indexOf("Win") > -1; - } - return isNoJSWindows.booleanValue(); - } - -// BH - preferred: -// -// /** -// * @return true if this is a Mac -// */ -// private static boolean isAMac() -// { -// if (isAMac == null) -// { -// isAMac = System.getProperty("os.name").indexOf("Mac") > -1; -// } -// -// return isAMac.booleanValue(); -// -// } -// -// /** -// * Check if we are on a Microsoft plaform... -// * -// * @return true if we have to cope with another platform variation -// */ -// private static boolean isWindows() -// { -// if (isWindows == null) -// { -// isWindows = System.getProperty("os.name").indexOf("Win") > -1; -// } -// return isWindows.booleanValue(); -// } -// + return (isNoJSWin == null ? (isNoJSWin = /** @j2sNative false && */isWin()) : isNoJSWin); + } /** * @@ -157,8 +132,7 @@ public class Platform */ public static boolean isControlDown(MouseEvent e) { - boolean aMac = isAMacAndNotJS(); - return isControlDown(e, aMac); + return isControlDown(e, isMac()); } /** @@ -170,29 +144,42 @@ public class Platform */ protected static boolean isControlDown(MouseEvent e, boolean aMac) { - if (aMac) - { - /* - * answer false for right mouse button - */ - if (e.isPopupTrigger()) - { - return false; - } - return (Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() - & e.getModifiers()) != 0; - // could we use e.isMetaDown() here? + if (!aMac) { + return e.isControlDown(); } - return e.isControlDown(); + // answer false for right mouse button + // shortcut key will be META for a Mac + return !e.isPopupTrigger() + && (Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() & e.getModifiers()) != 0; + // could we use e.isMetaDown() here? } + /** + * Windows (not Mac, Linux, or Unix) and right button + * to test for the right-mouse pressed event in Windows + * that would have opened a menu or a Mac. + * + * @param e + * @return + */ public static boolean isWinRightButton(MouseEvent e) { - return !isAMacAndNotJS() && SwingUtilities.isRightMouseButton(e); - } + // was !isAMac(), but that is true also for Linux and Unix and JS, + return isWin() && SwingUtilities.isRightMouseButton(e); + } + + + /** + * Windows (not Mac, Linux, or Unix) and middle button -- for mouse wheeling + * without pressing the button. + * + * @param e + * @return + */ public static boolean isWinMiddleButton(MouseEvent e) { - return !isAMacAndNotJS() && SwingUtilities.isMiddleMouseButton(e); + // was !isAMac(), but that is true also for Linux and Unix and JS + return isWin() && SwingUtilities.isMiddleMouseButton(e); } }