summaryrefslogtreecommitdiff
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.java100
1 files changed, 63 insertions, 37 deletions
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java
index 3b620f04989..b058175a454 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java
@@ -38,8 +38,6 @@ exception statement from your version. */
package javax.swing.plaf.basic;
-import gnu.classpath.NotImplementedException;
-
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
@@ -64,10 +62,12 @@ import javax.swing.JComponent;
import javax.swing.LookAndFeel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
+import javax.swing.TransferHandler;
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.AbstractDocument;
@@ -734,18 +734,8 @@ public abstract class BasicTextUI extends TextUI
// load any bindings for the newer InputMap / ActionMap interface
SwingUtilities.replaceUIInputMap(textComponent, JComponent.WHEN_FOCUSED,
- getInputMap(JComponent.WHEN_FOCUSED));
- 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);
+ getInputMap());
+ SwingUtilities.replaceUIActionMap(textComponent, getActionMap());
}
/**
@@ -753,40 +743,71 @@ public abstract class BasicTextUI extends TextUI
*
* @return an ActionMap to be installed on the text component
*/
- ActionMap createActionMap()
+ private ActionMap getActionMap()
+ {
+ // Note: There are no .actionMap entries in the standard L&Fs. However,
+ // with the RI it is possible to install action maps via such keys, so
+ // we must load them too. It can be observed that when there is no
+ // .actionMap entry in the UIManager, one gets installed after a text
+ // component of that type has been loaded.
+ String prefix = getPropertyPrefix();
+ String amName = prefix + ".actionMap";
+ ActionMap am = (ActionMap) UIManager.get(amName);
+ if (am == null)
+ {
+ am = createActionMap();
+ UIManager.put(amName, am);
+ }
+
+ ActionMap map = new ActionMapUIResource();
+ map.setParent(am);
+
+ return map;
+ }
+
+ /**
+ * Creates a default ActionMap for text components that have no UI default
+ * for this (the standard for the built-in L&Fs). The ActionMap is copied
+ * from the text component's getActions() method.
+ *
+ * @returna default ActionMap
+ */
+ private ActionMap createActionMap()
{
- Action[] actions = textComponent.getActions();
ActionMap am = new ActionMapUIResource();
- for (int i = 0; i < actions.length; ++i)
+ Action[] actions = textComponent.getActions();
+ for (int i = actions.length - 1; i >= 0; i--)
{
- String name = (String) actions[i].getValue(Action.NAME);
- if (name != null)
- am.put(name, actions[i]);
+ Action action = actions[i];
+ am.put(action.getValue(Action.NAME), action);
}
+ // Add TransferHandler's actions here. They don't seem to be in the
+ // JTextComponent's default actions, and I can't make up a better place
+ // to add them.
+ Action copyAction = TransferHandler.getCopyAction();
+ am.put(copyAction.getValue(Action.NAME), copyAction);
+ Action cutAction = TransferHandler.getCutAction();
+ am.put(cutAction.getValue(Action.NAME), cutAction);
+ Action pasteAction = TransferHandler.getPasteAction();
+ am.put(pasteAction.getValue(Action.NAME), pasteAction);
+
return am;
}
/**
* Gets the input map for the specified <code>condition</code>.
*
- * @param condition the condition for the InputMap
- *
* @return the InputMap for the specified condition
*/
- InputMap getInputMap(int condition)
+ private InputMap getInputMap()
{
+ InputMap im = new InputMapUIResource();
String prefix = getPropertyPrefix();
- switch (condition)
- {
- case JComponent.WHEN_IN_FOCUSED_WINDOW:
- // FIXME: is this the right string? nobody seems to use it.
- return (InputMap) UIManager.get(prefix + ".windowInputMap");
- case JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT:
- return (InputMap) UIManager.get(prefix + ".ancestorInputMap");
- default:
- case JComponent.WHEN_FOCUSED:
- return (InputMap) UIManager.get(prefix + ".focusInputMap");
- }
+ InputMap shared =
+ (InputMap) SharedUIDefaults.get(prefix + ".focusInputMap");
+ if (shared != null)
+ im.setParent(shared);
+ return im;
}
/**
@@ -831,9 +852,9 @@ public abstract class BasicTextUI extends TextUI
* this UI.
*/
protected void uninstallKeyboardActions()
- throws NotImplementedException
{
- // FIXME: Uninstall keyboard actions here.
+ SwingUtilities.replaceUIInputMap(textComponent, JComponent.WHEN_FOCUSED, null);
+ SwingUtilities.replaceUIActionMap(textComponent, null);
}
/**
@@ -1041,7 +1062,12 @@ public abstract class BasicTextUI extends TextUI
Rectangle l1 = modelToView(t, p0, firstBias);
Rectangle l2 = modelToView(t, p1, secondBias);
- if (l1.y == l2.y)
+ if (l1 == null || l2 == null)
+ {
+ // Unable to determine the start or end of the selection.
+ t.repaint();
+ }
+ else if (l1.y == l2.y)
{
SwingUtilities.computeUnion(l2.x, l2.y, l2.width, l2.height, l1);
t.repaint(l1);