summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java')
-rw-r--r--libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java112
1 files changed, 57 insertions, 55 deletions
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java
index e8eeece3b32..fc388948419 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java
+++ b/libjava/classpath/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;
@@ -334,9 +340,9 @@ public abstract class BasicTextUI extends TextUI
* Returns the document position that is (visually) nearest to the given
* document position <code>pos</code> in the given direction <code>d</code>.
*
- * @param c the text component
* @param pos the document position
* @param b the bias for <code>pos</code>
+ * @param a the allocation for the view
* @param d the direction, must be either {@link SwingConstants#NORTH},
* {@link SwingConstants#SOUTH}, {@link SwingConstants#WEST} or
* {@link SwingConstants#EAST}
@@ -351,12 +357,11 @@ public abstract class BasicTextUI extends TextUI
* @throws BadLocationException if <code>pos</code> is not a valid offset in
* the document model
*/
- public int getNextVisualPositionFrom(JTextComponent c, int pos,
- Position.Bias b, int d,
- Position.Bias[] biasRet)
+ public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a,
+ int d, Position.Bias[] biasRet)
throws BadLocationException
{
- return view.getNextVisualPositionFrom(c, pos, b, d, biasRet);
+ return view.getNextVisualPositionFrom(pos, b, a, d, biasRet);
}
}
@@ -616,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(),
@@ -637,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;
}
/**
@@ -675,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
OpenPOWER on IntegriCloud