1 |
/* InputMap.java -- |
/* InputMap.java -- |
2 |
Copyright (C) 2002 Free Software Foundation, Inc. |
Copyright (C) 2002 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
37 |
|
|
38 |
package javax.swing; |
package javax.swing; |
39 |
|
|
40 |
|
// Imports |
41 |
|
import java.util.*; |
42 |
|
import java.io.*; |
43 |
|
|
44 |
|
/** |
45 |
|
* InputMap |
46 |
|
* @author Andrew Selkirk |
47 |
|
* @version 1.0 |
48 |
|
*/ |
49 |
|
public class InputMap implements Serializable { |
50 |
|
|
51 |
|
//------------------------------------------------------------- |
52 |
|
// Variables -------------------------------------------------- |
53 |
|
//------------------------------------------------------------- |
54 |
|
|
55 |
|
/** |
56 |
|
* inputMap |
57 |
|
*/ |
58 |
|
private Map inputMap = new HashMap(); |
59 |
|
|
60 |
|
/** |
61 |
|
* parent |
62 |
|
*/ |
63 |
|
private InputMap parent = null; |
64 |
|
|
65 |
|
|
66 |
|
//------------------------------------------------------------- |
67 |
|
// Initialization --------------------------------------------- |
68 |
|
//------------------------------------------------------------- |
69 |
|
|
70 |
|
/** |
71 |
|
* Constructor InputMap |
72 |
|
*/ |
73 |
|
public InputMap() { |
74 |
|
// TODO |
75 |
|
} // InputMap() |
76 |
|
|
77 |
|
|
78 |
|
//------------------------------------------------------------- |
79 |
|
// Methods ---------------------------------------------------- |
80 |
|
//------------------------------------------------------------- |
81 |
|
|
82 |
|
/** |
83 |
|
* get |
84 |
|
* @param value0 TODO |
85 |
|
* @returns Object |
86 |
|
*/ |
87 |
|
public Object get(KeyStroke keystroke) { |
88 |
|
|
89 |
|
// Variables |
90 |
|
Object result; |
91 |
|
|
92 |
|
// Check Local store |
93 |
|
result = inputMap.get(keystroke); |
94 |
|
|
95 |
|
// Check Parent |
96 |
|
if (result == null) { |
97 |
|
result = parent.get(keystroke); |
98 |
|
} // if |
99 |
|
|
100 |
|
return result; |
101 |
|
|
102 |
|
} // get() |
103 |
|
|
104 |
|
/** |
105 |
|
* put |
106 |
|
* @param keystroke TODO |
107 |
|
* @param actionMapKey TODO |
108 |
|
*/ |
109 |
|
public void put(KeyStroke keystroke, Object actionMapKey) { |
110 |
|
if (actionMapKey == null) { |
111 |
|
inputMap.remove(keystroke); |
112 |
|
} else { |
113 |
|
inputMap.put(keystroke, actionMapKey); |
114 |
|
} // if |
115 |
|
} // put() |
116 |
|
|
117 |
|
/** |
118 |
|
* remove |
119 |
|
* @param keystroke TODO |
120 |
|
*/ |
121 |
|
public void remove(KeyStroke keystroke) { |
122 |
|
inputMap.remove(keystroke); |
123 |
|
} // remove() |
124 |
|
|
125 |
|
/** |
126 |
|
* getParent |
127 |
|
* @returns InputMap |
128 |
|
*/ |
129 |
|
public InputMap getParent() { |
130 |
|
return parent; |
131 |
|
} // getParent() |
132 |
|
|
133 |
|
/** |
134 |
|
* setParent |
135 |
|
* @param parentMap TODO |
136 |
|
*/ |
137 |
|
public void setParent(InputMap parentMap) { |
138 |
|
parent = parentMap; |
139 |
|
} // setParent() |
140 |
|
|
141 |
|
/** |
142 |
|
* size |
143 |
|
* @returns int |
144 |
|
*/ |
145 |
|
public int size() { |
146 |
|
return inputMap.size(); |
147 |
|
} // size() |
148 |
|
|
149 |
|
/** |
150 |
|
* clear |
151 |
|
*/ |
152 |
|
public void clear() { |
153 |
|
inputMap.clear(); |
154 |
|
} // clear() |
155 |
|
|
156 |
|
/** |
157 |
|
* keys |
158 |
|
* @returns KeyStroke[] |
159 |
|
*/ |
160 |
|
public KeyStroke[] keys() { |
161 |
|
return convertSet(inputMap.keySet()); |
162 |
|
} // keys() |
163 |
|
|
164 |
|
/** |
165 |
|
* allKeys |
166 |
|
* @returns KeyStroke[] |
167 |
|
*/ |
168 |
|
public KeyStroke[] allKeys() { |
169 |
|
|
170 |
|
// Variables |
171 |
|
Set set; |
172 |
|
|
173 |
|
// Initialize |
174 |
|
set = new HashSet(); |
175 |
|
|
176 |
|
// Get Key Sets |
177 |
|
if (parent != null) { |
178 |
|
set.addAll(Arrays.asList(parent.allKeys())); |
179 |
|
} // if |
180 |
|
set.addAll(inputMap.keySet()); |
181 |
|
|
182 |
|
return convertSet(set); |
183 |
|
|
184 |
|
} // allKeys() |
185 |
|
|
186 |
|
private KeyStroke[] convertSet(Set set) { |
187 |
|
|
188 |
|
// Variables |
189 |
|
int index; |
190 |
|
Iterator iterator; |
191 |
|
KeyStroke[] keys; |
192 |
|
|
193 |
|
// Create Final array |
194 |
|
keys = new KeyStroke[set.size()]; |
195 |
|
iterator = set.iterator(); |
196 |
|
index = 0; |
197 |
|
while (iterator.hasNext()) { |
198 |
|
keys[index++] = (KeyStroke) iterator.next(); |
199 |
|
} // while |
200 |
|
|
201 |
|
return keys; |
202 |
|
|
203 |
|
} // convertSet() |
204 |
|
|
205 |
|
|
206 |
|
//------------------------------------------------------------- |
207 |
|
// Interface: Serializable ------------------------------------ |
208 |
|
//------------------------------------------------------------- |
209 |
|
|
210 |
|
/** |
211 |
|
* writeObject |
212 |
|
* @param stream TODO |
213 |
|
* @exception IOException TODO |
214 |
|
*/ |
215 |
|
private void writeObject(ObjectOutputStream stream) throws IOException { |
216 |
|
// TODO |
217 |
|
} // writeObject() |
218 |
|
|
219 |
|
/** |
220 |
|
* readObject |
221 |
|
* @param stream TODO |
222 |
|
* @exception ClassNotFoundException TODO |
223 |
|
* @exception IOException TODO |
224 |
|
*/ |
225 |
|
private void readObject(ObjectInputStream stream) throws ClassNotFoundException, IOException { |
226 |
|
// TODO |
227 |
|
} // readObject() |
228 |
|
|
229 |
public class InputMap |
|
230 |
{ |
} // InputMap |
|
} |
|