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