This patch fixes all the FIXME notes in ComponentInputMap and tidies a few places in JComponent relating to ComponentInputMap. The main method however, JComponent.udpateComponentInputMap is not fully implemented because I first have to write a KeyboardManager class, which I'll do now.
2005-11-09 Anthony Balkissoon <[EMAIL PROTECTED]> * javax/swing/ComponentInputMap.java: (put): Notify the component. (clear): Likewise. (remove): Likewise. (setParent): Notify the parent. Improved the exception messages. * javax/swing/JComponent.java: (inputMap_whenInFocusedWindow): Changed type from InputMap to ComponentInputMap. (setInputMap): If we're setting the WHEN_IN_FOCUSED_WINDOW map and the parameter is not a ComponentInputMap or is not associated with the same Component, throw an IllegalArgumentException. (getInputMap): Create a new ComponentInputMap instead of a new InputMap when the WHEN_IN_FOCUSED_WINDOW map doesn't yet exist. (udpateComponentInputMap): New method. This is the method that ComponentInputMap calls when it is updated. Not yet completely implemented. --Tony
Index: javax/swing/ComponentInputMap.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/ComponentInputMap.java,v retrieving revision 1.8 diff -u -r1.8 ComponentInputMap.java --- javax/swing/ComponentInputMap.java 26 Jul 2005 15:30:54 -0000 1.8 +++ javax/swing/ComponentInputMap.java 9 Nov 2005 19:07:40 -0000 @@ -78,7 +78,8 @@ public void put(KeyStroke keystroke, Object value) { super.put(keystroke, value); - // FIXME: Notify component. + if (component != null) + component.updateComponentInputMap(this); } /** @@ -87,7 +88,8 @@ public void clear() { super.clear(); - // FIXME: Notify component. + if (component != null) + component.updateComponentInputMap(this); } /** @@ -98,7 +100,8 @@ public void remove(KeyStroke keystroke) { super.remove(keystroke); - // FIXME: Notify component. + if (component != null) + component.updateComponentInputMap(this); } /** @@ -111,14 +114,19 @@ */ public void setParent(InputMap parentMap) { - if (! (parentMap instanceof ComponentInputMap)) - throw new IllegalArgumentException(); - - if (((ComponentInputMap) parentMap).getComponent() != component) - throw new IllegalArgumentException(); + if (parentMap != null && !(parentMap instanceof ComponentInputMap)) + throw new IllegalArgumentException("ComponentInputMaps can only have " + + "ComponentInputMaps for parents"); + + if (parentMap != null && + ((ComponentInputMap) parentMap).getComponent() != component) + throw new + IllegalArgumentException("ComponentInputMaps' parents must " + + "be associated with the same JComponents"); super.setParent(parentMap); - // FIXME: Notify component. + if (component != null) + component.updateComponentInputMap(this); } /** Index: javax/swing/JComponent.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/JComponent.java,v retrieving revision 1.78 diff -u -r1.78 JComponent.java --- javax/swing/JComponent.java 9 Nov 2005 14:44:00 -0000 1.78 +++ javax/swing/JComponent.java 9 Nov 2005 19:07:41 -0000 @@ -546,7 +546,7 @@ private InputMap inputMap_whenFocused; private InputMap inputMap_whenAncestorOfFocused; - private InputMap inputMap_whenInFocusedWindow; + private ComponentInputMap inputMap_whenInFocusedWindow; private ActionMap actionMap; /** @since 1.3 */ private boolean verifyInputWhenFocusTarget; @@ -2022,7 +2022,11 @@ break; case WHEN_IN_FOCUSED_WINDOW: - inputMap_whenInFocusedWindow = map; + if (map != null && !(map instanceof ComponentInputMap)) + throw new + IllegalArgumentException("WHEN_IN_FOCUSED_WINDOW " + + "InputMap must be a ComponentInputMap"); + inputMap_whenInFocusedWindow = (ComponentInputMap)map; break; case UNDEFINED_CONDITION: @@ -2048,7 +2052,7 @@ case WHEN_IN_FOCUSED_WINDOW: if (inputMap_whenInFocusedWindow == null) - inputMap_whenInFocusedWindow = new InputMap(); + inputMap_whenInFocusedWindow = new ComponentInputMap(this); return inputMap_whenInFocusedWindow; case UNDEFINED_CONDITION: @@ -3297,5 +3301,27 @@ found = p; } return found; + } + + /** + * This is the method that gets called when the WHEN_IN_FOCUSED_WINDOW map + * is changed. + * @param c the JComponent associated with the WHEN_IN_FOCUSED_WINDOW map + */ + void updateComponentInputMap(ComponentInputMap changed) + { + // Since you can change a component's input map via + // setInputMap, we have to check if <code>changed</code> + // is still in our WHEN_IN_FOCUSED_WINDOW map hierarchy + InputMap curr = getInputMap(WHEN_IN_FOCUSED_WINDOW); + while (curr != null && curr != changed) + curr = curr.getParent(); + + // If curr is null then changed is not in the hierarchy + if (curr == null) + return; + + // Now we have to update the keyboard manager's hashtable + // FIXME: not yet implemented } }
_______________________________________________ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches