2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / javax / swing / InputMap.java
blobd748fb53e0218ea2cacd102685b2de0a95cf948f
1 /* InputMap.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.swing;
41 import java.io.IOException;
42 import java.io.ObjectInputStream;
43 import java.io.ObjectOutputStream;
44 import java.io.Serializable;
45 import java.util.Arrays;
46 import java.util.Iterator;
47 import java.util.HashMap;
48 import java.util.HashSet;
49 import java.util.Map;
50 import java.util.Set;
52 /**
53 * InputMap
54 * @author Andrew Selkirk
55 * @version 1.0
57 public class InputMap implements Serializable
59 static final long serialVersionUID = -5429059542008604257L;
61 //-------------------------------------------------------------
62 // Variables --------------------------------------------------
63 //-------------------------------------------------------------
65 /**
66 * inputMap
68 private Map inputMap = new HashMap();
70 /**
71 * parent
73 private InputMap parent = null;
76 //-------------------------------------------------------------
77 // Initialization ---------------------------------------------
78 //-------------------------------------------------------------
80 /**
81 * Constructor InputMap
83 public InputMap() {
84 // TODO
85 } // InputMap()
88 //-------------------------------------------------------------
89 // Methods ----------------------------------------------------
90 //-------------------------------------------------------------
92 /**
93 * get
94 * @param value0 TODO
95 * @returns Object
97 public Object get(KeyStroke keystroke) {
99 // Variables
100 Object result;
102 // Check Local store
103 result = inputMap.get(keystroke);
105 // Check Parent
106 if (result == null) {
107 result = parent.get(keystroke);
108 } // if
110 return result;
112 } // get()
115 * put
116 * @param keystroke TODO
117 * @param actionMapKey TODO
119 public void put(KeyStroke keystroke, Object actionMapKey) {
120 if (actionMapKey == null) {
121 inputMap.remove(keystroke);
122 } else {
123 inputMap.put(keystroke, actionMapKey);
124 } // if
125 } // put()
128 * remove
129 * @param keystroke TODO
131 public void remove(KeyStroke keystroke) {
132 inputMap.remove(keystroke);
133 } // remove()
136 * getParent
137 * @returns InputMap
139 public InputMap getParent() {
140 return parent;
141 } // getParent()
144 * setParent
145 * @param parentMap TODO
147 public void setParent(InputMap parentMap) {
148 parent = parentMap;
149 } // setParent()
152 * size
153 * @returns int
155 public int size() {
156 return inputMap.size();
157 } // size()
160 * clear
162 public void clear() {
163 inputMap.clear();
164 } // clear()
167 * keys
168 * @returns KeyStroke[]
170 public KeyStroke[] keys() {
171 return convertSet(inputMap.keySet());
172 } // keys()
175 * allKeys
176 * @returns KeyStroke[]
178 public KeyStroke[] allKeys() {
180 // Variables
181 Set set;
183 // Initialize
184 set = new HashSet();
186 // Get Key Sets
187 if (parent != null) {
188 set.addAll(Arrays.asList(parent.allKeys()));
189 } // if
190 set.addAll(inputMap.keySet());
192 return convertSet(set);
194 } // allKeys()
196 private KeyStroke[] convertSet(Set set) {
198 // Variables
199 int index;
200 Iterator iterator;
201 KeyStroke[] keys;
203 // Create Final array
204 keys = new KeyStroke[set.size()];
205 iterator = set.iterator();
206 index = 0;
207 while (iterator.hasNext()) {
208 keys[index++] = (KeyStroke) iterator.next();
209 } // while
211 return keys;
213 } // convertSet()
216 //-------------------------------------------------------------
217 // Interface: Serializable ------------------------------------
218 //-------------------------------------------------------------
221 * writeObject
222 * @param stream TODO
223 * @exception IOException TODO
225 private void writeObject(ObjectOutputStream stream) throws IOException {
226 // TODO
227 } // writeObject()
230 * readObject
231 * @param stream TODO
232 * @exception ClassNotFoundException TODO
233 * @exception IOException TODO
235 private void readObject(ObjectInputStream stream) throws ClassNotFoundException, IOException {
236 // TODO
237 } // readObject()
240 } // InputMap