| Method from java.awt.event.InputEvent Detail: |
public void consume() {
consumed = true;
}
Consumes this event so that it will not be processed
in the default manner by the source which originated it. |
public static int getMaskForButton(int button) {
if (button < = 0 || button > BUTTON_DOWN_MASK.length) {
throw new IllegalArgumentException("button doesn\'t exist " + button);
}
return BUTTON_DOWN_MASK[button - 1];
}
A method to obtain a mask for any existing mouse button.
The returned mask may be used for different purposes. Following are some of them:
|
public int getModifiers() {
return modifiers & (JDK_1_3_MODIFIERS | HIGH_MODIFIERS);
}
Returns the modifier mask for this event. |
public int getModifiersEx() {
return modifiers & ~JDK_1_3_MODIFIERS;
}
Returns the extended modifier mask for this event.
Extended modifiers represent the state of all modal keys,
such as ALT, CTRL, META, and the mouse buttons just after
the event occurred
For example, if the user presses button 1 followed by
button 2, and then releases them in the same order,
the following sequence of events is generated:
MOUSE_PRESSED: BUTTON1_DOWN_MASK
MOUSE_PRESSED: BUTTON1_DOWN_MASK | BUTTON2_DOWN_MASK
MOUSE_RELEASED: BUTTON2_DOWN_MASK
MOUSE_CLICKED: BUTTON2_DOWN_MASK
MOUSE_RELEASED:
MOUSE_CLICKED:
It is not recommended to compare the return value of this method
using == because new modifiers can be added in the future.
For example, the appropriate way to check that SHIFT and BUTTON1 are
down, but CTRL is up is demonstrated by the following code:
int onmask = SHIFT_DOWN_MASK | BUTTON1_DOWN_MASK;
int offmask = CTRL_DOWN_MASK;
if ((event.getModifiersEx() & (onmask | offmask)) == onmask) {
...
}
The above code will work even if new modifiers are added. |
public static String getModifiersExText(int modifiers) {
StringBuilder buf = new StringBuilder();
if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
buf.append(Toolkit.getProperty("AWT.meta", "Meta"));
buf.append("+");
}
if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
buf.append(Toolkit.getProperty("AWT.control", "Ctrl"));
buf.append("+");
}
if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0) {
buf.append(Toolkit.getProperty("AWT.alt", "Alt"));
buf.append("+");
}
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
buf.append(Toolkit.getProperty("AWT.shift", "Shift"));
buf.append("+");
}
if ((modifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
buf.append(Toolkit.getProperty("AWT.altGraph", "Alt Graph"));
buf.append("+");
}
int buttonNumber = 1;
for (int mask : InputEvent.BUTTON_DOWN_MASK){
if ((modifiers & mask) != 0) {
buf.append(Toolkit.getProperty("AWT.button"+buttonNumber, "Button"+buttonNumber));
buf.append("+");
}
buttonNumber++;
}
if (buf.length() > 0) {
buf.setLength(buf.length()-1); // remove trailing '+'
}
return buf.toString();
}
Returns a String describing the extended modifier keys and
mouse buttons, such as "Shift", "Button1", or "Ctrl+Shift".
These strings can be localized by changing the
awt.properties file.
Note that passing negative parameter is incorrect,
and will cause the returning an unspecified string.
Zero parameter means that no modifiers were passed and will
cause the returning an empty string. |
public long getWhen() {
return when;
}
Returns the difference in milliseconds between the timestamp of when this event occurred and
midnight, January 1, 1970 UTC. |
public boolean isAltDown() {
return (modifiers & ALT_MASK) != 0;
}
Returns whether or not the Alt modifier is down on this event. |
public boolean isAltGraphDown() {
return (modifiers & ALT_GRAPH_MASK) != 0;
}
Returns whether or not the AltGraph modifier is down on this event. |
public boolean isConsumed() {
return consumed;
}
Returns whether or not this event has been consumed. |
public boolean isControlDown() {
return (modifiers & CTRL_MASK) != 0;
}
Returns whether or not the Control modifier is down on this event. |
public boolean isMetaDown() {
return (modifiers & META_MASK) != 0;
}
Returns whether or not the Meta modifier is down on this event. |
public boolean isShiftDown() {
return (modifiers & SHIFT_MASK) != 0;
}
Returns whether or not the Shift modifier is down on this event. |