diff options
author | Anthony Balkissoon <abalkiss@redhat.com> | 2005-10-20 18:58:46 +0000 |
---|---|---|
committer | Anthony Balkissoon <abalkiss@redhat.com> | 2005-10-20 18:58:46 +0000 |
commit | bf7435e265cc0f4368c35336e6d9d46b287a6861 (patch) | |
tree | ba9808a315af7c1c8fd38388d3eb16e614db6242 | |
parent | e13f93378414561199c211e4b31f284c3335d551 (diff) | |
download | classpath-bf7435e265cc0f4368c35336e6d9d46b287a6861.tar.gz |
2005-10-20 Anthony Balkissoon <abalkiss@redhat.com>
* javax/swing/LookAndFeel.java:
(loadKeyBindings): Implemented and added docs.
(makeComponentInputMap): Likewise.
(makeInputMap): Likewise.
(makeKeyBindings): Likewise.
* javax/swing/plaf/basic/BasicListUI.java:
(convertModifiers): Removed this no longer needed private method.
(installKeyboardActions): Removed the code relating to modifier
conversion and made code more readable by using local variables.
* javax/swing/plaf/basic/BasicTableUI.java:
(convertModifiers): Removed this no longer needed private method.
(installKeyboardActions): Removed the code relating to modifier
conversion and made code more readbale by using local variables.
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | javax/swing/LookAndFeel.java | 68 | ||||
-rw-r--r-- | javax/swing/plaf/basic/BasicListUI.java | 55 | ||||
-rw-r--r-- | javax/swing/plaf/basic/BasicTableUI.java | 54 |
4 files changed, 96 insertions, 97 deletions
@@ -1,3 +1,19 @@ +2005-10-20 Anthony Balkissoon <abalkiss@redhat.com> + + * javax/swing/LookAndFeel.java: + (loadKeyBindings): Implemented and added docs. + (makeComponentInputMap): Likewise. + (makeInputMap): Likewise. + (makeKeyBindings): Likewise. + * javax/swing/plaf/basic/BasicListUI.java: + (convertModifiers): Removed this no longer needed private method. + (installKeyboardActions): Removed the code relating to modifier + conversion and made code more readable by using local variables. + * javax/swing/plaf/basic/BasicTableUI.java: + (convertModifiers): Removed this no longer needed private method. + (installKeyboardActions): Removed the code relating to modifier + conversion and made code more readbale by using local variables. + 2005-10-20 Lillian Angel <langel@redhat.com> * javax/swing/plaf/basic/BasicMenuItemUI.java: diff --git a/javax/swing/LookAndFeel.java b/javax/swing/LookAndFeel.java index 063ffd75d..1a67e8497 100644 --- a/javax/swing/LookAndFeel.java +++ b/javax/swing/LookAndFeel.java @@ -45,7 +45,9 @@ import java.awt.Toolkit; import java.net.URL; import javax.swing.border.Border; +import javax.swing.plaf.ComponentInputMapUIResource; import javax.swing.plaf.IconUIResource; +import javax.swing.plaf.InputMapUIResource; import javax.swing.plaf.UIResource; import javax.swing.text.JTextComponent; @@ -183,20 +185,47 @@ public abstract class LookAndFeel public abstract boolean isSupportedLookAndFeel(); /** - * Loads the bindings in keys into retMap. + * Loads the bindings in keys into retMap. Does not remove existing entries + * from retMap. <code>keys</code> describes the InputMap, every even indexed + * item is either a KeyStroke or a String representing a KeyStroke and every + * odd indexed item is the Object associated with that KeyStroke in an + * ActionMap. + * + * @param retMap the InputMap into which we load bindings + * @param keys the Object array describing the InputMap as above */ public static void loadKeyBindings(InputMap retMap, Object[] keys) { - // TODO: Implement this properly. + if (keys == null) + return; + for (int i = 0; i < keys.length - 1; i+= 2) + { + Object key = keys[i]; + KeyStroke keyStroke; + if (key instanceof KeyStroke) + keyStroke = (KeyStroke)key; + else + keyStroke = KeyStroke.getKeyStroke((String)key); + retMap.put(keyStroke, keys[i+1]); + } } /** - * Creates a ComponentInputMap from keys. + * Creates a ComponentInputMap from keys. + * <code>keys</code> describes the InputMap, every even indexed + * item is either a KeyStroke or a String representing a KeyStroke and every + * odd indexed item is the Object associated with that KeyStroke in an + * ActionMap. + * + * @param c the JComponent associated with the ComponentInputMap + * @param keys the Object array describing the InputMap as above */ public static ComponentInputMap makeComponentInputMap(JComponent c, Object[] keys) { - return null; + ComponentInputMap retMap = new ComponentInputMapUIResource(c); + loadKeyBindings(retMap, keys); + return retMap; } /** @@ -217,18 +246,43 @@ public abstract class LookAndFeel /** * Creates a InputMap from keys. + * <code>keys</code> describes the InputMap, every even indexed + * item is either a KeyStroke or a String representing a KeyStroke and every + * odd indexed item is the Object associated with that KeyStroke in an + * ActionMap. + * + * @param keys the Object array describing the InputMap as above */ public static InputMap makeInputMap(Object[] keys) { - return null; + InputMap retMap = new InputMapUIResource(); + loadKeyBindings(retMap, keys); + return retMap; } /** - * Convenience method for building lists of KeyBindings. + * Convenience method for building lists of KeyBindings. + * <code>keyBindingList</code> is an array of KeyStroke-Action pairs where + * even indexed elements are KeyStrokes or Strings representing KeyStrokes + * and odd indexed elements are the associated Actions. + * + * @param keyBindingList the array of KeyStroke-Action pairs + * @return a JTextComponent.KeyBinding array */ public static JTextComponent.KeyBinding[] makeKeyBindings(Object[] keyBindingList) { - return null; + JTextComponent.KeyBinding[] retBindings = + new JTextComponent.KeyBinding[keyBindingList.length / 2]; + for (int i = 0; i < keyBindingList.length - 1; i+= 2) + { + KeyStroke stroke; + if (keyBindingList[i] instanceof KeyStroke) + stroke = (KeyStroke)keyBindingList[i]; + else + stroke = KeyStroke.getKeyStroke((String)keyBindingList[i]); + retBindings[i/2] = new JTextComponent.KeyBinding(stroke, (String)keyBindingList[i+1]); + } + return retBindings; } /** diff --git a/javax/swing/plaf/basic/BasicListUI.java b/javax/swing/plaf/basic/BasicListUI.java index 892d783bb..1616d5e4f 100644 --- a/javax/swing/plaf/basic/BasicListUI.java +++ b/javax/swing/plaf/basic/BasicListUI.java @@ -930,36 +930,6 @@ public class BasicListUI extends ListUI list.removeMouseMotionListener(mouseInputListener); list.removePropertyChangeListener(propertyChangeListener); } - - private int convertModifiers(int mod) - { - if ((mod & KeyEvent.SHIFT_DOWN_MASK) != 0) - { - mod |= KeyEvent.SHIFT_MASK; - mod &= ~KeyEvent.SHIFT_DOWN_MASK; - } - if ((mod & KeyEvent.CTRL_DOWN_MASK) != 0) - { - mod |= KeyEvent.CTRL_MASK; - mod &= ~KeyEvent.CTRL_DOWN_MASK; - } - if ((mod & KeyEvent.META_DOWN_MASK) != 0) - { - mod |= KeyEvent.META_MASK; - mod &= ~KeyEvent.META_DOWN_MASK; - } - if ((mod & KeyEvent.ALT_DOWN_MASK) != 0) - { - mod |= KeyEvent.ALT_MASK; - mod &= ~KeyEvent.ALT_DOWN_MASK; - } - if ((mod & KeyEvent.ALT_GRAPH_DOWN_MASK) != 0) - { - mod |= KeyEvent.ALT_GRAPH_MASK; - mod &= ~KeyEvent.ALT_GRAPH_DOWN_MASK; - } - return mod; - } /** * Installs keyboard actions for this UI in the {@link JList}. @@ -974,24 +944,19 @@ public class BasicListUI extends ListUI action = new ListAction(); Object keys[] = focusInputMap.allKeys(); // Register key bindings in the UI InputMap-ActionMap pair - // Note that we register key bindings with both the old and new modifier - // masks: InputEvent.SHIFT_MASK and InputEvent.SHIFT_DOWN_MASK and so on. for (int i = 0; i < keys.length; i++) { - parentInputMap.put(KeyStroke.getKeyStroke - (((KeyStroke)keys[i]).getKeyCode(), convertModifiers - (((KeyStroke)keys[i]).getModifiers())), - (String)focusInputMap.get((KeyStroke)keys[i])); - - parentInputMap.put(KeyStroke.getKeyStroke - (((KeyStroke)keys[i]).getKeyCode(), - ((KeyStroke)keys[i]).getModifiers()), - (String)focusInputMap.get((KeyStroke)keys[i])); - - parentActionMap.put - ((String)focusInputMap.get((KeyStroke)keys[i]), new ActionListenerProxy - (action, (String)focusInputMap.get((KeyStroke)keys[i]))); + KeyStroke stroke = (KeyStroke)keys[i]; + String actionString = (String) focusInputMap.get(stroke); + parentInputMap.put(KeyStroke.getKeyStroke(stroke.getKeyCode(), + stroke.getModifiers()), + actionString); + + parentActionMap.put (actionString, + new ActionListenerProxy(action, actionString)); } + // Register the new InputMap-ActionMap as the parents of the list's + // InputMap and ActionMap parentInputMap.setParent(list.getInputMap().getParent()); parentActionMap.setParent(list.getActionMap().getParent()); list.getInputMap().setParent(parentInputMap); diff --git a/javax/swing/plaf/basic/BasicTableUI.java b/javax/swing/plaf/basic/BasicTableUI.java index 31835b97d..f089d58e1 100644 --- a/javax/swing/plaf/basic/BasicTableUI.java +++ b/javax/swing/plaf/basic/BasicTableUI.java @@ -335,36 +335,6 @@ public class BasicTableUI extends TableUI rendererPane = new CellRendererPane(); } - private int convertModifiers(int mod) - { - if ((mod & KeyEvent.SHIFT_DOWN_MASK) != 0) - { - mod |= KeyEvent.SHIFT_MASK; - mod &= ~KeyEvent.SHIFT_DOWN_MASK; - } - if ((mod & KeyEvent.CTRL_DOWN_MASK) != 0) - { - mod |= KeyEvent.CTRL_MASK; - mod &= ~KeyEvent.CTRL_DOWN_MASK; - } - if ((mod & KeyEvent.META_DOWN_MASK) != 0) - { - mod |= KeyEvent.META_MASK; - mod &= ~KeyEvent.META_DOWN_MASK; - } - if ((mod & KeyEvent.ALT_DOWN_MASK) != 0) - { - mod |= KeyEvent.ALT_MASK; - mod &= ~KeyEvent.ALT_DOWN_MASK; - } - if ((mod & KeyEvent.ALT_GRAPH_DOWN_MASK) != 0) - { - mod |= KeyEvent.ALT_GRAPH_MASK; - mod &= ~KeyEvent.ALT_GRAPH_DOWN_MASK; - } - return mod; - } - protected void installKeyboardActions() { UIDefaults defaults = UIManager.getLookAndFeelDefaults(); @@ -375,23 +345,17 @@ public class BasicTableUI extends TableUI action = new TableAction(); Object keys[] = ancestorMap.allKeys(); // Register key bindings in the UI InputMap-ActionMap pair - // Note that we register key bindings with both the old and new modifier - // masks: InputEvent.SHIFT_MASK and InputEvent.SHIFT_DOWN_MASK and so on. for (int i = 0; i < keys.length; i++) { - parentInputMap.put(KeyStroke.getKeyStroke - (((KeyStroke)keys[i]).getKeyCode(), convertModifiers - (((KeyStroke)keys[i]).getModifiers())), - (String)ancestorMap.get((KeyStroke)keys[i])); - - parentInputMap.put(KeyStroke.getKeyStroke - (((KeyStroke)keys[i]).getKeyCode(), - ((KeyStroke)keys[i]).getModifiers()), - (String)ancestorMap.get((KeyStroke)keys[i])); - - parentActionMap.put - ((String)ancestorMap.get((KeyStroke)keys[i]), new ActionListenerProxy - (action, (String)ancestorMap.get((KeyStroke)keys[i]))); + KeyStroke stroke = (KeyStroke)keys[i]; + String actionString = (String) ancestorMap.get(stroke); + + parentInputMap.put(KeyStroke.getKeyStroke(stroke.getKeyCode(), + stroke.getModifiers()), + actionString); + + parentActionMap.put (actionString, + new ActionListenerProxy (action, actionString)); } // Set the UI InputMap-ActionMap pair to be the parents of the |