equal
deleted
inserted
replaced
31 import java.awt.Toolkit; |
31 import java.awt.Toolkit; |
32 import java.io.IOException; |
32 import java.io.IOException; |
33 import java.io.ObjectInputStream; |
33 import java.io.ObjectInputStream; |
34 import java.awt.IllegalComponentStateException; |
34 import java.awt.IllegalComponentStateException; |
35 import java.awt.MouseInfo; |
35 import java.awt.MouseInfo; |
|
36 import sun.awt.SunToolkit; |
36 |
37 |
37 /** |
38 /** |
38 * An event which indicates that a mouse action occurred in a component. |
39 * An event which indicates that a mouse action occurred in a component. |
39 * A mouse action is considered to occur in a particular component if and only |
40 * A mouse action is considered to occur in a particular component if and only |
40 * if the mouse cursor is over the unobscured part of the component's bounds |
41 * if the mouse cursor is over the unobscured part of the component's bounds |
377 /* |
378 /* |
378 * JDK 1.1 serialVersionUID |
379 * JDK 1.1 serialVersionUID |
379 */ |
380 */ |
380 private static final long serialVersionUID = -991214153494842848L; |
381 private static final long serialVersionUID = -991214153494842848L; |
381 |
382 |
|
383 /** |
|
384 * A number of buttons available on the mouse at the {@code Toolkit} machinery startup. |
|
385 */ |
|
386 private static int cachedNumberOfButtons; |
|
387 |
382 static { |
388 static { |
383 /* ensure that the necessary native libraries are loaded */ |
389 /* ensure that the necessary native libraries are loaded */ |
384 NativeLibLoader.loadLibraries(); |
390 NativeLibLoader.loadLibraries(); |
385 if (!GraphicsEnvironment.isHeadless()) { |
391 if (!GraphicsEnvironment.isHeadless()) { |
386 initIDs(); |
392 initIDs(); |
|
393 } |
|
394 final Toolkit tk = Toolkit.getDefaultToolkit(); |
|
395 if (tk instanceof SunToolkit) { |
|
396 cachedNumberOfButtons = ((SunToolkit)tk).getNumberOfButtons(); |
|
397 } else { |
|
398 //It's expected that some toolkits (Headless, |
|
399 //whatever besides SunToolkit) could also operate. |
|
400 cachedNumberOfButtons = 3; |
387 } |
401 } |
388 } |
402 } |
389 |
403 |
390 /** |
404 /** |
391 * Initialize JNI field and method IDs for fields that may be |
405 * Initialize JNI field and method IDs for fields that may be |
407 * @see java.awt.GraphicsConfiguration |
421 * @see java.awt.GraphicsConfiguration |
408 * @since 1.6 |
422 * @since 1.6 |
409 */ |
423 */ |
410 public Point getLocationOnScreen(){ |
424 public Point getLocationOnScreen(){ |
411 return new Point(xAbs, yAbs); |
425 return new Point(xAbs, yAbs); |
412 } |
|
413 |
|
414 /** |
|
415 * A number of buttons available on the mouse at the {@code Toolkit} machinery startup. |
|
416 */ |
|
417 private static int cachedNumberOfButtons; |
|
418 |
|
419 static { |
|
420 cachedNumberOfButtons = MouseInfo.getNumberOfButtons(); |
|
421 } |
426 } |
422 |
427 |
423 /** |
428 /** |
424 * Returns the absolute horizontal x position of the event. |
429 * Returns the absolute horizontal x position of the event. |
425 * In a virtual device multi-screen environment in which the |
430 * In a virtual device multi-screen environment in which the |
733 this.clickCount = clickCount; |
738 this.clickCount = clickCount; |
734 this.popupTrigger = popupTrigger; |
739 this.popupTrigger = popupTrigger; |
735 if (button < NOBUTTON){ |
740 if (button < NOBUTTON){ |
736 throw new IllegalArgumentException("Invalid button value :" + button); |
741 throw new IllegalArgumentException("Invalid button value :" + button); |
737 } |
742 } |
738 //TODO: initialize MouseInfo.cachedNumber on toolkit creation. |
|
739 if (button > BUTTON3) { |
743 if (button > BUTTON3) { |
740 if (!Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){ |
744 if (!Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){ |
741 throw new IllegalArgumentException("Extra mouse events are disabled " + button); |
745 throw new IllegalArgumentException("Extra mouse events are disabled " + button); |
742 } else { |
746 } else { |
743 if (button > cachedNumberOfButtons) { |
747 if (button > cachedNumberOfButtons) { |