275
276 public byte[] getBData(AWTEvent ev) {
277 return ev.bdata;
278 }
279
280 public void setBData(AWTEvent ev, byte[] bdata) {
281 ev.bdata = bdata;
282 }
283
284 });
285 }
286
287 /**
288 * Initialize JNI field and method IDs for fields that may be
289 * accessed from C.
290 */
291 private static native void initIDs();
292
293 /**
294 * Constructs an AWTEvent object from the parameters of a 1.0-style event.
295 * @param event the old-style event
296 */
297 public AWTEvent(Event event) {
298 this(event.target, event.id);
299 }
300
301 /**
302 * Constructs an AWTEvent object with the specified source object and type.
303 *
304 * @param source the object where the event originated
305 * @param id the event type
306 */
307 public AWTEvent(Object source, int id) {
308 super(source);
309 this.id = id;
310 switch(id) {
311 case ActionEvent.ACTION_PERFORMED:
312 case ItemEvent.ITEM_STATE_CHANGED:
313 case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED:
314 case TextEvent.TEXT_VALUE_CHANGED:
315 consumed = true;
316 break;
419
420 /**
421 * Returns whether this event has been consumed.
422 *
423 * @return {@code true} if this event has been consumed;
424 * otherwise {@code false}
425 */
426 protected boolean isConsumed() {
427 return consumed;
428 }
429
430 /**
431 * Converts a new event to an old one (used for compatibility).
432 * If the new event cannot be converted (because no old equivalent
433 * exists) then this returns null.
434 *
435 * Note: this method is here instead of in each individual new
436 * event class in java.awt.event because we don't want to make
437 * it public and it needs to be called from java.awt.
438 */
439 Event convertToOld() {
440 Object src = getSource();
441 int newid = id;
442
443 switch(id) {
444 case KeyEvent.KEY_PRESSED:
445 case KeyEvent.KEY_RELEASED:
446 KeyEvent ke = (KeyEvent)this;
447 if (ke.isActionKey()) {
448 newid = (id == KeyEvent.KEY_PRESSED?
449 Event.KEY_ACTION : Event.KEY_ACTION_RELEASE);
450 }
451 int keyCode = ke.getKeyCode();
452 if (keyCode == KeyEvent.VK_SHIFT ||
453 keyCode == KeyEvent.VK_CONTROL ||
454 keyCode == KeyEvent.VK_ALT) {
455 return null; // suppress modifier keys in old event model.
456 }
457 // no mask for button1 existed in old Event - strip it out
458 return new Event(src, ke.getWhen(), newid, 0, 0,
|
275
276 public byte[] getBData(AWTEvent ev) {
277 return ev.bdata;
278 }
279
280 public void setBData(AWTEvent ev, byte[] bdata) {
281 ev.bdata = bdata;
282 }
283
284 });
285 }
286
287 /**
288 * Initialize JNI field and method IDs for fields that may be
289 * accessed from C.
290 */
291 private static native void initIDs();
292
293 /**
294 * Constructs an AWTEvent object from the parameters of a 1.0-style event.
295 *
296 * @param event the old-style event
297 * @deprecated It is recommended that {@link #AWTEvent(Object, int)} be used
298 * instead
299 */
300 @Deprecated(since = "9")
301 public AWTEvent(Event event) {
302 this(event.target, event.id);
303 }
304
305 /**
306 * Constructs an AWTEvent object with the specified source object and type.
307 *
308 * @param source the object where the event originated
309 * @param id the event type
310 */
311 public AWTEvent(Object source, int id) {
312 super(source);
313 this.id = id;
314 switch(id) {
315 case ActionEvent.ACTION_PERFORMED:
316 case ItemEvent.ITEM_STATE_CHANGED:
317 case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED:
318 case TextEvent.TEXT_VALUE_CHANGED:
319 consumed = true;
320 break;
423
424 /**
425 * Returns whether this event has been consumed.
426 *
427 * @return {@code true} if this event has been consumed;
428 * otherwise {@code false}
429 */
430 protected boolean isConsumed() {
431 return consumed;
432 }
433
434 /**
435 * Converts a new event to an old one (used for compatibility).
436 * If the new event cannot be converted (because no old equivalent
437 * exists) then this returns null.
438 *
439 * Note: this method is here instead of in each individual new
440 * event class in java.awt.event because we don't want to make
441 * it public and it needs to be called from java.awt.
442 */
443 @SuppressWarnings("deprecation")
444 Event convertToOld() {
445 Object src = getSource();
446 int newid = id;
447
448 switch(id) {
449 case KeyEvent.KEY_PRESSED:
450 case KeyEvent.KEY_RELEASED:
451 KeyEvent ke = (KeyEvent)this;
452 if (ke.isActionKey()) {
453 newid = (id == KeyEvent.KEY_PRESSED?
454 Event.KEY_ACTION : Event.KEY_ACTION_RELEASE);
455 }
456 int keyCode = ke.getKeyCode();
457 if (keyCode == KeyEvent.VK_SHIFT ||
458 keyCode == KeyEvent.VK_CONTROL ||
459 keyCode == KeyEvent.VK_ALT) {
460 return null; // suppress modifier keys in old event model.
461 }
462 // no mask for button1 existed in old Event - strip it out
463 return new Event(src, ke.getWhen(), newid, 0, 0,
|