1 15 16 package swingwtx.swing; 17 18 import java.util.HashMap ; 19 20 26 public class InputMap 27 { 28 private HashMap hashMap = new HashMap (); 29 private InputMap parent = null; 30 31 public void setParent(InputMap parent) { this.parent = parent; } 32 public InputMap getParent() { return parent; } 33 34 public Object get(KeyStroke keyStroke) 35 { 36 Object value = null; 37 38 if (hashMap.containsKey(value)) 39 value = hashMap.get(keyStroke); 40 else if (parent != null) 41 value = parent.get(keyStroke); 42 43 return value; 44 } 45 46 public void put(KeyStroke keyStroke, Object actionMapKey) 47 { 48 if (keyStroke != null) 49 { 50 if (actionMapKey == null) remove(keyStroke); 51 else hashMap.put(keyStroke, actionMapKey); 52 } 53 } 54 55 public void remove(KeyStroke key) { hashMap.remove(key); } 56 public void clear() { hashMap.clear(); } 57 public KeyStroke[] keys() { return (KeyStroke[]) hashMap.keySet().toArray(new KeyStroke[0]); } 58 public int size() { return hashMap.size(); } 59 60 HashMap getHashMap() { return hashMap; } 62 HashMap allKeyValues() 63 { 64 HashMap keyValues = (HashMap ) hashMap.clone(); 65 if (parent != null) keyValues.putAll(parent.allKeyValues()); 66 return keyValues; 67 } 68 69 public KeyStroke[] allKeys() 70 { 71 return (KeyStroke[]) allKeyValues().keySet().toArray(new KeyStroke[0]); 72 } 73 } 74 | Popular Tags |