298 public int[] getButtonDownMasks() {
299 return InputEvent.getButtonDownMasks();
300 }
301
302 public boolean canAccessSystemClipboard(InputEvent event) {
303 return event.canAccessSystemClipboard;
304 }
305 });
306 }
307
308 /**
309 * Initialize JNI field and method IDs for fields that may be
310 accessed from C.
311 */
312 private static native void initIDs();
313
314 /**
315 * Constructs an InputEvent object with the specified source component,
316 * modifiers, and type.
317 * <p> This method throws an
318 * <code>IllegalArgumentException</code> if <code>source</code>
319 * is <code>null</code>.
320 *
321 * @param source the object where the event originated
322 * @param id the integer that identifies the event type.
323 * It is allowed to pass as parameter any value that
324 * allowed for some subclass of {@code InputEvent} class.
325 * Passing in the value different from those values result
326 * in unspecified behavior
327 * @param when a long int that gives the time the event occurred.
328 * Passing negative or zero value
329 * is not recommended
330 * @param modifiers a modifier mask describing the modifier keys and mouse
331 * buttons (for example, shift, ctrl, alt, and meta) that
332 * are down during the event.
333 * Only extended modifiers are allowed to be used as a
334 * value for this parameter (see the {@link InputEvent#getModifiersEx}
335 * class for the description of extended modifiers).
336 * Passing negative parameter
337 * is not recommended.
338 * Zero value means that no modifiers were passed
339 * @throws IllegalArgumentException if <code>source</code> is null
340 * @see #getSource()
341 * @see #getID()
342 * @see #getWhen()
343 * @see #getModifiers()
344 */
345 InputEvent(Component source, int id, long when, int modifiers) {
346 super(source, id);
347 this.when = when;
348 this.modifiers = modifiers;
349 canAccessSystemClipboard = canAccessSystemClipboard();
350 }
351
352 private boolean canAccessSystemClipboard() {
353 boolean b = false;
354
355 if (!GraphicsEnvironment.isHeadless()) {
356 SecurityManager sm = System.getSecurityManager();
357 if (sm != null) {
358 try {
359 sm.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
425 * @return the modifier mask for this event
426 */
427 public int getModifiers() {
428 return modifiers & (JDK_1_3_MODIFIERS | HIGH_MODIFIERS);
429 }
430
431 /**
432 * Returns the extended modifier mask for this event.
433 * <P>
434 * Extended modifiers are the modifiers that ends with the _DOWN_MASK suffix,
435 * such as ALT_DOWN_MASK, BUTTON1_DOWN_MASK, and others.
436 * <P>
437 * Extended modifiers represent the state of all modal keys,
438 * such as ALT, CTRL, META, and the mouse buttons just after
439 * the event occurred.
440 * <P>
441 * For example, if the user presses <b>button 1</b> followed by
442 * <b>button 2</b>, and then releases them in the same order,
443 * the following sequence of events is generated:
444 * <PRE>
445 * <code>MOUSE_PRESSED</code>: <code>BUTTON1_DOWN_MASK</code>
446 * <code>MOUSE_PRESSED</code>: <code>BUTTON1_DOWN_MASK | BUTTON2_DOWN_MASK</code>
447 * <code>MOUSE_RELEASED</code>: <code>BUTTON2_DOWN_MASK</code>
448 * <code>MOUSE_CLICKED</code>: <code>BUTTON2_DOWN_MASK</code>
449 * <code>MOUSE_RELEASED</code>:
450 * <code>MOUSE_CLICKED</code>:
451 * </PRE>
452 * <P>
453 * It is not recommended to compare the return value of this method
454 * using <code>==</code> because new modifiers can be added in the future.
455 * For example, the appropriate way to check that SHIFT and BUTTON1 are
456 * down, but CTRL is up is demonstrated by the following code:
457 * <PRE>
458 * int onmask = SHIFT_DOWN_MASK | BUTTON1_DOWN_MASK;
459 * int offmask = CTRL_DOWN_MASK;
460 * if ((event.getModifiersEx() & (onmask | offmask)) == onmask) {
461 * ...
462 * }
463 * </PRE>
464 * The above code will work even if new modifiers are added.
465 *
466 * @return the extended modifier mask for this event
467 * @since 1.4
468 */
469 public int getModifiersEx() {
470 return modifiers & ~JDK_1_3_MODIFIERS;
471 }
472
473 /**
474 * Consumes this event so that it will not be processed
477 public void consume() {
478 consumed = true;
479 }
480
481 /**
482 * Returns whether or not this event has been consumed.
483 * @return whether or not this event has been consumed
484 * @see #consume
485 */
486 public boolean isConsumed() {
487 return consumed;
488 }
489
490 // state serialization compatibility with JDK 1.1
491 static final long serialVersionUID = -2482525981698309786L;
492
493 /**
494 * Returns a String describing the extended modifier keys and
495 * mouse buttons, such as "Shift", "Button1", or "Ctrl+Shift".
496 * These strings can be localized by changing the
497 * <code>awt.properties</code> file.
498 * <p>
499 * Note that passing negative parameter is incorrect,
500 * and will cause the returning an unspecified string.
501 * Zero parameter means that no modifiers were passed and will
502 * cause the returning an empty string.
503 *
504 * @return a String describing the extended modifier keys and
505 * mouse buttons
506 *
507 * @param modifiers a modifier mask describing the extended
508 * modifier keys and mouse buttons for the event
509 * @return a text description of the combination of extended
510 * modifier keys and mouse buttons that were held down
511 * during the event.
512 * @since 1.4
513 */
514 public static String getModifiersExText(int modifiers) {
515 StringBuilder buf = new StringBuilder();
516 if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
517 buf.append(Toolkit.getProperty("AWT.meta", "Meta"));
|
298 public int[] getButtonDownMasks() {
299 return InputEvent.getButtonDownMasks();
300 }
301
302 public boolean canAccessSystemClipboard(InputEvent event) {
303 return event.canAccessSystemClipboard;
304 }
305 });
306 }
307
308 /**
309 * Initialize JNI field and method IDs for fields that may be
310 accessed from C.
311 */
312 private static native void initIDs();
313
314 /**
315 * Constructs an InputEvent object with the specified source component,
316 * modifiers, and type.
317 * <p> This method throws an
318 * {@code IllegalArgumentException} if {@code source}
319 * is {@code null}.
320 *
321 * @param source the object where the event originated
322 * @param id the integer that identifies the event type.
323 * It is allowed to pass as parameter any value that
324 * allowed for some subclass of {@code InputEvent} class.
325 * Passing in the value different from those values result
326 * in unspecified behavior
327 * @param when a long int that gives the time the event occurred.
328 * Passing negative or zero value
329 * is not recommended
330 * @param modifiers a modifier mask describing the modifier keys and mouse
331 * buttons (for example, shift, ctrl, alt, and meta) that
332 * are down during the event.
333 * Only extended modifiers are allowed to be used as a
334 * value for this parameter (see the {@link InputEvent#getModifiersEx}
335 * class for the description of extended modifiers).
336 * Passing negative parameter
337 * is not recommended.
338 * Zero value means that no modifiers were passed
339 * @throws IllegalArgumentException if {@code source} is null
340 * @see #getSource()
341 * @see #getID()
342 * @see #getWhen()
343 * @see #getModifiers()
344 */
345 InputEvent(Component source, int id, long when, int modifiers) {
346 super(source, id);
347 this.when = when;
348 this.modifiers = modifiers;
349 canAccessSystemClipboard = canAccessSystemClipboard();
350 }
351
352 private boolean canAccessSystemClipboard() {
353 boolean b = false;
354
355 if (!GraphicsEnvironment.isHeadless()) {
356 SecurityManager sm = System.getSecurityManager();
357 if (sm != null) {
358 try {
359 sm.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
425 * @return the modifier mask for this event
426 */
427 public int getModifiers() {
428 return modifiers & (JDK_1_3_MODIFIERS | HIGH_MODIFIERS);
429 }
430
431 /**
432 * Returns the extended modifier mask for this event.
433 * <P>
434 * Extended modifiers are the modifiers that ends with the _DOWN_MASK suffix,
435 * such as ALT_DOWN_MASK, BUTTON1_DOWN_MASK, and others.
436 * <P>
437 * Extended modifiers represent the state of all modal keys,
438 * such as ALT, CTRL, META, and the mouse buttons just after
439 * the event occurred.
440 * <P>
441 * For example, if the user presses <b>button 1</b> followed by
442 * <b>button 2</b>, and then releases them in the same order,
443 * the following sequence of events is generated:
444 * <PRE>
445 * {@code MOUSE_PRESSED}: {@code BUTTON1_DOWN_MASK}
446 * {@code MOUSE_PRESSED}: {@code BUTTON1_DOWN_MASK | BUTTON2_DOWN_MASK}
447 * {@code MOUSE_RELEASED}: {@code BUTTON2_DOWN_MASK}
448 * {@code MOUSE_CLICKED}: {@code BUTTON2_DOWN_MASK}
449 * {@code MOUSE_RELEASED}:
450 * {@code MOUSE_CLICKED}:
451 * </PRE>
452 * <P>
453 * It is not recommended to compare the return value of this method
454 * using {@code ==} because new modifiers can be added in the future.
455 * For example, the appropriate way to check that SHIFT and BUTTON1 are
456 * down, but CTRL is up is demonstrated by the following code:
457 * <PRE>
458 * int onmask = SHIFT_DOWN_MASK | BUTTON1_DOWN_MASK;
459 * int offmask = CTRL_DOWN_MASK;
460 * if ((event.getModifiersEx() & (onmask | offmask)) == onmask) {
461 * ...
462 * }
463 * </PRE>
464 * The above code will work even if new modifiers are added.
465 *
466 * @return the extended modifier mask for this event
467 * @since 1.4
468 */
469 public int getModifiersEx() {
470 return modifiers & ~JDK_1_3_MODIFIERS;
471 }
472
473 /**
474 * Consumes this event so that it will not be processed
477 public void consume() {
478 consumed = true;
479 }
480
481 /**
482 * Returns whether or not this event has been consumed.
483 * @return whether or not this event has been consumed
484 * @see #consume
485 */
486 public boolean isConsumed() {
487 return consumed;
488 }
489
490 // state serialization compatibility with JDK 1.1
491 static final long serialVersionUID = -2482525981698309786L;
492
493 /**
494 * Returns a String describing the extended modifier keys and
495 * mouse buttons, such as "Shift", "Button1", or "Ctrl+Shift".
496 * These strings can be localized by changing the
497 * {@code awt.properties} file.
498 * <p>
499 * Note that passing negative parameter is incorrect,
500 * and will cause the returning an unspecified string.
501 * Zero parameter means that no modifiers were passed and will
502 * cause the returning an empty string.
503 *
504 * @return a String describing the extended modifier keys and
505 * mouse buttons
506 *
507 * @param modifiers a modifier mask describing the extended
508 * modifier keys and mouse buttons for the event
509 * @return a text description of the combination of extended
510 * modifier keys and mouse buttons that were held down
511 * during the event.
512 * @since 1.4
513 */
514 public static String getModifiersExText(int modifiers) {
515 StringBuilder buf = new StringBuilder();
516 if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
517 buf.append(Toolkit.getProperty("AWT.meta", "Meta"));
|