summaryrefslogtreecommitdiff
path: root/javax/swing/JComponent.java
diff options
context:
space:
mode:
authorDavid Gilbert <david.gilbert@object-refinery.com>2006-06-30 09:32:20 +0000
committerDavid Gilbert <david.gilbert@object-refinery.com>2006-06-30 09:32:20 +0000
commitaf8fdbf114aebd8e5fbb614de9b6c0cab4faf02a (patch)
tree10f76ad88a3d8967967154a327d1884c4c5845da /javax/swing/JComponent.java
parent40f7d677b88e201d5a53f645e28a175a03f20acf (diff)
downloadclasspath-af8fdbf114aebd8e5fbb614de9b6c0cab4faf02a.tar.gz
2006-06-30 David Gilbert <david.gilbert@object-refinery.com>
* java/awt/TextComponent.java: Reformatted source code, * java/awt/TextField.java: Likewise.
Diffstat (limited to 'javax/swing/JComponent.java')
-rw-r--r--javax/swing/JComponent.java39
1 files changed, 31 insertions, 8 deletions
diff --git a/javax/swing/JComponent.java b/javax/swing/JComponent.java
index 22afebba0..f238d186b 100644
--- a/javax/swing/JComponent.java
+++ b/javax/swing/JComponent.java
@@ -2383,7 +2383,13 @@ public abstract class JComponent extends Container implements Serializable
/**
* A variant of {@link
* #registerKeyboardAction(ActionListener,String,KeyStroke,int)} which
- * provides <code>null</code> for the command name.
+ * provides <code>null</code> for the command name.
+ *
+ * @param act the action listener to notify when the keystroke occurs.
+ * @param stroke the key stroke.
+ * @param cond the condition (one of {@link #WHEN_FOCUSED},
+ * {@link #WHEN_IN_FOCUSED_WINDOW} and
+ * {@link #WHEN_ANCESTOR_OF_FOCUSED_COMPONENT}).
*/
public void registerKeyboardAction(ActionListener act,
KeyStroke stroke,
@@ -2460,9 +2466,22 @@ public abstract class JComponent extends Container implements Serializable
KeyStroke stroke,
int cond)
{
- getInputMap(cond).put(stroke, new ActionListenerProxy(act, cmd));
+ ActionListenerProxy proxy = new ActionListenerProxy(act, cmd);
+ getInputMap(cond).put(stroke, proxy);
+ getActionMap().put(proxy, proxy);
}
+ /**
+ * Sets the input map for the given condition.
+ *
+ * @param condition the condition (one of {@link #WHEN_FOCUSED},
+ * {@link #WHEN_IN_FOCUSED_WINDOW} and
+ * {@link #WHEN_ANCESTOR_OF_FOCUSED_COMPONENT}).
+ * @param map the map.
+ *
+ * @throws IllegalArgumentException if <code>condition</code> is not one of
+ * the specified values.
+ */
public final void setInputMap(int condition, InputMap map)
{
enableEvents(AWTEvent.KEY_EVENT_MASK);
@@ -2598,13 +2617,17 @@ public abstract class JComponent extends Container implements Serializable
*/
public ActionListener getActionForKeyStroke(KeyStroke ks)
{
- Object cmd = getInputMap().get(ks);
- if (cmd != null)
+ Object key = getInputMap(JComponent.WHEN_FOCUSED).get(ks);
+ if (key == null)
+ key = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).get(ks);
+ if (key == null)
+ key = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).get(ks);
+ if (key != null)
{
- if (cmd instanceof ActionListenerProxy)
- return (ActionListenerProxy) cmd;
- else if (cmd instanceof String)
- return getActionMap().get(cmd);
+ if (key instanceof ActionListenerProxy)
+ return ((ActionListenerProxy) key).target;
+ else
+ return getActionMap().get(key);
}
return null;
}