001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Michael Danilov
019: * @version $Revision$
020: */package java.awt.event;
021:
022: import java.awt.Component;
023:
024: public abstract class InputEvent extends ComponentEvent {
025:
026: private static final long serialVersionUID = -2482525981698309786L;
027:
028: public static final int SHIFT_MASK = 1;
029:
030: public static final int CTRL_MASK = 2;
031:
032: public static final int META_MASK = 4;
033:
034: public static final int ALT_MASK = 8;
035:
036: public static final int ALT_GRAPH_MASK = 32;
037:
038: public static final int BUTTON1_MASK = 16;
039:
040: public static final int BUTTON2_MASK = 8;
041:
042: public static final int BUTTON3_MASK = 4;
043:
044: public static final int SHIFT_DOWN_MASK = 64;
045:
046: public static final int CTRL_DOWN_MASK = 128;
047:
048: public static final int META_DOWN_MASK = 256;
049:
050: public static final int ALT_DOWN_MASK = 512;
051:
052: public static final int BUTTON1_DOWN_MASK = 1024;
053:
054: public static final int BUTTON2_DOWN_MASK = 2048;
055:
056: public static final int BUTTON3_DOWN_MASK = 4096;
057:
058: public static final int ALT_GRAPH_DOWN_MASK = 8192;
059:
060: static final int MASKS = SHIFT_MASK | CTRL_MASK | META_MASK
061: | ALT_MASK | ALT_GRAPH_MASK | BUTTON1_MASK | BUTTON2_MASK
062: | BUTTON3_MASK;
063:
064: static final int DOWN_MASKS = SHIFT_DOWN_MASK | CTRL_DOWN_MASK
065: | META_DOWN_MASK | ALT_DOWN_MASK | ALT_GRAPH_DOWN_MASK
066: | BUTTON1_DOWN_MASK | BUTTON2_DOWN_MASK | BUTTON3_DOWN_MASK;
067:
068: private long when;
069: int modifiers;
070:
071: InputEvent(Component source, int id, long when, int modifiers) {
072: super (source, id);
073:
074: this .when = when;
075: this .modifiers = modifiers;
076: }
077:
078: public static String getModifiersExText(int modifiers) {
079: return MouseEvent.addMouseModifiersExText(KeyEvent
080: .getKeyModifiersExText(modifiers), modifiers);
081: }
082:
083: public int getModifiers() {
084: return modifiers & MASKS;
085: }
086:
087: public int getModifiersEx() {
088: return modifiers & DOWN_MASKS;
089: }
090:
091: public boolean isAltDown() {
092: return ((modifiers & ALT_DOWN_MASK) != 0);
093: }
094:
095: public boolean isAltGraphDown() {
096: return ((modifiers & ALT_GRAPH_DOWN_MASK) != 0);
097: }
098:
099: public boolean isControlDown() {
100: return ((modifiers & CTRL_DOWN_MASK) != 0);
101: }
102:
103: public boolean isMetaDown() {
104: return ((modifiers & META_DOWN_MASK) != 0);
105: }
106:
107: public boolean isShiftDown() {
108: return ((modifiers & SHIFT_DOWN_MASK) != 0);
109: }
110:
111: public long getWhen() {
112: return when;
113: }
114:
115: @Override
116: public void consume() {
117: super .consume();
118: }
119:
120: @Override
121: public boolean isConsumed() {
122: return super.isConsumed();
123: }
124: }
|