1 /*
2 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
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
371 (comp.peer instanceof LightweightPeer)) {
372 comp = comp.parent;
373 }
374 }
375
376 synchronized (this) {
377 source = newSource;
378 if (comp != null) {
379 ComponentPeer peer = comp.peer;
380 if (peer != null) {
381 nativeSetSource(peer);
382 }
383 }
384 }
385 }
386
387 private native void nativeSetSource(ComponentPeer peer);
388
389 /**
390 * Returns the event type.
391 */
392 public int getID() {
393 return id;
394 }
395
396 /**
397 * Returns a String representation of this object.
398 */
399 public String toString() {
400 String srcName = null;
401 if (source instanceof Component) {
402 srcName = ((Component)source).getName();
403 } else if (source instanceof MenuComponent) {
404 srcName = ((MenuComponent)source).getName();
405 }
406 return getClass().getName() + "[" + paramString() + "] on " +
407 (srcName != null? srcName : source);
408 }
409
410 /**
429 case KeyEvent.KEY_PRESSED:
430 case KeyEvent.KEY_RELEASED:
431 case MouseEvent.MOUSE_PRESSED:
432 case MouseEvent.MOUSE_RELEASED:
433 case MouseEvent.MOUSE_MOVED:
434 case MouseEvent.MOUSE_DRAGGED:
435 case MouseEvent.MOUSE_ENTERED:
436 case MouseEvent.MOUSE_EXITED:
437 case MouseEvent.MOUSE_WHEEL:
438 case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
439 case InputMethodEvent.CARET_POSITION_CHANGED:
440 consumed = true;
441 break;
442 default:
443 // event type cannot be consumed
444 }
445 }
446
447 /**
448 * Returns whether this event has been consumed.
449 */
450 protected boolean isConsumed() {
451 return consumed;
452 }
453
454 /**
455 * Converts a new event to an old one (used for compatibility).
456 * If the new event cannot be converted (because no old equivalent
457 * exists) then this returns null.
458 *
459 * Note: this method is here instead of in each individual new
460 * event class in java.awt.event because we don't want to make
461 * it public and it needs to be called from java.awt.
462 */
463 Event convertToOld() {
464 Object src = getSource();
465 int newid = id;
466
467 switch(id) {
468 case KeyEvent.KEY_PRESSED:
|
1 /*
2 * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
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
371 (comp.peer instanceof LightweightPeer)) {
372 comp = comp.parent;
373 }
374 }
375
376 synchronized (this) {
377 source = newSource;
378 if (comp != null) {
379 ComponentPeer peer = comp.peer;
380 if (peer != null) {
381 nativeSetSource(peer);
382 }
383 }
384 }
385 }
386
387 private native void nativeSetSource(ComponentPeer peer);
388
389 /**
390 * Returns the event type.
391 *
392 * @return the event's type id
393 */
394 public int getID() {
395 return id;
396 }
397
398 /**
399 * Returns a String representation of this object.
400 */
401 public String toString() {
402 String srcName = null;
403 if (source instanceof Component) {
404 srcName = ((Component)source).getName();
405 } else if (source instanceof MenuComponent) {
406 srcName = ((MenuComponent)source).getName();
407 }
408 return getClass().getName() + "[" + paramString() + "] on " +
409 (srcName != null? srcName : source);
410 }
411
412 /**
431 case KeyEvent.KEY_PRESSED:
432 case KeyEvent.KEY_RELEASED:
433 case MouseEvent.MOUSE_PRESSED:
434 case MouseEvent.MOUSE_RELEASED:
435 case MouseEvent.MOUSE_MOVED:
436 case MouseEvent.MOUSE_DRAGGED:
437 case MouseEvent.MOUSE_ENTERED:
438 case MouseEvent.MOUSE_EXITED:
439 case MouseEvent.MOUSE_WHEEL:
440 case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
441 case InputMethodEvent.CARET_POSITION_CHANGED:
442 consumed = true;
443 break;
444 default:
445 // event type cannot be consumed
446 }
447 }
448
449 /**
450 * Returns whether this event has been consumed.
451 *
452 * @return {@code true} if this event has been consumed;
453 * otherwise {@code false}
454 */
455 protected boolean isConsumed() {
456 return consumed;
457 }
458
459 /**
460 * Converts a new event to an old one (used for compatibility).
461 * If the new event cannot be converted (because no old equivalent
462 * exists) then this returns null.
463 *
464 * Note: this method is here instead of in each individual new
465 * event class in java.awt.event because we don't want to make
466 * it public and it needs to be called from java.awt.
467 */
468 Event convertToOld() {
469 Object src = getSource();
470 int newid = id;
471
472 switch(id) {
473 case KeyEvent.KEY_PRESSED:
|