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

(-)a/editor.lib2/nbproject/project.properties (-1 / +1 lines)
Lines 40-46 Link Here
40
is.autoload=true
40
is.autoload=true
41
javac.source=1.5
41
javac.source=1.5
42
javac.compilerargs=-Xlint:unchecked
42
javac.compilerargs=-Xlint:unchecked
43
spec.version.base=1.15.0
43
spec.version.base=1.16.0
44
cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar
44
cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar
45
45
46
javadoc.arch=${basedir}/arch.xml
46
javadoc.arch=${basedir}/arch.xml
(-)a/editor.lib2/nbproject/project.xml (-1 / +1 lines)
Lines 87-93 Link Here
87
                    <build-prerequisite/>
87
                    <build-prerequisite/>
88
                    <compile-dependency/>
88
                    <compile-dependency/>
89
                    <run-dependency>
89
                    <run-dependency>
90
                        <specification-version>7.15</specification-version>
90
                        <specification-version>7.17</specification-version>
91
                    </run-dependency>
91
                    </run-dependency>
92
                </dependency>
92
                </dependency>
93
                <dependency>
93
                <dependency>
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/EditorActionRegistrationProcessor.java (-3 / +4 lines)
Lines 292-299 Link Here
292
        }
292
        }
293
293
294
        if (preferencesKey.length() > 0) {
294
        if (preferencesKey.length() > 0) {
295
            file.stringvalue("PreferencesKey", preferencesKey);
295
            file.stringvalue("preferencesKey", preferencesKey);
296
            file.methodvalue("PreferencesNode", EditorActionUtilities.class.getName(), "getGlobalPreferences");
296
            file.methodvalue("preferencesNode", EditorActionUtilities.class.getName(), "getGlobalPreferences");
297
        }
297
        }
298
298
299
        // Deafult helpID is action's name
299
        // Deafult helpID is action's name
Lines 314-320 Link Here
314
            }
314
            }
