Hi Roman,
> I have some comments on your patch that you might want to have a look
> at.
>
> "TextPaneUI", "javax.swing.plaf.basic.BasicTextPaneUI",
> "TextAreaUI", "javax.swing.plaf.basic.BasicTextAreaUI",
> "TextFieldUI", "javax.swing.plaf.basic.BasicTextFieldUI",
> - "TextPaneUI", "javax.swing.plaf.basic.BasicTextPaneUI",
> + "TextUI", "javax.swing.plaf.basic.BasicTextUI",
>
Fixed
>
> I see that TextPaneUI is a double, but why do we need TextUI?
> BasicTextUI is abstract and every attempt to instantiate would cause
> exceptions. Also, there is no component using TextUI.
>
> + "TextArea.focusInputMap", new UIDefaults.LazyInputMap(new
> Object[] {
> + "UP", "caret-up",
> + "DOWN", "caret-down",
> + "PAGE_UP", "page-up",
> + "PAGE_DOWN", "page-down",
> + "ENTER", "insert-break",
> + "TAB", "insert-tab",
> + "LEFT", "caret-backward",
> + "RIGHT", "caret-forward",
> + "BACK_SPACE", "delete-previous",
> + "ctrl X", "cut-to-clipboard",
> + "ctrl C", "copy-to-clipboard",
> + "ctrl V", "paste-from-clipboard",
> + "shift LEFT", "selection-backward",
> + "shift RIGHT", "selection-forward",
> + "HOME", "caret-begin-line",
> + "END", "caret-end-line",
> + "DELETE", "delete-next"
> + }),
>
> Why not put in all the bindings at once. I pasted the bindings (for
> JTextField) from JDK1.5 here:
> http://pastebin.com/473135
I added them all in.
>
> The others are easy to find out using my attache UIDefaultsInspector
> class. Simple call it like that:
>
> java UIDefaultsInspector MyBasicLookAndFeel |grep TextField
> (if you want to inspect the MetalLookAndFeel, simply leave out the
> MyBasicLookAndFeel parameter).
>
> Also, we have a mauve test for BasicLookAndFeel.initComponentDefaults()
> that should be updated.
I will do this next.
>
> - SwingUtilities.replaceUIActionMap(textComponent, getActionMap());
> + SwingUtilities.replaceUIActionMap(textComponent,
> textComponent.getActionMap());
>
> This is a bad idea. replaceUIActionMap() replaces the top-level
> actionMap for a component with another actionMap. What you would get
> from this is a component actionMap A referring to itself as a parent,
> this calls for problems.
Fixed.
>
> + InputMap focusInputMap =
> textComponent.getInputMap(JComponent.WHEN_FOCUSED);
> + InputMapUIResource parentInputMap = new InputMapUIResource();
> + ActionMap parentActionMap = new ActionMapUIResource();
> + Object keys[] = focusInputMap.allKeys();
>
> I would think that instead of going through all the keys, we should
> fetch all the actions of a textComponent and register them by their
> names. Like this:
>
> Action[] actions = textComponent.getActions();
> for (int i = 0; i < actions.length; i++)
> {
> String name = actions[i].getValue(Action.NAME);
> parentActionMap.put(name, action[i]);
> }
Fixed.
>
>
> + for (int i = 0; i < keys.length; i++)
> + {
> + String act = (String) focusInputMap.get((KeyStroke) keys[i]);
> + Action[] actions = textComponent.getActions();
> + for (int j = 0; j < actions.length; j++)
> + {
> + Action currAction = actions[j];
> + if (currAction != null
> + && (currAction.getValue(Action.NAME).equals(act)))
> + parentActionMap.put(act, new
> ActionListenerProxy(currAction, act));
> + }
> +
> + parentInputMap.put(KeyStroke.getKeyStroke(((KeyStroke)
> keys[i]).getKeyCode(),
> +
> convertModifiers(((KeyStroke) keys[i]).getModifiers())),
> + act);
> + parentInputMap.put(KeyStroke.getKeyStroke(((KeyStroke)
> keys[i]).getKeyCode(),
> + ((KeyStroke)
> keys[i]).getModifiers()),
> + act);
> + }
>
> Replace this with the one loop like pasted above. I suppose you are
> doing all this work to load the inputMap from the UI Object[]? Then you
> might want to use LookAndFeel.loadKeyBindings(). That takes an Object[]
> and loads the key bindings into an InputMap.
I made this loop more efficent by far. I attempted to use the
loadKeyBindings, but I realized its not possible. I need to pass the
entire array of strings from the Text*.focusInputMap. But if I use the
UIManager to get the focusInputMap, an instance of InputMapUIResource is
returned (not an array). This InputMap contains half as many entries as
those in the array of strings (the key/value pairs). To get the values
of the input map, keys() is called and this returns an array of all the
KeyStrokes- not the strings. Therefore, in this case loadKeyBindings is
not helpful.
>
> parentInputMap.setParent(textComponent.getInputMap(JComponent.WHEN_FOCUSED).getParent());
> +
> parentActionMap.setParent(textComponent.getActionMap().getParent());
> +
> textComponent.getInputMap(JComponent.WHEN_FOCUSED).setParent(parentInputMap);
> + textComponent.getActionMap().setParent(parentActionMap);
>
> You don't really want to do this. Instead, simply call
> SwingUtilities.replaceUIInputMap() or
> SwingUtilities.replaceUIActionMap() to properly install the top-level
> Input/ActionMaps.
This is setting the parents of the map. I don't see why I should call
replaceUI*Map here.
2005-12-20 Lillian Angel <[EMAIL PROTECTED]>
* javax/swing/UIDefaults.java:
(LazyInputMap): InputMap should be an InputMapUIResource.
* javax/swing/plaf/basic/BasicLookAndFeel.java
(initComponentDefaults): Added all key bindings for Text*.
* javax/swing/plaf/basic/BasicTextUI.java
(installKeyboardActions): Fixed call to replaceUIActionMap
to create a new ActionMap from textComponent's actions. Prevents
an infinite loop. Fixed loop to set the parentActionMap and the
parentInputMap.
(ActionListenerProxy): Removed. No longer needed.
(convertModifiers): Likewise.
Index: javax/swing/UIDefaults.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/UIDefaults.java,v
retrieving revision 1.24
diff -u -r1.24 UIDefaults.java
--- javax/swing/UIDefaults.java 12 Oct 2005 20:21:48 -0000 1.24
+++ javax/swing/UIDefaults.java 21 Dec 2005 19:43:13 -0000
@@ -54,6 +54,7 @@
import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.InputMapUIResource;
/**
* UIDefaults is a database where all settings and interface bindings are
@@ -95,7 +96,7 @@
}
public Object createValue(UIDefaults table)
{
- InputMap im = new InputMap ();
+ InputMapUIResource im = new InputMapUIResource ();
for (int i = 0; 2*i+1 < bind.length; ++i)
{
im.put (KeyStroke.getKeyStroke ((String) bind[2*i]),
Index: javax/swing/plaf/basic/BasicLookAndFeel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicLookAndFeel.java,v
retrieving revision 1.71
diff -u -r1.71 BasicLookAndFeel.java
--- javax/swing/plaf/basic/BasicLookAndFeel.java 21 Dec 2005 17:06:40 -0000 1.71
+++ javax/swing/plaf/basic/BasicLookAndFeel.java 21 Dec 2005 19:43:13 -0000
@@ -220,7 +220,6 @@
"TextPaneUI", "javax.swing.plaf.basic.BasicTextPaneUI",
"TextAreaUI", "javax.swing.plaf.basic.BasicTextAreaUI",
"TextFieldUI", "javax.swing.plaf.basic.BasicTextFieldUI",
- "TextUI", "javax.swing.plaf.basic.BasicTextUI",
"ToggleButtonUI", "javax.swing.plaf.basic.BasicToggleButtonUI",
"ToolBarSeparatorUI", "javax.swing.plaf.basic.BasicToolBarSeparatorUI",
"ToolBarUI", "javax.swing.plaf.basic.BasicToolBarUI",
@@ -1070,23 +1069,61 @@
"TextArea.foreground", new ColorUIResource(Color.black),
"TextArea.inactiveForeground", new ColorUIResource(Color.gray),
"TextArea.focusInputMap", new UIDefaults.LazyInputMap(new Object[] {
- "UP", "caret-up",
+ "shift UP", "selection-up",
+ "ctrl RIGHT", "caret-next-word",
+ "shift ctrl LEFT", "selection-previous-word",
+ "shift KP_UP", "selection-up",
"DOWN", "caret-down",
- "PAGE_UP", "page-up",
- "PAGE_DOWN", "page-down",
- "ENTER", "insert-break",
- "TAB", "insert-tab",
+ "shift ctrl T", "previous-link-action",
+ "ctrl LEFT", "caret-previous-word",
+ "CUT", "cut-to-clipboard",
+ "END", "caret-end-line",
+ "shift PAGE_UP", "selection-page-up",
+ "KP_UP", "caret-up",
+ "DELETE", "delete-next",
+ "ctrl HOME", "caret-begin",
+ "shift LEFT", "selection-backward",
+ "ctrl END", "caret-end",
+ "BACK_SPACE", "delete-previous",
+ "shift ctrl RIGHT", "selection-next-word",
"LEFT", "caret-backward",
+ "KP_LEFT", "caret-backward",
+ "shift KP_RIGHT", "selection-forward",
+ "ctrl SPACE", "activate-link-action",
+ "ctrl H", "delete-previous",
+ "ctrl BACK_SLASH", "unselect",
+ "ENTER", "insert-break",
+ "shift HOME", "selection-begin-line",
"RIGHT", "caret-forward",
- "BACK_SPACE", "delete-previous",
+ "shift ctrl PAGE_UP", "selection-page-left",
+ "shift DOWN", "selection-down",
+ "PAGE_DOWN", "page-down",
+ "shift KP_LEFT", "selection-backward",
+ "shift ctrl O", "toggle-componentOrientation",
"ctrl X", "cut-to-clipboard",
+ "shift ctrl PAGE_DOWN", "selection-page-right",
"ctrl C", "copy-to-clipboard",
+ "ctrl KP_RIGHT", "caret-next-word",
+ "shift END", "selection-end-line",
+ "ctrl KP_LEFT", "caret-previous-word",
+ "HOME", "caret-begin-line",
"ctrl V", "paste-from-clipboard",
- "shift LEFT", "selection-backward",
+ "KP_DOWN", "caret-down",
+ "ctrl A", "select-all",
"shift RIGHT", "selection-forward",
- "HOME", "caret-begin-line",
- "END", "caret-end-line",
- "DELETE", "delete-next"
+ "shift ctrl END", "selection-end",
+ "COPY", "copy-to-clipboard",
+ "shift ctrl KP_LEFT", "selection-previous-word",
+ "ctrl T", "next-link-action",
+ "shift KP_DOWN", "selection-down",
+ "TAB", "insert-tab",
+ "UP", "caret-up",
+ "shift ctrl HOME", "selection-begin",
+ "shift PAGE_DOWN", "selection-page-down",
+ "KP_RIGHT", "caret-forward",
+ "shift ctrl KP_RIGHT", "selection-next-word",
+ "PAGE_UP", "page-up",
+ "PASTE", "paste-from-clipboard"
}),
"TextArea.margin", new InsetsUIResource(0, 0, 0, 0),
"TextArea.selectionBackground", new ColorUIResource(Color.black),
@@ -1115,7 +1152,28 @@
"shift RIGHT", "selection-forward",
"HOME", "caret-begin-line",
"END", "caret-end-line",
- "DELETE", "delete-next"
+ "DELETE", "delete-next",
+ "shift ctrl O", "toggle-componentOrientation",
+ "shift KP_LEFT", "selection-backward",
+ "ctrl H", "delete-previous",
+ "KP_LEFT", "caret-backward",
+ "KP_RIGHT", "caret-forward",
+ "shift ctrl KP_RIGHT", "selection-next-word",
+ "COPY", "copy-to-clipboard",
+ "shift HOME", "selection-begin-line",
+ "shift ctrl LEFT", "selection-previous-word",
+ "ctrl KP_LEFT", "caret-previous-word",
+ "ctrl KP_RIGHT", "caret-next-word",
+ "PASTE", "paste-from-clipboard",
+ "shift ctrl RIGHT", "selection-next-word",
+ "ctrl BACK_SLASH", "unselect",
+ "ctrl A", "select-all",
+ "shift KP_RIGHT", "selection-forward",
+ "CUT", "cut-to-clipboard",
+ "ctrl LEFT", "caret-previous-word",
+ "shift ctrl KP_LEFT", "selection-previous-word",
+ "shift END", "selection-end-line",
+ "ctrl RIGHT", "caret-next-word"
}),
"TextField.margin", new InsetsUIResource(0, 0, 0, 0),
"TextField.selectionBackground", new ColorUIResource(Color.black),
@@ -1128,23 +1186,61 @@
"TextPane.foreground", new ColorUIResource(Color.black),
"TextPane.inactiveForeground", new ColorUIResource(Color.gray),
"TextPane.focusInputMap", new UIDefaults.LazyInputMap(new Object[] {
- "UP", "caret-up",
- "DOWN", "caret-down",
- "PAGE_DOWN", "page-down",
- "PAGE_UP", "page-up",
- "ENTER", "insert-break",
- "TAB", "insert-tab",
- "LEFT", "caret-backward",
- "RIGHT", "caret-forward",
- "BACK_SPACE", "delete-previous",
- "ctrl X", "cut-to-clipboard",
- "ctrl C", "copy-to-clipboard",
- "ctrl V", "paste-from-clipboard",
- "shift LEFT", "selection-backward",
- "shift RIGHT", "selection-forward",
- "HOME", "caret-begin-line",
- "END", "caret-end-line",
- "DELETE", "delete-next"
+ "shift UP", "selection-up",
+ "ctrl RIGHT", "caret-next-word",
+ "shift ctrl LEFT", "selection-previous-word",
+ "shift KP_UP", "selection-up",
+ "DOWN", "caret-down",
+ "shift ctrl T", "previous-link-action",
+ "ctrl LEFT", "caret-previous-word",
+ "CUT", "cut-to-clipboard",
+ "END", "caret-end-line",
+ "shift PAGE_UP", "selection-page-up",
+ "KP_UP", "caret-up",
+ "DELETE", "delete-next",
+ "ctrl HOME", "caret-begin",
+ "shift LEFT", "selection-backward",
+ "ctrl END", "caret-end",
+ "BACK_SPACE", "delete-previous",
+ "shift ctrl RIGHT", "selection-next-word",
+ "LEFT", "caret-backward",
+ "KP_LEFT", "caret-backward",
+ "shift KP_RIGHT", "selection-forward",
+ "ctrl SPACE", "activate-link-action",
+ "ctrl H", "delete-previous",
+ "ctrl BACK_SLASH", "unselect",
+ "ENTER", "insert-break",
+ "shift HOME", "selection-begin-line",
+ "RIGHT", "caret-forward",
+ "shift ctrl PAGE_UP", "selection-page-left",
+ "shift DOWN", "selection-down",
+ "PAGE_DOWN", "page-down",
+ "shift KP_LEFT", "selection-backward",
+ "shift ctrl O", "toggle-componentOrientation",
+ "ctrl X", "cut-to-clipboard",
+ "shift ctrl PAGE_DOWN", "selection-page-right",
+ "ctrl C", "copy-to-clipboard",
+ "ctrl KP_RIGHT", "caret-next-word",
+ "shift END", "selection-end-line",
+ "ctrl KP_LEFT", "caret-previous-word",
+ "HOME", "caret-begin-line",
+ "ctrl V", "paste-from-clipboard",
+ "KP_DOWN", "caret-down",
+ "ctrl A", "select-all",
+ "shift RIGHT", "selection-forward",
+ "shift ctrl END", "selection-end",
+ "COPY", "copy-to-clipboard",
+ "shift ctrl KP_LEFT", "selection-previous-word",
+ "ctrl T", "next-link-action",
+ "shift KP_DOWN", "selection-down",
+ "TAB", "insert-tab",
+ "UP", "caret-up",
+ "shift ctrl HOME", "selection-begin",
+ "shift PAGE_DOWN", "selection-page-down",
+ "KP_RIGHT", "caret-forward",
+ "shift ctrl KP_RIGHT", "selection-next-word",
+ "PAGE_UP", "page-up",
+ "PASTE", "paste-from-clipboard"
}),
"TextPane.margin", new InsetsUIResource(3, 3, 3, 3),
"TextPane.selectionBackground", new ColorUIResource(Color.black),
Index: javax/swing/plaf/basic/BasicTextUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTextUI.java,v
retrieving revision 1.58
diff -u -r1.58 BasicTextUI.java
--- javax/swing/plaf/basic/BasicTextUI.java 21 Dec 2005 16:52:39 -0000 1.58
+++ javax/swing/plaf/basic/BasicTextUI.java 21 Dec 2005 19:43:13 -0000
@@ -652,33 +652,26 @@
// load any bindings for the newer InputMap / ActionMap interface
SwingUtilities.replaceUIInputMap(textComponent, JComponent.WHEN_FOCUSED,
getInputMap(JComponent.WHEN_FOCUSED));
- SwingUtilities.replaceUIActionMap(textComponent, textComponent.getActionMap());
+ SwingUtilities.replaceUIActionMap(textComponent, createActionMap());
- InputMap focusInputMap = textComponent.getInputMap(JComponent.WHEN_FOCUSED);
+ InputMap focusInputMap = (InputMap) UIManager.get(getPropertyPrefix() + ".focusInputMap");
InputMapUIResource parentInputMap = new InputMapUIResource();
ActionMap parentActionMap = new ActionMapUIResource();
- Object keys[] = focusInputMap.allKeys();
-
+ KeyStroke[] keys = focusInputMap.allKeys();
+
+ Action[] actions = textComponent.getActions();
+ for (int j = 0; j < actions.length; j++)
+ {
+ Action currAction = actions[j];
+ parentActionMap.put(currAction.getValue(Action.NAME), currAction);
+ }
+
for (int i = 0; i < keys.length; i++)
{
String act = (String) focusInputMap.get((KeyStroke) keys[i]);
- Action[] actions = textComponent.getActions();
- for (int j = 0; j < actions.length; j++)
- {
- Action currAction = actions[j];
- if (currAction != null
- && (currAction.getValue(Action.NAME).equals(act)))
- parentActionMap.put(act, new ActionListenerProxy(currAction, act));
- }
-
- parentInputMap.put(KeyStroke.getKeyStroke(((KeyStroke) keys[i]).getKeyCode(),
- convertModifiers(((KeyStroke) keys[i]).getModifiers())),
- act);
- parentInputMap.put(KeyStroke.getKeyStroke(((KeyStroke) keys[i]).getKeyCode(),
- ((KeyStroke) keys[i]).getModifiers()),
- act);
+ parentInputMap.put(KeyStroke.getKeyStroke(act),act);
}
-
+
parentInputMap.setParent(textComponent.getInputMap(JComponent.WHEN_FOCUSED).getParent());
parentActionMap.setParent(textComponent.getActionMap().getParent());
textComponent.getInputMap(JComponent.WHEN_FOCUSED).setParent(parentInputMap);
@@ -686,68 +679,21 @@
}
/**
- * This class is used to mimic the behaviour of the JDK when registering
- * keyboard actions. It is the same as the private class used in JComponent
- * for the same reason. This class receives an action event and dispatches it
- * to the true receiver after altering the actionCommand property of the
- * event.
- */
- private static class ActionListenerProxy extends AbstractAction
- {
- ActionListener target;
-
- String bindingCommandName;
-
- public ActionListenerProxy(ActionListener li, String cmd)
- {
- target = li;
- bindingCommandName = cmd;
- }
-
- public void actionPerformed(ActionEvent e)
- {
- ActionEvent derivedEvent = new ActionEvent(e.getSource(), e.getID(),
- bindingCommandName,
- e.getModifiers());
- target.actionPerformed(derivedEvent);
- }
- }
-
- /**
- * Converts the modifiers.
+ * Creates an ActionMap to be installed on the text component.
*
- * @param mod -
- * modifier to convert
- * @returns the new modifier
+ * @return an ActionMap to be installed on the text component
*/
- private int convertModifiers(int mod)
+ ActionMap createActionMap()
{
- 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)
+ Action[] actions = textComponent.getActions();
+ ActionMap am = new ActionMapUIResource();
+ for (int i = 0; i < actions.length; ++i)
{
- mod |= KeyEvent.ALT_GRAPH_MASK;
- mod &= ~KeyEvent.ALT_GRAPH_DOWN_MASK;
+ String name = (String) actions[i].getValue(Action.NAME);
+ if (name != null)
+ am.put(name, actions[i]);
}
- return mod;
+ return am;
}
/**
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches