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="31"/>
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/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.openide.awt
2
OpenIDE-Module: org.openide.awt
3
OpenIDE-Module-Localizing-Bundle: org/openide/awt/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/awt/Bundle.properties
4
AutoUpdate-Essential-Module: true
4
AutoUpdate-Essential-Module: true
5
OpenIDE-Module-Specification-Version: 7.30
5
OpenIDE-Module-Specification-Version: 7.31
6
6
(-)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.31 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 / +42 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
    private 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/loaders/unknown.gif", false); //NOI18N
460
                }
461
                retValue = unknownIcon;
462
            }
463
            return retValue;
464
        }
465
    }
466
426
}
467
}

Return to bug 197639