source: trunk/gcc/libjava/javax/swing/ActionMap.java

Last change on this file was 1389, checked in by bird, 21 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.1 KB
Line 
1/* ActionMap.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38package javax.swing;
39
40// Imports
41import java.io.*;
42import java.util.*;
43
44/**
45 * ActionMap
46 * @author Andrew Selkirk
47 * @version 1.0
48 */
49public class ActionMap implements Serializable {
50
51 //-------------------------------------------------------------
52 // Variables --------------------------------------------------
53 //-------------------------------------------------------------
54
55 /**
56 * actionMap
57 */
58 private Map actionMap = new HashMap();
59
60 /**
61 * parent
62 */
63 private ActionMap parent = null;
64
65
66 //-------------------------------------------------------------
67 // Initialization ---------------------------------------------
68 //-------------------------------------------------------------
69
70 /**
71 * Constructor ActionMap
72 */
73 public ActionMap() {
74 } // ActionMap()
75
76
77 //-------------------------------------------------------------
78 // Methods ----------------------------------------------------
79 //-------------------------------------------------------------
80
81 /**
82 * get
83 * @param key TODO
84 * @returns Action
85 */
86 public Action get(Object key) {
87
88 // Variables
89 Object result;
90
91 // Check Local store
92 result = actionMap.get(key);
93
94 // Check Parent
95 if (result == null) {
96 result = parent.get(key);
97 } // if
98
99 return (Action) result;
100
101 } // get()
102
103 /**
104 * put
105 * @param key TODO
106 * @param action TODO
107 */
108 public void put(Object key, Action action) {
109 if (action == null) {
110 actionMap.remove(key);
111 } else {
112 actionMap.put(key, action);
113 } // if
114 } // put()
115
116 /**
117 * remove
118 * @param key TODO
119 */
120 public void remove(Object key) {
121 actionMap.remove(key);
122 } // remove()
123
124 /**
125 * getParent
126 * @returns ActionMap
127 */
128 public ActionMap getParent() {
129 return parent;
130 } // getParent()
131
132 /**
133 * setParent
134 * @param parentMap TODO
135 */
136 public void setParent(ActionMap parentMap) {
137 parent = parentMap;
138 } // setParent()
139
140 /**
141 * size
142 * @returns int
143 */
144 public int size() {
145 return actionMap.size();
146 } // size()
147
148 /**
149 * clear
150 */
151 public void clear() {
152 actionMap.clear();
153 } // clear()
154
155 /**
156 * keys
157 * @returns Object[]
158 */
159 public Object[] keys() {
160 return convertSet(actionMap.keySet());
161 } // keys()
162
163 /**
164 * allKeys
165 * @returns Object[]
166 */
167 public Object[] allKeys() {
168
169 // Variables
170 Set set;
171
172 // Initialize
173 set = new HashSet();
174
175 // Get Key Sets
176 if (parent != null) {
177 set.addAll(Arrays.asList(parent.allKeys()));
178 } // if
179 set.addAll(actionMap.keySet());
180
181 return convertSet(set);
182
183 } // allKeys()
184
185 private Object[] convertSet(Set set) {
186
187 // Variables
188 int index;
189 Iterator iterator;
190 Object[] keys;
191
192 // Create Final array
193 keys = new Object[set.size()];
194 iterator = set.iterator();
195 index = 0;
196 while (iterator.hasNext()) {
197 keys[index++] = iterator.next();
198 } // while
199
200 return keys;
201
202 } // convertSet()
203
204
205 //-------------------------------------------------------------
206 // Interface: Serializable ------------------------------------
207 //-------------------------------------------------------------
208
209 /**
210 * writeObject
211 * @param stream TODO
212 * @exception IOException TODO
213 */
214 private void writeObject(ObjectOutputStream value0) throws IOException {
215 // TODO
216 } // writeObject()
217
218 /**
219 * readObject
220 * @param stream TODO
221 * @exception ClassNotFoundException TODO
222 * @exception IOException TODO
223 */
224 private void readObject(ObjectInputStream value0) throws ClassNotFoundException, IOException {
225 // TODO
226 } // readObject()
227
228
229} // ActionMap
Note: See TracBrowser for help on using the repository browser.