| 1 | /* InputMap.java --
|
|---|
| 2 | Copyright (C) 2002 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 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.
|
|---|
| 10 |
|
|---|
| 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.
|
|---|
| 15 |
|
|---|
| 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.
|
|---|
| 20 |
|
|---|
| 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.
|
|---|
| 25 |
|
|---|
| 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. */
|
|---|
| 37 |
|
|---|
| 38 | 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 |
|
|---|
| 230 | } // InputMap
|
|---|