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 197639
Collapse All | Expand All

(-)a/openide.awt/apichanges.xml (+17 lines)
Lines 50-55 Link Here
50
<apidef name="awt">AWT API</apidef>
50
<apidef name="awt">AWT API</apidef>
51
</apidefs>
51
</apidefs>
52
<changes>
52
<changes>
53
    <change id="Actions.connect">
54
        <api name="awt"/>
55
        <summary>Support "selected" icons in Actions and Actions.checkbox</summary>
56
        <version major="7" minor="32"/>
57
        <date day="18" month="4" year="2011"/>
58
        <author login="err"/>
59
        <compatibility addition="yes" binary="compatible" deletion="no" semantic="compatible"/>
60
        <description>
61
            <p>
62
                Handle _selected, _rolloverSelected and _disabledSelected
63
                icon resources in Actions.connect.
64
                Actions.checkbox on a Toolbar uses them if they are available.
65
            </p>
66
        </description>
67
        <class package="org.openide.awt" name="Actions"/>
68
        <issue number="197639"/>
69
    </change>
53
    <change id="ActionReference">
70
    <change id="ActionReference">
54
        <api name="awt"/>
71
        <api name="awt"/>
55
        <summary>New @ActionReference annotations</summary>
72
        <summary>New @ActionReference annotations</summary>
(-)a/openide.awt/src/org/openide/awt/Actions.java (-8 / +30 lines)
Lines 219-233 Link Here
219
    }
219
    }
220
220
221
    /** Connects buttons to action. If the action supplies value for "iconBase"
221
    /** Connects buttons to action. If the action supplies value for "iconBase"
222
     * key from getValue(String) with a path to icons the methods setIcon,
222
     * key from getValue(String) with a path to icons, the methods set*Icon
223
     * setPressedIcon, setDisabledIcon and setRolloverIcon will be called on the
223
     * will be called on the
224
     * button with loaded icons using the iconBase. E.g. if the value for "iconBase"
224
     * button with loaded icons using the iconBase. E.g. if the value for "iconBase"
225
     * will be "com/mycompany/myIcon.gif" following images will be tried "com/mycompany/myIcon.gif"
225
     * is "com/mycompany/myIcon.gif" then the following images are tried
226
     * for setIcon, "com/mycompany/myIcon_pressed.gif" for setPressedIcon,
226
     * <ul>
227
     * "com/mycompany/myIcon_disabled.gif" for setDisabledIcon and
227
     *  <li>setIcon with "com/mycompany/myIcon.gif"</li>
228
     * "com/mycompany/myIcon_rollover.gif" for setRolloverIcon. SystemAction has
228
     *  <li>setPressedIcon with "com/mycompany/myIcon_pressed.gif"</li>
229
     * special support for iconBase - please check {@link SystemAction#iconResource}
229
     *  <li>setDisabledIcon with "com/mycompany/myIcon_disabled.gif"</li>
230
     * for more details.
230
     *  <li>setRolloverIcon with "com/mycompany/myIcon_rollover.gif"</li>
231
     *  <li>setSelectedIcon with "com/mycompany/myIcon_selected.gif"</li>
232
     *  <li>setRolloverSelectedIcon with "com/mycompany/myIcon_rolloverSelected.gif"</li>
233
     *  <li>setDisabledSelectedIcon with "com/mycompany/myIcon_disabledSelected.gif"</li>
234
     * </ul>
235
     * SystemAction has special support for iconBase - please check
236
     * {@link SystemAction#iconResource} for more details.
231
     * You can supply an alternative implementation
237
     * You can supply an alternative implementation
232
     * for this method by implementing method
238
     * for this method by implementing method
233
     * {@link ButtonActionConnector#connect(AbstractButton, Action)} and
239
     * {@link ButtonActionConnector#connect(AbstractButton, Action)} and
Lines 236-241 Link Here
236
     * @param button the button
242
     * @param button the button
237
     * @param action the action
243
     * @param action the action
238
     * @since 3.29
244
     * @since 3.29
245
     * @since 7.32 for set*SelectedIcon
239
     */
246
     */
