Index: openide-spec-vers.properties =================================================================== RCS file: /cvs/openide/openide-spec-vers.properties,v retrieving revision 1.172 diff -u -r1.172 openide-spec-vers.properties --- openide-spec-vers.properties 11 Apr 2005 12:01:46 -0000 1.172 +++ openide-spec-vers.properties 19 Apr 2005 15:58:33 -0000 @@ -4,4 +4,4 @@ # Must always be numeric (numbers separated by '.', e.g. 4.11). # See http://openide.netbeans.org/versioning-policy.html for more. -openide.specification.version=6.1 +openide.specification.version=6.2 Index: api/doc/changes/apichanges.xml =================================================================== RCS file: /cvs/openide/api/doc/changes/apichanges.xml,v retrieving revision 1.244 diff -u -r1.244 apichanges.xml --- api/doc/changes/apichanges.xml 11 Apr 2005 12:01:47 -0000 1.244 +++ api/doc/changes/apichanges.xml 19 Apr 2005 15:58:45 -0000 @@ -114,6 +114,20 @@ + + + Actions with custom tooltip have tooltip with shortcut in toolbars + + + + + + If an action specifies a tooltip, the tooltip of the corresponding toolbar button is augmented + with shortcut in the same way as when the action does not specify tooltip. + + + + Friend Modules Index: src/org/openide/awt/Actions.java =================================================================== RCS file: /cvs/openide/src/org/openide/awt/Actions.java,v retrieving revision 1.110 diff -u -r1.110 Actions.java --- src/org/openide/awt/Actions.java 5 Apr 2005 13:37:55 -0000 1.110 +++ src/org/openide/awt/Actions.java 19 Apr 2005 15:58:46 -0000 @@ -513,7 +513,6 @@ * or null if it is not known */ public void updateState (String changedProperty) { - boolean didToolTip = false; // note: "enabled" (== SA.PROP_ENABLED) hardcoded in AbstractAction if (changedProperty == null || changedProperty.equals (SystemAction.PROP_ENABLED)) { button.setEnabled (action.isEnabled ()); @@ -522,25 +521,22 @@ changedProperty.equals(Action.SMALL_ICON) || changedProperty.equals("iconBase")) { // NOI18N updateButtonIcon(); } - if (changedProperty == null || changedProperty.equals (Action.SHORT_DESCRIPTION)) { - String shortDesc = (String) action.getValue (Action.SHORT_DESCRIPTION); - if (shortDesc != null && !shortDesc.equals (action.getValue (Action.NAME))) { - button.setToolTipText (shortDesc); - didToolTip = true; - } - } - if (! didToolTip && (changedProperty == null || - changedProperty.equals (Action.ACCELERATOR_KEY) || - changedProperty.equals (Action.NAME))) { + if (changedProperty == null || + changedProperty.equals (Action.ACCELERATOR_KEY) || + (changedProperty.equals (Action.NAME) && action.getValue (Action.SHORT_DESCRIPTION) == null) || + changedProperty.equals (Action.SHORT_DESCRIPTION)) { String tip = findKey (action); - String nm = (String)action.getValue (Action.NAME); - String an = nm == null ? "" : cutAmpersand(nm); + String toolTip = (String) action.getValue (Action.SHORT_DESCRIPTION); + if (toolTip == null) { + toolTip = (String)action.getValue (Action.NAME); + toolTip = toolTip == null ? "" : cutAmpersand(toolTip); + } if (tip == null || tip.equals("")) { // NOI18N - button.setToolTipText(an); + button.setToolTipText(toolTip); } else { button.setToolTipText(org.openide.util.NbBundle.getMessage( - Actions.class, "FMT_ButtonHint", an, tip)); + Actions.class, "FMT_ButtonHint", toolTip, tip)); } } @@ -788,7 +784,7 @@ menu = item; this.model = model; } - + public void addNotify () { super.addNotify (); model.addChangeListener (this); Index: test/unit/src/org/openide/awt/ActionsTest.java =================================================================== RCS file: /cvs/openide/test/unit/src/org/openide/awt/ActionsTest.java,v retrieving revision 1.10 diff -u -r1.10 ActionsTest.java --- test/unit/src/org/openide/awt/ActionsTest.java 15 Apr 2005 12:16:21 -0000 1.10 +++ test/unit/src/org/openide/awt/ActionsTest.java 19 Apr 2005 15:58:48 -0000 @@ -12,20 +12,21 @@ package org.openide.awt; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.util.HashMap; import java.util.Map; import java.util.Observable; -import javax.swing.AbstractButton; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JButton; import javax.swing.Icon; -import javax.swing.ImageIcon; +import javax.swing.JFrame; import javax.swing.JMenuItem; import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; import javax.swing.text.Keymap; -import org.openide.util.Utilities; import org.openide.util.actions.SystemAction; @@ -240,6 +241,142 @@ assertGC ("action can dissappear", ref); } + /** + * Tests if changes in accelerator key or name of the action does not change the tooltip + * of the button if the action has a custom tooltip. See first part of #57974. + */ + public void testTooltipsArePersistent() throws Exception { + if (!SwingUtilities.isEventDispatchThread()) { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + try { + testTooltipsArePersistent(); + } catch (Exception e) { + IllegalStateException exc = new IllegalStateException(e.getMessage()); + + exc.initCause(e); + throw exc; + } + } + }); + return ; + } + + Action action = new ActionsTest.TestActionWithTooltip(); + JButton button = new JButton(); + + Actions.connect(button, action); + + JFrame f = new JFrame(); + + f.getContentPane().add(button); + f.setVisible(true); + + assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP)); + + action.putValue(Action.NAME, "new-name"); + + assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP)); + + action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('a')); + + assertTrue(button.getToolTipText().indexOf(TestActionWithTooltip.TOOLTIP) != (-1)); + + f.setVisible(false); + } + + /** + * Tests if the tooltip is made out of the NAME if there is not tooltip set for an action. + * See also #57974. + */ + public void testTooltipsIsBuiltFromNameIfNoTooltip() throws Exception { + if (!SwingUtilities.isEventDispatchThread()) { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + try { + testTooltipsIsBuiltFromNameIfNoTooltip(); + } catch (Exception e) { + IllegalStateException exc = new IllegalStateException(e.getMessage()); + + exc.initCause(e); + throw exc; + } + } + }); + return ; + } + + Action action = new ActionsTest.TestAction(); + JButton button = new JButton(); + + Actions.connect(button, action); + + JFrame f = new JFrame(); + + f.getContentPane().add(button); + f.setVisible(true); + + assertTrue(button.getToolTipText().equals("test")); + + action.putValue(Action.NAME, "new-name"); + + assertTrue(button.getToolTipText().equals("new-name")); + + action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('a')); + + assertTrue(button.getToolTipText().indexOf("new-name") != (-1)); + + f.setVisible(false); + } + + /** + * Tests if the accelerator key is shown in the button's tooltip for actions with + * custom tooltips. + */ + public void testTooltipsContainAccelerator() throws Exception { + if (!SwingUtilities.isEventDispatchThread()) { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + try { + testTooltipsContainAccelerator(); + } catch (Exception e) { + IllegalStateException exc = new IllegalStateException(e.getMessage()); + + exc.initCause(e); + throw exc; + } + } + }); + return ; + } + + Action action = new ActionsTest.TestActionWithTooltip(); + JButton button = new JButton(); + + Actions.connect(button, action); + + JFrame f = new JFrame(); + + f.getContentPane().add(button); + f.setVisible(true); + + assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP)); + + action.putValue(Action.NAME, "new-name"); + + assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP)); + + action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK)); + + assertTrue(button.getToolTipText().indexOf("Ctrl+C") != (-1)); + + action.putValue(Action.SHORT_DESCRIPTION, null); + + assertTrue(button.getToolTipText().indexOf("Ctrl+C") != (-1)); + + f.setVisible(false); + } + private void checkIfLoadedCorrectIcon (Icon icon, java.awt.Component c, int rowToCheck, String nameOfIcon) { checkIfIconOk (icon, c, 0, 0, RESULT_COLORS_00[rowToCheck], nameOfIcon); checkIfIconOk (icon, c, 0, 1, RESULT_COLORS_01[rowToCheck], nameOfIcon); @@ -305,6 +442,20 @@ } } + + private static final class TestActionWithTooltip extends AbstractAction { + + private static String TOOLTIP = "tooltip"; + + public TestActionWithTooltip() { + putValue(NAME, "name"); + putValue(SHORT_DESCRIPTION, TOOLTIP); + } + + public void actionPerformed(ActionEvent e) { + } + + } public static final class Lkp extends AbstractLookup { public Lkp () {