1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.xnap.commons.gui.shortcut;
22
23 import java.beans.PropertyChangeListener;
24 import java.util.HashMap;
25 import javax.swing.KeyStroke;
26 import javax.swing.event.SwingPropertyChangeSupport;
27
28 /***
29 *
30 */
31 public abstract class AbstractShortcut implements Shortcut
32 {
33
34 private SwingPropertyChangeSupport changeSupport =
35 new SwingPropertyChangeSupport(this);
36
37 private HashMap<String, Object> values = new HashMap<String, Object>();
38
39
40
41
42 public void putValue(String key, Object value)
43 {
44 Object oldValue = null;
45 if (values.containsKey(key)) {
46 oldValue = values.get(key);
47 }
48 values.put(key, value);
49 firePropertChange(key, oldValue, value);
50 }
51
52 protected void firePropertChange(String key, Object oldValue, Object newValue)
53 {
54 if (oldValue != newValue
55 && (oldValue == null || newValue == null || !oldValue.equals(newValue))) {
56 changeSupport.firePropertyChange(key, oldValue, newValue);
57 }
58 }
59
60
61
62
63 public Object getValue(String key)
64 {
65 return values.get(key);
66 }
67
68
69
70
71 public synchronized void addPropertyChangeListener(PropertyChangeListener l)
72 {
73 changeSupport.addPropertyChangeListener(l);
74 }
75
76
77
78
79 public synchronized void removePropertyChangeListener(PropertyChangeListener l)
80 {
81 changeSupport.removePropertyChangeListener(l);
82 }
83
84
85
86
87 public KeyStroke getKeyStroke()
88 {
89 return (KeyStroke)values.get(KEYSTROKE);
90 }
91
92
93
94
95 public void setKeyStroke(KeyStroke stroke)
96 {
97 putValue(KEYSTROKE, stroke);
98 }
99 }