240
    public static void connect(AbstractButton button, Action action) {
247
    public static void connect(AbstractButton button, Action action) {
241
        for (ButtonActionConnector bac : buttonActionConnectors()) {
248
        for (ButtonActionConnector bac : buttonActionConnectors()) {
Lines 1025-1030 Link Here
1025
                } else if (imgIcon != null) {
1032
                } else if (imgIcon != null) {
1026
                    button.setDisabledIcon(ImageUtilities.createDisabledIcon(imgIcon));
1033
                    button.setDisabledIcon(ImageUtilities.createDisabledIcon(imgIcon));
1027
                }
1034
                }
1035
1036
                ImageIcon sImgIcon = ImageUtilities.loadImageIcon(insertBeforeSuffix(b, "_selected"), true); // NOI18N
1037
                if (sImgIcon != null) {
1038
                    button.setSelectedIcon(sImgIcon);
1039
                }
1040
1041
                sImgIcon = ImageUtilities.loadImageIcon(insertBeforeSuffix(b, "_rolloverSelected"), true); // NOI18N
1042
                if (sImgIcon != null) {
1043
                    button.setRolloverSelectedIcon(sImgIcon);
1044
                }
1045
1046
                sImgIcon = ImageUtilities.loadImageIcon(insertBeforeSuffix(b, "_disabledSelected"), true); // NOI18N
1047
                if (sImgIcon != null) {
1048
                    button.setDisabledSelectedIcon(sImgIcon);
1049
                }
1028
            }
1050
            }
1029
        }
1051
        }
1030
1052
(-)a/openide.awt/src/org/openide/awt/AlwaysEnabledAction.java (-1 / +43 lines)
Lines 17-32 Link Here
17
import java.util.prefs.PreferenceChangeListener;
17
import java.util.prefs.PreferenceChangeListener;
18
import java.util.prefs.Preferences;
18
import java.util.prefs.Preferences;
19
import javax.swing.AbstractAction;
19
import javax.swing.AbstractAction;
20
import javax.swing.AbstractButton;
20
import javax.swing.Action;
21
import javax.swing.Action;
21
import javax.swing.Icon;
22
import javax.swing.Icon;
22
import javax.swing.JCheckBoxMenuItem;
23
import javax.swing.JCheckBoxMenuItem;
23
import javax.swing.JMenuItem;
24
import javax.swing.JMenuItem;
25
import javax.swing.JToggleButton;
24
import org.openide.util.ContextAwareAction;
26
import org.openide.util.ContextAwareAction;
25
import org.openide.util.ImageUtilities;
27
import org.openide.util.ImageUtilities;
26
import org.openide.util.Lookup;
28
import org.openide.util.Lookup;
27
import org.openide.util.LookupEvent;
29
import org.openide.util.LookupEvent;
28
import org.openide.util.LookupListener;
30
import org.openide.util.LookupListener;
29
import org.openide.util.NbPreferences;
31
import org.openide.util.NbPreferences;
32
import org.openide.util.WeakSet;
30
import org.openide.util.actions.Presenter;
33
import org.openide.util.actions.Presenter;
31
import org.openide.util.actions.ActionInvoker;
34
import org.openide.util.actions.ActionInvoker;
32
35
Lines 256-262 Link Here
256
    }
259
    }
257
260
258
    static final class CheckBox extends AlwaysEnabledAction
261
    static final class CheckBox extends AlwaysEnabledAction
259
            implements Presenter.Menu, Presenter.Popup, PreferenceChangeListener, LookupListener
262
            implements Presenter.Menu, Presenter.Popup, Presenter.Toolbar, PreferenceChangeListener, LookupListener
260
    {
263
    {
261
264
262
        private static final long serialVersionUID = 1L;
265
        private static final long serialVersionUID = 1L;
Lines 271-276 Link Here
271
274
272
        private JCheckBoxMenuItem popupItem;
275
        private JCheckBoxMenuItem popupItem;
273
276
277
        private WeakSet<AbstractButton> toolbarItems;
278
274
        private Preferences preferencesNode;
279
        private Preferences preferencesNode;
275
280
276
        private Lookup.Result<Preferences> preferencesNodeResult;
281
        private Lookup.Result<Preferences> preferencesNodeResult;
Lines 311-316 Link Here
311
            return popupItem;
316
            return popupItem;
312
        }
317
        }
313
318
319
        public AbstractButton getToolbarPresenter() {
320
            if(toolbarItems == null) {
321
                toolbarItems = new WeakSet<AbstractButton>(4);
322
            }
323
            AbstractButton b = new DefaultIconToggleButton();
324
            toolbarItems.add(b);
325
            b.setSelected(isPreferencesSelected());
326
            Actions.connect(b, this);
327
            return b;
328
        }
329
314
        public void preferenceChange(PreferenceChangeEvent pce) {
330
        public void preferenceChange(PreferenceChangeEvent pce) {
315
            updateItemsSelected();
331
            updateItemsSelected();
316
        }
332
        }