315
315
316
        } else { // Create always enabled action
316
        } else { // Create always enabled action
317
            file.methodvalue("instanceCreate", "org.openide.awt.Actions", "alwaysEnabled");
317
            file.methodvalue("instanceCreate", "org.openide.awt.Actions",
318
                    checkBoxPresenter ? "checkbox" : "alwaysEnabled");
318
            file.stringvalue("displayName", actionName);
319
            file.stringvalue("displayName", actionName);
319
320
320
            if (methodName != null) {
321
            if (methodName != null) {
(-)a/openide.awt/apichanges.xml (+15 lines)
Lines 47-52 Link Here
47
<apidef name="awt">AWT API</apidef>
47
<apidef name="awt">AWT API</apidef>
48
</apidefs>
48
</apidefs>
49
<changes>
49
<changes>
50
    <change id="Actions.checkbox">
51
        <api name="awt"/>
52
        <summary>Actions.checkbox() can represent a boolean key in Preferences.</summary>
53
        <version major="7" minor="17"/>
54
        <date day="9" month="10" year="2009"/>
55
        <author login="mmetelka"/>
56
        <compatibility addition="yes" binary="compatible" semantic="compatible" deprecation="no" deletion="no" modification="no"/>
57
        <description>
58
            <a href="@TOP@/org/openide/awt/Actions.html#checkbox(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20boolean)">
59
                checkbox</a>
60
            added to create an action that represents a key in Preferences.
61
        </description>
62
        <class package="org.openide.awt" name="Actions"/>
63
        <issue number="166027"/>
64
    </change>
50
    <change id="AlwaysEnabledAction.CheckBox">
65
    <change id="AlwaysEnabledAction.CheckBox">
51
        <api name="awt"/>
66
        <api name="awt"/>
52
        <summary>AwlaysEnabledAction can represent a boolean key in Preferences.</summary>
67
        <summary>AwlaysEnabledAction can represent a boolean key in Preferences.</summary>
(-)a/openide.awt/nbproject/project.properties (-1 / +1 lines)
Lines 44-47 Link Here
44
javadoc.arch=${basedir}/arch.xml
44
javadoc.arch=${basedir}/arch.xml
45
javadoc.apichanges=${basedir}/apichanges.xml
45
javadoc.apichanges=${basedir}/apichanges.xml
46
46
47
spec.version.base=7.16.0
47
spec.version.base=7.17.0
(-)a/openide.awt/src/org/openide/awt/Actions.java (+49 lines)
Lines 356-361 Link Here
356
        return AlwaysEnabledAction.create(map);
356
        return AlwaysEnabledAction.create(map);
357
    }
357
    }
358
358
359
    /** Creates action which represents a boolean value in {@link java.util.prefs.Preferences}.
360
     * When added to a menu the action is presented as a JCheckBox.
361
     * This method can also be used from
362
     * <a href="@org-openide-modules@/org/openide/modules/doc-files/api.html#how-layer">XML Layer</a>
363
     * directly by following XML definition:
364
     * <pre>
365
     * &lt;file name="your-pkg-action-id.instance"&gt;
366
     *   &lt;attr name="preferencesNode" methodvalue="method-returning-Preferences-instance" or
367
     *                                   methodvalue="method-returning-Lookup-that-contains-Preferences-instance" or
368
     *                                   stringvalue="see below for the preferencesNode parameter description"
369
     * /&gt;
370
     *   &lt;attr name="preferencesKey" stringvalue="preferences-key-name"/&gt;
371
     *   &lt;attr name="instanceCreate" methodvalue="org.openide.awt.Actions.checkbox"/&gt;
372
     *   &lt;attr name="displayName" bundlevalue="your.pkg.Bundle#key"/&gt;
373
     *   &lt;attr name="iconBase" stringvalue="your/pkg/YourImage.png"/&gt;
374
     *   &lt;!-- if desired: &lt;attr name="noIconInMenu" boolvalue="false"/&gt; --&gt;
375
     *   &lt;!-- if desired: &lt;attr name="asynchronous" boolvalue="true"/&gt; --&gt;
376
     * &lt;/file&gt;
377
     * </pre>
378
     *
379
     * @param preferencesNode It's one of:
380
     * <ul>
381
     *   <li>Absolute path to preferences node under <code>NbPreferences.root()</code>.</li>
382
     *   <li>"system:" followed by absolute path to preferences node under <code>Preferences.systemRoot()</code>.</li>
383
     *   <li>"user:" followed by absolute path to preferences node under <code>Preferences.userRoot()</code>.</li>
384
     * </ul>
385
     * @param preferencesKey name of the preferences key.
386
     * @param displayName the name of the action
387
     * @param iconBase the location to the actions icon
388
     * @param noIconInMenu true if this icon shall not have an item in menu
389
     * @since 7.17
390
     */
391
    public static Action checkbox(
392
        String preferencesNode, String preferencesKey,
393
        String displayName, String iconBase, boolean noIconInMenu
394
    ) {
395
        HashMap<String,Object> map = new HashMap<String,Object>();
396
        map.put("preferencesNode", preferencesNode); // NOI18N
397
        map.put("preferencesKey", preferencesKey); // NOI18N
398
        map.put("displayName", displayName); // NOI18N
399
        map.put("iconBase", iconBase); // NOI18N
400
        map.put("noIconInMenu", noIconInMenu); // NOI18N
401
        return checkbox(map);
402
    }
403
    // for use from layers
404
    static Action checkbox(Map map) {
405
        return AlwaysEnabledAction.create(map);
406
    }
407
359
    /** Creates new "callback" action. Such action has an assigned key
408
    /** Creates new "callback" action. Such action has an assigned key
360
     * which is used to find proper delegate in {@link ActionMap} of currently
409
     * which is used to find proper delegate in {@link ActionMap} of currently
361
     * active component.
410
     * active component.
(-)a/openide.awt/src/org/openide/awt/AlwaysEnabledAction.java (-30 / +15 lines)
Lines 21-28 Link Here
21
import javax.swing.Icon;
21
import javax.swing.Icon;
22
import javax.swing.JCheckBoxMenuItem;
22
import javax.swing.JCheckBoxMenuItem;
23
import javax.swing.JMenuItem;
23
import javax.swing.JMenuItem;
24
import javax.swing.KeyStroke;
25
import javax.swing.text.Keymap;
26
import org.netbeans.modules.openide.util.ActionsBridge;
24
import org.netbeans.modules.openide.util.ActionsBridge;
27
import org.netbeans.modules.openide.util.ActionsBridge.ActionRunnable;
25
import org.netbeans.modules.openide.util.ActionsBridge.ActionRunnable;
28
import org.openide.util.ContextAwareAction;
26
import org.openide.util.ContextAwareAction;
Lines 43-72 Link Here
43
    // -J-Dorg.openide.awt.AlwaysEnabledAction.level=FINE
41
    // -J-Dorg.openide.awt.AlwaysEnabledAction.level=FINE
44
    private static final Logger LOG = Logger.getLogger(AlwaysEnabledAction.class.getName());
42
    private static final Logger LOG = Logger.getLogger(AlwaysEnabledAction.class.getName());
45
43
46
    /**
44
    private static final String PREFERENCES_NODE = "preferencesNode"; // NOI18N
47
     * Action property for key in {@link java.util.prefs.Preferences}.
48
     * <code>
49
     *   String key = (String) action.getValue("PreferencesKey");
50
     *   boolean selected = preferencesNode.getBoolean(key, false);
51
     * </code>
52
     */
53
    private static final String PREFERENCES_KEY = "PreferencesKey"; // NOI18N
54
45
55
    /**
46
    private static final String PREFERENCES_KEY = "preferencesKey"; // NOI18N
56
     * Action property for retrieving {@link java.util.prefs.Preferences} node.
57
     * Its value can be a String:
58
     * <ul>
59
     *   <li>"system:/path" for {@link java.util.prefs.Preferences#systemRoot() }.</li>
60
     *   <li>"user:/key" for {@link java.util.prefs.Preferences#userRoot() }.</li>
61
     *   <li>"nb:/key" for {@link org.openide.util.NbPreferences#root() }.</li>
62
     * </ul>
63
     * or a method value returning one of the following:
64
     * <ul>
65
     *   <li>{@link java.util.prefs.Preferences } instance.</li>
66
     *   <li>{@link org.openide.util.Lookup }.</li>
67
     * </ul>
68
     */
69
    private static final String PREFERENCES_NODE = "PreferencesNode"; // NOI18N
70
47
71
    static AlwaysEnabledAction create(Map m) {
48
    static AlwaysEnabledAction create(Map m) {
72
        return (m.containsKey(PREFERENCES_KEY)) ? new CheckBox(m) : new AlwaysEnabledAction(m);
49
        return (m.containsKey(PREFERENCES_KEY)) ? new CheckBox(m) : new AlwaysEnabledAction(m);
Lines 101-107 Link Here
101
        return a;
78
        return a;
102
    }
79
    }
103
80
104
    private ActionListener getDelegate() {
81
    protected ActionListener getDelegate() {
105
        if (delegate == null) {
82
        if (delegate == null) {
106
            Object listener = map.get("delegate"); // NOI18N
83
            Object listener = map.get("delegate"); // NOI18N
107
            if (!(listener instanceof ActionListener)) {
84
            if (!(listener instanceof ActionListener)) {
Lines 283-288 Link Here
283
260
284
        private static final long serialVersionUID = 1L;
261
        private static final long serialVersionUID = 1L;
285
262
263
        private static final ActionListener EMPTY = new ActionListener() {
264
            public void actionPerformed(ActionEvent ae) {
265
                // Do nothing
266
            }
267
        };
268
286
        private JCheckBoxMenuItem menuItem;
269
        private JCheckBoxMenuItem menuItem;
287
270
288
        private JCheckBoxMenuItem popupItem;
271
        private JCheckBoxMenuItem popupItem;
Lines 332-337 Link Here
332
        }
315
        }
333
316
334
        @Override
317
        @Override
318
        protected ActionListener getDelegate() {
319
            return EMPTY;
320
        }
321
322
        @Override
335
        public Action createContextAwareInstance(Lookup actionContext) {
323
        public Action createContextAwareInstance(Lookup actionContext) {
336
            return new CheckBox(map, delegate, actionContext, equals);
324
            return new CheckBox(map, delegate, actionContext, equals);
337
        }
325
        }
Lines 389-406 Link Here
389
                                preferencesNode = null;
377
                                preferencesNode = null;
390
                            }
378
                            }
391
                        }
379
                        }
392
                    } else if (nodeName.startsWith("nb:")) {
380
                    } else {
393
                        preferencesNode = NbPreferences.root();
381
                        preferencesNode = NbPreferences.root();
394
                        if (preferencesNode != null) {
382
                        if (preferencesNode != null) {
395
                            nodeName = nodeName.substring("nb:".length());;
396
                            try {
383
                            try {
397
                                preferencesNode = preferencesNode.nodeExists(nodeName) ? preferencesNode.node(nodeName) : null;
384
                                preferencesNode = preferencesNode.nodeExists(nodeName) ? preferencesNode.node(nodeName) : null;
398
                            } catch (BackingStoreException ex) {
385
                            } catch (BackingStoreException ex) {
399
                                preferencesNode = null;
386
                                preferencesNode = null;
400
                            }
387
                            }
401
                        }
388
                        }
402
                    } else {
403
                        preferencesNode = null;
404
                    }
