AWTEventpublic abstract class AWTEvent extends EventObject The root event class for all AWT events.
This class and its subclasses supercede the original
java.awt.Event class.
Subclasses of this root AWTEvent class defined outside of the
java.awt.event package should define event ID values greater than
the value defined by RESERVED_ID_MAX.
The event masks defined in this class are needed by Component subclasses
which are using Component.enableEvents() to select for event types not
selected by registered listeners. If a listener is registered on a
component, the appropriate event mask is already set internally by the
component.
The masks are also used to specify to which types of events an
AWTEventListener should listen. The masks are bitwise-ORed together
and passed to Toolkit.addAWTEventListener. |
Fields Summary |
---|
private byte[] | bdata | protected int | idThe event's id. | protected boolean | consumedControls whether or not the event is sent back down to the peer once the
source has processed it - false means it's sent to the peer; true means
it's not. Semantic events always have a 'true' value since they were
generated by the peer in response to a low-level event. | transient boolean | focusManagerIsDispatching | transient boolean | isPosted | public static final long | COMPONENT_EVENT_MASKThe event mask for selecting component events. | public static final long | CONTAINER_EVENT_MASKThe event mask for selecting container events. | public static final long | FOCUS_EVENT_MASKThe event mask for selecting focus events. | public static final long | KEY_EVENT_MASKThe event mask for selecting key events. | public static final long | MOUSE_EVENT_MASKThe event mask for selecting mouse events. | public static final long | MOUSE_MOTION_EVENT_MASKThe event mask for selecting mouse motion events. | public static final long | WINDOW_EVENT_MASKThe event mask for selecting window events. | public static final long | ACTION_EVENT_MASKThe event mask for selecting action events. | public static final long | ADJUSTMENT_EVENT_MASKThe event mask for selecting adjustment events. | public static final long | ITEM_EVENT_MASKThe event mask for selecting item events. | public static final long | TEXT_EVENT_MASKThe event mask for selecting text events. | public static final long | INPUT_METHOD_EVENT_MASKThe event mask for selecting input method events. | static final long | INPUT_METHODS_ENABLED_MASKThe pseudo event mask for enabling input methods.
We're using one bit in the eventMask so we don't need
a separate field inputMethodsEnabled. | public static final long | PAINT_EVENT_MASKThe event mask for selecting paint events. | public static final long | INVOCATION_EVENT_MASKThe event mask for selecting invocation events. | public static final long | HIERARCHY_EVENT_MASKThe event mask for selecting hierarchy events. | public static final long | HIERARCHY_BOUNDS_EVENT_MASKThe event mask for selecting hierarchy bounds events. | public static final long | MOUSE_WHEEL_EVENT_MASKThe event mask for selecting mouse wheel events. | public static final long | WINDOW_STATE_EVENT_MASKThe event mask for selecting window state events. | public static final long | WINDOW_FOCUS_EVENT_MASKThe event mask for selecting window focus events. | public static final int | RESERVED_ID_MAXThe maximum value for reserved AWT event IDs. Programs defining
their own event IDs should use IDs greater than this value. | private static Field | inputEvent_CanAccessSystemClipboard_Field | private static final long | serialVersionUID |
Constructors Summary |
---|
public AWTEvent(Event event)Constructs an AWTEvent object from the parameters of a 1.0-style event.
this(event.target, event.id);
| public AWTEvent(Object source, int id)Constructs an AWTEvent object with the specified source object and type.
super(source);
this.id = id;
switch(id) {
case ActionEvent.ACTION_PERFORMED:
case ItemEvent.ITEM_STATE_CHANGED:
case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED:
case TextEvent.TEXT_VALUE_CHANGED:
consumed = true;
break;
default:
}
|
Methods Summary |
---|
protected void | consume()Consumes this event, if this event can be consumed. Only low-level,
system events can be consumed
switch(id) {
case KeyEvent.KEY_PRESSED:
case KeyEvent.KEY_RELEASED:
case MouseEvent.MOUSE_PRESSED:
case MouseEvent.MOUSE_RELEASED:
case MouseEvent.MOUSE_MOVED:
case MouseEvent.MOUSE_DRAGGED:
case MouseEvent.MOUSE_ENTERED:
case MouseEvent.MOUSE_EXITED:
case MouseEvent.MOUSE_WHEEL:
case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
case InputMethodEvent.CARET_POSITION_CHANGED:
consumed = true;
break;
default:
// event type cannot be consumed
}
| java.awt.Event | convertToOld()Converts a new event to an old one (used for compatibility).
If the new event cannot be converted (because no old equivalent
exists) then this returns null.
Note: this method is here instead of in each individual new
event class in java.awt.event because we don't want to make
it public and it needs to be called from java.awt.
Object src = getSource();
int newid = id;
switch(id) {
case KeyEvent.KEY_PRESSED:
case KeyEvent.KEY_RELEASED:
KeyEvent ke = (KeyEvent)this;
if (ke.isActionKey()) {
newid = (id == KeyEvent.KEY_PRESSED?
Event.KEY_ACTION : Event.KEY_ACTION_RELEASE);
}
int keyCode = ke.getKeyCode();
if (keyCode == KeyEvent.VK_SHIFT ||
keyCode == KeyEvent.VK_CONTROL ||
keyCode == KeyEvent.VK_ALT) {
return null; // suppress modifier keys in old event model.
}
// no mask for button1 existed in old Event - strip it out
return new Event(src, ke.getWhen(), newid, 0, 0,
Event.getOldEventKey(ke),
(ke.getModifiers() & ~InputEvent.BUTTON1_MASK));
case MouseEvent.MOUSE_PRESSED:
case MouseEvent.MOUSE_RELEASED:
case MouseEvent.MOUSE_MOVED:
case MouseEvent.MOUSE_DRAGGED:
case MouseEvent.MOUSE_ENTERED:
case MouseEvent.MOUSE_EXITED:
MouseEvent me = (MouseEvent)this;
// no mask for button1 existed in old Event - strip it out
Event olde = new Event(src, me.getWhen(), newid,
me.getX(), me.getY(), 0,
(me.getModifiers() & ~InputEvent.BUTTON1_MASK));
olde.clickCount = me.getClickCount();
return olde;
case FocusEvent.FOCUS_GAINED:
return new Event(src, Event.GOT_FOCUS, null);
case FocusEvent.FOCUS_LOST:
return new Event(src, Event.LOST_FOCUS, null);
case WindowEvent.WINDOW_CLOSING:
case WindowEvent.WINDOW_ICONIFIED:
case WindowEvent.WINDOW_DEICONIFIED:
return new Event(src, newid, null);
case ComponentEvent.COMPONENT_MOVED:
if (src instanceof Frame || src instanceof Dialog) {
Point p = ((Component)src).getLocation();
return new Event(src, 0, Event.WINDOW_MOVED, p.x, p.y, 0, 0);
}
break;
case ActionEvent.ACTION_PERFORMED:
ActionEvent ae = (ActionEvent)this;
String cmd;
if (src instanceof Button) {
cmd = ((Button)src).getLabel();
} else if (src instanceof MenuItem) {
cmd = ((MenuItem)src).getLabel();
} else {
cmd = ae.getActionCommand();
}
return new Event(src, 0, newid, 0, 0, 0, ae.getModifiers(), cmd);
case ItemEvent.ITEM_STATE_CHANGED:
ItemEvent ie = (ItemEvent)this;
Object arg;
if (src instanceof List) {
newid = (ie.getStateChange() == ItemEvent.SELECTED?
Event.LIST_SELECT : Event.LIST_DESELECT);
arg = ie.getItem();
} else {
newid = Event.ACTION_EVENT;
if (src instanceof Choice) {
arg = ie.getItem();
} else { // Checkbox
arg = new Boolean(ie.getStateChange() == ItemEvent.SELECTED);
}
}
return new Event(src, newid, arg);
case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED:
AdjustmentEvent aje = (AdjustmentEvent)this;
switch(aje.getAdjustmentType()) {
case AdjustmentEvent.UNIT_INCREMENT:
newid = Event.SCROLL_LINE_DOWN;
break;
case AdjustmentEvent.UNIT_DECREMENT:
newid = Event.SCROLL_LINE_UP;
break;
case AdjustmentEvent.BLOCK_INCREMENT:
newid = Event.SCROLL_PAGE_DOWN;
break;
case AdjustmentEvent.BLOCK_DECREMENT:
newid = Event.SCROLL_PAGE_UP;
break;
case AdjustmentEvent.TRACK:
if (aje.getValueIsAdjusting()) {
newid = Event.SCROLL_ABSOLUTE;
}
else {
newid = Event.SCROLL_END;
}
break;
default:
return null;
}
return new Event(src, newid, new Integer(aje.getValue()));
default:
}
return null;
| void | copyPrivateDataInto(java.awt.AWTEvent that)Copies all private data from this event into that.
Space is allocated for the copied data that will be
freed when the that is finalized. Upon completion,
this event is not changed.
that.bdata = this.bdata;
// Copy canAccessSystemClipboard value from this into that.
if (this instanceof InputEvent && that instanceof InputEvent) {
Field field = get_InputEvent_CanAccessSystemClipboard();
if (field != null) {
try {
boolean b = field.getBoolean(this);
field.setBoolean(that, b);
} catch(IllegalAccessException e) {
}
}
}
| void | dispatched()
if (this instanceof InputEvent) {
Field field = get_InputEvent_CanAccessSystemClipboard();
if (field != null) {
try {
field.setBoolean(this, false);
} catch(IllegalAccessException e) {
}
}
}
| public int | getID()Returns the event type.
return id;
| private static synchronized java.lang.reflect.Field | get_InputEvent_CanAccessSystemClipboard()
/* ensure that the necessary native libraries are loaded */
Toolkit.loadLibraries();
if (!GraphicsEnvironment.isHeadless()) {
initIDs();
}
if (inputEvent_CanAccessSystemClipboard_Field == null) {
inputEvent_CanAccessSystemClipboard_Field =
(Field)java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
Field field = null;
try {
field = InputEvent.class.
getDeclaredField("canAccessSystemClipboard");
field.setAccessible(true);
return field;
} catch (SecurityException e) {
} catch (NoSuchFieldException e) {
}
return null;
}
});
}
return inputEvent_CanAccessSystemClipboard_Field;
| private static native void | initIDs()Initialize JNI field and method IDs for fields that may be
accessed from C.
| protected boolean | isConsumed()Returns whether this event has been consumed.
return consumed;
| private native void | nativeSetSource(java.awt.peer.ComponentPeer peer)
| public java.lang.String | paramString()Returns a string representing the state of this Event .
This method is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not be
null .
return "";
| public void | setSource(java.lang.Object newSource)Retargets an event to a new source. This method is typically used to
retarget an event to a lightweight child Component of the original
heavyweight source.
This method is intended to be used only by event targeting subsystems,
such as client-defined KeyboardFocusManagers. It is not for general
client use.
if (source == newSource) {
return;
}
Component comp = null;
if (newSource instanceof Component) {
comp = (Component)newSource;
while (comp != null && comp.peer != null &&
(comp.peer instanceof LightweightPeer)) {
comp = comp.parent;
}
}
synchronized (this) {
source = newSource;
if (comp != null) {
ComponentPeer peer = comp.peer;
if (peer != null) {
nativeSetSource(peer);
}
}
}
| public java.lang.String | toString()Returns a String representation of this object.
String srcName = null;
if (source instanceof Component) {
srcName = ((Component)source).getName();
} else if (source instanceof MenuComponent) {
srcName = ((MenuComponent)source).getName();
}
return getClass().getName() + "[" + paramString() + "] on " +
(srcName != null? srcName : source);
|
|