16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.awt.event; 27 28 import java.awt.Component; 29 import java.awt.GraphicsEnvironment; 30 import java.awt.Point; 31 import java.awt.Toolkit; 32 import java.io.IOException; 33 import java.io.ObjectInputStream; 34 import java.awt.IllegalComponentStateException; 35 import java.awt.MouseInfo; 36 import sun.awt.SunToolkit; 37 38 /** 39 * An event which indicates that a mouse action occurred in a component. 40 * A mouse action is considered to occur in a particular component if and only 41 * if the mouse cursor is over the unobscured part of the component's bounds 42 * when the action happens. 43 * For lightweight components, such as Swing's components, mouse events 44 * are only dispatched to the component if the mouse event type has been 45 * enabled on the component. A mouse event type is enabled by adding the 46 * appropriate mouse-based {@code EventListener} to the component 47 * ({@link MouseListener} or {@link MouseMotionListener}), or by invoking 48 * {@link Component#enableEvents(long)} with the appropriate mask parameter 49 * ({@code AWTEvent.MOUSE_EVENT_MASK} or {@code AWTEvent.MOUSE_MOTION_EVENT_MASK}). 50 * If the mouse event type has not been enabled on the component, the 51 * corresponding mouse events are dispatched to the first ancestor that 52 * has enabled the mouse event type. 53 *<p> 54 * For example, if a {@code MouseListener} has been added to a component, or 55 * {@code enableEvents(AWTEvent.MOUSE_EVENT_MASK)} has been invoked, then all 315 * @serial 316 */ 317 private int yAbs; 318 319 /** 320 * Indicates the number of quick consecutive clicks of 321 * a mouse button. 322 * clickCount will be valid for only three mouse events :<BR> 323 * {@code MOUSE_CLICKED}, 324 * {@code MOUSE_PRESSED} and 325 * {@code MOUSE_RELEASED}. 326 * For the above, the {@code clickCount} will be at least 1. 327 * For all other events the count will be 0. 328 * 329 * @serial 330 * @see #getClickCount() 331 */ 332 int clickCount; 333 334 /** 335 * Indicates which, if any, of the mouse buttons has changed state. 336 * 337 * The valid values are ranged from 0 to the value returned by the 338 * {@link java.awt.MouseInfo#getNumberOfButtons() MouseInfo.getNumberOfButtons()} method. 339 * This range already includes constants {@code NOBUTTON}, {@code BUTTON1}, 340 * {@code BUTTON2}, and {@code BUTTON3} 341 * if these buttons are present. So it is allowed to use these constants too. 342 * For example, for a mouse with two buttons this field may contain the following values: 343 * <ul> 344 * <li> 0 ({@code NOBUTTON}) 345 * <li> 1 ({@code BUTTON1}) 346 * <li> 2 ({@code BUTTON2}) 347 * </ul> 348 * If a mouse has 5 buttons, this field may contain the following values: 349 * <ul> 350 * <li> 0 ({@code NOBUTTON}) 351 * <li> 1 ({@code BUTTON1}) 352 * <li> 2 ({@code BUTTON2}) 353 * <li> 3 ({@code BUTTON3}) 354 * <li> 4 382 383 /** 384 * A number of buttons available on the mouse at the {@code Toolkit} machinery startup. 385 */ 386 private static int cachedNumberOfButtons; 387 388 static { 389 /* ensure that the necessary native libraries are loaded */ 390 NativeLibLoader.loadLibraries(); 391 if (!GraphicsEnvironment.isHeadless()) { 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; 401 } 402 } 403 404 /** 405 * Initialize JNI field and method IDs for fields that may be 406 * accessed from C. 407 */ 408 private static native void initIDs(); 409 410 /** 411 * Returns the absolute x, y position of the event. 412 * In a virtual device multi-screen environment in which the 413 * desktop area could span multiple physical screen devices, 414 * these coordinates are relative to the virtual coordinate system. 415 * Otherwise, these coordinates are relative to the coordinate system 416 * associated with the Component's GraphicsConfiguration. 417 * 418 * @return a {@code Point} object containing the absolute x 419 * and y coordinates. 420 * 421 * @see java.awt.GraphicsConfiguration | 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.awt.event; 27 28 import java.awt.Component; 29 import java.awt.GraphicsEnvironment; 30 import java.awt.Point; 31 import java.awt.Toolkit; 32 import java.io.IOException; 33 import java.io.ObjectInputStream; 34 import java.awt.IllegalComponentStateException; 35 import java.awt.MouseInfo; 36 37 import sun.awt.AWTAccessor; 38 import sun.awt.SunToolkit; 39 40 /** 41 * An event which indicates that a mouse action occurred in a component. 42 * A mouse action is considered to occur in a particular component if and only 43 * if the mouse cursor is over the unobscured part of the component's bounds 44 * when the action happens. 45 * For lightweight components, such as Swing's components, mouse events 46 * are only dispatched to the component if the mouse event type has been 47 * enabled on the component. A mouse event type is enabled by adding the 48 * appropriate mouse-based {@code EventListener} to the component 49 * ({@link MouseListener} or {@link MouseMotionListener}), or by invoking 50 * {@link Component#enableEvents(long)} with the appropriate mask parameter 51 * ({@code AWTEvent.MOUSE_EVENT_MASK} or {@code AWTEvent.MOUSE_MOTION_EVENT_MASK}). 52 * If the mouse event type has not been enabled on the component, the 53 * corresponding mouse events are dispatched to the first ancestor that 54 * has enabled the mouse event type. 55 *<p> 56 * For example, if a {@code MouseListener} has been added to a component, or 57 * {@code enableEvents(AWTEvent.MOUSE_EVENT_MASK)} has been invoked, then all 317 * @serial 318 */ 319 private int yAbs; 320 321 /** 322 * Indicates the number of quick consecutive clicks of 323 * a mouse button. 324 * clickCount will be valid for only three mouse events :<BR> 325 * {@code MOUSE_CLICKED}, 326 * {@code MOUSE_PRESSED} and 327 * {@code MOUSE_RELEASED}. 328 * For the above, the {@code clickCount} will be at least 1. 329 * For all other events the count will be 0. 330 * 331 * @serial 332 * @see #getClickCount() 333 */ 334 int clickCount; 335 336 /** 337 * Indicates whether the event is a result of a touch event. 338 */ 339 private boolean causedByTouchEvent; 340 341 /** 342 * Indicates which, if any, of the mouse buttons has changed state. 343 * 344 * The valid values are ranged from 0 to the value returned by the 345 * {@link java.awt.MouseInfo#getNumberOfButtons() MouseInfo.getNumberOfButtons()} method. 346 * This range already includes constants {@code NOBUTTON}, {@code BUTTON1}, 347 * {@code BUTTON2}, and {@code BUTTON3} 348 * if these buttons are present. So it is allowed to use these constants too. 349 * For example, for a mouse with two buttons this field may contain the following values: 350 * <ul> 351 * <li> 0 ({@code NOBUTTON}) 352 * <li> 1 ({@code BUTTON1}) 353 * <li> 2 ({@code BUTTON2}) 354 * </ul> 355 * If a mouse has 5 buttons, this field may contain the following values: 356 * <ul> 357 * <li> 0 ({@code NOBUTTON}) 358 * <li> 1 ({@code BUTTON1}) 359 * <li> 2 ({@code BUTTON2}) 360 * <li> 3 ({@code BUTTON3}) 361 * <li> 4 389 390 /** 391 * A number of buttons available on the mouse at the {@code Toolkit} machinery startup. 392 */ 393 private static int cachedNumberOfButtons; 394 395 static { 396 /* ensure that the necessary native libraries are loaded */ 397 NativeLibLoader.loadLibraries(); 398 if (!GraphicsEnvironment.isHeadless()) { 399 initIDs(); 400 } 401 final Toolkit tk = Toolkit.getDefaultToolkit(); 402 if (tk instanceof SunToolkit) { 403 cachedNumberOfButtons = ((SunToolkit)tk).getNumberOfButtons(); 404 } else { 405 //It's expected that some toolkits (Headless, 406 //whatever besides SunToolkit) could also operate. 407 cachedNumberOfButtons = 3; 408 } 409 AWTAccessor.setMouseEventAccessor( 410 new AWTAccessor.MouseEventAccessor() { 411 public boolean isCausedByTouchEvent(MouseEvent ev) { 412 return ev.causedByTouchEvent; 413 } 414 415 public void setCausedByTouchEvent(MouseEvent ev, 416 boolean causedByTouchEvent) { 417 ev.causedByTouchEvent = causedByTouchEvent; 418 } 419 }); 420 } 421 422 /** 423 * Initialize JNI field and method IDs for fields that may be 424 * accessed from C. 425 */ 426 private static native void initIDs(); 427 428 /** 429 * Returns the absolute x, y position of the event. 430 * In a virtual device multi-screen environment in which the 431 * desktop area could span multiple physical screen devices, 432 * these coordinates are relative to the virtual coordinate system. 433 * Otherwise, these coordinates are relative to the coordinate system 434 * associated with the Component's GraphicsConfiguration. 435 * 436 * @return a {@code Point} object containing the absolute x 437 * and y coordinates. 438 * 439 * @see java.awt.GraphicsConfiguration |