Author: rwhitcomb Date: Wed Sep 23 16:01:44 2020 New Revision: 1881960 URL: http://svn.apache.org/viewvc?rev=1881960&view=rev Log: Fixed a TODO item in Keyboard related to checking the correct modifiers for each platform to determine the drop action. To that end, add methods to Platform to determine the current platform for testing.
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java pivot/trunk/wtk/src/org/apache/pivot/wtk/Platform.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=1881960&r1=1881959&r2=1881960&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Keyboard.java Wed Sep 23 16:01:44 2020 @@ -46,6 +46,19 @@ public final class Keyboard { } /** + * Determine the complete mask for all the given modifiers. + * @param modifiers The set of modifiers to test. + * @return The complete mask corresponding to the set. + */ + public static getCompleteMask(final Set<Modifier> modifiers) { + int mask = 0; + for (Modifier mod : modifiers) { + mask |= mod.getMask(); + } + return mask; + } + + /** * The set of all possible keyboard modifiers (for use with {@link #isPressed} * or {@link #areAnyPressed}). */ @@ -307,35 +320,43 @@ public final class Keyboard { * if none are pressed. */ public static boolean areAnyPressed(final Set<Modifier> modifiers) { - boolean result = false; - for (Modifier modifier : modifiers) { - if (isPressed(modifier)) { - result = true; - break; - } - } - return result; + int completeMask = Modifier.getCompleteMask(modifiers); + return (modifiers & completeMask) > 0; } /** * Returns the current drop action. * - * @return The drop action corresponding to the currently pressed modifier - * keys, or <tt>null</tt> if no modifiers are pressed. + * @return The drop action corresponding to the currently pressed modifier keys. */ public static DropAction getDropAction() { - // TODO Return an appropriate action for OS: - // Windows: no modifier - move; control - copy; control-shift - link - // Mac OS X: no modifier - move; option - copy; option-command - link - DropAction dropAction = null; - if (isPressed(Modifier.CTRL) && isPressed(Modifier.SHIFT)) { - dropAction = DropAction.LINK; - } else if (isPressed(Modifier.CTRL)) { - dropAction = DropAction.COPY; + if (Platform.isOSX()) { + if (isPressed(Modifier.ALT) && isPressed(Modifier.META)) { + dropAction = DropAction.LINK; + } else if (isPressed(Modifier.ALT)) { + dropAction = DropAction.COPY; + } else { + dropAction = DropAction.MOVE; + } + } else if (Platform.isWindows()) { + if (isPressed(Modifier.CTRL) && isPressed(Modifier.SHIFT)) { + dropAction = DropAction.LINK; + } else if (isPressed(Modifier.CTRL)) { + dropAction = DropAction.COPY; + } else { + dropAction = DropAction.MOVE; + } } else { - dropAction = DropAction.MOVE; + // TODO: is this correct for Linux / Unix / ??? + if (isPressed(Modifier.CTRL) && isPressed(Modifier.SHIFT)) { + dropAction = DropAction.LINK; + } else if (isPressed(Modifier.CTRL)) { + dropAction = DropAction.COPY; + } else { + dropAction = DropAction.MOVE; + } } return dropAction; Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Platform.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Platform.java?rev=1881960&r1=1881959&r2=1881960&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/Platform.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Platform.java Wed Sep 23 16:01:44 2020 @@ -31,6 +31,11 @@ import org.apache.pivot.wtk.Keyboard.Mod public final class Platform { private static FontRenderContext fontRenderContext; + private static final String OS_NAME; + private static final boolean osIsWindows; + private static final boolean osIsOSX; + private static final boolean osIsLinux; + private static final int DEFAULT_MULTI_CLICK_INTERVAL = 400; private static final int DEFAULT_CURSOR_BLINK_RATE = 600; @@ -39,13 +44,17 @@ public final class Platform { private static final String KEYSTROKE_MODIFIER_SEPARATOR; static { - String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); + OS_NAME = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); + + osIsWindows = OS_NAME.startsWith("windows"); + osIsOSX = OS_NAME.startsWith("mac os x"); + osIsLinux = OS_NAME.startsWith("linux"); - if (osName.startsWith("mac os x")) { + if (osIsOSX) { COMMAND_MODIFIER = Modifier.META; WORD_NAVIGATION_MODIFIER = Modifier.ALT; KEYSTROKE_MODIFIER_SEPARATOR = ""; - } else if (osName.startsWith("windows")) { + } else if (osIsWindows) { COMMAND_MODIFIER = Modifier.CTRL; WORD_NAVIGATION_MODIFIER = Modifier.CTRL; KEYSTROKE_MODIFIER_SEPARATOR = "+"; @@ -74,6 +83,27 @@ public final class Platform { } /** + * @return true if this is a Windows platform we're running on. + */ + public static boolean isWindows() { + return osIsWindows; + } + + /** + * @return true if this is a Mac OS X platform we're running on. + */ + public static boolean isOSX() { + return osIsOSX; + } + + /** + * @return true if this is a Linux platform we're running on. + */ + public static boolean isLinux() { + return osIsLinux; + } + + /** * @return The platform's font rendering context. */ public static FontRenderContext getFontRenderContext() {