You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2021/02/25 16:56:55 UTC

svn commit: r1886926 - /pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java

Author: rwhitcomb
Date: Thu Feb 25 16:56:55 2021
New Revision: 1886926

URL: http://svn.apache.org/viewvc?rev=1886926&view=rev
Log:
Refactor Keyboard a little bit and add "arePressed" methods.

Modified:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java?rev=1886926&r1=1886925&r2=1886926&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java Thu Feb 25 16:56:55 2021
@@ -301,18 +301,21 @@ public final class Keyboard {
         public static final int UNDEFINED = KeyEvent.VK_UNDEFINED;
     }
 
-    private static int modifiers = 0;
+    /**
+     * The current set of pressed modifier keys.
+     */
+    private static int currentModifiers = 0;
 
     /**
      * @return A bitfield representing the keyboard modifiers that are currently
      * pressed.
      */
     public static int getModifiers() {
-        return modifiers;
+        return currentModifiers;
     }
 
     protected static void setModifiers(final int modifiers) {
-        Keyboard.modifiers = modifiers;
+        currentModifiers = modifiers;
     }
 
     /**
@@ -323,7 +326,29 @@ public final class Keyboard {
      * otherwise.
      */
     public static boolean isPressed(final Modifier modifier) {
-        return (modifiers & modifier.getMask()) > 0;
+        return (currentModifiers & modifier.getMask()) > 0;
+    }
+
+    /**
+     * Test to see if and only if the given set of modifier(s) are pressed.
+     *
+     * @param modifierSet The set of modifiers to test.
+     * @return {@code true} if only those modifiers (and no others)
+     * are pressed.
+     */
+    public static boolean arePressed(final Set<Modifier> modifierSet) {
+       return currentModifiers == Modifier.getMask(modifierSet);
+    }
+
+    /**
+     * Test to see if and only if the given modifier(s) are pressed.
+     *
+     * @param modifiers The modifiers to test.
+     * @return {@code true} if only those modifiers (and no others)
+     * are pressed.
+     */
+    public static boolean arePressed(final Modifier... modifiers) {
+       return currentModifiers == Modifier.getMask(modifiers);
     }
 
     /**
@@ -334,18 +359,18 @@ public final class Keyboard {
      * if none are pressed.
      */
     public static boolean areAnyPressed(final Set<Modifier> modifierSet) {
-        return (modifiers & Modifier.getMask(modifierSet)) > 0;
+        return (currentModifiers & Modifier.getMask(modifierSet)) > 0;
     }
 
     /**
      * Are any of the given list of {@link Modifier}s pressed?
      *
-     * @param modifierList The list of modifiers to test.
+     * @param modifiers The modifiers to test.
      * @return {@code true} if any of them are pressed, {@code false}
      * if none are pressed.
      */
-    public static boolean areAnyPressed(final Modifier... modifierList) {
-        return (modifiers & Modifier.getMask(modifierList)) > 0;
+    public static boolean areAnyPressed(final Modifier... modifiers {
+        return (currentModifiers & Modifier.getMask(modifiers)) > 0;
     }
 
     /**
@@ -358,20 +383,20 @@ public final class Keyboard {
      */
     public static boolean areAllPressed(final Set<Modifier> modifierSet) {
         int mask = Modifier.getMask(modifierSet);
-        return (modifiers & mask) == mask;
+        return (currentModifiers & mask) == mask;
     }
 
     /**
      * Are all of the given list of {@link Modifier}s pressed?
      * <p> This is typically used to test two modifiers (like CTRL and SHIFT).
      *
-     * @param modifierList The list of modifiers to test.
+     * @param modifiers The modifiers to test.
      * @return {@code true} if all of the modifiers are pressed, {@code false}
      * if only some or none are pressed.
      */
-    public static boolean areAllPressed(final Modifier... modifierList) {
-        int mask = Modifier.getMask(modifierList);
-        return (modifiers & mask) == mask;
+    public static boolean areAllPressed(final Modifier... modifiers) {
+        int mask = Modifier.getMask(modifiers);
+        return (currentModifiers & mask) == mask;
     }
 
     /**
@@ -392,26 +417,26 @@ public final class Keyboard {
         DropAction dropAction = null;
 
         if (Platform.isOSX()) {
-            if (areAllPressed(Modifier.ALT, Modifier.META)) {
+            if (arePressed(Modifier.ALT, Modifier.META)) {
                 dropAction = DropAction.LINK;
-            } else if (isPressed(Modifier.ALT)) {
+            } else if (arePressed(Modifier.ALT)) {
                 dropAction = DropAction.COPY;
             } else {
                 dropAction = DropAction.MOVE;
             }
         } else if (Platform.isWindows()) {
-            if (areAllPressed(Modifier.CTRL, Modifier.SHIFT)) {
+            if (arePressed(Modifier.CTRL, Modifier.SHIFT)) {
                 dropAction = DropAction.LINK;
-            } else if (isPressed(Modifier.CTRL)) {
+            } else if (arePressed(Modifier.CTRL)) {
                 dropAction = DropAction.COPY;
             } else {
                 dropAction = DropAction.MOVE;
             }
         } else {
             // TODO: is this correct for Linux / Unix / ???
-            if (areAllPressed(Modifier.CTRL, Modifier.SHIFT)) {
+            if (arePressed(Modifier.CTRL, Modifier.SHIFT)) {
                 dropAction = DropAction.LINK;
-            } else if (isPressed(Modifier.CTRL)) {
+            } else if (arePressed(Modifier.CTRL)) {
                 dropAction = DropAction.COPY;
             } else {
                 dropAction = DropAction.MOVE;