- XXX no answer for exec-component -
+
+ * Since version 7.1 the action can also provide properties
+ * "menuText" and "popupText" if one wants to use other text on the JMenuItem
+ * than the name
+ * of the action taken from Action.NAME. The popupText is checked only if the
+ * popup parameter is true and takes the biggest precedence. The menuText is
+ * tested everytime and takes precedence over standard Action.NAME
+ *
* @param item menu item
* @param action action
* @param popup create popup or menu item
@@ -908,7 +916,16 @@ public class Actions extends Object {
}
if ((changedProperty == null) || changedProperty.equals(Action.NAME)) {
- Object s = action.getValue(Action.NAME);
+ Object s = null;
+ if (popup) {
+ s = action.getValue("popupText"); // NOI18N
+ }
+ if (s == null) {
+ s = action.getValue("menuText"); // NOI18N
+ }
+ if (s == null) {
+ s = action.getValue(Action.NAME);
+ }
if (s instanceof String) {
setMenuText(((JMenuItem) comp), (String) s, true);
diff -r 651f26a030c7 openide.awt/test/unit/src/org/openide/awt/ActionsTest.java
--- a/openide.awt/test/unit/src/org/openide/awt/ActionsTest.java Wed Mar 05 11:31:11 2008 +0100
+++ b/openide.awt/test/unit/src/org/openide/awt/ActionsTest.java Wed Mar 05 17:11:45 2008 +0100
@@ -55,6 +55,7 @@ import javax.swing.Icon;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JFrame;
+import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.text.Keymap;
@@ -372,6 +373,68 @@ public class ActionsTest extends NbTestC
assertEquals(3, tc.getConnectCalled());
tc.setActive(false);
}
+
+ @SuppressWarnings("deprecation")
+ private static Object peer(Component menu) {
+ return menu.getPeer();
+ }
+
+ public void testPopupTextIsTaken() throws Exception {
+ Action action = new ActionsTest.TestAction();
+ JMenuItem item = new JMenuItem();
+ JMenu jmenu = new JMenu();
+ jmenu.addNotify();
+ assertNotNull("Peer created", peer(jmenu));
+ jmenu.getPopupMenu().addNotify();
+ assertNotNull("Peer for popup", peer(jmenu.getPopupMenu()));
+
+ action.putValue("popupText", "&Ahoj");
+ action.putValue("menuText", "&Ble");
+ action.putValue(action.NAME, "&Mle");
+
+ Actions.connect(item, action, true);
+
+ assertEquals('A', item.getMnemonic());
+ assertEquals("Ahoj", item.getText());
+ }
+
+ public void testMenuTextIsTaken() throws Exception {
+ Action action = new ActionsTest.TestAction();
+ JMenuItem item = new JMenuItem();
+ JMenu jmenu = new JMenu();
+ jmenu.addNotify();
+ assertNotNull("Peer created", peer(jmenu));
+ jmenu.getPopupMenu().addNotify();
+ assertNotNull("Peer for popup", peer(jmenu.getPopupMenu()));
+
+ //action.putValue("popupText", "&Ahoj");
+ action.putValue("menuText", "&Ble");
+ action.putValue(action.NAME, "&Mle");
+
+ Actions.connect(item, action, true);
+
+ assertEquals('B', item.getMnemonic());
+ assertEquals("Ble", item.getText());
+ }
+
+ public void testActionNameIsTaken() throws Exception {
+ Action action = new ActionsTest.TestAction();
+ JMenuItem item = new JMenuItem();
+ JMenu jmenu = new JMenu();
+ jmenu.addNotify();
+ assertNotNull("Peer created", peer(jmenu));
+ jmenu.getPopupMenu().addNotify();
+ assertNotNull("Peer for popup", peer(jmenu.getPopupMenu()));
+
+ //action.putValue("popupText", "&Ahoj");
+ //action.putValue("menuText", "&Ble");
+ action.putValue(action.NAME, "&Mle");
+
+ Actions.connect(item, action, true);
+
+ assertEquals('M', item.getMnemonic());
+ assertEquals("Mle", item.getText());
+ }
protected boolean runInEQ() {