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 Dmitry A. Durnev
019: * @version $Revision$
020: */package java.awt;
021:
022: import java.io.Serializable;
023:
024: public class Event implements Serializable {
025: private static final long serialVersionUID = 5488922509400504703L;
026: public static final int SHIFT_MASK = 1;
027:
028: public static final int CTRL_MASK = 2;
029:
030: public static final int META_MASK = 4;
031:
032: public static final int ALT_MASK = 8;
033:
034: public static final int HOME = 1000;
035:
036: public static final int END = 1001;
037:
038: public static final int PGUP = 1002;
039:
040: public static final int PGDN = 1003;
041:
042: public static final int UP = 1004;
043:
044: public static final int DOWN = 1005;
045:
046: public static final int LEFT = 1006;
047:
048: public static final int RIGHT = 1007;
049:
050: public static final int F1 = 1008;
051:
052: public static final int F2 = 1009;
053:
054: public static final int F3 = 1010;
055:
056: public static final int F4 = 1011;
057:
058: public static final int F5 = 1012;
059:
060: public static final int F6 = 1013;
061:
062: public static final int F7 = 1014;
063:
064: public static final int F8 = 1015;
065:
066: public static final int F9 = 1016;
067:
068: public static final int F10 = 1017;
069:
070: public static final int F11 = 1018;
071:
072: public static final int F12 = 1019;
073:
074: public static final int PRINT_SCREEN = 1020;
075:
076: public static final int SCROLL_LOCK = 1021;
077:
078: public static final int CAPS_LOCK = 1022;
079:
080: public static final int NUM_LOCK = 1023;
081:
082: public static final int PAUSE = 1024;
083:
084: public static final int INSERT = 1025;
085:
086: public static final int ENTER = 10;
087:
088: public static final int BACK_SPACE = 8;
089:
090: public static final int TAB = 9;
091:
092: public static final int ESCAPE = 27;
093:
094: public static final int DELETE = 127;
095:
096: public static final int WINDOW_DESTROY = 201;
097:
098: public static final int WINDOW_EXPOSE = 202;
099:
100: public static final int WINDOW_ICONIFY = 203;
101:
102: public static final int WINDOW_DEICONIFY = 204;
103:
104: public static final int WINDOW_MOVED = 205;
105:
106: public static final int KEY_PRESS = 401;
107:
108: public static final int KEY_RELEASE = 402;
109:
110: public static final int KEY_ACTION = 403;
111:
112: public static final int KEY_ACTION_RELEASE = 404;
113:
114: public static final int MOUSE_DOWN = 501;
115:
116: public static final int MOUSE_UP = 502;
117:
118: public static final int MOUSE_MOVE = 503;
119:
120: public static final int MOUSE_ENTER = 504;
121:
122: public static final int MOUSE_EXIT = 505;
123:
124: public static final int MOUSE_DRAG = 506;
125:
126: public static final int SCROLL_LINE_UP = 601;
127:
128: public static final int SCROLL_LINE_DOWN = 602;
129:
130: public static final int SCROLL_PAGE_UP = 603;
131:
132: public static final int SCROLL_PAGE_DOWN = 604;
133:
134: public static final int SCROLL_ABSOLUTE = 605;
135:
136: public static final int SCROLL_BEGIN = 606;
137:
138: public static final int SCROLL_END = 607;
139:
140: public static final int LIST_SELECT = 701;
141:
142: public static final int LIST_DESELECT = 702;
143:
144: public static final int ACTION_EVENT = 1001;
145:
146: public static final int LOAD_FILE = 1002;
147:
148: public static final int SAVE_FILE = 1003;
149:
150: public static final int GOT_FOCUS = 1004;
151:
152: public static final int LOST_FOCUS = 1005;
153:
154: public Object target;
155:
156: public long when;
157:
158: public int id;
159:
160: public int x;
161:
162: public int y;
163:
164: public int key;
165:
166: public int modifiers;
167:
168: public int clickCount;
169:
170: public Object arg;
171:
172: public Event evt;
173:
174: public Event(Object target, int id, Object arg) {
175: this (target, 0l, id, 0, 0, 0, 0, arg);
176: }
177:
178: public Event(Object target, long when, int id, int x, int y,
179: int key, int modifiers) {
180: this (target, when, id, x, y, key, modifiers, null);
181: }
182:
183: public Event(Object target, long when, int id, int x, int y,
184: int key, int modifiers, Object arg) {
185: this .target = target;
186: this .when = when;
187: this .id = id;
188: this .x = x;
189: this .y = y;
190: this .key = key;
191: this .modifiers = modifiers;
192: this .arg = arg;
193: }
194:
195: @Override
196: public String toString() {
197: /* The format is based on 1.5 release behavior
198: * which can be revealed by the following code:
199: *
200: * Event e = new Event(new Button(), 0l, Event.KEY_PRESS,
201: * 0, 0, Event.TAB, Event.SHIFT_MASK, "arg");
202: * System.out.println(e);
203: */
204:
205: return getClass().getName() + "[" + paramString() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
206: }
207:
208: protected String paramString() {
209: return "id=" + id + ",x=" + x + ",y=" + y + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
210: (key != 0 ? ",key=" + key + getModifiersString() : "") + //$NON-NLS-1$ //$NON-NLS-2$
211: ",target=" + target + //$NON-NLS-1$
212: (arg != null ? ",arg=" + arg : ""); //$NON-NLS-1$ //$NON-NLS-2$
213: }
214:
215: private String getModifiersString() {
216: String strMod = ""; //$NON-NLS-1$
217: if (shiftDown()) {
218: strMod += ",shift"; //$NON-NLS-1$
219: }
220: if (controlDown()) {
221: strMod += ",control"; //$NON-NLS-1$
222: }
223: if (metaDown()) {
224: strMod += ",meta"; //$NON-NLS-1$
225: }
226: return strMod;
227: }
228:
229: public void translate(int dx, int dy) {
230: x += dx;
231: y += dy;
232: }
233:
234: public boolean controlDown() {
235: return (modifiers & CTRL_MASK) != 0;
236: }
237:
238: public boolean metaDown() {
239: return (modifiers & META_MASK) != 0;
240: }
241:
242: public boolean shiftDown() {
243: return (modifiers & SHIFT_MASK) != 0;
244: }
245:
246: }
|