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)
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
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
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. */
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
;
54 * @author Andrew Selkirk
57 public class InputMap
implements Serializable
59 static final long serialVersionUID
= -5429059542008604257L;
61 //-------------------------------------------------------------
62 // Variables --------------------------------------------------
63 //-------------------------------------------------------------
68 private Map inputMap
= new HashMap();
73 private InputMap parent
= null;
76 //-------------------------------------------------------------
77 // Initialization ---------------------------------------------
78 //-------------------------------------------------------------
81 * Constructor InputMap
88 //-------------------------------------------------------------
89 // Methods ----------------------------------------------------
90 //-------------------------------------------------------------
97 public Object
get(KeyStroke keystroke
) {
103 result
= inputMap
.get(keystroke
);
106 if (result
== null) {
107 result
= parent
.get(keystroke
);
116 * @param keystroke TODO
117 * @param actionMapKey TODO
119 public void put(KeyStroke keystroke
, Object actionMapKey
) {
120 if (actionMapKey
== null) {
121 inputMap
.remove(keystroke
);
123 inputMap
.put(keystroke
, actionMapKey
);
129 * @param keystroke TODO
131 public void remove(KeyStroke keystroke
) {
132 inputMap
.remove(keystroke
);
139 public InputMap
getParent() {
145 * @param parentMap TODO
147 public void setParent(InputMap parentMap
) {
156 return inputMap
.size();
162 public void clear() {
168 * @returns KeyStroke[]
170 public KeyStroke
[] keys() {
171 return convertSet(inputMap
.keySet());
176 * @returns KeyStroke[]
178 public KeyStroke
[] allKeys() {
187 if (parent
!= null) {
188 set
.addAll(Arrays
.asList(parent
.allKeys()));
190 set
.addAll(inputMap
.keySet());
192 return convertSet(set
);
196 private KeyStroke
[] convertSet(Set set
) {
203 // Create Final array
204 keys
= new KeyStroke
[set
.size()];
205 iterator
= set
.iterator();
207 while (iterator
.hasNext()) {
208 keys
[index
++] = (KeyStroke
) iterator
.next();
216 //-------------------------------------------------------------
217 // Interface: Serializable ------------------------------------
218 //-------------------------------------------------------------
223 * @exception IOException TODO
225 private void writeObject(ObjectOutputStream stream
) throws IOException
{
232 * @exception ClassNotFoundException TODO
233 * @exception IOException TODO
235 private void readObject(ObjectInputStream stream
) throws ClassNotFoundException
, IOException
{