1:
37:
38:
39: package ;
40:
41: import ;
42:
43:
48: public class MenuShortcut implements java.io.Serializable
49: {
50:
51:
54:
55:
56: private static final long serialVersionUID = 143448358473180225L;
57:
58:
59:
60:
63:
64:
67: private int key;
68:
69:
73: private boolean usesShift;
74:
75: private String keyName;
76:
77:
78:
79:
85: public
86: MenuShortcut(int key)
87: {
88: this(key, false);
89: }
90:
91:
92:
93:
101: public
102: MenuShortcut(int key, boolean usesShift)
103: {
104: this.key = key;
105: this.usesShift = usesShift;
106: setKeyName(key);
107: }
108:
109:
110:
111:
114:
115:
120: public int
121: getKey()
122: {
123: return(key);
124: }
125:
126:
127:
128:
134: public boolean
135: usesShiftModifier()
136: {
137: return(usesShift);
138: }
139:
140:
141:
142:
153: public boolean
154: equals(MenuShortcut obj)
155: {
156: if (obj == null)
157: return(false);
158:
159: if (obj.key != this.key)
160: return(false);
161:
162: if (obj.usesShift != this.usesShift)
163: return(false);
164:
165: return(true);
166: }
167:
168: public boolean
169: equals(Object obj)
170: {
171: if (obj instanceof MenuShortcut)
172: {
173: MenuShortcut ms = (MenuShortcut) obj;
174: return (ms.key == key && ms.usesShift == usesShift);
175: }
176: return false;
177: }
178:
179:
180:
181:
186: public String
187: toString()
188: {
189: String temp = "Ctrl+";
190: if (usesShift)
191: temp = temp + "Shift+";
192: temp = temp + keyName;
193: return temp;
194: }
195:
196: public int
197: hashCode()
198: {
199:
200: return key + (usesShift ? 23 : 57);
201: }
202:
203:
204:
205:
210: protected String
211: paramString()
212: {
213: return "key=" + key + ",usesShift=" + usesShift;
214: }
215:
216: private void
217: setKeyName(int key)
218: {
219: if (key == '\n')
220: keyName = "Enter";
221: else if (key == '\b')
222: keyName = "Backspace";
223: else if (key == '\t')
224: keyName = "Tab";
225: else if (key == ' ')
226: keyName = "Space";
227: else if (key == ',')
228: keyName = "Comma";
229: else if (key == '.')
230: keyName = "Period";
231: else if (key == '/')
232: keyName = "Slash";
233: else if (key == '\\')
234: keyName = "Back Slash";
235: else if (key == ';')
236: keyName = "Semicolon";
237: else if (key == '=')
238: keyName = "Equals";
239: else if (key == '[')
240: keyName = "Open Bracket";
241: else if (key == ']')
242: keyName = "Close Bracket";
243: else if (key == '0')
244: keyName = "0";
245: else if (key == '1')
246: keyName = "1";
247: else if (key == '2')
248: keyName = "2";
249: else if (key == '3')
250: keyName = "3";
251: else if (key == '4')
252: keyName = "4";
253: else if (key == '5')
254: keyName = "5";
255: else if (key == '6')
256: keyName = "6";
257: else if (key == '7')
258: keyName = "7";
259: else if (key == '8')
260: keyName = "8";
261: else if (key == '9')
262: keyName = "9";
263: else if (key == 'A')
264: keyName = "A";
265: else if (key == 'B')
266: keyName = "B";
267: else if (key == 'C')
268: keyName = "C";
269: else if (key == 'D')
270: keyName = "D";
271: else if (key == 'E')
272: keyName = "E";
273: else if (key == 'F')
274: keyName = "F";
275: else if (key == 'G')
276: keyName = "G";
277: else if (key == 'H')
278: keyName = "H";
279: else if (key == 'I')
280: keyName = "I";
281: else if (key == 'J')
282: keyName = "J";
283: else if (key == 'K')
284: keyName = "K";
285: else if (key == 'L')
286: keyName = "L";
287: else if (key == 'M')
288: keyName = "M";
289: else if (key == 'N')
290: keyName = "N";
291: else if (key == 'O')
292: keyName = "O";
293: else if (key == 'P')
294: keyName = "P";
295: else if (key == 'Q')
296: keyName = "Q";
297: else if (key == 'R')
298: keyName = "R";
299: else if (key == 'S')
300: keyName = "S";
301: else if (key == 'T')
302: keyName = "T";
303: else if (key == 'U')
304: keyName = "U";
305: else if (key == 'V')
306: keyName = "V";
307: else if (key == 'W')
308: keyName = "W";
309: else if (key == 'X')
310: keyName = "X";
311: else if (key == 'Y')
312: keyName = "Y";
313: else if (key == 'Z')
314: keyName = "Z";
315: else if (key == 3)
316: keyName = "Cancel";
317: else if (key == 12)
318: keyName = "Clear";
319: else if (key == 16)
320: keyName = "Shift";
321: else if (key == 17)
322: keyName = "Ctrl";
323: else if (key == 18)
324: keyName = "Alt";
325: else if (key == 19)
326: keyName = "Pause";
327: else if (key == 20)
328: keyName = "Caps Lock";
329: else if (key == 21)
330: keyName = "Kana";
331: else if (key == 24)
332: keyName = "Final";
333: else if (key == 25)
334: keyName = "Kanji";
335: else if (key == 27)
336: keyName = "Escape";
337: else if (key == 28)
338: keyName = "Convert";
339: else if (key == 29)
340: keyName = "No Convert";
341: else if (key == 30)
342: keyName = "Accept";
343: else if (key == 31)
344: keyName = "Mode Change";
345: else if (key == 33)
346: keyName = "Page Up";
347: else if (key == 34)
348: keyName = "Page Down";
349: else if (key == 35)
350: keyName = "End";
351: else if (key == 36)
352: keyName = "Home";
353: else if (key == 37)
354: keyName = "Left";
355: else if (key == 38)
356: keyName = "Up";
357: else if (key == 39)
358: keyName = "Right";
359: else if (key == 40)
360: keyName = "Down";
361: else if (key == 96)
362: keyName = "NumPad-0";
363: else if (key == 97)
364: keyName = "NumPad-1";
365: else if (key == 98)
366: keyName = "NumPad-2";
367: else if (key == 99)
368: keyName = "NumPad-3";
369: else if (key == 100)
370: keyName = "NumPad-4";
371: else if (key == 101)
372: keyName = "NumPad-5";
373: else if (key == 102)
374: keyName = "NumPad-6";
375: else if (key == 103)
376: keyName = "NumPad-7";
377: else if (key == 104)
378: keyName = "NumPad-8";
379: else if (key == 105)
380: keyName = "NumPad-9";
381: else if (key == 106)
382: keyName = "NumPad *";
383: else if (key == 107)
384: keyName = "NumPad +";
385: else if (key == 108)
386: keyName = "NumPad ,";
387: else if (key == 109)
388: keyName = "NumPad -";
389: else if (key == 110)
390: keyName = "NumPad .";
391: else if (key == 111)
392: keyName = "NumPad /";
393: else if (key == 112)
394: keyName = "F1";
395: else if (key == 113)
396: keyName = "F2";
397: else if (key == 114)
398: keyName = "F3";
399: else if (key == 115)
400: keyName = "F4";
401: else if (key == 116)
402: keyName = "F5";
403: else if (key == 117)
404: keyName = "F6";
405: else if (key == 118)
406: keyName = "F7";
407: else if (key == 119)
408: keyName = "F8";
409: else if (key == 120)
410: keyName = "F9";
411: else if (key == 121)
412: keyName = "F10";
413: else if (key == 122)
414: keyName = "F11";
415: else if (key == 123)
416: keyName = "F12";
417: else if (key == 127)
418: keyName = "Delete";
419: else if (key == 144)
420: keyName = "Num Lock";
421: else if (key == 145)
422: keyName = "Scroll Lock";
423: else if (key == 154)
424: keyName = "Print Screen";
425: else if (key == 155)
426: keyName = "Insert";
427: else if (key == 156)
428: keyName = "Help";
429: else if (key == 157)
430: keyName = "Meta";
431: else if (key == 192)
432: keyName = "Back Quote";
433: else if (key == 222)
434: keyName = "Quote";
435: }
436: }