389
                    }
405
390
406
                } else if (prefsNodeOrLookup instanceof Preferences) {
391
                } else if (prefsNodeOrLookup instanceof Preferences) {
(-)a/openide.awt/test/unit/src/org/openide/awt/AlwaysEnabledActionTest.java (-7 / +12 lines)
Lines 343-359 Link Here
343
    @RandomlyFails
343
    @RandomlyFails
344
    public void testPreferencesAction() throws Exception {
344
    public void testPreferencesAction() throws Exception {
345
//        checkPreferencesAction("testSystemPreferences.instance", Preferences.systemRoot());
345
//        checkPreferencesAction("testSystemPreferences.instance", Preferences.systemRoot());
346
        checkPreferencesAction("testUserPreferences.instance", Preferences.userRoot());
346
        checkPreferencesAction("testUserPreferences.instance", "user:", Preferences.userRoot());
347
        checkPreferencesAction("testNbPreferences.instance", NbPreferences.root());
347
        checkPreferencesAction("testNbPreferences.instance", "", NbPreferences.root());
348
        checkPreferencesAction("testCustomPreferences.instance", Preferences.userRoot()); // customPreferences() uses "myNode" subnode
348
        checkPreferencesAction("testCustomPreferences.instance", "user:", Preferences.userRoot()); // customPreferences() uses "myNode" subnode
349
    }
349
    }
350
350
351
    private void checkPreferencesAction(String actionFileName, Preferences prefsRoot) throws Exception {
351
    private void checkPreferencesAction(String actionFileName, String preferencesNodePrefix, Preferences prefsRoot) throws Exception {
352
        final int[] changeCount = new int[] { 0 };
353
        Action a = readAction(actionFileName);
352
        Action a = readAction(actionFileName);
354
        Preferences prefsNode = prefsRoot.node("myNode");
353
        Preferences prefsNode = prefsRoot.node("myNode");
354
        checkPreferencesAction(a, prefsNode);
355
        a = Actions.checkbox(preferencesNodePrefix + "/myNode", "myKey", null, null, false);
356
        checkPreferencesAction(a, prefsNode);
357
    }
358
359
    private void checkPreferencesAction(Action a, Preferences prefsNode) throws Exception {
355
        prefsNode.putBoolean("myKey", true);
360
        prefsNode.putBoolean("myKey", true);
356
        prefsRoot.sync();
361
        prefsNode.sync();
357
        int delay = 1;
362
        int delay = 1;
358
        Thread.sleep(delay);
363
        Thread.sleep(delay);
359
        // Verify value
364
        // Verify value
Lines 368-374 Link Here
368
        JMenuItem item = ((Presenter.Menu) a).getMenuPresenter();
373
        JMenuItem item = ((Presenter.Menu) a).getMenuPresenter();
369
        TestCase.assertTrue("Expected to be selected", item.isSelected());
374
        TestCase.assertTrue("Expected to be selected", item.isSelected());
370
        prefsNode.putBoolean("myKey", false);
375
        prefsNode.putBoolean("myKey", false);
371
        prefsRoot.sync();
376
        prefsNode.sync();
372
        Thread.sleep(delay);
377
        Thread.sleep(delay);
373
        TestCase.assertFalse("Expected to not be selected", item.isSelected());
378
        TestCase.assertFalse("Expected to not be selected", item.isSelected());
374
        a.actionPerformed(null); // new ActionEvent(null, 0, ""));
379
        a.actionPerformed(null); // new ActionEvent(null, 0, ""));
(-)a/openide.awt/test/unit/src/org/openide/awt/test-layer.xml (-18 / +12 lines)
Lines 99-132 Link Here
99
                    <attr name='displayName' stringvalue='Name1'/>
99
                    <attr name='displayName' stringvalue='Name1'/>
100
                </file>
100
                </file>
101
                <file name="testSystemPreferences.instance">
101
                <file name="testSystemPreferences.instance">
102
                    <attr name='instanceCreate' methodvalue='org.openide.awt.Actions.alwaysEnabled'/>
102
                    <attr name='instanceCreate' methodvalue='org.openide.awt.Actions.checkbox'/>
103
                    <attr name='delegate' methodvalue='org.openide.awt.AlwaysEnabledActionTest.preferencesAction'/>
103
                    <attr name='delegate' methodvalue='org.openide.awt.AlwaysEnabledActionTest.preferencesAction'/>
104
                    <attr name='PreferencesKey' stringvalue='myKey'/>
104
                    <attr name='preferencesKey' stringvalue='myKey'/>
105
                    <attr name='PreferencesNode' stringvalue='system:/myNode'/>
105
                    <attr name='preferencesNode' stringvalue='system:/myNode'/>
106
                </file>
107
                <file name="testSystemPreferences.instance">
108
                    <attr name='instanceCreate' methodvalue='org.openide.awt.Actions.alwaysEnabled'/>
109
                    <attr name='delegate' methodvalue='org.openide.awt.AlwaysEnabledActionTest.preferencesAction'/>
110
                    <attr name='PreferencesKey' stringvalue='myKey'/>
111
                    <attr name='PreferencesNode' stringvalue='system:/myNode'/>
112
                </file>
106
                </file>
113
                <file name="testUserPreferences.instance">
107
                <file name="testUserPreferences.instance">
114
                    <attr name='instanceCreate' methodvalue='org.openide.awt.Actions.alwaysEnabled'/>
108
                    <attr name='instanceCreate' methodvalue='org.openide.awt.Actions.checkbox'/>
115
                    <attr name='delegate' methodvalue='org.openide.awt.AlwaysEnabledActionTest.preferencesAction'/>
109
                    <attr name='delegate' methodvalue='org.openide.awt.AlwaysEnabledActionTest.preferencesAction'/>
116
                    <attr name='PreferencesKey' stringvalue='myKey'/>
110
                    <attr name='preferencesKey' stringvalue='myKey'/>
117
                    <attr name='PreferencesNode' stringvalue='user:/myNode'/>
111
                    <attr name='preferencesNode' stringvalue='user:/myNode'/>
118
                </file>
112
                </file>
119
                <file name="testNbPreferences.instance">
113
                <file name="testNbPreferences.instance">
120
                    <attr name='instanceCreate' methodvalue='org.openide.awt.Actions.alwaysEnabled'/>
114
                    <attr name='instanceCreate' methodvalue='org.openide.awt.Actions.checkbox'/>
121
                    <attr name='delegate' methodvalue='org.openide.awt.AlwaysEnabledActionTest.preferencesAction'/>
115
                    <attr name='delegate' methodvalue='org.openide.awt.AlwaysEnabledActionTest.preferencesAction'/>
122
                    <attr name='PreferencesKey' stringvalue='myKey'/>
116
                    <attr name='preferencesKey' stringvalue='myKey'/>
123
                    <attr name='PreferencesNode' stringvalue='nb:/myNode'/>
117
                    <attr name='preferencesNode' stringvalue='/myNode'/>
124
                </file>
118
                </file>
125
                <file name="testCustomPreferences.instance">
119
                <file name="testCustomPreferences.instance">
126
                    <attr name='instanceCreate' methodvalue='org.openide.awt.Actions.alwaysEnabled'/>
120
                    <attr name='instanceCreate' methodvalue='org.openide.awt.Actions.checkbox'/>
127
                    <attr name='delegate' methodvalue='org.openide.awt.AlwaysEnabledActionTest.preferencesAction'/>
121
                    <attr name='delegate' methodvalue='org.openide.awt.AlwaysEnabledActionTest.preferencesAction'/>
128
                    <attr name='PreferencesKey' stringvalue='myKey'/>
122
                    <attr name='preferencesKey' stringvalue='myKey'/>
129
                    <attr name='PreferencesNode' methodvalue='org.openide.awt.AlwaysEnabledActionTest.customPreferences'/>
123
                    <attr name='preferencesNode' methodvalue='org.openide.awt.AlwaysEnabledActionTest.customPreferences'/>
130
                </file>
124
                </file>
131
                <file name="testCallback.instance">
125
                <file name="testCallback.instance">
132
                    <attr name='instanceCreate' methodvalue='org.openide.awt.Actions.callback'/>
126
                    <attr name='instanceCreate' methodvalue='org.openide.awt.Actions.callback'/>

Return to bug 166027