This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 57974
Collapse All | Expand All

(-)openide-spec-vers.properties (-1 / +1 lines)
Lines 4-7 Link Here
4
# Must always be numeric (numbers separated by '.', e.g. 4.11).
4
# Must always be numeric (numbers separated by '.', e.g. 4.11).
5
# See http://openide.netbeans.org/versioning-policy.html for more.
5
# See http://openide.netbeans.org/versioning-policy.html for more.
6
6
7
openide.specification.version=6.1
7
openide.specification.version=6.2
(-)api/doc/changes/apichanges.xml (+14 lines)
Lines 114-119 Link Here
114
114
115
<!-- ACTUAL CHANGES BEGIN HERE: -->
115
<!-- ACTUAL CHANGES BEGIN HERE: -->
116
<changes>
116
<changes>
117
    <change id="actions-with-custom-tooltip-have-shortcuts-in-toolbar">
118
        <api name="util"/>
119
        <summary>Actions with custom tooltip have tooltip with shortcut in toolbars</summary>
120
        <version major="6" minor="2"/>
121
        <date day="19" month="4" year="2005"/>
122
        <author login="jlahoda"/>
123
        <compatibility semantic="incompatible"/>
124
        <description>
125
            If an action specifies a tooltip, the tooltip of the corresponding toolbar button is augmented
126
            with shortcut in the same way as when the action does not specify tooltip.
127
        </description>
128
        <issue number="57974"/>
129
    </change>
130
    
117
    <change id="FriendModulesRestriction">
131
    <change id="FriendModulesRestriction">
118
        <api name="modules"/>
132
        <api name="modules"/>
119
        <summary>Friend Modules</summary>
133
        <summary>Friend Modules</summary>
(-)src/org/openide/awt/Actions.java (-16 / +12 lines)
Lines 513-519 Link Here
513
        * or null if it is not known
513
        * or null if it is not known
514
        */
514
        */
515
        public void updateState (String changedProperty) {
515
        public void updateState (String changedProperty) {
516
            boolean didToolTip = false;
517
            // note: "enabled" (== SA.PROP_ENABLED) hardcoded in AbstractAction
516
            // note: "enabled" (== SA.PROP_ENABLED) hardcoded in AbstractAction
518
            if (changedProperty == null || changedProperty.equals (SystemAction.PROP_ENABLED)) {
517
            if (changedProperty == null || changedProperty.equals (SystemAction.PROP_ENABLED)) {
519
                button.setEnabled (action.isEnabled ());
518
                button.setEnabled (action.isEnabled ());
Lines 522-546 Link Here
522
                changedProperty.equals(Action.SMALL_ICON) || changedProperty.equals("iconBase")) { // NOI18N
521
                changedProperty.equals(Action.SMALL_ICON) || changedProperty.equals("iconBase")) { // NOI18N
523
                updateButtonIcon();
522
                updateButtonIcon();
524
            }
523
            }
525
            if (changedProperty == null || changedProperty.equals (Action.SHORT_DESCRIPTION)) {
526
                String shortDesc = (String) action.getValue (Action.SHORT_DESCRIPTION);
527
                if (shortDesc != null && !shortDesc.equals (action.getValue (Action.NAME))) {
528
                    button.setToolTipText (shortDesc);
529
                    didToolTip = true;
530
                }
531
            }
532
524
533
            if (! didToolTip && (changedProperty == null ||
525
            if (changedProperty == null ||
534
                                 changedProperty.equals (Action.ACCELERATOR_KEY) ||
526
                changedProperty.equals (Action.ACCELERATOR_KEY) ||
535
                                 changedProperty.equals (Action.NAME))) {
527
                (changedProperty.equals (Action.NAME) && action.getValue (Action.SHORT_DESCRIPTION) == null) ||
528
                changedProperty.equals (Action.SHORT_DESCRIPTION)) {
536
                String tip = findKey (action);
529
                String tip = findKey (action);
537
                String nm = (String)action.getValue (Action.NAME);
530
                String toolTip = (String) action.getValue (Action.SHORT_DESCRIPTION);
538
                String an = nm == null ? "" : cutAmpersand(nm);
531
                if (toolTip == null) {
532
                    toolTip = (String)action.getValue (Action.NAME);
533
                    toolTip = toolTip == null ? "" : cutAmpersand(toolTip);
534
                }
539
                if (tip == null || tip.equals("")) { // NOI18N
535
                if (tip == null || tip.equals("")) { // NOI18N
540
                    button.setToolTipText(an);
536
                    button.setToolTipText(toolTip);
541
                } else {
537
                } else {
542
                    button.setToolTipText(org.openide.util.NbBundle.getMessage(
538
                    button.setToolTipText(org.openide.util.NbBundle.getMessage(
543
			    Actions.class, "FMT_ButtonHint", an, tip));
539
			    Actions.class, "FMT_ButtonHint", toolTip, tip));
544
                }
540
                }
545
            }
541
            }
546
            
542
            
Lines 788-794 Link Here
788
            menu = item;
784
            menu = item;
789
            this.model = model;
785
            this.model = model;
790
        }
786
        }