Lines 351-356 Link Here
351
            if (popupItem != null) {
367
            if (popupItem != null) {
352
                popupItem.setSelected(selected);
368
                popupItem.setSelected(selected);
353
            }
369
            }
370
            if (toolbarItems != null) {
371
                for(AbstractButton b : toolbarItems) {
372
                    b.setSelected(selected);
373
                }
374
            }
354
        }
375
        }
355
376
356
        private synchronized Preferences prefs() {
377
        private synchronized Preferences prefs() {
Lines 423-426 Link Here
423
444
424
    }
445
    }
425
446
447
    /**
448
     * A button that provides a default icon when no text and no custom icon have been set.
449
     * Copied from Toolbar.java and made a toggle button.
450
     */
451
    static class DefaultIconToggleButton extends JToggleButton {
452
        private Icon unknownIcon;
453
454
        @Override
455
        public Icon getIcon() {
456
            Icon retValue = super.getIcon();
457
            if( null == retValue && (null == getText() || getText().isEmpty()) ) {
458
                if (unknownIcon == null) {
459
                    unknownIcon = ImageUtilities.loadImageIcon("org/openide/awt/resources/unknown.gif", false); //NOI18N
460
                    //unknownIcon = ImageUtilities.loadImageIcon("org/openide/loaders/unknown.gif", false); //NOI18N
461
                }
462
                retValue = unknownIcon;
463
            }
464
            return retValue;
465
        }
466
    }
467
426
}
468
}
(-)a/openide.awt/test/unit/src/org/openide/awt/ActionsTest.java (-12 / +103 lines)
Lines 60-65 Link Here
60
import org.netbeans.junit.MockServices;
60
import org.netbeans.junit.MockServices;
61
import org.netbeans.junit.NbTestCase;
61
import org.netbeans.junit.NbTestCase;
62
import org.openide.util.HelpCtx;
62
import org.openide.util.HelpCtx;
63
import org.openide.util.ImageUtilities;
63
import org.openide.util.Lookup;
64
import org.openide.util.Lookup;
64
import org.openide.util.Utilities;
65
import org.openide.util.Utilities;
65
import org.openide.util.actions.SystemAction;
66
import org.openide.util.actions.SystemAction;
Lines 77-86 Link Here
77
    
78
    
78
    // colors of the testing images in this order:
79
    // colors of the testing images in this order:
79
    // (test recognizes the icon by the white/black colors in specified positions :-)))
80
    // (test recognizes the icon by the white/black colors in specified positions :-)))
80
    // testIcon.gif
81
    //  FIRST EIGHT (original)         SECOND EIGHT (selected)
81
    // testIcon_rollover.gif
82
    // 0 testIcon.gif                 8 testIcon_selected.gif
82
    // testIcon_pressed.gif
83
    // 1 testIcon_rollover.gif        9 testIcon_rolloverSelected.gif
83
    // testIcon_disabled.gif
84
    // 2 testIcon_pressed.gif        10      --not-used--
85
    // 3 testIcon_disabled.gif       11 testIcon_disabledSelected.gif
86
    // 4 testIcon24.gif              12 testIcon24_selected.gif
87
    // 5 testIcon24_rollover.gif     13 testIcon24_rolloverSelected.gif
88
    // 6 testIcon24_pressed.gif      14      --not-used--
89
    // 7 testIcon24_disabled.gif     15 testIcon24_disabledSelected.gif
84
    private static int[][] RESULT_COLORS_00 = {
90
    private static int[][] RESULT_COLORS_00 = {
85
        {255, 255, 255},
91
        {255, 255, 255},
86
        {0, 0, 0},
92
        {0, 0, 0},
Lines 90-95 Link Here
90
        {0, 0, 0},
96
        {0, 0, 0},
91
        {255, 255, 255},
97
        {255, 255, 255},
92
        {0, 0, 0},
98
        {0, 0, 0},
99
        {255, 255, 255},
100
        {0, 0, 0},
101
        {255, 255, 255},
102
        {0, 0, 0},
103
        {255, 255, 255},
104
        {0, 0, 0},
105
        {255, 255, 255},
106
        {0, 0, 0},
93
    };
107
    };
