summaryrefslogtreecommitdiff
path: root/javax/swing/SwingUtilities.java
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2005-01-14 10:24:02 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2005-01-14 10:24:02 +0000
commitc61f399b1d3c471a8e459a4a2be645f95560f088 (patch)
tree14e7f5759d2cded647d22e019435a770b8ed69e5 /javax/swing/SwingUtilities.java
parent451c55a31fbc6b949f7609dd90932bb2a0d91a19 (diff)
downloadclasspath-c61f399b1d3c471a8e459a4a2be645f95560f088.tar.gz
2005-01-14 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of September 2004 HEAD patches to generics branch.
Diffstat (limited to 'javax/swing/SwingUtilities.java')
-rw-r--r--javax/swing/SwingUtilities.java103
1 files changed, 103 insertions, 0 deletions
diff --git a/javax/swing/SwingUtilities.java b/javax/swing/SwingUtilities.java
index 05a3a6191..731a7bc8d 100644
--- a/javax/swing/SwingUtilities.java
+++ b/javax/swing/SwingUtilities.java
@@ -51,9 +51,13 @@ import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.Window;
+import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.lang.reflect.InvocationTargetException;
+import javax.swing.plaf.ActionMapUIResource;
+import javax.swing.plaf.InputMapUIResource;
/**
@@ -911,4 +915,103 @@ public class SwingUtilities implements SwingConstants
return true;
}
}
+
+ public static boolean notifyAction(Action action,
+ KeyStroke ks,
+ KeyEvent event,
+ Object sender,
+ int modifiers)
+ {
+ if (action != null && action.isEnabled())
+ {
+ String name = (String) action.getValue(Action.ACTION_COMMAND_KEY);
+ if (name == null
+ && event.getKeyChar() != KeyEvent.CHAR_UNDEFINED)
+ name = new String(new char[] {event.getKeyChar()});
+ action.actionPerformed(new ActionEvent(sender,
+ ActionEvent.ACTION_PERFORMED,
+ name, modifiers));
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * <p>Change the shared, UI-managed {@link ActionMap} for a given
+ * component. ActionMaps are arranged in a hierarchy, in order to
+ * encourage sharing of common actions between components. The hierarchy
+ * unfortunately places UI-managed ActionMaps at the <em>end</em> of the
+ * parent-pointer chain, as illustrated:</p>
+ *
+ * <pre>
+ * [{@link javax.swing.JComponent#getActionMap()}]
+ * --&gt; [{@link javax.swing.ActionMap}]
+ * parent --&gt; [{@link javax.swing.text.KeymapActionMap}]
+ * parent --&gt; [{@link javax.swing.plaf.ActionMapUIResource}]
+ * </pre>
+ *
+ * <p>Our goal with this method is to replace the first ActionMap along
+ * this chain which is an instance of {@link ActionMapUIResource}, since
+ * these are the ActionMaps which are supposed to be shared between
+ * components.</p>
+ *
+ * <p>If the provided ActionMap is <code>null</code>, we interpret the
+ * call as a request to remove the UI-managed ActionMap from the
+ * component's ActionMap parent chain.</p>
+ */
+ public static void replaceUIActionMap(JComponent component,
+ ActionMap uiActionMap)
+ {
+ ActionMap child = component.getActionMap();
+ if (child == null)
+ component.setActionMap(uiActionMap);
+ else
+ {
+ while(child.getParent() != null
+ && !(child.getParent() instanceof ActionMapUIResource))
+ child = child.getParent();
+ if (child != null)
+ child.setParent(uiActionMap);
+ }
+ }
+
+ /**
+ * <p>Change the shared, UI-managed {@link InputMap} for a given
+ * component. InputMaps are arranged in a hierarchy, in order to
+ * encourage sharing of common input mappings between components. The
+ * hierarchy unfortunately places UI-managed InputMaps at the
+ * <em>end</em> of the parent-pointer chain, as illustrated:</p>
+ *
+ * <pre>
+ * [{@link javax.swing.JComponent#getInputMap()}]
+ * --&gt; [{@link javax.swing.InputMap}]
+ * parent --&gt; [{@link javax.swing.text.KeymapWrapper}]
+ * parent --&gt; [{@link javax.swing.plaf.InputMapUIResource}]
+ * </pre>
+ *
+ * <p>Our goal with this method is to replace the first InputMap along
+ * this chain which is an instance of {@link InputMapUIResource}, since
+ * these are the InputMaps which are supposed to be shared between
+ * components.</p>
+ *
+ * <p>If the provided InputMap is <code>null</code>, we interpret the
+ * call as a request to remove the UI-managed InputMap from the
+ * component's InputMap parent chain.</p>
+ */
+ public static void replaceUIInputMap(JComponent component,
+ int condition,
+ InputMap uiInputMap)
+ {
+ InputMap child = component.getInputMap(condition);
+ if (child == null)
+ component.setInputMap(condition, uiInputMap);
+ else
+ {
+ while(child.getParent() != null
+ && !(child.getParent() instanceof InputMapUIResource))
+ child = child.getParent();
+ if (child != null)
+ child.setParent(uiInputMap);
+ }
+ }
}