001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.gvt.event;
020:
021: import java.awt.event.InputEvent;
022:
023: import org.apache.batik.gvt.GraphicsNode;
024:
025: /**
026: * The root event class for all graphics node-level input events.
027: *
028: * @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
029: * @version $Id: GraphicsNodeInputEvent.java 498514 2007-01-22 03:03:41Z cam $
030: */
031: public abstract class GraphicsNodeInputEvent extends GraphicsNodeEvent {
032:
033: /**
034: * The shift key modifier constant.
035: */
036: public static final int SHIFT_MASK = InputEvent.SHIFT_MASK;
037:
038: /**
039: * The control key modifier constant.
040: */
041: public static final int CTRL_MASK = InputEvent.CTRL_MASK;
042:
043: /**
044: * The meta key modifier constant.
045: */
046: public static final int META_MASK = InputEvent.META_MASK;
047:
048: /**
049: * The alt key modifier constant.
050: */
051: public static final int ALT_MASK = InputEvent.ALT_MASK;
052:
053: /**
054: * The alt-graph key modifier constant.
055: */
056: public static final int ALT_GRAPH_MASK = InputEvent.ALT_GRAPH_MASK;
057:
058: /**
059: * The mouse button1 modifier constant.
060: */
061: public static final int BUTTON1_MASK = InputEvent.BUTTON1_MASK;
062:
063: /**
064: * The mouse button2 modifier constant.
065: */
066: public static final int BUTTON2_MASK = InputEvent.ALT_MASK;
067:
068: /**
069: * The mouse button3 modifier constant.
070: */
071: public static final int BUTTON3_MASK = InputEvent.META_MASK;
072:
073: /**
074: * The caps lock constant.
075: */
076: public static final int CAPS_LOCK_MASK = 0x01;
077:
078: /**
079: * The num lock constant.
080: */
081: public static final int NUM_LOCK_MASK = 0x02;
082:
083: /**
084: * The scroll lock constant.
085: */
086: public static final int SCROLL_LOCK_MASK = 0x04;
087:
088: /**
089: * The kana lock constant.
090: */
091: public static final int KANA_LOCK_MASK = 0x08;
092:
093: /**
094: * The graphics node input events Time stamp. The time stamp is in
095: * UTC format that indicates when the input event was
096: * created.
097: */
098: long when;
099:
100: /**
101: * The state of the modifier key at the time the graphics node
102: * input event was fired.
103: */
104: int modifiers;
105:
106: /**
107: * The state of the key locks at the time the graphics node input
108: * event was fired.
109: */
110: int lockState;
111:
112: /**
113: * Constructs a new graphics node input event.
114: * @param source the graphics node where the event originated
115: * @param id the id of this event
116: * @param when the time the event occurred
117: * @param modifiers the modifier keys down while event occurred
118: */
119: protected GraphicsNodeInputEvent(GraphicsNode source, int id,
120: long when, int modifiers, int lockState) {
121: super (source, id);
122: this .when = when;
123: this .modifiers = modifiers;
124: this .lockState = lockState;
125: }
126:
127: /**
128: * Constructs a new graphics node input event from an AWT InputEvent.
129: * @param source the graphics node where the event originated
130: * @param evt the AWT InputEvent triggering this event's creation
131: */
132: protected GraphicsNodeInputEvent(GraphicsNode source,
133: InputEvent evt, int lockState) {
134: super (source, evt.getID());
135: this .when = evt.getWhen();
136: this .modifiers = evt.getModifiers();
137: this .lockState = lockState;
138: }
139:
140: /**
141: * Returns whether or not the Shift modifier is down on this event.
142: */
143: public boolean isShiftDown() {
144: return (modifiers & SHIFT_MASK) != 0;
145: }
146:
147: /**
148: * Returns whether or not the Control modifier is down on this event.
149: */
150: public boolean isControlDown() {
151: return (modifiers & CTRL_MASK) != 0;
152: }
153:
154: /**
155: * Returns whether or not the Meta modifier is down on this event.
156: */
157: public boolean isMetaDown() {
158: return AWTEventDispatcher.isMetaDown(modifiers);
159: }
160:
161: /**
162: * Returns whether or not the Alt modifier is down on this event.
163: */
164: public boolean isAltDown() {
165: return (modifiers & ALT_MASK) != 0;
166: }
167:
168: /**
169: * Returns whether or not the Alt-Graph modifier is down on this event.
170: */
171: public boolean isAltGraphDown() {
172: return (modifiers & ALT_GRAPH_MASK) != 0;
173: }
174:
175: /**
176: * Returns the timestamp of when this event occurred.
177: */
178: public long getWhen() {
179: return when;
180: }
181:
182: /**
183: * Returns the modifiers flag for this event.
184: */
185: public int getModifiers() {
186: return modifiers;
187: }
188:
189: /**
190: * Returns the lock state flags for this event.
191: */
192: public int getLockState() {
193: return lockState;
194: }
195: }
|