java.awt.event

Class InputEvent

Implemented Interfaces:
Serializable
Known Direct Subclasses:
KeyEvent, MouseEvent

public abstract class InputEvent
extends ComponentEvent

This is the common superclass for all component input classes. These are passed to listeners before the component, so that listeners can consume the event before it does its default behavior.
Since:
1.1
See Also:
KeyEvent, KeyAdapter, MouseEvent, MouseAdapter, MouseMotionAdapter, MouseWheelEvent, Serialized Form

Field Summary

static int
ALT_DOWN_MASK
The ALT key extended modifier.
static int
ALT_GRAPH_DOWN_MASK
The ALT_GRAPH key extended modifier.
static int
ALT_GRAPH_MASK
This is the bit mask which indicates the alt-graph modifier is in effect.
static int
ALT_MASK
This is the bit mask which indicates the alt key is down.
static int
BUTTON1_DOWN_MASK
The mouse button1 key extended modifier.
static int
BUTTON1_MASK
This bit mask indicates mouse button one is down.
static int
BUTTON2_DOWN_MASK
The mouse button2 extended modifier.
static int
BUTTON2_MASK
This bit mask indicates mouse button two is down.
static int
BUTTON3_DOWN_MASK
The mouse button3 extended modifier.
static int
BUTTON3_MASK
This bit mask indicates mouse button three is down.
static int
CTRL_DOWN_MASK
The CTRL key extended modifier.
static int
CTRL_MASK
This is the bit mask which indicates the control key is down.
static int
META_DOWN_MASK
The META key extended modifier.
static int
META_MASK
This is the bit mask which indicates the meta key is down.
static int
SHIFT_DOWN_MASK
The SHIFT key extended modifier.
static int
SHIFT_MASK
This is the bit mask which indicates the shift key is down.

Fields inherited from class java.awt.event.ComponentEvent

COMPONENT_FIRST, COMPONENT_HIDDEN, COMPONENT_LAST, COMPONENT_MOVED, COMPONENT_RESIZED, COMPONENT_SHOWN

Fields inherited from class java.awt.AWTEvent

ACTION_EVENT_MASK, ADJUSTMENT_EVENT_MASK, COMPONENT_EVENT_MASK, CONTAINER_EVENT_MASK, FOCUS_EVENT_MASK, HIERARCHY_BOUNDS_EVENT_MASK, HIERARCHY_EVENT_MASK, INPUT_METHOD_EVENT_MASK, INVOCATION_EVENT_MASK, ITEM_EVENT_MASK, KEY_EVENT_MASK, MOUSE_EVENT_MASK, MOUSE_MOTION_EVENT_MASK, MOUSE_WHEEL_EVENT_MASK, PAINT_EVENT_MASK, RESERVED_ID_MAX, TEXT_EVENT_MASK, WINDOW_EVENT_MASK, WINDOW_FOCUS_EVENT_MASK, WINDOW_STATE_EVENT_MASK, consumed, id

Fields inherited from class java.util.EventObject

source

Method Summary

void
consume()
Consumes this event.
int
getModifiers()
This method returns the old-style modifiers in effect for this event.
int
getModifiersEx()
Returns the extended modifiers (new-style) for this event.
static String
getModifiersExText(int modifiers)
Convert the extended modifier bitmask into a String, such as "Shift" or "Ctrl+Button1".
long
getWhen()
This method returns the timestamp when this event occurred.
boolean
isAltDown()
This method tests whether or not the alt key was down during the event.
boolean
isAltGraphDown()
This method tests whether or not the alt-graph modifier was in effect during the event.
boolean
isConsumed()
This method tests whether or not this event has been consumed.
boolean
isControlDown()
This method tests whether or not the control key was down during the event.
boolean
isMetaDown()
This method tests whether or not the meta key was down during the event.
boolean
isShiftDown()
This method tests whether or not the shift key was down during the event.

Methods inherited from class java.awt.event.ComponentEvent

getComponent, paramString

Methods inherited from class java.awt.AWTEvent

consume, getID, isConsumed, paramString, setSource, toString

Methods inherited from class java.util.EventObject

getSource, toString

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

ALT_DOWN_MASK

public static final int ALT_DOWN_MASK
The ALT key extended modifier.
Field Value:
512
Since:
1.4

ALT_GRAPH_DOWN_MASK

public static final int ALT_GRAPH_DOWN_MASK
The ALT_GRAPH key extended modifier.
Field Value:
8192
Since:
1.4

ALT_GRAPH_MASK

public static final int ALT_GRAPH_MASK
This is the bit mask which indicates the alt-graph modifier is in effect. It is recommended that ALT_GRAPH_DOWN_MASK be used instead.
Field Value:
32

ALT_MASK

