From 50363b5d740fdf06f22db3812ebcfe32bd7908b8 Mon Sep 17 00:00:00 2001 From: BobHanson Date: Tue, 2 Jun 2020 11:47:07 -0500 Subject: [PATCH] JAL-3446 test for simpler key mask operation --- src/jalview/bin/JalviewJS2.java | 29 ++++- src/jalview/gui/Desktop.java | 4 +- src/jalview/gui/SplitFrame.java | 6 +- src/jalview/jbgui/GAlignFrame.java | 58 +++++----- src/jalview/jbgui/GCutAndPasteHtmlTransfer.java | 13 +-- src/jalview/jbgui/GCutAndPasteTransfer.java | 9 +- src/jalview/jbgui/GDesktop.java | 2 +- src/jalview/util/Platform.java | 133 ++++++++++++----------- src/jalview/util/ShortcutKeyMaskExWrapper.java | 80 +++++++------- src/jalview/util/ShortcutKeyMaskExWrapperI.java | 3 - 10 files changed, 178 insertions(+), 159 deletions(-) diff --git a/src/jalview/bin/JalviewJS2.java b/src/jalview/bin/JalviewJS2.java index 26110f8..6f69f8a 100644 --- a/src/jalview/bin/JalviewJS2.java +++ b/src/jalview/bin/JalviewJS2.java @@ -20,16 +20,37 @@ public class JalviewJS2 static { /** - * @j2sNative + * @ could do it this way: * - * J2S.thisApplet.__Info.args = - * ["open","examples/uniref50.fa","features", - * "examples/exampleFeatures.txt"]; + * j2sNative + * + * J2S.thisApplet.__Info.args = [ "open","examples/uniref50.fa", + * "features","examples/exampleFeatures.txt", "noannotation" ]; */ } public static void main(String[] args) throws Exception { + if (args.length == 0) + { + args = new String[] { + // "headless", + "open", "examples/uniref50.fa", + "features", + "examples/exampleFeatures.txt" + , "noannotation" + , "showoverview" + // , "png", "test-bh.png" + }; + } + + // String cmds = "nodisplay -open examples/uniref50.fa -sortbytree -props + // test/jalview/io/testProps.jvprops -colour zappo " + // + "-jabaws http://www.compbio.dundee.ac.uk/jabaws -nosortbytree " + // + "-features examples/testdata/plantfdx.features -annotations + // examples/testdata/plantfdx.annotations -tree + // examples/testdata/uniref50_test_tree"; + // args = cmds.split(" "); Jalview.main(args); //showFocusTimer(); } diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 1b85dd5..0e2fcf0 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -995,7 +995,7 @@ public class Desktop extends jalview.jbgui.GDesktop KeyStroke ctrlWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK); KeyStroke cmdWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W, - ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx()); + Platform.SHORTCUT_KEY_MASK); InputMap inputMap = frame .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); @@ -2448,7 +2448,7 @@ public class Desktop extends jalview.jbgui.GDesktop { getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx()), + Platform.SHORTCUT_KEY_MASK), "Quit"); getRootPane().getActionMap().put("Quit", new AbstractAction() { diff --git a/src/jalview/gui/SplitFrame.java b/src/jalview/gui/SplitFrame.java index e8f30b7..f57279e 100644 --- a/src/jalview/gui/SplitFrame.java +++ b/src/jalview/gui/SplitFrame.java @@ -427,7 +427,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI * Ctrl-W / Cmd-W - close view or window */ KeyStroke key_cmdW = KeyStroke.getKeyStroke(KeyEvent.VK_W, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); action = new AbstractAction() { @Override @@ -448,7 +448,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI * Ctrl-T / Cmd-T open new view */ KeyStroke key_cmdT = KeyStroke.getKeyStroke(KeyEvent.VK_T, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); AbstractAction action = new AbstractAction() { @Override @@ -804,7 +804,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI * Ctrl-F / Cmd-F open Finder dialog, 'focused' on the right alignment */ KeyStroke key_cmdF = KeyStroke.getKeyStroke(KeyEvent.VK_F, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); AbstractAction action = new AbstractAction() { @Override diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 1eb0fb9..edaabf1 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -40,6 +40,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; +import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -277,15 +278,12 @@ public class GAlignFrame extends JInternalFrame }; // FIXME getDefaultToolkit throws an exception in Headless mode - KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_S, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx() - | jalview.util.ShortcutKeyMaskExWrapper.SHIFT_DOWN_MASK, + KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_S, Platform.SHORTCUT_KEY_MASK | InputEvent.SHIFT_DOWN_MASK, false); addMenuActionAndAccelerator(keyStroke, saveAs, al); closeMenuItem.setText(MessageManager.getString("action.close")); - keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_W, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_W, Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @Override @@ -308,7 +306,7 @@ public class GAlignFrame extends JInternalFrame JMenuItem selectAllSequenceMenuItem = new JMenuItem( MessageManager.getString("action.select_all")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_A, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @Override @@ -335,7 +333,7 @@ public class GAlignFrame extends JInternalFrame JMenuItem invertSequenceMenuItem = new JMenuItem( MessageManager.getString("action.invert_sequence_selection")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_I, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @Override @@ -371,7 +369,7 @@ public class GAlignFrame extends JInternalFrame JMenuItem remove2LeftMenuItem = new JMenuItem( MessageManager.getString("action.remove_left")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_L, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @Override @@ -385,7 +383,7 @@ public class GAlignFrame extends JInternalFrame JMenuItem remove2RightMenuItem = new JMenuItem( MessageManager.getString("action.remove_right")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_R, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @Override @@ -399,7 +397,7 @@ public class GAlignFrame extends JInternalFrame JMenuItem removeGappedColumnMenuItem = new JMenuItem( MessageManager.getString("action.remove_empty_columns")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_E, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @Override @@ -413,8 +411,8 @@ public class GAlignFrame extends JInternalFrame JMenuItem removeAllGapsMenuItem = new JMenuItem( MessageManager.getString("action.remove_all_gaps")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_E, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx() - | jalview.util.ShortcutKeyMaskExWrapper.SHIFT_DOWN_MASK, + Platform.SHORTCUT_KEY_MASK + | InputEvent.SHIFT_DOWN_MASK, false); al = new ActionListener() { @@ -521,7 +519,7 @@ public class GAlignFrame extends JInternalFrame JMenuItem removeRedundancyMenuItem = new JMenuItem( MessageManager.getString("action.remove_redundancy")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_D, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @Override @@ -696,7 +694,7 @@ public class GAlignFrame extends JInternalFrame undoMenuItem.setEnabled(false); undoMenuItem.setText(MessageManager.getString("action.undo")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_Z, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @Override @@ -710,7 +708,7 @@ public class GAlignFrame extends JInternalFrame redoMenuItem.setEnabled(false); redoMenuItem.setText(MessageManager.getString("action.redo")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_Y, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @Override @@ -734,7 +732,7 @@ public class GAlignFrame extends JInternalFrame JMenuItem printMenuItem = new JMenuItem( MessageManager.getString("action.print")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_P, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @Override @@ -760,7 +758,7 @@ public class GAlignFrame extends JInternalFrame JMenuItem findMenuItem = new JMenuItem( MessageManager.getString("action.find")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); findMenuItem.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.getString("label.find_tip"))); al = new ActionListener() @@ -921,7 +919,7 @@ public class GAlignFrame extends JInternalFrame JMenuItem deleteGroups = new JMenuItem( MessageManager.getString("action.undefine_groups")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_U, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @Override @@ -946,7 +944,7 @@ public class GAlignFrame extends JInternalFrame JMenuItem createGroup = new JMenuItem( MessageManager.getString("action.create_group")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_G, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @Override @@ -960,8 +958,8 @@ public class GAlignFrame extends JInternalFrame JMenuItem unGroup = new JMenuItem( MessageManager.getString("action.remove_group")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_G, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx() - | jalview.util.ShortcutKeyMaskExWrapper.SHIFT_DOWN_MASK, + Platform.SHORTCUT_KEY_MASK + | InputEvent.SHIFT_DOWN_MASK, false); al = new ActionListener() { @@ -975,7 +973,7 @@ public class GAlignFrame extends JInternalFrame copy.setText(MessageManager.getString("action.copy")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_C, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @@ -989,7 +987,7 @@ public class GAlignFrame extends JInternalFrame cut.setText(MessageManager.getString("action.cut")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_X, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @Override @@ -1015,8 +1013,8 @@ public class GAlignFrame extends JInternalFrame JMenuItem pasteNew = new JMenuItem( MessageManager.getString("label.to_new_alignment")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_V, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx() - | jalview.util.ShortcutKeyMaskExWrapper.SHIFT_DOWN_MASK, + Platform.SHORTCUT_KEY_MASK + | InputEvent.SHIFT_DOWN_MASK, false); al = new ActionListener() { @@ -1031,7 +1029,7 @@ public class GAlignFrame extends JInternalFrame JMenuItem pasteThis = new JMenuItem( MessageManager.getString("label.to_this_alignment")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_V, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @Override @@ -1548,8 +1546,8 @@ public class GAlignFrame extends JInternalFrame JMenuItem invertColSel = new JMenuItem( MessageManager.getString("action.invert_column_selection")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_I, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx() - | jalview.util.ShortcutKeyMaskExWrapper.ALT_DOWN_MASK, + Platform.SHORTCUT_KEY_MASK + | InputEvent.ALT_DOWN_MASK, false); al = new ActionListener() { @@ -1612,7 +1610,7 @@ public class GAlignFrame extends JInternalFrame JMenuItem save = new JMenuItem(MessageManager.getString("action.save")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_S, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @Override @@ -1637,7 +1635,7 @@ public class GAlignFrame extends JInternalFrame JMenuItem newView = new JMenuItem( MessageManager.getString("action.new_view")); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_T, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false); + Platform.SHORTCUT_KEY_MASK, false); al = new ActionListener() { @Override diff --git a/src/jalview/jbgui/GCutAndPasteHtmlTransfer.java b/src/jalview/jbgui/GCutAndPasteHtmlTransfer.java index 1c9e907..121917e 100644 --- a/src/jalview/jbgui/GCutAndPasteHtmlTransfer.java +++ b/src/jalview/jbgui/GCutAndPasteHtmlTransfer.java @@ -22,6 +22,7 @@ package jalview.jbgui; import jalview.gui.JvSwingUtils; import jalview.util.MessageManager; +import jalview.util.Platform; import java.awt.BorderLayout; import java.awt.Font; @@ -135,14 +136,12 @@ public class GCutAndPasteHtmlTransfer extends JInternalFrame }); close.setAccelerator(javax.swing.KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_W, - jalview.util.ShortcutKeyMaskExWrapper - .getMenuShortcutKeyMaskEx(), + Platform.SHORTCUT_KEY_MASK, false)); selectAll.setText(MessageManager.getString("action.select_all")); selectAll.setAccelerator(javax.swing.KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_A, - jalview.util.ShortcutKeyMaskExWrapper - .getMenuShortcutKeyMaskEx(), + Platform.SHORTCUT_KEY_MASK, false)); selectAll.addActionListener(new ActionListener() { @@ -156,8 +155,7 @@ public class GCutAndPasteHtmlTransfer extends JInternalFrame save.setText(MessageManager.getString("action.save")); save.setAccelerator(javax.swing.KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_S, - jalview.util.ShortcutKeyMaskExWrapper - .getMenuShortcutKeyMaskEx(), + Platform.SHORTCUT_KEY_MASK, false)); save.addActionListener(new ActionListener() { @@ -169,8 +167,7 @@ public class GCutAndPasteHtmlTransfer extends JInternalFrame }); copyItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_C, - jalview.util.ShortcutKeyMaskExWrapper - .getMenuShortcutKeyMaskEx(), + Platform.SHORTCUT_KEY_MASK, false)); editMenubar.add(jMenu1); diff --git a/src/jalview/jbgui/GCutAndPasteTransfer.java b/src/jalview/jbgui/GCutAndPasteTransfer.java index 94a4677..bd3e8dc 100755 --- a/src/jalview/jbgui/GCutAndPasteTransfer.java +++ b/src/jalview/jbgui/GCutAndPasteTransfer.java @@ -22,6 +22,7 @@ package jalview.jbgui; import jalview.gui.JvSwingUtils; import jalview.util.MessageManager; +import jalview.util.Platform; import java.awt.BorderLayout; import java.awt.Font; @@ -123,7 +124,7 @@ public class GCutAndPasteTransfer extends JInternalFrame selectAll.setText(MessageManager.getString("action.select_all")); selectAll.setAccelerator(javax.swing.KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_A, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false)); + Platform.SHORTCUT_KEY_MASK, false)); selectAll.addActionListener(new ActionListener() { @Override @@ -136,7 +137,7 @@ public class GCutAndPasteTransfer extends JInternalFrame save.setText(MessageManager.getString("action.save")); save.setAccelerator(javax.swing.KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_S, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false)); + Platform.SHORTCUT_KEY_MASK, false)); save.addActionListener(new ActionListener() { @Override @@ -147,10 +148,10 @@ public class GCutAndPasteTransfer extends JInternalFrame }); copyItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_C, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false)); + Platform.SHORTCUT_KEY_MASK, false)); pasteMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_V, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false)); + Platform.SHORTCUT_KEY_MASK, false)); editMenubar.add(jMenu1); editMenubar.add(editMenu); textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 12)); diff --git a/src/jalview/jbgui/GDesktop.java b/src/jalview/jbgui/GDesktop.java index 6793663..8e30f5a 100755 --- a/src/jalview/jbgui/GDesktop.java +++ b/src/jalview/jbgui/GDesktop.java @@ -148,7 +148,7 @@ public class GDesktop extends JFrame .setText(MessageManager.getString("label.load_tree_from_file")); inputLocalFileMenuItem.setAccelerator( javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, - jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), + Platform.SHORTCUT_KEY_MASK, false)); inputLocalFileMenuItem .addActionListener(new java.awt.event.ActionListener() diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java index c06c755..036ae17 100644 --- a/src/jalview/util/Platform.java +++ b/src/jalview/util/Platform.java @@ -20,11 +20,11 @@ */ package jalview.util; -import jalview.javascript.json.JSON; - 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; @@ -34,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.util.Properties; import java.util.logging.ConsoleHandler; @@ -47,6 +48,7 @@ import org.json.simple.parser.ParseException; import com.stevesoft.pat.Regex; +import jalview.javascript.json.JSON; import swingjs.api.JSUtilI; /** @@ -54,6 +56,7 @@ import swingjs.api.JSUtilI; * * @author Jim Procter */ + public class Platform { @@ -64,11 +67,14 @@ public class Platform isWin = null; private static Boolean isHeadless = null; - + private static swingjs.api.JSUtilI jsutil; + - static { - if (isJS) { + static + { + if (isJS) + { try { jsutil = ((JSUtilI) Class.forName("swingjs.JSUtil").newInstance()); @@ -77,7 +83,7 @@ public class Platform { e.printStackTrace(); } - } + } } // private static Boolean isHeadless = null; @@ -93,6 +99,35 @@ 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); + + static + { + if (!GraphicsEnvironment.isHeadless()) + { + try + { + + Class tk = Toolkit.getDefaultToolkit().getClass(); + Method method = tk.getMethod("getMenuShortcutKeyMaskEx"); + if (method == null) + method = tk.getMethod("getMenuShortcutKeyMask"); + SHORTCUT_KEY_MASK = ((int) method.invoke(tk, new Object[0])); + if (SHORTCUT_KEY_MASK <= 0xF) + { + // shift this into the extended region (was Java 8) + SHORTCUT_KEY_MASK = SHORTCUT_KEY_MASK << 6; + } + } catch (Exception e) + { + } + } + } + /** * added to group mouse events into Windows and nonWindows (mac, unix, linux) * @@ -136,18 +171,18 @@ 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; - } + /** + * + * @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; + } /** * @@ -170,7 +205,7 @@ public class Platform { return s == null ? null : s.replace("\\", "\\\\"); } - + /** * Answers true if the mouse event has Meta-down (Command key on Mac) or * Ctrl-down (on other o/s). Note this answers _false_ if the Ctrl key is @@ -194,31 +229,14 @@ public class Platform */ protected static boolean isControlDown(MouseEvent e, boolean aMac) { - if (!aMac) - { - return e.isControlDown(); - - // Jalview 2.11 code below: above is as amended for JalviewJS - // /* - // * answer false for right mouse button - // */ - // if (e.isPopupTrigger()) - // { - // return false; - // } - // return - // (jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx() // - // .getMenuShortcutKeyMaskEx() - // & jalview.util.ShortcutKeyMaskExWrapper - // .getModifiersEx(e)) != 0; // getModifiers()) != 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()); } - // 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? - } // BH: I don't know about that previous method. Here is what SwingJS uses. // Notice the distinction in mouse events. (BUTTON3_MASK == META) @@ -360,7 +378,6 @@ public class Platform } } - public static void cacheFileData(File file) { if (isJS) @@ -390,7 +407,7 @@ public class Platform } return null; } - + public static String getFileAsString(String url) { if (isJS && url != null) @@ -414,7 +431,6 @@ public class Platform return false; } - public static void addJ2SBinaryType(String ext) { if (isJS) @@ -422,7 +438,7 @@ public class Platform jsutil.addBinaryFileType(ext); } } - + /** * Encode the URI using JavaScript encodeURIComponent * @@ -463,7 +479,6 @@ public class Platform return (isJS ? (String) jsutil.getAppletAttribute("_uniqueId") : null); } - /** * Read the Info block for this applet. * @@ -538,8 +553,7 @@ public class Platform public static Object parseJSON(String json) throws ParseException { - return (isJS() ? JSON.parse(json) - : new JSONParser().parse(json)); + return (isJS() ? JSON.parse(json) : new JSONParser().parse(json)); } public static Object parseJSON(Reader r) @@ -570,8 +584,8 @@ public class Platform * @param is * @param outFile * @throws IOException - * if the file cannot be created or there is a problem - * reading the input stream. + * if the file cannot be created or there is a problem reading the + * input stream. */ public static void streamToFile(InputStream is, File outFile) throws IOException @@ -617,8 +631,8 @@ public class Platform jsutil.addDirectDatabaseCall(domain); System.out.println( - "Platform adding known access-control-allow-origin * for domain " - + domain); + "Platform adding known access-control-allow-origin * for domain " + + domain); } } @@ -640,8 +654,8 @@ public class Platform } /** - * A (case sensitive) file path comparator that ignores the difference between / - * and \ + * A (case sensitive) file path comparator that ignores the difference between + * / and \ * * @param path1 * @param path2 @@ -662,11 +676,8 @@ public class Platform return p1.equals(p2); } + ///////////// JAL-3253 Applet additions ////////////// - -///////////// JAL-3253 Applet additions ////////////// - - /** * Retrieve the object's embedded size from a div's style on a page if * embedded in SwingJS. @@ -753,7 +764,6 @@ public class Platform } } - /** * load a resource -- probably a core file -- if and only if a particular * class has not been instantialized. We use a String here because if we used @@ -833,5 +843,4 @@ public class Platform return (isJS ? jsutil.getCodeBase() : null); } - } diff --git a/src/jalview/util/ShortcutKeyMaskExWrapper.java b/src/jalview/util/ShortcutKeyMaskExWrapper.java index 83330b9..5b26f3d 100644 --- a/src/jalview/util/ShortcutKeyMaskExWrapper.java +++ b/src/jalview/util/ShortcutKeyMaskExWrapper.java @@ -20,50 +20,46 @@ */ package jalview.util; -import java.awt.event.MouseEvent; +import java.awt.GraphicsEnvironment; +import java.awt.Toolkit; +import java.awt.event.KeyEvent; +import java.lang.reflect.Method; public class ShortcutKeyMaskExWrapper { - - private static final Float specversion; - - private static final float modern; - - public static final int SHIFT_DOWN_MASK; - - public static final int ALT_DOWN_MASK; - - private static final ShortcutKeyMaskExWrapperI wrapper; - - static - { - specversion = Platform.isJS() ? Float.valueOf(8) - : Float.parseFloat( - System.getProperty("java.specification.version")); - modern = 11; - - if (specversion >= modern) - { - wrapper = new jalview.util.ShortcutKeyMaskExWrapper11(); - SHIFT_DOWN_MASK = jalview.util.ShortcutKeyMaskExWrapper11.SHIFT_DOWN_MASK; - ALT_DOWN_MASK = jalview.util.ShortcutKeyMaskExWrapper11.ALT_DOWN_MASK; - } - else - { - wrapper = new jalview.util.ShortcutKeyMaskExWrapper8(); - SHIFT_DOWN_MASK = jalview.util.ShortcutKeyMaskExWrapper8.SHIFT_DOWN_MASK; - ALT_DOWN_MASK = jalview.util.ShortcutKeyMaskExWrapper8.ALT_DOWN_MASK; - } - } - - public static int getMenuShortcutKeyMaskEx() - { - return wrapper.getMenuShortcutKeyMaskEx(); - } - - public static int getModifiersEx(MouseEvent e) - { - return wrapper.getModifiersEx(e); - } +// +// 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); +// +// static +// { +// if (!GraphicsEnvironment.isHeadless()) +// { +// try +// { +// +// Class tk = Toolkit.getDefaultToolkit().getClass(); +// Method method = tk.getMethod("getMenuShortcutKeyMaskEx"); +// if (method == null) +// method = tk.getMethod("getMenuShortcutKeyMask"); +// SHORTCUT_KEY_MASK = ((int) method.invoke(tk, new Object[0])); +// if (SHORTCUT_KEY_MASK <= 0xF) +// { +// // shift this into the extended region (was Java 8) +// SHORTCUT_KEY_MASK = SHORTCUT_KEY_MASK << 6; +// } +// } catch (Exception e) +// { +// } +// } +// } +// +// public static int getMenuShortcutKeyMaskEx() +// { +// return SHORTCUT_KEY_MASK; +// } } diff --git a/src/jalview/util/ShortcutKeyMaskExWrapperI.java b/src/jalview/util/ShortcutKeyMaskExWrapperI.java index 74c565d..a00e0d3 100644 --- a/src/jalview/util/ShortcutKeyMaskExWrapperI.java +++ b/src/jalview/util/ShortcutKeyMaskExWrapperI.java @@ -24,9 +24,6 @@ import java.awt.event.MouseEvent; public interface ShortcutKeyMaskExWrapperI { - public static int SHIFT_DOWN_MASK = 0; - - public static int ALT_DOWN_MASK = 0; public int getMenuShortcutKeyMaskEx(); -- 1.7.10.2