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 / +154 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
        if (!SwingUtilities.isEventDispatchThread()) {
250
            SwingUtilities.invokeAndWait(new Runnable() {
251
                public void run() {
252
                    try {
253
                        testTooltipsArePersistent();
254
                    } catch (Exception e) {
255
                        IllegalStateException exc = new IllegalStateException(e.getMessage());
256
                        
257
                        exc.initCause(e);
258
                        throw exc;
259
                    }
260
                }
261
            });
262
            return ;
263
        }
264
        
265
        Action action = new ActionsTest.TestActionWithTooltip();
266
        JButton button = new JButton();
267
        
268
        Actions.connect(button, action);
269
        
270
        JFrame f = new JFrame();
271
        
272
        f.getContentPane().add(button);
273
        f.setVisible(true);
274
        
275
        assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP));
276
        
277
        action.putValue(Action.NAME, "new-name");
278
        
279
        assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP));
280
        
281
        action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('a'));
282
        
283
        assertTrue(button.getToolTipText().indexOf(TestActionWithTooltip.TOOLTIP) != (-1));
284
        
285
        f.setVisible(false);
286
    }
287
    
288
    /**
289
     * Tests if the tooltip is made out of the NAME if there is not tooltip set for an action.
290
     * See also #57974.
291
     */
292
    public void testTooltipsIsBuiltFromNameIfNoTooltip() throws Exception {
293
        if (!SwingUtilities.isEventDispatchThread()) {
294
            SwingUtilities.invokeAndWait(new Runnable() {
295
                public void run() {
296
                    try {
297
                        testTooltipsIsBuiltFromNameIfNoTooltip();
298
                    } catch (Exception e) {
299
                        IllegalStateException exc = new IllegalStateException(e.getMessage());
300
                        
301
                        exc.initCause(e);
302
                        throw exc;
303
                    }
304
                }
305
            });
306
            return ;
307
        }
308
        
309
        Action action = new ActionsTest.TestAction();
310
        JButton button = new JButton();
311
        
312
        Actions.connect(button, action);
313
        
314
        JFrame f = new JFrame();
315
        
316
        f.getContentPane().add(button);
317
        f.setVisible(true);
318
        
319
        assertTrue(button.getToolTipText().equals("test"));
320
        
321
        action.putValue(Action.NAME, "new-name");
322
        
323
        assertTrue(button.getToolTipText().equals("new-name"));
324
        
325
        action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('a'));
326
        
327
        assertTrue(button.getToolTipText().indexOf("new-name") != (-1));
328
        
329
        f.setVisible(false);
330
    }
331
    
332
    /**
333
     * Tests if the accelerator key is shown in the button's tooltip for actions with
334
     * custom tooltips.
335
     */
336
    public void testTooltipsContainAccelerator() throws Exception {
337
        if (!SwingUtilities.isEventDispatchThread()) {
338
            SwingUtilities.invokeAndWait(new Runnable() {
339
                public void run() {
340
                    try {
341
                        testTooltipsContainAccelerator();
342
                    } catch (Exception e) {
343
                        IllegalStateException exc = new IllegalStateException(e.getMessage());
344
                        
345
                        exc.initCause(e);
346
                        throw exc;
347
                    }
348
                }
349
            });
350
            return ;
351
        }
352
        
353
        Action action = new ActionsTest.TestActionWithTooltip();
354
        JButton button = new JButton();
355
        
356
        Actions.connect(button, action);
357
        
358
        JFrame f = new JFrame();
359
        
360
        f.getContentPane().add(button);
361
        f.setVisible(true);
362
        
363
        assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP));
364
        
365
        action.putValue(Action.NAME, "new-name");
366
        
367
        assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP));
368
        
369
        action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK));
370
        
371
        assertTrue(button.getToolTipText().indexOf("Ctrl+C") != (-1));
372
        
373
        action.putValue(Action.SHORT_DESCRIPTION, null);
374
        
375
        assertTrue(button.getToolTipText().indexOf("Ctrl+C") != (-1));
376
        
377
        f.setVisible(false);
378
    }
379
    
243
    private void checkIfLoadedCorrectIcon (Icon icon, java.awt.Component c, int rowToCheck, String nameOfIcon) {
380
    private void checkIfLoadedCorrectIcon (Icon icon, java.awt.Component c, int rowToCheck, String nameOfIcon) {
244
        checkIfIconOk (icon, c, 0, 0, RESULT_COLORS_00[rowToCheck], nameOfIcon);
381
        checkIfIconOk (icon, c, 0, 0, RESULT_COLORS_00[rowToCheck], nameOfIcon);
245
        checkIfIconOk (icon, c, 0, 1, RESULT_COLORS_01[rowToCheck], nameOfIcon);
382
        checkIfIconOk (icon, c, 0, 1, RESULT_COLORS_01[rowToCheck], nameOfIcon);
Lines 305-310 Link Here
305
        }
442
        }
306
        
443
        
307
    }    
444
    }    
445
    
446
    private static final class TestActionWithTooltip extends AbstractAction {
447
        
448
        private static String TOOLTIP = "tooltip";
449
        
450
        public TestActionWithTooltip() {
451
            putValue(NAME, "name");
452
            putValue(SHORT_DESCRIPTION, TOOLTIP);
453
        }
454
        
455
        public void actionPerformed(ActionEvent e) {
456
        }
457
        
458
    }
308
    
459
    
309
    public static final class Lkp extends AbstractLookup {
460
    public static final class Lkp extends AbstractLookup {
310
        public Lkp () {
461
        public Lkp () {

Return to bug 57974