01: /*
02: * Javu WingS - Lightweight Java Component Set
03: * Copyright (c) 2005-2007 Krzysztof A. Sadlocha
04: * e-mail: ksadlocha@programics.com
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20:
21: package com.javujavu.javux.wings;
22:
23: import java.awt.event.ActionEvent;
24: import java.awt.event.ActionListener;
25: import java.awt.event.KeyEvent;
26:
27: /**
28: * Simple class implementing <code>Shortcut</code><br>
29: * Notifies an action listener when the shortcut is pressed
30: * <br>
31: * <b>This class is thread safe.</b>
32: **/
33: public class ShortcutAdapter implements Shortcut {
34: private int keyCode;
35: private int modifiers;
36: private ActionListener actionListener;
37:
38: /**
39: * Creates a new <code>ShortcutAdapter</code>
40: * @param keyCode shortcut key code
41: * @param modifiers shortcut key modifiers
42: * @param actionListener action listener
43: */
44: public ShortcutAdapter(int keyCode, int modifiers,
45: ActionListener actionListener) {
46: this .keyCode = keyCode;
47: this .modifiers = modifiers;
48: this .actionListener = actionListener;
49: }
50:
51: /**
52: * @see Shortcut#getShortcutCode()
53: */
54: public int getShortcutCode() {
55: return keyCode;
56: }
57:
58: /**
59: * @see Shortcut#getShortcutModifiers()
60: */
61: public int getShortcutModifiers() {
62: return modifiers;
63: }
64:
65: /**
66: * Implements <code>processShortcut(KeyEvent e)</code>
67: * Notifies the action listener when the shortcut is pressed
68: * @see Shortcut#processShortcut(java.awt.event.KeyEvent)
69: */
70: public void processShortcut(KeyEvent e) {
71: int id = e.getID();
72: if (id == KeyEvent.KEY_PRESSED && actionListener != null) {
73: actionListener.actionPerformed(new ActionEvent(this ,
74: ActionEvent.ACTION_PERFORMED, "shortcut"));
75: }
76: e.consume();
77: }
78: }
|