94
    private static int[][] RESULT_COLORS_01 = {
108
    private static int[][] RESULT_COLORS_01 = {
95
        {255, 255, 255},
109
        {255, 255, 255},
Lines 100-105 Link Here
100
        {255, 255, 255},
114
        {255, 255, 255},
101
        {0, 0, 0},
115
        {0, 0, 0},
102
        {0, 0, 0},
116
        {0, 0, 0},
117
        {255, 255, 255},
118
        {255, 255, 255},
119
        {0, 0, 0},
120
        {0, 0, 0},
121
        {255, 255, 255},
122
        {255, 255, 255},
123
        {0, 0, 0},
124
        {0, 0, 0},
103
    };
125
    };
104
    private static int[][] RESULT_COLORS_11 = {
126
    private static int[][] RESULT_COLORS_11 = {
105
        {255, 255, 255},
127
        {255, 255, 255},
Lines 110-115 Link Here
110
        {0, 0, 0},
132
        {0, 0, 0},
111
        {0, 0, 0},
133
        {0, 0, 0},
112
        {0, 0, 0},
134
        {0, 0, 0},
135
        {255, 255, 255},
136
        {255, 255, 255},
137
        {255, 255, 255},
138
        {255, 255, 255},
139
        {0, 0, 0},
140
        {0, 0, 0},
141
        {0, 0, 0},
142
        {0, 0, 0},
143
    };
144
    private static int[][] RESULT_COLORS_10 = {
145
        {255, 255, 255},
146
        {255, 255, 255},
147
        {255, 255, 255},
148
        {255, 255, 255},
149
        {255, 255, 255},
150
        {255, 255, 255},
151
        {255, 255, 255},
152
        {255, 255, 255},
153
        {0, 0, 0},
154
        {0, 0, 0},
155
        {0, 0, 0},
156
        {0, 0, 0},
157
        {0, 0, 0},
158
        {0, 0, 0},
159
        {0, 0, 0},
160
        {0, 0, 0},
113
    };
161
    };
114
    
162
    
115
    
163
    
Lines 124-145 Link Here
124
    public void testIconsAction() throws Exception {
172
    public void testIconsAction() throws Exception {
125
        JButton jb = new JButton();
173
        JButton jb = new JButton();
126
        Actions.connect(jb, new TestAction());
174
        Actions.connect(jb, new TestAction());
127
        
175
128
        Icon icon = jb.getIcon();
176
        Icon icon = jb.getIcon();
129
        assertNotNull(icon);
177
        assertNotNull(icon);
130
        checkIfLoadedCorrectIcon(icon, jb, 0, "Enabled icon");
178
        checkIfLoadedCorrectIcon(icon, jb, 0, "Enabled icon");
131
        
179
132
        Icon rolloverIcon = jb.getRolloverIcon();
180
        Icon rolloverIcon = jb.getRolloverIcon();
133
        assertNotNull(rolloverIcon);
181
        assertNotNull(rolloverIcon);
134
        checkIfLoadedCorrectIcon(rolloverIcon, jb, 1, "Rollover icon");
182
        checkIfLoadedCorrectIcon(rolloverIcon, jb, 1, "Rollover icon");
135
        
183
136
        Icon pressedIcon = jb.getPressedIcon();
184
        Icon pressedIcon = jb.getPressedIcon();
137
        assertNotNull(pressedIcon);
185
        assertNotNull(pressedIcon);
138
        checkIfLoadedCorrectIcon(pressedIcon, jb, 2, "Pressed icon");
186
        checkIfLoadedCorrectIcon(pressedIcon, jb, 2, "Pressed icon");
139
        
187
140
        Icon disabledIcon = jb.getDisabledIcon();
188
        Icon disabledIcon = jb.getDisabledIcon();
141
        assertNotNull(disabledIcon);
189
        assertNotNull(disabledIcon);
142
        checkIfLoadedCorrectIcon(disabledIcon, jb, 3, "Disabled icon");
190
        checkIfLoadedCorrectIcon(disabledIcon, jb, 3, "Disabled icon");
191
        
192
        Icon selectedIcon = jb.getSelectedIcon();
193
        assertNotNull(selectedIcon);
194
        checkIfLoadedCorrectIcon(selectedIcon, jb, 8, "Selected icon");
195
        
196
        Icon rolloverSelectedIcon = jb.getRolloverSelectedIcon();
197
        assertNotNull(rolloverSelectedIcon);
198
        checkIfLoadedCorrectIcon(rolloverSelectedIcon, jb, 9, "RolloverSelected icon");
199
200
        // no pressedSelected
201
        
202
        Icon disabledSelectedIcon = jb.getDisabledSelectedIcon();
203
        assertNotNull(disabledSelectedIcon);
204
        checkIfLoadedCorrectIcon(disabledSelectedIcon, jb, 11, "DisabledSelected icon");
143
    }
205
    }
