1 7 package javax.swing; 8 9 20 public class ComponentInputMap extends InputMap { 21 22 private JComponent component; 23 24 31 public ComponentInputMap(JComponent component) { 32 this.component = component; 33 if (component == null) { 34 throw new IllegalArgumentException ("ComponentInputMaps must be associated with a non-null JComponent"); 35 } 36 } 37 38 49 public void setParent(InputMap map) { 50 if (getParent() == map) { 51 return; 52 } 53 if (map != null && (!(map instanceof ComponentInputMap ) || 54 ((ComponentInputMap )map).getComponent() != getComponent())) { 55 throw new IllegalArgumentException ("ComponentInputMaps must have a parent ComponentInputMap associated with the same component"); 56 } 57 super.setParent(map); 58 getComponent().componentInputMapChanged(this); 59 } 60 61 64 public JComponent getComponent() { 65 return component; 66 } 67 68 73 public void put(KeyStroke keyStroke, Object actionMapKey) { 74 super.put(keyStroke, actionMapKey); 75 if (getComponent() != null) { 76 getComponent().componentInputMapChanged(this); 77 } 78 } 79 80 83 public void remove(KeyStroke key) { 84 super.remove(key); 85 if (getComponent() != null) { 86 getComponent().componentInputMapChanged(this); 87 } 88 } 89 90 93 public void clear() { 94 int oldSize = size(); 95 super.clear(); 96 if (oldSize > 0 && getComponent() != null) { 97 getComponent().componentInputMapChanged(this); 98 } 99 } 100 } 101 | Popular Tags |