summaryrefslogtreecommitdiff
path: root/javax/swing/plaf/basic/BasicTextUI.java
diff options
context:
space:
mode:
Diffstat (limited to 'javax/swing/plaf/basic/BasicTextUI.java')
-rw-r--r--javax/swing/plaf/basic/BasicTextUI.java103
1 files changed, 53 insertions, 50 deletions
diff --git a/javax/swing/plaf/basic/BasicTextUI.java b/javax/swing/plaf/basic/BasicTextUI.java
index be668671b..fc3889484 100644
--- a/javax/swing/plaf/basic/BasicTextUI.java
+++ b/javax/swing/plaf/basic/BasicTextUI.java
@@ -46,15 +46,20 @@ import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
+import java.awt.event.KeyEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
+import javax.swing.KeyStroke;
import javax.swing.LookAndFeel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
@@ -62,6 +67,7 @@ import javax.swing.UIManager;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.plaf.ActionMapUIResource;
+import javax.swing.plaf.InputMapUIResource;
import javax.swing.plaf.TextUI;
import javax.swing.plaf.UIResource;
import javax.swing.text.BadLocationException;
@@ -615,15 +621,25 @@ public abstract class BasicTextUI extends TextUI
*/
protected Keymap createKeymap()
{
+ JTextComponent.KeyBinding[] bindings = null;
String prefix = getPropertyPrefix();
- JTextComponent.KeyBinding[] bindings =
- (JTextComponent.KeyBinding[]) UIManager.get(prefix + ".keyBindings");
+ InputMapUIResource m = (InputMapUIResource) UIManager.get(prefix + ".focusInputMap");
+ if (m != null)
+ {
+ KeyStroke[] keys = m.keys();
+ int len = keys.length;
+ bindings = new JTextComponent.KeyBinding[len];
+ for (int i = 0; i < len; i++)
+ {
+ KeyStroke curr = keys[i];
+ bindings[i] = new JTextComponent.KeyBinding(curr,
+ (String) m.get(curr));
+ }
+ }
if (bindings == null)
{
bindings = new JTextComponent.KeyBinding[0];
- // FIXME: Putting something into the defaults map is certainly wrong.
- // Must be fixed somehow.
- UIManager.put(prefix + ".keyBindings", bindings);
+ UIManager.put(prefix + ".focusInputMap", bindings);
}
Keymap km = JTextComponent.addKeymap(getKeymapName(),
@@ -636,18 +652,45 @@ public abstract class BasicTextUI extends TextUI
* Installs the keyboard actions on the text components.
*/
protected void installKeyboardActions()
- {
- // load any bindings for the older Keymap interface
+ {
+ // load key bindings for the older interface
Keymap km = JTextComponent.getKeymap(getKeymapName());
if (km == null)
km = createKeymap();
textComponent.setKeymap(km);
// load any bindings for the newer InputMap / ActionMap interface
- SwingUtilities.replaceUIInputMap(textComponent,
- JComponent.WHEN_FOCUSED,
+ SwingUtilities.replaceUIInputMap(textComponent, JComponent.WHEN_FOCUSED,
getInputMap(JComponent.WHEN_FOCUSED));
- SwingUtilities.replaceUIActionMap(textComponent, getActionMap());
+ SwingUtilities.replaceUIActionMap(textComponent, createActionMap());
+
+ ActionMap parentActionMap = new ActionMapUIResource();
+ Action[] actions = textComponent.getActions();
+ for (int j = 0; j < actions.length; j++)
+ {
+ Action currAction = actions[j];
+ parentActionMap.put(currAction.getValue(Action.NAME), currAction);
+ }
+
+ SwingUtilities.replaceUIActionMap(textComponent, parentActionMap);
+ }
+
+ /**
+ * Creates an ActionMap to be installed on the text component.
+ *
+ * @return an ActionMap to be installed on the text component
+ */
+ ActionMap createActionMap()
+ {
+ Action[] actions = textComponent.getActions();
+ ActionMap am = new ActionMapUIResource();
+ for (int i = 0; i < actions.length; ++i)
+ {
+ String name = (String) actions[i].getValue(Action.NAME);
+ if (name != null)
+ am.put(name, actions[i]);
+ }
+ return am;
}
/**
@@ -674,46 +717,6 @@ public abstract class BasicTextUI extends TextUI
}
/**
- * Returns the ActionMap to be installed on the text component.
- *
- * @return the ActionMap to be installed on the text component
- */
- // FIXME: The UIDefaults have no entries for .actionMap, so this should
- // be handled somehow different.
- ActionMap getActionMap()
- {
- String prefix = getPropertyPrefix();
- ActionMap am = (ActionMap) UIManager.get(prefix + ".actionMap");
- if (am == null)
- {
- am = createActionMap();
- // FIXME: Putting something in the UIDefaults map is certainly wrong.
- // However, the whole method seems wrong and must be replaced by
- // something that is less wrong.
- UIManager.put(prefix + ".actionMap", am);
- }
- return am;
- }
-
- /**
- * Creates an ActionMap to be installed on the text component.
- *
- * @return an ActionMap to be installed on the text component
- */
- ActionMap createActionMap()
- {
- Action[] actions = textComponent.getActions();
- ActionMap am = new ActionMapUIResource();
- for (int i = 0; i < actions.length; ++i)
- {
- String name = (String) actions[i].getValue(Action.NAME);
- if (name != null)
- am.put(name, actions[i]);
- }
- return am;
- }
-
- /**
* Uninstalls this TextUI from the text component.
*
* @param component the text component to uninstall the UI from