diff --git a/make/sun/xawt/mapfile-vers b/make/sun/xawt/mapfile-vers index 9e0b434b557361e0cb36de61d0ad7b45d7d80e6b..59c5577877382b205fc5ccd49cf246bf20847c13 100644 --- a/make/sun/xawt/mapfile-vers +++ b/make/sun/xawt/mapfile-vers @@ -151,6 +151,7 @@ SUNWprivate_1.1 { Java_sun_awt_X11_XRobotPeer_mouseReleaseImpl; Java_sun_awt_X11_XRobotPeer_mouseWheelImpl; Java_sun_awt_X11_XRobotPeer_setup; + Java_sun_awt_X11_XRobotPeer_getNumberOfButtonsImpl; Java_java_awt_Component_initIDs; Java_java_awt_Container_initIDs; Java_java_awt_Button_initIDs; diff --git a/src/share/classes/java/awt/Robot.java b/src/share/classes/java/awt/Robot.java index 2ce6a2686f1e381f33cefa726c613e48bfc73442..94c71283cee338bcfafe55ae63fd5201adeffd6a 100644 --- a/src/share/classes/java/awt/Robot.java +++ b/src/share/classes/java/awt/Robot.java @@ -70,10 +70,7 @@ public class Robot { private RobotPeer peer; private boolean isAutoWaitForIdle = false; private int autoDelay = 0; - private static final int LEGAL_BUTTON_MASK = - InputEvent.BUTTON1_MASK| - InputEvent.BUTTON2_MASK| - InputEvent.BUTTON3_MASK; + private static int LEGAL_BUTTON_MASK; // location of robot's GC, used in mouseMove(), getPixelColor() and captureScreenImage() private Point gdLoc; @@ -98,6 +95,19 @@ public class Robot { } init(GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice()); + int tmpMask = 0; + if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){ + for (int i = 0; i < peer.getNumberOfButtons(); i++){ + tmpMask |= InputEvent.getMaskForButton(i+1); + } + } + tmpMask |= InputEvent.BUTTON1_MASK| + InputEvent.BUTTON2_MASK| + InputEvent.BUTTON3_MASK| + InputEvent.BUTTON1_DOWN_MASK| + InputEvent.BUTTON2_DOWN_MASK| + InputEvent.BUTTON3_DOWN_MASK; + LEGAL_BUTTON_MASK = tmpMask; } /** @@ -187,18 +197,55 @@ public class Robot { /** * Presses one or more mouse buttons. The mouse buttons should - * be released using the mouseRelease method. + * be released using the {@link #mouseRelease(int)} method. + * + * @param buttons the Button mask; a combination of one or more + * mouse button masks. + *

+ * It is allowed to use only a combination of valid values as a {@code buttons} parameter. + * A valid combination consists of {@code InputEvent.BUTTON1_DOWN_MASK}, + * {@code InputEvent.BUTTON2_DOWN_MASK}, {@code InputEvent.BUTTON3_DOWN_MASK} + * and values returned by the + * {@link InputEvent#getMaskForButton(int) InputEvent.getMaskForButton(button)} method. * - * @param buttons the Button mask; a combination of one or more - * of these flags: + * The valid combination also depends on a + * {@link Toolkit#areExtraMouseButtonsEnabled() Toolkit.areExtraMouseButtonsEnabled()} value as follows: + *

+ *

+ * The following standard button masks are also accepted: *

- * @throws IllegalArgumentException if the button mask is not a - * valid combination + * However, it is recommended to use {@code InputEvent.BUTTON1_DOWN_MASK}, + * {@code InputEvent.BUTTON2_DOWN_MASK}, {@code InputEvent.BUTTON3_DOWN_MASK} instead. + * Either extended {@code _DOWN_MASK} or old {@code _MASK} values + * should be used, but both those models should not be mixed. + * @throws IllegalArgumentException if the {@code buttons} mask contains the mask for extra mouse button + * and support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java + * @throws IllegalArgumentException if the {@code buttons} mask contains the mask for extra mouse button + * that does not exist on the mouse and support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled} by Java * @see #mouseRelease(int) + * @see InputEvent#getMaskForButton(int) + * @see Toolkit#areExtraMouseButtonsEnabled() + * @see java.awt.MouseInfo#getNumberOfButtons() + * @see java.awt.event.MouseEvent */ public synchronized void mousePress(int buttons) { checkButtonsArgument(buttons); @@ -209,16 +256,53 @@ public class Robot { /** * Releases one or more mouse buttons. * - * @param buttons the Button mask; a combination of one or more - * of these flags: + * @param buttons the Button mask; a combination of one or more + * mouse button masks. + *

+ * It is allowed to use only a combination of valid values as a {@code buttons} parameter. + * A valid combination consists of {@code InputEvent.BUTTON1_DOWN_MASK}, + * {@code InputEvent.BUTTON2_DOWN_MASK}, {@code InputEvent.BUTTON3_DOWN_MASK} + * and values returned by the + * {@link InputEvent#getMaskForButton(int) InputEvent.getMaskForButton(button)} method. + * + * The valid combination also depends on a + * {@link Toolkit#areExtraMouseButtonsEnabled() Toolkit.areExtraMouseButtonsEnabled()} value as follows: + *

+ *

+ * The following standard button masks are also accepted: *

+ * However, it is recommended to use {@code InputEvent.BUTTON1_DOWN_MASK}, + * {@code InputEvent.BUTTON2_DOWN_MASK}, {@code InputEvent.BUTTON3_DOWN_MASK} instead. + * Either extended {@code _DOWN_MASK} or old {@code _MASK} values + * should be used, but both those models should not be mixed. + * @throws IllegalArgumentException if the {@code buttons} mask contains the mask for extra mouse button + * and support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java + * @throws IllegalArgumentException if the {@code buttons} mask contains the mask for extra mouse button + * that does not exist on the mouse and support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled} by Java * @see #mousePress(int) - * @throws IllegalArgumentException if the button mask is not a valid - * combination + * @see InputEvent#getMaskForButton(int) + * @see Toolkit#areExtraMouseButtonsEnabled() + * @see java.awt.MouseInfo#getNumberOfButtons() + * @see java.awt.event.MouseEvent */ public synchronized void mouseRelease(int buttons) { checkButtonsArgument(buttons); diff --git a/src/share/classes/java/awt/Toolkit.java b/src/share/classes/java/awt/Toolkit.java index 5ac97013d1ad0a3b4d9412733e6173fdff2ca752..aaa6afdd5a08993f1956ad5425c4651ea49340ef 100644 --- a/src/share/classes/java/awt/Toolkit.java +++ b/src/share/classes/java/awt/Toolkit.java @@ -1,5 +1,5 @@ /* - * Copyright 1995-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1995-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -2550,4 +2550,37 @@ public abstract class Toolkit { } } } + + /** + * Reports whether events from extra mouse buttons are allowed to be processed and posted into + * {@code EventQueue}. + *
+ * To change the returned value it is necessary to set the {@code sun.awt.enableExtraMouseButtons} + * property before the {@code Toolkit} class initialization. This setting could be done on the application + * startup by the following command: + *
+    * java -Dsun.awt.enableExtraMouseButtons=false Application
+    * 
+ * Alternatively, the property could be set in the application by using the following code: + *
+    * System.setProperty("sun.awt.enableExtraMouseButtons", "true");
+    * 
+ * before the {@code Toolkit} class initialization. + * If not set by the time of the {@code Toolkit} class initialization, this property will be + * initialized with {@code true}. + * Changing this value after the {@code Toolkit} class initialization will have no effect. + *

+ * The current value could be queried by using the + * {@code System.getProperty("sun.awt.enableExtraMouseButtons")} method. + * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true + * @return {@code true} if events from extra mouse buttons are allowed to be processed and posted; + * {@code false} otherwise + * @see System#getProperty(String propertyName) + * @see System#setProperty(String propertyName, String value) + * @see java.awt.EventQueue + * @since 1.7 + */ + public boolean areExtraMouseButtonsEnabled() throws HeadlessException { + return Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled(); + } } diff --git a/src/share/classes/java/awt/doc-files/DesktopProperties.html b/src/share/classes/java/awt/doc-files/DesktopProperties.html index f699ba2fa7af79775e0423d4bd4842a67339d8d3..5f3afb37442b4575b77174bddf92207f42b347cc 100644 --- a/src/share/classes/java/awt/doc-files/DesktopProperties.html +++ b/src/share/classes/java/awt/doc-files/DesktopProperties.html @@ -1,5 +1,5 @@