1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.xnap.gui.shortcut;
20
21 import javax.swing.KeyStroke;
22
23 import org.apache.log4j.Logger;
24 import org.xnap.XNap;
25 import org.xnap.util.Preferences;
26 import org.xnap.util.PreferencesProvider;
27
28 public class DefaultShortcut implements Shortcut
29 {
30
31
32
33
34 private String category;
35 private PreferencesProvider prefs;
36 private String description;
37 private String prefsKey;
38 private KeyStroke defaultKeyStroke;
39 private KeyStroke keyStroke;
40
41 private static Logger logger = Logger.getLogger(DefaultShortcut.class);
42
43
44
45 public DefaultShortcut(KeyStroke defaultKeyStroke, String category,
46 String description, String prefsKey,
47 PreferencesProvider prefs)
48 {
49 this.category = category;
50 this.description = description;
51 this.defaultKeyStroke = defaultKeyStroke;
52 this.keyStroke = defaultKeyStroke;
53 this.prefsKey = prefsKey;
54 this.prefs = prefs;
55
56 if (prefs != null && prefsKey != null) {
57 setKeyStroke(prefs.getKeyStroke(prefsKey + "Shortcut"));
58 }
59 }
60
61 public DefaultShortcut(KeyStroke defaultKeyStroke, String category,
62 String description, String prefsKey)
63 {
64 this(defaultKeyStroke, category, description, prefsKey,
65 Preferences.getInstance());
66 }
67
68 public DefaultShortcut(KeyStroke defaultKeyStroke, String description,
69 String prefsKey)
70 {
71 this(defaultKeyStroke, XNap.tr("General"), description, prefsKey);
72 }
73
74
75
76 public String getCategory()
77 {
78 return category;
79 }
80
81 public String getKey()
82 {
83 return prefsKey;
84 }
85
86 public String getDescription()
87 {
88 return description;
89 }
90
91 public KeyStroke getDefaultKeyStroke()
92 {
93 return defaultKeyStroke;
94 }
95
96 public KeyStroke getKeyStroke()
97 {
98 return keyStroke;
99 }
100
101 public void setKeyStroke(KeyStroke stroke)
102 {
103 keyStroke = stroke;
104 if (prefs != null && prefsKey != null) {
105 prefs.set(prefsKey + "Shortcut", keyStroke);
106 }
107 }
108 }
109
110
111
112