From 96026e673c3629afa54a0d03be4b0022c7b42869 Mon Sep 17 00:00:00 2001 From: hansonr Date: Mon, 21 Jan 2019 12:23:59 -0600 Subject: [PATCH] added Platform settings separating mouse use of win/mac difference --- src/jalview/appletgui/EmbmenuFrame.java | 1 + src/jalview/appletgui/OverviewPanel.java | 2 +- src/jalview/gui/FeatureSettings.java | 15 +--- src/jalview/gui/OverviewPanel.java | 17 ++--- src/jalview/gui/SequenceFetcher.java | 4 +- src/jalview/jbgui/GAlignFrame.java | 2 +- src/jalview/jbgui/GDesktop.java | 2 +- src/jalview/util/Platform.java | 119 +++++++++++++----------------- 8 files changed, 69 insertions(+), 93 deletions(-) diff --git a/src/jalview/appletgui/EmbmenuFrame.java b/src/jalview/appletgui/EmbmenuFrame.java index af5fec0..b6b81fa 100644 --- a/src/jalview/appletgui/EmbmenuFrame.java +++ b/src/jalview/appletgui/EmbmenuFrame.java @@ -51,6 +51,7 @@ import java.util.Map; * @author Jim Procter and Andrew Waterhouse * */ +@SuppressWarnings("serial") public class EmbmenuFrame extends Frame implements MouseListener { protected static final Font FONT_ARIAL_PLAIN_11 = new Font("Arial", diff --git a/src/jalview/appletgui/OverviewPanel.java b/src/jalview/appletgui/OverviewPanel.java index 1b29ef6..fa30819 100755 --- a/src/jalview/appletgui/OverviewPanel.java +++ b/src/jalview/appletgui/OverviewPanel.java @@ -144,7 +144,7 @@ public class OverviewPanel extends Panel implements Runnable, if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { - if (!Platform.isAMacAndNotJS()) + if (!Platform.isMac()) // BH was excluding JavaScript { showPopupMenu(evt); } diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index f5ae15c..26cb104 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -403,18 +403,9 @@ public class FeatureSettings extends JPanel frame = new JInternalFrame(); frame.setContentPane(this); - if (Platform.isAMacAndNotJS()) - { - Desktop.addInternalFrame(frame, - MessageManager.getString("label.sequence_feature_settings"), - 600, 480); - } - else - { - Desktop.addInternalFrame(frame, - MessageManager.getString("label.sequence_feature_settings"), - 600, 450); - } + Desktop.addInternalFrame(frame, + MessageManager.getString("label.sequence_feature_settings"), + 600, Platform.isAMacAndNotJS() ? 480 : 450); frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); frame.addInternalFrameListener( diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 1785e70..66634ee 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -194,16 +194,14 @@ public class OverviewPanel extends JPanel @Override public void mousePressed(MouseEvent evt) { - if (SwingUtilities.isRightMouseButton(evt)) - { - if (!Platform.isAMacAndNotJS()) - { - // BH - MAC L&F here - forces popup and cancels any drag operation - showPopupMenu(evt); - } + + if (Platform.isWinRightButton(evt)) { + showPopupMenu(evt); + return; + } + if (SwingUtilities.isRightMouseButton(evt)) { + return; } - else - { // don't do anything if the mouse press is in the overview's box // (wait to see if it's a drag instead) // otherwise update the viewport @@ -225,7 +223,6 @@ public class OverviewPanel extends JPanel av.getAlignment().getHiddenSequences(), av.getAlignment().getHiddenColumns()); } - } } @Override diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index 79f25e2..24db866 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -145,8 +145,8 @@ public class SequenceFetcher extends JPanel implements Runnable frame = new JInternalFrame(); frame.setContentPane(this); - int height = Platform.isAMacAndNotJS() ? 240 : 180; - Desktop.addInternalFrame(frame, getFrameTitle(), true, 400, height); + Desktop.addInternalFrame(frame, getFrameTitle(), true, 400, + Platform.isAMacAndNotJS() ? 240 : 180); } private String getFrameTitle() diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index d1732cf..2b056fc 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -236,7 +236,7 @@ public class GAlignFrame extends JInternalFrame System.err.println(e.toString()); } - if (!Platform.isAMacAndNotJS()) + if (Platform.isWin()) // was "not mac and not JS" { closeMenuItem.setMnemonic('C'); outputTextboxMenu.setMnemonic('T'); diff --git a/src/jalview/jbgui/GDesktop.java b/src/jalview/jbgui/GDesktop.java index 89b8781..bbde757 100755 --- a/src/jalview/jbgui/GDesktop.java +++ b/src/jalview/jbgui/GDesktop.java @@ -143,7 +143,7 @@ public class GDesktop extends JFrame e.printStackTrace(); } - if (!Platform.isAMacAndNotJS()) + if (Platform.isWin()) //!Platform.isAMacAndNotJS()) { FileMenu.setMnemonic('F'); inputLocalFileMenuItem.setMnemonic('L'); 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); } } -- 1.7.10.2