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