diff -r 651f26a030c7 openide.awt/apichanges.xml --- a/openide.awt/apichanges.xml Wed Mar 05 11:31:11 2008 +0100 +++ b/openide.awt/apichanges.xml Wed Mar 05 17:11:45 2008 +0100 @@ -47,6 +47,20 @@ made subject to such option by the copyr AWT API + + + Actions can have "menuText" and "popupText" properties + + + + + + In order to allow dynamic names of actions, the Actions.connect + method now understands additional properties that influence the text + of menu items or popup menu items build for this action. + + + Hidden field SpinButton.rt made accessible diff -r 651f26a030c7 openide.awt/arch.xml --- a/openide.awt/arch.xml Wed Mar 05 11:31:11 2008 +0100 +++ b/openide.awt/arch.xml Wed Mar 05 17:11:45 2008 +0100 @@ -458,9 +458,14 @@ made subject to such option by the copyr --> -

- XXX no answer for exec-component -

+
    +
  • + +
  • +
  • + +
  • +
diff -r 651f26a030c7 openide.awt/nbproject/project.properties --- a/openide.awt/nbproject/project.properties Wed Mar 05 11:31:11 2008 +0100 +++ b/openide.awt/nbproject/project.properties Wed Mar 05 17:11:45 2008 +0100 @@ -46,4 +46,4 @@ javadoc.arch=${basedir}/arch.xml #javadoc.apichanges=${basedir}/api/apichanges.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=7.0.0 +spec.version.base=7.1 diff -r 651f26a030c7 openide.awt/src/org/openide/awt/Actions.java --- a/openide.awt/src/org/openide/awt/Actions.java Wed Mar 05 11:31:11 2008 +0100 +++ b/openide.awt/src/org/openide/awt/Actions.java Wed Mar 05 17:11:45 2008 +0100 @@ -168,7 +168,15 @@ public class Actions extends Object { * for this method by implementing method * {@link ButtonActionConnector#connect(JMenuItem, Action, boolean)} and * registering an instance of {@link ButtonActionConnector} in the - * default lookup. + * default lookup. + *

+ * 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() {