--- a/jdk/src/share/classes/java/awt/event/MouseEvent.java Thu May 21 15:04:23 2009 +0400
+++ b/jdk/src/share/classes/java/awt/event/MouseEvent.java Fri May 22 16:09:45 2009 +0400
@@ -33,6 +33,7 @@
import java.io.ObjectInputStream;
import java.awt.IllegalComponentStateException;
import java.awt.MouseInfo;
+import sun.awt.SunToolkit;
/**
* An event which indicates that a mouse action occurred in a component.
@@ -379,12 +380,25 @@
*/
private static final long serialVersionUID = -991214153494842848L;
+ /**
+ * A number of buttons available on the mouse at the {@code Toolkit} machinery startup.
+ */
+ private static int cachedNumberOfButtons;
+
static {
/* ensure that the necessary native libraries are loaded */
NativeLibLoader.loadLibraries();
if (!GraphicsEnvironment.isHeadless()) {
initIDs();
}
+ final Toolkit tk = Toolkit.getDefaultToolkit();
+ if (tk instanceof SunToolkit) {
+ cachedNumberOfButtons = ((SunToolkit)tk).getNumberOfButtons();
+ } else {
+ //It's expected that some toolkits (Headless,
+ //whatever besides SunToolkit) could also operate.
+ cachedNumberOfButtons = 3;
+ }
}
/**
@@ -412,15 +426,6 @@
}
/**
- * A number of buttons available on the mouse at the {@code Toolkit} machinery startup.
- */
- private static int cachedNumberOfButtons;
-
- static {
- cachedNumberOfButtons = MouseInfo.getNumberOfButtons();
- }
-
- /**
* Returns the absolute horizontal x position of the event.
* In a virtual device multi-screen environment in which the
* desktop area could span multiple physical screen devices,
@@ -735,7 +740,6 @@
if (button < NOBUTTON){
throw new IllegalArgumentException("Invalid button value :" + button);
}
- //TODO: initialize MouseInfo.cachedNumber on toolkit creation.
if (button > BUTTON3) {
if (!Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
throw new IllegalArgumentException("Extra mouse events are disabled " + button);