public static final int ALT_MASK
This is the bit mask which indicates the alt key is down. It is recommended that ALT_DOWN_MASK be used instead.
Field Value:
8
See Also:
ALT_DOWN_MASK

BUTTON1_DOWN_MASK

public static final int BUTTON1_DOWN_MASK
The mouse button1 key extended modifier.
Field Value:
1024
Since:
1.4

BUTTON1_MASK

public static final int BUTTON1_MASK
This bit mask indicates mouse button one is down. It is recommended that BUTTON1_DOWN_MASK be used instead.
Field Value:
16

BUTTON2_DOWN_MASK

public static final int BUTTON2_DOWN_MASK
The mouse button2 extended modifier.
Field Value:
2048
Since:
1.4

BUTTON2_MASK

public static final int BUTTON2_MASK
This bit mask indicates mouse button two is down. It is recommended that BUTTON2_DOWN_MASK be used instead.
Field Value:
8

BUTTON3_DOWN_MASK

public static final int BUTTON3_DOWN_MASK
The mouse button3 extended modifier.
Field Value:
4096
Since:
1.4

BUTTON3_MASK

public static final int BUTTON3_MASK
This bit mask indicates mouse button three is down. It is recommended that BUTTON3_DOWN_MASK be used instead.
Field Value:
4

CTRL_DOWN_MASK

public static final int CTRL_DOWN_MASK
The CTRL key extended modifier.
Field Value:
128
Since:
1.4

CTRL_MASK

public static final int CTRL_MASK
This is the bit mask which indicates the control key is down. It is recommended that CTRL_DOWN_MASK be used instead.
Field Value:
2

META_DOWN_MASK

public static final int META_DOWN_MASK
The META key extended modifier.
Field Value:
256
Since:
1.4

META_MASK

public static final int META_MASK
This is the bit mask which indicates the meta key is down. It is recommended that META_DOWN_MASK be used instead.
Field Value:
4

SHIFT_DOWN_MASK

public static final int SHIFT_DOWN_MASK
The SHIFT key extended modifier.
Field Value:
64
Since:
1.4

SHIFT_MASK

public static final int SHIFT_MASK
This is the bit mask which indicates the shift key is down. It is recommended that SHIFT_DOWN_MASK be used instead.
Field Value:
1

Method Details

consume

public void consume()
Consumes this event. A consumed event is not processed further by the AWT system.
Overrides:
consume in interface AWTEvent

getModifiers

public int getModifiers()
This method returns the old-style modifiers in effect for this event. Note that this is ambiguous between button2 and alt, and between button3 and meta. Also, code which generated these modifiers tends to only list the modifier that just changed, even if others were down at the time. Consider using getModifiersEx instead. This will be a union of the bit masks defined in this class that are applicable to the event.
Returns:
the modifiers in effect for this event

getModifiersEx

public int getModifiersEx()
Returns the extended modifiers (new-style) for this event. This represents the state of all modal keys and mouse buttons at the time of the event, and does not suffer from the problems mentioned in getModifiers.

For an example of checking multiple modifiers, this code will return true only if SHIFT and BUTTON1 were pressed and CTRL was not:

 int onmask = InputEvent.SHIFT_DOWN_MASK | InputEvent.BUTTON1_DOWN_MASK;
 int offmask = InputEvent.CTRL_DOWN_MASK;
 return (event.getModifiersEx() & (onmask | offmask)) == onmask;
 
Returns:
the bitwise or of all modifiers pressed during the event
Since:
1.4

getModifiersExText

public static String getModifiersExText(int modifiers)
Convert the extended modifier bitmask into a String, such as "Shift" or "Ctrl+Button1". XXX Sun claims this can be localized via the awt.properties file - how do we implement that?
Parameters:
modifiers - the modifiers
Returns:
a string representation of the modifiers in this bitmask
Since:
1.4

getWhen

public long getWhen()
This method returns the timestamp when this event occurred.
Returns:
the timestamp when this event occurred

isAltDown

public boolean isAltDown()
This method tests whether or not the alt key was down during the event.
Returns:
true if the alt key is down

isAltGraphDown

public boolean isAltGraphDown()
This method tests whether or not the alt-graph modifier was in effect during the event.
Returns:
true if the alt-graph modifier is down

isConsumed

public boolean isConsumed()
This method tests whether or not this event has been consumed.
Overrides:
isConsumed in interface AWTEvent
Returns:
true if this event has been consumed

isControlDown

public boolean isControlDown()
This method tests whether or not the control key was down during the event.
Returns:
true if the control key is down

isMetaDown

public boolean isMetaDown()
This method tests whether or not the meta key was down during the event.
Returns:
true if the meta key is down

isShiftDown

public boolean isShiftDown()
This method tests whether or not the shift key was down during the event.
Returns:
true if the shift key is down

InputEvent.java -- common superclass of component input events Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.