50 |
|
|
51 |
|
|
52 |
/** |
/** |
53 |
* @author Andrew Selkirk |
* @author Andrew Selkirk |
54 |
* @author Michael Koch |
* @author Michael Koch |
55 |
* |
* |
56 |
* @since 1.3 |
* @since 1.3 |
60 |
{ |
{ |
61 |
private static final long serialVersionUID = -5429059542008604257L; |
private static final long serialVersionUID = -5429059542008604257L; |
62 |
|
|
63 |
/** |
/** |
64 |
* inputMap |
* inputMap |
65 |
*/ |
*/ |
66 |
private Map inputMap = new HashMap(); |
private Map inputMap = new HashMap(); |
67 |
|
|
68 |
/** |
/** |
69 |
* parent |
* parent |
70 |
*/ |
*/ |
71 |
private InputMap parent; |
private InputMap parent; |
72 |
|
|
73 |
/** |
/** |
74 |
* Creates a new <code>InputMap</code> instance. |
* Creates a new <code>InputMap</code> instance. |
75 |
*/ |
*/ |
76 |
public InputMap() |
public InputMap() |
77 |
{ |
{ |
78 |
// TODO |
// TODO |
79 |
} |
} |
80 |
|
|
81 |
/** |
/** |
82 |
* Returns the binding for keystroke. |
* Returns the binding for keystroke. |
83 |
* |
* |
84 |
* @param key the key of the enty |
* @param key the key of the enty |
85 |
* |
* |
86 |
* @return the binding associated with keystroke may be null |
* @return the binding associated with keystroke may be null |
87 |
*/ |
*/ |
88 |
public Object get(KeyStroke keystroke) |
public Object get(KeyStroke keystroke) |
89 |
{ |
{ |
90 |
Object result = inputMap.get(keystroke); |
Object result = inputMap.get(keystroke); |
91 |
|
|
92 |
if (result == null) |
if (result == null) |
93 |
result = parent.get(keystroke); |
result = parent.get(keystroke); |
94 |
return result; |
return result; |
95 |
} |
} |
96 |
|
|
97 |
/** |
/** |
98 |
* Puts a new entry into the <code>InputMap</code>. |
* Puts a new entry into the <code>InputMap</code>. |
99 |
* If actionMapKey is null an existing entry will be removed. |
* If actionMapKey is null an existing entry will be removed. |
100 |
* |
* |
101 |
* @param keystroke the keystroke for the entry |
* @param keystroke the keystroke for the entry |
102 |
* @param actionMapKey the action. |
* @param actionMapKey the action. |
103 |
*/ |
*/ |
104 |
public void put(KeyStroke keystroke, Object actionMapKey) |
public void put(KeyStroke keystroke, Object actionMapKey) |
105 |
{ |
{ |
106 |
if (actionMapKey == null) |
if (actionMapKey == null) |
107 |
inputMap.remove(keystroke); |
inputMap.remove(keystroke); |
108 |
else |
else |
109 |
inputMap.put(keystroke, actionMapKey); |
inputMap.put(keystroke, actionMapKey); |
110 |
} |
} |
111 |
|
|
112 |
/** |
/** |
113 |
* Remove an entry from the <code>InputMap</code>. |
* Remove an entry from the <code>InputMap</code>. |
114 |
* |
* |
115 |
* @param key the key of the entry to remove |
* @param key the key of the entry to remove |
116 |
*/ |
*/ |
117 |
public void remove(KeyStroke keystroke) |
public void remove(KeyStroke keystroke) |
118 |
{ |
{ |
119 |
inputMap.remove(keystroke); |
inputMap.remove(keystroke); |
120 |
} |
} |
121 |
|
|
122 |
/** |
/** |
123 |
* Returns the parent of this <code>InputMap</code>. |
* Returns the parent of this <code>InputMap</code>. |
124 |
* |
* |
125 |
* @return the parent, may be null. |
* @return the parent, may be null. |
126 |
*/ |
*/ |
127 |
public InputMap getParent() |
public InputMap getParent() |
128 |
{ |
{ |
129 |
return parent; |
return parent; |
130 |
} |
} |
131 |
|
|
132 |
/** |
/** |
133 |
* Sets a parent for this <code>InputMap</code>. |
* Sets a parent for this <code>InputMap</code>. |
134 |
* |
* |
135 |
* @param parentMap the new parent |
* @param parentMap the new parent |
136 |
*/ |
*/ |
137 |
public void setParent(InputMap parentMap) |
public void setParent(InputMap parentMap) |
138 |
{ |
{ |
139 |
parent = parentMap; |
parent = parentMap; |
140 |
} |
} |
141 |
|
|
142 |
/** |
/** |
143 |
* Returns the number of entries in this <code>InputMap</code>. |
* Returns the number of entries in this <code>InputMap</code>. |
144 |
* |
* |
145 |
* @return the number of entries |
* @return the number of entries |
146 |
*/ |
*/ |
147 |
public int size() |
public int size() |
148 |
{ |
{ |
149 |
return inputMap.size(); |
return inputMap.size(); |
150 |
} |
} |
151 |
|
|
152 |
/** |
/** |
153 |
* Clears the <code>InputMap</code>. |
* Clears the <code>InputMap</code>. |
154 |
*/ |
*/ |
155 |
public void clear() |
public void clear() |
156 |
{ |
{ |
157 |
inputMap.clear(); |
inputMap.clear(); |
158 |
} |
} |
159 |
|
|
160 |
/** |
/** |
161 |
* Returns all keys of entries in this <code>InputMap</code>. |
* Returns all keys of entries in this <code>InputMap</code>. |
162 |
* |
* |
163 |
* @return an array of keys |
* @return an array of keys |
164 |
*/ |
*/ |
165 |
public KeyStroke[] keys() |
public KeyStroke[] keys() |
166 |
{ |
{ |
167 |
KeyStroke[] array = new KeyStroke[size()]; |
KeyStroke[] array = new KeyStroke[size()]; |
168 |
return (KeyStroke[]) inputMap.keySet().toArray(array); |
return (KeyStroke[]) inputMap.keySet().toArray(array); |
169 |
} |
} |
170 |
|
|
171 |
/** |
/** |
172 |
* Returns all keys of entries in this <code>InputMap</code> |
* Returns all keys of entries in this <code>InputMap</code> |
173 |
* and all its parents. |
* and all its parents. |
174 |
* |
* |
175 |
* @return an array of keys |
* @return an array of keys |
176 |
*/ |
*/ |
177 |
public KeyStroke[] allKeys() |
public KeyStroke[] allKeys() |
178 |
{ |
{ |
179 |
Set set = new HashSet(); |
Set set = new HashSet(); |
180 |
|
|
181 |
if (parent != null) |
if (parent != null) |
182 |
set.addAll(Arrays.asList(parent.allKeys())); |
set.addAll(Arrays.asList(parent.allKeys())); |
183 |
|
|
184 |
set.addAll(inputMap.keySet()); |
set.addAll(inputMap.keySet()); |
185 |
KeyStroke[] array = new KeyStroke[size()]; |
KeyStroke[] array = new KeyStroke[size()]; |
186 |
return (KeyStroke[]) set.toArray(array); |
return (KeyStroke[]) set.toArray(array); |
187 |
} |
} |
188 |
|
|
189 |
/** |
/** |
190 |
* writeObject |
* writeObject |
191 |
* |
* |
192 |
* @param stream the stream to write to |
* @param stream the stream to write to |
193 |
* |
* |
194 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
195 |
*/ |
*/ |
196 |
private void writeObject(ObjectOutputStream stream) throws IOException |
private void writeObject(ObjectOutputStream stream) throws IOException |
197 |
{ |
{ |
198 |
// TODO |
// TODO |
199 |
} |
} |
200 |
|
|
201 |
/** |
/** |
202 |
* readObject |
* readObject |
203 |
* |
* |
204 |
* @param stream the stream to read from |
* @param stream the stream to read from |
205 |
* |
* |
206 |
* @exception ClassNotFoundException If the serialized class cannot be found |
* @exception ClassNotFoundException If the serialized class cannot be found |
207 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
208 |
*/ |
*/ |
209 |
private void readObject(ObjectInputStream stream) |
private void readObject(ObjectInputStream stream) |
210 |
throws ClassNotFoundException, IOException |
throws ClassNotFoundException, IOException |
211 |
{ |
{ |
212 |
// TODO |
// TODO |
213 |
} |
} |
214 |
} |
} |