144
    
206
    
145
    /**
207
    /**
Lines 180-198 Link Here
180
        
242
        
181
        Icon icon = jb.getIcon();
243
        Icon icon = jb.getIcon();
182
        assertNotNull(icon);
244
        assertNotNull(icon);
183
        checkIfLoadedCorrectIcon(icon, jb, 4, "Enabled icon");
245
        checkIfLoadedCorrectIcon(icon, jb, 4, "Enabled icon24");
184
        
246
        
185
        Icon rolloverIcon = jb.getRolloverIcon();
247
        Icon rolloverIcon = jb.getRolloverIcon();
186
        assertNotNull(rolloverIcon);
248
        assertNotNull(rolloverIcon);
187
        checkIfLoadedCorrectIcon(rolloverIcon, jb, 5, "Rollover icon");
249
        checkIfLoadedCorrectIcon(rolloverIcon, jb, 5, "Rollover icon24");
188
        
250
        
189
        Icon pressedIcon = jb.getPressedIcon();
251
        Icon pressedIcon = jb.getPressedIcon();
190
        assertNotNull(pressedIcon);
252
        assertNotNull(pressedIcon);
191
        checkIfLoadedCorrectIcon(pressedIcon, jb, 6, "Pressed icon");
253
        checkIfLoadedCorrectIcon(pressedIcon, jb, 6, "Pressed icon24");
192
        
254
        
193
        Icon disabledIcon = jb.getDisabledIcon();
255
        Icon disabledIcon = jb.getDisabledIcon();
194
        assertNotNull(disabledIcon);
256
        assertNotNull(disabledIcon);
195
        checkIfLoadedCorrectIcon(disabledIcon, jb, 7, "Disabled icon");
257
        checkIfLoadedCorrectIcon(disabledIcon, jb, 7, "Disabled icon24");
258
259
        Icon selectedIcon = jb.getSelectedIcon();
260
        assertNotNull(selectedIcon);
261
        checkIfLoadedCorrectIcon(selectedIcon, jb, 12, "Selected icon24");
262
263
        Icon rolloverSelectedIcon = jb.getRolloverSelectedIcon();
264
        assertNotNull(rolloverSelectedIcon);
265
        checkIfLoadedCorrectIcon(rolloverSelectedIcon, jb, 13, "RolloverSelected icon24");
266
267
        // no pressedSelected
268
269
        Icon disabledSelectedIcon = jb.getDisabledSelectedIcon();
270
        assertNotNull(disabledSelectedIcon);
271
        checkIfLoadedCorrectIcon(disabledSelectedIcon, jb, 15, "DisabledSelected icon24");
272
    }
273
274
    /**
275
     * Tests that "unknownIcon" is used if no iconBase
276
     */
277
    public void testToggleButtonUnknownIcon() throws Exception {
278
        AbstractButton b = new AlwaysEnabledAction.DefaultIconToggleButton();
279
        Action action = new TestAction();
280
        action.putValue("iconBase", null);
281
        Actions.connect(b, action);
282
        Icon icon = b.getIcon();
283
        assertNotNull("null ToggleButton icon", icon);
284
        Icon expectedIcon = ImageUtilities.loadImageIcon("org/openide/awt/resources/unknown.gif", false); //NOI18N
285
        assertEquals("unkownIcon not used", expectedIcon, icon);
196
    }
286
    }
197
    
287
    
198
    /**
288
    /**
Lines 437-442 Link Here
437
        checkIfIconOk(icon, c, 0, 0, RESULT_COLORS_00[rowToCheck], nameOfIcon);
527
        checkIfIconOk(icon, c, 0, 0, RESULT_COLORS_00[rowToCheck], nameOfIcon);
438
        checkIfIconOk(icon, c, 0, 1, RESULT_COLORS_01[rowToCheck], nameOfIcon);
528
        checkIfIconOk(icon, c, 0, 1, RESULT_COLORS_01[rowToCheck], nameOfIcon);
439
        checkIfIconOk(icon, c, 1, 1, RESULT_COLORS_11[rowToCheck], nameOfIcon);
529
        checkIfIconOk(icon, c, 1, 1, RESULT_COLORS_11[rowToCheck], nameOfIcon);
530
        checkIfIconOk(icon, c, 1, 0, RESULT_COLORS_10[rowToCheck], nameOfIcon);
440
    }
531
    }
441
    
532
    
442
    /**
533
    /**

Return to bug 197639