791
787
792
        public void addNotify () {
788
        public void addNotify () {
793
            super.addNotify ();
789
            super.addNotify ();
794
            model.addChangeListener (this);
790
            model.addChangeListener (this);
(-)test/unit/src/org/openide/awt/ActionsTest.java (-3 / +110 lines)
Lines 12-31 Link Here
12
12
13
package org.openide.awt;
13
package org.openide.awt;
14
14
15
import java.awt.event.ActionEvent;
16
import java.awt.event.KeyEvent;
15
import java.awt.image.BufferedImage;
17
import java.awt.image.BufferedImage;
16
import java.util.HashMap;
18
import java.util.HashMap;
17
import java.util.Map;
19
import java.util.Map;
18
import java.util.Observable;
20
import java.util.Observable;
19
import javax.swing.AbstractButton;
20
import javax.swing.AbstractAction;
21
import javax.swing.AbstractAction;
21
import javax.swing.Action;
22
import javax.swing.Action;
22
import javax.swing.JButton;
23
import javax.swing.JButton;
23
import javax.swing.Icon;
24
import javax.swing.Icon;
24
import javax.swing.ImageIcon;
25
import javax.swing.JFrame;
25
import javax.swing.JMenuItem;
26
import javax.swing.JMenuItem;
26
import javax.swing.KeyStroke;
27
import javax.swing.KeyStroke;
28
import javax.swing.SwingUtilities;
27
import javax.swing.text.Keymap;
29
import javax.swing.text.Keymap;
28
import org.openide.util.Utilities;
29
30
30
import org.openide.util.actions.SystemAction;
31
import org.openide.util.actions.SystemAction;
31
32
Lines 240-245 Link Here
240
        assertGC ("action can dissappear", ref);        
241
        assertGC ("action can dissappear", ref);        
241
    }
242
    }
242
    
243
    
244
    /**
245
     * Tests if changes in accelerator key or name of the action does not change the tooltip
246
     * of the button if the action has a custom tooltip. See first part of #57974.
247
     */
248
    public void testTooltipsArePersistent() throws Exception {
249
        Action action = new ActionsTest.TestActionWithTooltip();
250
        JButton button = new JButton();
251
        
252
        Actions.connect(button, action);
253
        
254
        JFrame f = new JFrame();
255
        
256
        f.getContentPane().add(button);
257
        f.setVisible(true);
258
        
259
        assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP));
260
        
261
        action.putValue(Action.NAME, "new-name");
262
        
263
        assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP));
264
        
265
        action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('a'));
266
        
267
        assertTrue(button.getToolTipText().indexOf(TestActionWithTooltip.TOOLTIP) != (-1));
268
        
269
        f.setVisible(false);
270
    }
271
    
272
    /**
273
     * Tests if the tooltip is made out of the NAME if there is not tooltip set for an action.
274
     * See also #57974.
275
     */
276
    public void testTooltipsIsBuiltFromNameIfNoTooltip() throws Exception {
277
        Action action = new ActionsTest.TestAction();
278
        JButton button = new JButton();
279
        
280
        Actions.connect(button, action);
281
        
282
        JFrame f = new JFrame();
283
        
284
        f.getContentPane().add(button);
285
        f.setVisible(true);
286
        
287
        assertTrue(button.getToolTipText().equals("test"));
288
        
289
        action.putValue(Action.NAME, "new-name");
290
        
291
        assertTrue(button.getToolTipText().equals("new-name"));
292
        
293
        action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('a'));
294
        
295
        assertTrue(button.getToolTipText().indexOf("new-name") != (-1));
296
        
297
        f.setVisible(false);
298
    }
299
    
300
    /**
301
     * Tests if the accelerator key is shown in the button's tooltip for actions with
302
     * custom tooltips.
303
     */
304
    public void testTooltipsContainAccelerator() throws Exception {
305
        Action action = new ActionsTest.TestActionWithTooltip();
306
        JButton button = new JButton();
307
        
308
        Actions.connect(button, action);
309
        
310
        JFrame f = new JFrame();
311
        
312
        f.getContentPane().add(button);
313
        f.setVisible(true);
314
        
315
        assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP));
316
        
317
        action.putValue(Action.NAME, "new-name");
318
        
319
        assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP));
320
        
321
        action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK));
322
        
323
        assertTrue(button.getToolTipText().indexOf("Ctrl+C") != (-1));
324
        
325
        action.putValue(Action.SHORT_DESCRIPTION, null);
326
        
327
        assertTrue(button.getToolTipText().indexOf("Ctrl+C") != (-1));
328
        
329
        f.setVisible(false);
330
    }
331
    
332
    protected boolean runInEQ() {
333
        return true;
334
    }
335
    
243
    private void checkIfLoadedCorrectIcon (Icon icon, java.awt.Component c, int rowToCheck, String nameOfIcon) {
336
    private void checkIfLoadedCorrectIcon (Icon icon, java.awt.Component c, int rowToCheck, String nameOfIcon) {
244
        checkIfIconOk (icon, c, 0, 0, RESULT_COLORS_00[rowToCheck], nameOfIcon);
337
        checkIfIconOk (icon, c, 0, 0, RESULT_COLORS_00[rowToCheck], nameOfIcon);
245
        checkIfIconOk (icon, c, 0, 1, RESULT_COLORS_01[rowToCheck], nameOfIcon);
338
        checkIfIconOk (icon, c, 0, 1, RESULT_COLORS_01[rowToCheck], nameOfIcon);
Lines 305-310 Link Here
305
        }
398
        }
306
        
399
        
307
    }    
400
    }    
401
    
402
    private static final class TestActionWithTooltip extends AbstractAction {
403
        
404
        private static String TOOLTIP = "tooltip";
405
        
406
        public TestActionWithTooltip() {
407
            putValue(NAME, "name");
408
            putValue(SHORT_DESCRIPTION, TOOLTIP);
409
        }
410
        
411
        public void actionPerformed(ActionEvent e) {
412
        }
413
        
414
    }
308
    
415
    
309
    public static final class Lkp extends AbstractLookup {
416
    public static final class Lkp extends AbstractLookup {
310
        public Lkp () {
417
        public Lkp () {

Return to bug 57974