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

(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/resources/layer.xml (+1 lines)
Lines 185-190 made subject to such option by the copyr Link Here
185
            <attr name="position" intvalue="0"/>
185
            <attr name="position" intvalue="0"/>
186
            <attr name="simple" boolvalue="false"/>
186
            <attr name="simple" boolvalue="false"/>
187
            <file name="callableSystemAction.java" url="../wizard/action/callableSystemAction.javx"/>
187
            <file name="callableSystemAction.java" url="../wizard/action/callableSystemAction.javx"/>
188
            <file name="actionListener.java" url="../wizard/action/actionListener.javx"/>
188
            <file name="cookieAction.java" url="../wizard/action/cookieAction.javx"/>
189
            <file name="cookieAction.java" url="../wizard/action/cookieAction.javx"/>
189
            <file name="codeGenerator.java" url="../wizard/codegenerator/codeGenerator.javx"/>
190
            <file name="codeGenerator.java" url="../wizard/codegenerator/codeGenerator.javx"/>
190
            <file name="contextProvider.java" url="../wizard/codegenerator/contextProvider.javx"/>
191
            <file name="contextProvider.java" url="../wizard/codegenerator/contextProvider.javx"/>
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/DataModel.java (-3 / +51 lines)
Lines 41-46 Link Here
41
41
42
package org.netbeans.modules.apisupport.project.ui.wizard.action;
42
package org.netbeans.modules.apisupport.project.ui.wizard.action;
43
43
44
import java.io.IOException;
45
import java.net.MalformedURLException;
46
import java.net.URL;
44
import java.util.Arrays;
47
import java.util.Arrays;
45
import java.util.Collections;
48
import java.util.Collections;
46
import java.util.HashMap;
49
import java.util.HashMap;
Lines 48-57 import java.util.Map; Link Here
48
import java.util.Map;
51
import java.util.Map;
49
import java.util.Set;
52
import java.util.Set;
50
import java.util.TreeSet;
53
import java.util.TreeSet;
54
import java.util.logging.Level;
55
import java.util.logging.Logger;
51
import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
56
import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
52
import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
57
import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
53
import org.openide.WizardDescriptor;
58
import org.openide.WizardDescriptor;
54
import org.openide.filesystems.FileObject;
59
import org.openide.filesystems.FileObject;
60
import org.openide.modules.SpecificationVersion;
61
import org.openide.util.Exceptions;
55
62
56
/**
63
/**
57
 * Data model used across the <em>New Action Wizard</em>.
64
 * Data model used across the <em>New Action Wizard</em>.
Lines 145-154 final class DataModel extends BasicWizar Link Here
145
        String shadow = dashedFqClassName + ".shadow"; // NOI18N
152
        String shadow = dashedFqClassName + ".shadow"; // NOI18N
146
        
153
        
147
        cmf = new CreatedModifiedFiles(getProject());
154
        cmf = new CreatedModifiedFiles(getProject());
155
156
        boolean actionProxy;
157
        try {
158
            SpecificationVersion current = getModuleInfo().getDependencyVersion("org.openide.awt");
159
            actionProxy = current.compareTo(new SpecificationVersion("7.3")) >= 0; // NOI18N
160
        } catch (IOException ex) {
161
            Logger.getLogger(DataModel.class.getName()).log(Level.INFO, null, ex);
162
            actionProxy = false;
163
        }
148
        
164
        
149
        String actionPath = getDefaultPackagePath(className + ".java", false); // NOI18N
165
        String actionPath = getDefaultPackagePath(className + ".java", false); // NOI18N
150
        // XXX use nbresloc URL protocol rather than DataModel.class.getResource(...):
166
        // XXX use nbresloc URL protocol rather than DataModel.class.getResource(...):
151
        FileObject template = CreatedModifiedFiles.getTemplate(alwaysEnabled ? "callableSystemAction.java" : "cookieAction.java"); // NOI18N
167
        FileObject template = CreatedModifiedFiles.getTemplate(
168
            alwaysEnabled ? (
169
                actionProxy ?
170
                "actionListener.java" 
171
                :
172
                "callableSystemAction.java"
173
            ):
174
            "cookieAction.java"
175
        ); // NOI18N
152
        assert template != null;
176
        assert template != null;
153
        String actionNameKey = "CTL_" + className; // NOI18N
177
        String actionNameKey = "CTL_" + className; // NOI18N
154
        Map<String,String> replaceTokens = new HashMap<String,String>();
178
        Map<String,String> replaceTokens = new HashMap<String,String>();
Lines 196-203 final class DataModel extends BasicWizar Link Here
196
        cmf.add(cmf.bundleKey(getDefaultPackagePath("Bundle.properties", true), actionNameKey, displayName)); // NOI18N
220
        cmf.add(cmf.bundleKey(getDefaultPackagePath("Bundle.properties", true), actionNameKey, displayName)); // NOI18N
197
        
221
        
198
        // Copy action icon
222
        // Copy action icon
223
        String relativeIconPath = null;
199
        if (origIconPath != null) {
224
        if (origIconPath != null) {
200
            String relativeIconPath = addCreateIconOperation(cmf, origIconPath);
225
            relativeIconPath = addCreateIconOperation(cmf, origIconPath);
201
            replaceTokens.put("ICON_RESOURCE_METHOD", DataModel.generateIconResourceMethod(relativeIconPath)); // NOI18N
226
            replaceTokens.put("ICON_RESOURCE_METHOD", DataModel.generateIconResourceMethod(relativeIconPath)); // NOI18N
202
            replaceTokens.put("INITIALIZE_METHOD", ""); // NOI18N
227
            replaceTokens.put("INITIALIZE_METHOD", ""); // NOI18N
203
        } else {
228
        } else {
Lines 212-218 final class DataModel extends BasicWizar Link Here
212
        // add layer entry about the action
237
        // add layer entry about the action
213
        String instanceFullPath = category + "/" // NOI18N
238
        String instanceFullPath = category + "/" // NOI18N
214
                + dashedFqClassName + ".instance"; // NOI18N
239
                + dashedFqClassName + ".instance"; // NOI18N
215
        cmf.add(cmf.createLayerEntry(instanceFullPath, null, null, null, null));
240
        if (!alwaysEnabled || !actionProxy) {
241
            cmf.add(cmf.createLayerEntry(instanceFullPath, null, null, null, null));
242
        } else {
243
            Map<String,Object> attrs = new HashMap<String,Object>();
244
            attrs.put("instanceCreate", "methodvalue:org.openide.awt.Actions.alwaysEnabled"); // NOI18N
245
            attrs.put("delegate", "newvalue:" + getPackageName() + '.' + className); // NOI18N
246
            attrs.put("noIconInMenu", "false"); // NOI18N
247
            if (relativeIconPath != null) {
248
                try {
249
                    attrs.put("SystemFileSystem.icon", new URL("nbresloc://" + relativeIconPath)); // NOI18N
250
                } catch (MalformedURLException ex) {
251
                    Exceptions.printStackTrace(ex);
252
                }
253
            }
254
            cmf.add(
255
                cmf.createLayerEntry(
256
                    instanceFullPath,
257
                    null,
258
                    null,
259
                    displayName,
260
                    attrs
261
                )
262
            );
263
        }
216
        
264
        
217
        // add dependency on util to project.xml
265
        // add dependency on util to project.xml
218
        cmf.add(cmf.addModuleDependency("org.openide.util")); // NOI18N
266
        cmf.add(cmf.addModuleDependency("org.openide.util")); // NOI18N
(-)428419c1ab32 (+15 lines)
Added Link Here
1
<#assign licenseFirst = "/*">
2
<#assign licensePrefix = " * ">
3
<#assign licenseLast = " */">
4
<#include "../Licenses/license-${project.license}.txt">
5
6
package ${PACKAGE_NAME};
7
8
import java.awt.event.ActionEvent;
9
import java.awt.event.ActionListener;
10
11
public final class ${CLASS_NAME} implements ActionListener {
12
    public void actionPerformed(ActionEvent e) {
13
       // TODO implement action body
14
    }
15
}
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NewTCIterator.java (-9 / +66 lines)
Lines 43-52 package org.netbeans.modules.apisupport. Link Here
43
43
44
import java.io.File;
44
import java.io.File;
45
import java.io.IOException;
45
import java.io.IOException;
46
import java.net.MalformedURLException;
47
import java.net.URL;
46
import java.util.Collections;
48
import java.util.Collections;
47
import java.util.HashMap;
49
import java.util.HashMap;
48
import java.util.Map;
50
import java.util.Map;
49
import java.util.Set;
51
import java.util.Set;
52
import java.util.logging.Level;
53
import java.util.logging.Logger;
50
import org.netbeans.api.project.Project;
54
import org.netbeans.api.project.Project;
51
import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
55
import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
52
import org.netbeans.modules.apisupport.project.Util;
56
import org.netbeans.modules.apisupport.project.Util;
Lines 56-61 import org.openide.filesystems.FileObjec Link Here
56
import org.openide.filesystems.FileObject;
60
import org.openide.filesystems.FileObject;
57
import org.openide.filesystems.FileSystem;
61
import org.openide.filesystems.FileSystem;
58
import org.openide.filesystems.FileUtil;
62
import org.openide.filesystems.FileUtil;
63
import org.openide.modules.SpecificationVersion;
64
import org.openide.util.Exceptions;
59
import org.openide.util.NbBundle;
65
import org.openide.util.NbBundle;
60
66
61
/**
67
/**
Lines 170-175 final class NewTCIterator extends BasicW Link Here
170
        final String name = model.getName();
176
        final String name = model.getName();
171
        final String packageName = model.getPackageName();
177
        final String packageName = model.getPackageName();
172
        final String mode = model.getMode();
178
        final String mode = model.getMode();
179
180
        boolean actionLessTC;
181
        try {
182
            SpecificationVersion current = model.getModuleInfo().getDependencyVersion("org.openide.windows");
183
            actionLessTC = current.compareTo(new SpecificationVersion("6.24")) >= 0; // NOI18N
184
        } catch (IOException ex) {
185
            Logger.getLogger(NewTCIterator.class.getName()).log(Level.INFO, null, ex);
186
            actionLessTC = false;
187
        }
188
173
        
189
        
174
        Map<String,String> replaceTokens = new HashMap<String,String>();
190
        Map<String,String> replaceTokens = new HashMap<String,String>();
175
        replaceTokens.put("TEMPLATENAME", name);//NOI18N
191
        replaceTokens.put("TEMPLATENAME", name);//NOI18N
Lines 189-197 final class NewTCIterator extends BasicW Link Here
189
                fil = null;
205
                fil = null;
190
            }
206
            }
191
        }
207
        }
208
        String relativeIconPath = null;
192
        if (fil != null) {
209
        if (fil != null) {
193
            FileObject fo = FileUtil.toFileObject(fil);
210
            FileObject fo = FileUtil.toFileObject(fil);
194
            String relativeIconPath = null;
195
            if (!FileUtil.isParentOf(Util.getResourceDirectory(project), fo)) {
211
            if (!FileUtil.isParentOf(Util.getResourceDirectory(project), fo)) {
196
                String iconPath = getRelativePath(moduleInfo.getResourceDirectoryPath(false), packageName, 
212
                String iconPath = getRelativePath(moduleInfo.getResourceDirectoryPath(false), packageName, 
197
                                                "", fo.getNameExt()); //NOI18N
213
                                                "", fo.getNameExt()); //NOI18N
Lines 228-238 final class NewTCIterator extends BasicW Link Here
228
                name, "TopComponent.form"); //NOI18N
244
                name, "TopComponent.form"); //NOI18N
229
        template = CreatedModifiedFiles.getTemplate("templateTopComponent.form");//NOI18N
245
        template = CreatedModifiedFiles.getTemplate("templateTopComponent.form");//NOI18N
230
        fileChanges.add(fileChanges.createFileWithSubstitutions(tcFormName, template, replaceTokens));
246
        fileChanges.add(fileChanges.createFileWithSubstitutions(tcFormName, template, replaceTokens));
231
        
247
232
        final String actionName = getRelativePath(moduleInfo.getSourceDirectoryPath(), packageName,
248
        if (!actionLessTC) {
233
                name, "Action.java"); //NOI18N
249
            final String actionName = getRelativePath(moduleInfo.getSourceDirectoryPath(), packageName,
234
        template = CreatedModifiedFiles.getTemplate("templateAction.java");//NOI18N
250
                    name, "Action.java"); //NOI18N
235
        fileChanges.add(fileChanges.createFileWithSubstitutions(actionName, template, replaceTokens));
251
            template = CreatedModifiedFiles.getTemplate("templateAction.java");//NOI18N
252
            fileChanges.add(fileChanges.createFileWithSubstitutions(actionName, template, replaceTokens));
253
        }
236
        
254
        
237
        final String settingsName = name + "TopComponent.settings"; //NOI18N
255
        final String settingsName = name + "TopComponent.settings"; //NOI18N
238
        template = CreatedModifiedFiles.getTemplate("templateSettings.xml");//NOI18N
256
        template = CreatedModifiedFiles.getTemplate("templateSettings.xml");//NOI18N
Lines 242-251 final class NewTCIterator extends BasicW Link Here
242
        template = CreatedModifiedFiles.getTemplate("templateWstcref.xml");//NOI18N
260
        template = CreatedModifiedFiles.getTemplate("templateWstcref.xml");//NOI18N
243
        fileChanges.add(fileChanges.createLayerEntry("Windows2/Modes/" + mode + "/" + wstcrefName, // NOI18N
261
        fileChanges.add(fileChanges.createLayerEntry("Windows2/Modes/" + mode + "/" + wstcrefName, // NOI18N
244
                             template, replaceTokens, null, null));
262
                             template, replaceTokens, null, null));
245
        
263
246
        fileChanges.add(fileChanges.layerModifications(new CreateActionEntryOperation(name + "Action", packageName), // NOI18N
264
        String bundlePath = getRelativePath(moduleInfo.getResourceDirectoryPath(false), packageName, "", "Bundle.properties"); //NOI18N
265
        if (actionLessTC) {
266
            String path = "Actions/Window/" + packageName.replace('.','-') + "-" + name + "Action.instance"; // NOI18N
267
            {
268
                Map<String,Object> attrs = new HashMap<String,Object>();
269
                attrs.put("instanceCreate", "methodvalue:org.openide.windows.TopComponent.openAction"); // NOI18N
270
                attrs.put("component", "methodvalue:" + packageName + '.' + name + "TopComponent.findInstance"); // NOI18N
271
                if (relativeIconPath != null) {
272
                    try {
273
                        attrs.put("SystemFileSystem.icon", new URL("nbresloc://" + relativeIconPath)); // NOI18N
274
                    } catch (MalformedURLException ex) {
275
                        Exceptions.printStackTrace(ex);
276
                    }
277
                }
278
                fileChanges.add(
279
                    fileChanges.createLayerEntry(
280
                        path,
281
                        null,
282
                        null,
283
                        NbBundle.getMessage(NewTCIterator.class, "LBL_TemplateActionName", name), // NOI18N
284
                        attrs
285
                    )
286
                );
287
            }
288
289
            {
290
                Map<String,Object> attrs = new HashMap<String,Object>();
291
                attrs.put("originalFile", path); // NOI18N
292
                fileChanges.add(
293
                    fileChanges.createLayerEntry(
294
                        "Menu/Window/" + name + "Action.shadow", // NOI18N
295
                        null,
296
                        null,
297
                        null,
298
                        attrs
299
                    )
300
                );
301
            }
302
        } else {
303
            fileChanges.add(fileChanges.layerModifications(new CreateActionEntryOperation(name + "Action", packageName), // NOI18N
247
                                                       Collections.<String>emptySet()));
304
                                                       Collections.<String>emptySet()));
248
        String bundlePath = getRelativePath(moduleInfo.getResourceDirectoryPath(false), packageName, "", "Bundle.properties"); //NOI18N
305
        }
249
        fileChanges.add(fileChanges.bundleKey(bundlePath, "CTL_" + name + "Action",  // NOI18N
306
        fileChanges.add(fileChanges.bundleKey(bundlePath, "CTL_" + name + "Action",  // NOI18N
250
                                NbBundle.getMessage(NewTCIterator.class, "LBL_TemplateActionName", name))); //NOI18N
307
                                NbBundle.getMessage(NewTCIterator.class, "LBL_TemplateActionName", name))); //NOI18N
251
        
308
        
(-)a/core.startup/src/org/netbeans/core/startup/layers/BinaryFS.java (-2 / +46 lines)
Lines 41-46 Link Here
41
41
42
package org.netbeans.core.startup.layers;
42
package org.netbeans.core.startup.layers;
43
43
44
import java.beans.BeanInfo;
44
import java.beans.PropertyVetoException;
45
import java.beans.PropertyVetoException;
45
import java.io.ByteArrayInputStream;
46
import java.io.ByteArrayInputStream;
46
import java.io.File;
47
import java.io.File;
Lines 75-80 import org.openide.filesystems.FileChang Link Here
75
import org.openide.filesystems.FileChangeListener;
76
import org.openide.filesystems.FileChangeListener;
76
import org.openide.filesystems.FileLock;
77
import org.openide.filesystems.FileLock;
77
import org.openide.filesystems.FileObject;
78
import org.openide.filesystems.FileObject;
79
import org.openide.filesystems.FileStateInvalidException;
78
import org.openide.filesystems.FileSystem;
80
import org.openide.filesystems.FileSystem;
79
import org.openide.util.Enumerations;
81
import org.openide.util.Enumerations;
80
import org.openide.util.Exceptions;
82
import org.openide.util.Exceptions;
Lines 878-884 public class BinaryFS extends FileSystem Link Here
878
        }
880
        }
879
881
880
        public Object get(String key) {
882
        public Object get(String key) {
881
            return fo.getAttribute(key);
883
            Object ret = fo.getAttribute(key);
884
            if (ret != null) {
885
                return ret;
886
            }
887
            if ("displayName".equals(key)) { // NOI18N
888
                try {
889
                    // NOI18N
890
                    return fo.getFileSystem().getStatus().annotateName(fo.getNameExt(), Collections.<FileObject>singleton(fo));
891
                } catch (FileStateInvalidException ex) {
892
                    Exceptions.printStackTrace(ex);
893
                }
894
            }
895
            return null;
882
        }
896
        }
883
897
884
        public Object remove(Object key) {
898
        public Object remove(Object key) {
Lines 899-911 public class BinaryFS extends FileSystem Link Here
899
913
900
        public Iterator<Map.Entry<String, Object>> iterator() {
914
        public Iterator<Map.Entry<String, Object>> iterator() {
901
            class Iter implements Iterator<Map.Entry<String, Object>> {
915
            class Iter implements Iterator<Map.Entry<String, Object>> {
916
                int fixed;
902
                Enumeration<String> attrs = fo.getAttributes();
917
                Enumeration<String> attrs = fo.getAttributes();
903
918
904
                public boolean hasNext() {
919
                public boolean hasNext() {
905
                    return attrs.hasMoreElements();
920
                    return fixed < 2 || attrs.hasMoreElements();
906
                }
921
                }
907
922
908
                public Map.Entry<String, Object> next() {
923
                public Map.Entry<String, Object> next() {
924
                    if (fixed < 2) {
925
                        return new LocEntry(fo, fixed++);
926
                    }
909
                    String s = attrs.nextElement();
927
                    String s = attrs.nextElement();
910
                    return new FOEntry(fo, s);
928
                    return new FOEntry(fo, s);
911
                }
929
                }
Lines 953-956 public class BinaryFS extends FileSystem Link Here
953
            throw new UnsupportedOperationException();
971
            throw new UnsupportedOperationException();
954
        }
972
        }
955
    } // end of FOEntry
973
    } // end of FOEntry
974
    private static final class LocEntry implements Map.Entry<String, Object> {
975
        private FileObject fo;
976
        private int type;
977
978
        private LocEntry(FileObject fo, int cnt) {
979
            this.fo = fo;
980
            this.type = cnt;
981
        }
982
983
        public String getKey() {
984
            return type == 0 ? "displayName" : "image"; // NOI18N
985
        }
986
987
        public Object getValue() {
988
            switch (type) {
989
                case 0: return SystemFileSystem.annotateName(fo);
990
                case 1: return SystemFileSystem.annotateIcon(fo, BeanInfo.ICON_COLOR_16x16);
991
                default: return null;
992
            }
993
        }
994
        
995
996
        public Object setValue(Object value) {
997
            throw new UnsupportedOperationException();
998
        }
999
    } // end of FOEntry
956
}
1000
}
(-)a/core.startup/src/org/netbeans/core/startup/layers/SystemFileSystem.java (-33 / +48 lines)
Lines 185-190 implements FileSystem.Status { Link Here
185
    public FileSystem.Status getStatus () {
185
    public FileSystem.Status getStatus () {
186
        return this;
186
        return this;
187
    }
187
    }
188
    
189
    static final String annotateName(FileObject fo) {
190
191
        String bundleName = (String) fo.getAttribute(ATTR_BUNDLE); // NOI18N
192
        if (bundleName != null) {
193
            try {
194
                bundleName = org.openide.util.Utilities.translate(bundleName);
195
                ResourceBundle b = NbBundle.getBundle(bundleName);
196
                try {
197
                    return b.getString(fo.getPath());
198
                } catch (MissingResourceException ex) {
199
                    // ignore--normal
200
                    }
201
            } catch (MissingResourceException ex) {
202
                ModuleLayeredFileSystem.err.log(
203
                        Level.WARNING,
204
                        "Computing display name for " + fo, ex); // NOI18N
205
            // ignore
206
            }
207
        }
208
        return null;
209
    }
188
210
189
    /** Annotate name
211
    /** Annotate name
190
    */
212
    */
Lines 197-231 implements FileSystem.Status { Link Here
197
        while (it.hasNext ()) {
219
        while (it.hasNext ()) {
198
            // annotate a name
220
            // annotate a name
199
            FileObject fo = (FileObject) it.next ();
221
            FileObject fo = (FileObject) it.next ();
200
222
            String displayName = annotateName(fo);
201
            String bundleName = (String)fo.getAttribute (ATTR_BUNDLE); // NOI18N
223
            if (displayName != null) {
202
            if (bundleName != null) {
224
                return displayName;
203
                try {
204
                    bundleName = org.openide.util.Utilities.translate(bundleName);
205
                    ResourceBundle b = NbBundle.getBundle(bundleName);
206
                    try {
207
                        return b.getString (fo.getPath());
208
                    } catch (MissingResourceException ex) {
209
                        // ignore--normal
210
                    }
211
                } catch (MissingResourceException ex) {
212
                    ModuleLayeredFileSystem.err.log(
213
                        Level.WARNING,
214
                        "Computing display name for " + fo, ex); // NOI18N
215
                    // ignore
216
                }
217
            }
225
            }
218
            
219
            String fixedName = FixedFileSystem.deflt.annotateName(fo.getPath());
226
            String fixedName = FixedFileSystem.deflt.annotateName(fo.getPath());
220
            if (fixedName != null) return fixedName;
227
            if (fixedName != null) return fixedName;
221
        }
228
        }
222
229
223
        return s;
230
        return s;
224
    }
231
    }
225
232
    
226
    /** Annotate icon
233
    static Image annotateIcon(FileObject fo, int type) {
227
    */
228
    public Image annotateIcon (Image im, int type, Set s) {
229
        String attr;
234
        String attr;
230
        if (type == BeanInfo.ICON_COLOR_16x16) {
235
        if (type == BeanInfo.ICON_COLOR_16x16) {
231
            attr = ATTR_ICON_16;
236
            attr = ATTR_ICON_16;
Lines 233-253 implements FileSystem.Status { Link Here
233
            attr = ATTR_ICON_32;
238
            attr = ATTR_ICON_32;
234
        } else {
239
        } else {
235
            // mono icons not supported
240
            // mono icons not supported
236
            return im;
241
            return null;
237
        }
242
        }
243
        Object value = fo.getAttribute(attr);
244
        if (value != null) {
245
            if (value instanceof URL) {
246
                return Toolkit.getDefaultToolkit().getImage((URL) value);
247
            } else if (value instanceof Image) {
248
                // #18832
249
                return (Image) value;
250
            } else {
251
                ModuleLayeredFileSystem.err.warning("Attribute " + attr + " on " + fo + " expected to be a URL or Image; was: " + value);
252
            }
253
        }
254
        return null;
255
    }
256
257
    /** Annotate icon
258
    */
259
    public Image annotateIcon (Image im, int type, Set s) {
238
        Iterator it = s.iterator ();
260
        Iterator it = s.iterator ();
239
        while (it.hasNext ()) {
261
        while (it.hasNext ()) {
240
            FileObject fo = (FileObject) it.next ();
262
            FileObject fo = (FileObject) it.next ();
241
            Object value = fo.getAttribute (attr);
263
            Image img = annotateIcon(fo, type);
242
            if (value != null) {
264
            if (img != null) {
243
                if (value instanceof URL) {
265
                return img;
244
                    return Toolkit.getDefaultToolkit ().getImage ((URL) value);
245
                } else if (value instanceof Image) {
246
                    // #18832
247
                    return (Image)value;
248
                } else {
249
                    ModuleLayeredFileSystem.err.warning("Attribute " + attr + " on " + fo + " expected to be a URL or Image; was: " + value);
250
                }
251
            }
266
            }
252
            Image anntIm = FixedFileSystem.deflt.annotateIcon(fo.getPath());
267
            Image anntIm = FixedFileSystem.deflt.annotateIcon(fo.getPath());
253
            if (anntIm != null) {
268
            if (anntIm != null) {
(-)a/core.startup/test/unit/src/org/netbeans/core/startup/layers/CacheManagerTestBaseHid.java (+20 lines)
Lines 41-46 Link Here
41
41
42
package org.netbeans.core.startup.layers;
42
package org.netbeans.core.startup.layers;
43
43
44
import java.awt.Image;
45
import java.awt.image.BufferedImage;
44
import java.io.IOException;
46
import java.io.IOException;
45
import java.io.InputStream;
47
import java.io.InputStream;
46
import java.net.URL;
48
import java.net.URL;
Lines 51-61 import org.openide.filesystems.FileObjec Link Here
51
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileObject;
52
import org.openide.filesystems.FileSystem;
54
import org.openide.filesystems.FileSystem;
53
import org.openide.filesystems.MultiFileSystem;
55
import org.openide.filesystems.MultiFileSystem;
56
import org.openide.util.ImageUtilities;
54
/** Test layer cache managers generally.
57
/** Test layer cache managers generally.
55
 * @author Jesse Glick
58
 * @author Jesse Glick
56
 */
59
 */
57
public abstract class CacheManagerTestBaseHid extends NbTestCase {
60
public abstract class CacheManagerTestBaseHid extends NbTestCase {
58
    private long initTime = System.currentTimeMillis ();
61
    private long initTime = System.currentTimeMillis ();
62
    private static Image icon;
59
    
63
    
60
    /**
64
    /**
61
     * Called from layer, do not rename!
65
     * Called from layer, do not rename!
Lines 65-75 public abstract class CacheManagerTestBa Link Here
65
        return String.valueOf(fo.getAttribute("x")) + "/" + attr;
69
        return String.valueOf(fo.getAttribute("x")) + "/" + attr;
66
    }
70
    }
67
    
71
    
72
    public static Image icon() {
73
        assertNull("Called just once", icon);
74
        icon = new BufferedImage(133, 133, BufferedImage.TYPE_INT_ARGB);
75
        return icon;
76
    }
77
    
68
    public static Object map1(Map map) {
78
    public static Object map1(Map map) {
69
        return String.valueOf(map.get("x"));
79
        return String.valueOf(map.get("x"));
70
    }
80
    }
71
    public static Object map2(Map map, String attr) {
81
    public static Object map2(Map map, String attr) {
72
        return String.valueOf(map.get("x")) + "/" + attr;
82
        return String.valueOf(map.get("x")) + "/" + attr;
83
    }
84
    public static Object mapImage(Map map) {
85
        return map.get("image");
86
    }
87
    public static Object mapDisplayName(Map map) {
88
        return map.get("displayName");
73
    }
89
    }
74
    
90
    
75
    protected CacheManagerTestBaseHid(String name) {
91
    protected CacheManagerTestBaseHid(String name) {
Lines 143-148 public abstract class CacheManagerTestBa Link Here
143
        assertEquals("val/a", attr(mfs, "foo/29356", "a"));
159
        assertEquals("val/a", attr(mfs, "foo/29356", "a"));
144
        assertEquals("val", attr(mfs, "foo/29356", "map1"));
160
        assertEquals("val", attr(mfs, "foo/29356", "map1"));
145
        assertEquals("val/map2", attr(mfs, "foo/29356", "map2"));
161
        assertEquals("val/map2", attr(mfs, "foo/29356", "map2"));
162
        assertEquals("Ahoj", attr(mfs, "foo/29356", "mapDisplayName"));
163
        Image read = (Image) attr(mfs, "foo/29356", "mapImage");
164
        assertNotNull("Image loaded", icon);
165
        assertEquals("Same image", icon, read);
146
    }
166
    }
147
    
167
    
148
    private static String slurp(FileSystem f, String path) throws IOException {
168
    private static String slurp(FileSystem f, String path) throws IOException {
(-)428419c1ab32 (+38 lines)
Added Link Here
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
# 
3
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
4
# 
5
# The contents of this file are subject to the terms of either the GNU
6
# General Public License Version 2 only ("GPL") or the Common
7
# Development and Distribution License("CDDL") (collectively, the
8
# "License"). You may not use this file except in compliance with the
9
# License. You can obtain a copy of the License at
10
# http://www.netbeans.org/cddl-gplv2.html
11
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
12
# specific language governing permissions and limitations under the
13
# License.  When distributing the software, include this License Header
14
# Notice in each file and include the License file at
15
# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
16
# particular file as subject to the "Classpath" exception as provided
17
# by Sun in the GPL Version 2 section of the License file that
18
# accompanied this code. If applicable, add the following below the
19
# License Header, with the fields enclosed by brackets [] replaced by
20
# your own identifying information:
21
# "Portions Copyrighted [year] [name of copyright owner]"
22
# 
23
# If you wish your version of this file to be governed by only the CDDL
24
# or only the GPL Version 2, indicate your decision by adding
25
# "[Contributor] elects to include this software in this distribution
26
# under the [CDDL or GPL Version 2] license." If you do not indicate a
27
# single choice of license, a recipient has the option to distribute
28
# your version of this file under either the CDDL, the GPL Version 2 or
29
# to extend the choice of license to its licensees as provided above.
30
# However, if you add GPL Version 2 code and therefore, elected the GPL
31
# Version 2 license, then the option applies only if the new code is
32
# made subject to such option by the copyright holder.
33
# 
34
# Contributor(s):
35
# 
36
# Portions Copyrighted 2008 Sun Microsystems, Inc.
37
38
foo/29356=Ahoj
(-)a/core.startup/test/unit/src/org/netbeans/core/startup/layers/data/layer1.xml (+4 lines)
Lines 12-17 Link Here
12
            <attr name="a" methodvalue="org.netbeans.core.startup.layers.CacheManagerTestBaseHid.method"/>
12
            <attr name="a" methodvalue="org.netbeans.core.startup.layers.CacheManagerTestBaseHid.method"/>
13
            <attr name="map1" methodvalue="org.netbeans.core.startup.layers.CacheManagerTestBaseHid.map1"/>
13
            <attr name="map1" methodvalue="org.netbeans.core.startup.layers.CacheManagerTestBaseHid.map1"/>
14
            <attr name="map2" methodvalue="org.netbeans.core.startup.layers.CacheManagerTestBaseHid.map2"/>
14
            <attr name="map2" methodvalue="org.netbeans.core.startup.layers.CacheManagerTestBaseHid.map2"/>
15
            <attr name="mapImage" methodvalue="org.netbeans.core.startup.layers.CacheManagerTestBaseHid.mapImage"/>
16
            <attr name="mapDisplayName" methodvalue="org.netbeans.core.startup.layers.CacheManagerTestBaseHid.mapDisplayName"/>
17
            <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.core.startup.layers.TestBundle"/>
18
            <attr name="SystemFileSystem.icon" methodvalue="org.netbeans.core.startup.layers.CacheManagerTestBaseHid.icon"/>
15
        </file>
19
        </file>
16
    </folder>
20
    </folder>
17
    <folder name="baz">
21
    <folder name="baz">
(-)a/core.ui/nbproject/project.xml (-1 / +1 lines)
Lines 86-92 made subject to such option by the copyr Link Here
86
                    <build-prerequisite/>
86
                    <build-prerequisite/>
87
                    <compile-dependency/>
87
                    <compile-dependency/>
88
                    <run-dependency>
88
                    <run-dependency>
89
                        <specification-version>6.8</specification-version>
89
                        <specification-version>7.3</specification-version>
90
                    </run-dependency>
90
                    </run-dependency>
91
                </dependency>
91
                </dependency>
92
                <dependency>
92
                <dependency>
(-)a/core.ui/src/org/netbeans/core/ui/resources/layer.xml (-1 / +6 lines)
Lines 102-108 made subject to such option by the copyr Link Here
102
            <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.core.ui.resources.Bundle"/>
102
            <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.core.ui.resources.Bundle"/>
103
            <file name="org-openide-actions-CustomizeAction.instance"/>
103
            <file name="org-openide-actions-CustomizeAction.instance"/>
104
            <file name="org-netbeans-core-actions-HTMLViewAction.instance"/>
104
            <file name="org-netbeans-core-actions-HTMLViewAction.instance"/>
105
            <file name="org-netbeans-core-actions-LogAction.instance"/>	 
105
            <file name="org-netbeans-core-actions-LogAction.instance">
106
                <attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/>
107
                <attr name="noIconInMenu" boolvalue="true"/>
108
                <attr name="SystemFileSystem.icon" stringvalue="org/netbeans/core/resources/log-file.gif"/>
109
                <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.core.actions.Bundle"/>
110
            </file>
106
        </folder>        
111
        </folder>        
107
        
112
        
108
        <folder name="Tools">
113
        <folder name="Tools">
(-)a/java.hints.analyzer/nbproject/project.xml (-1 / +1 lines)
Lines 160-166 Link Here
160
                    <build-prerequisite/>
160
                    <build-prerequisite/>
161
                    <compile-dependency/>
161
                    <compile-dependency/>
162
                    <run-dependency>
162
                    <run-dependency>
163
                        <specification-version>6.16</specification-version>
163
                        <specification-version>6.23</specification-version>
164
                    </run-dependency>
164
                    </run-dependency>
165
                </dependency>
165
                </dependency>
166
            </module-dependencies>
166
            </module-dependencies>
(-)a/java.hints.analyzer/src/org/netbeans/modules/java/hints/analyzer/layer.xml (-1 / +5 lines)
Lines 47-53 made subject to such option by the copyr Link Here
47
            <file name="org-netbeans-modules-java-hints-analyzer-AnalyzeFolder.instance"/>
47
            <file name="org-netbeans-modules-java-hints-analyzer-AnalyzeFolder.instance"/>
48
        </folder>
48
        </folder>
49
        <folder name="Window">
49
        <folder name="Window">
50
            <file name="org-netbeans-modules-java-hints-analyzer-ui-AnalyzerAction.instance"/>
50
            <file name="org-netbeans-modules-java-hints-analyzer-ui-AnalyzerAction.instance">
51
                <attr name="instanceCreate" methodvalue="org.openide.windows.TopComponent.openAction"/>
52
                <attr name="component" methodvalue="org.netbeans.modules.java.hints.analyzer.ui.AnalyzerTopComponent.findInstance"/>
53
                <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.java.hints.analyzer.ui.Bundle"/>
54
            </file>
51
        </folder>
55
        </folder>
52
    </folder>
56
    </folder>
53
    <folder name="Menu">
57
    <folder name="Menu">
(-)a/java.hints.analyzer/src/org/netbeans/modules/java/hints/analyzer/ui/AnalyzerAction.java (-60 lines)
Removed Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
package org.netbeans.modules.java.hints.analyzer.ui;
40
41
import java.awt.event.ActionEvent;
42
import javax.swing.AbstractAction;
43
import org.openide.util.NbBundle;
44
import org.openide.windows.TopComponent;
45
46
/**
47
 * Action which shows Analyzer component.
48
 */
49
public class AnalyzerAction extends AbstractAction {
50
    public AnalyzerAction() {
51
        super(NbBundle.getMessage(AnalyzerAction.class, "CTL_AnalyzerAction"));
52
//        putValue(SMALL_ICON, new ImageIcon(Utilities.loadImage(AnalyzerTopComponent.ICON_PATH, true)));
53
    }
54
55
    public void actionPerformed(ActionEvent evt) {
56
        TopComponent win = AnalyzerTopComponent.findInstance();
57
        win.open();
58
        win.requestActive();
59
    }
60
}
(-)a/java.hints.analyzer/src/org/netbeans/modules/java/hints/analyzer/ui/Bundle.properties (+2 lines)
Lines 38-43 Link Here
38
# made subject to such option by the copyright holder.
38
# made subject to such option by the copyright holder.
39
39
40
CTL_AnalyzerAction=&Analyzer
40
CTL_AnalyzerAction=&Analyzer
41
Actions/Window/org-netbeans-modules-java-hints-analyzer-ui-AnalyzerAction.instance=&Analyzer
42
41
CTL_AnalyzerTopComponent=Analyzer Window
43
CTL_AnalyzerTopComponent=Analyzer Window
42
CTL_TaskListAction=Task List
44
CTL_TaskListAction=Task List
43
CTL_TaskListTopComponent=Task List
45
CTL_TaskListTopComponent=Task List
(-)a/o.n.core/src/org/netbeans/core/actions/Bundle.properties (+1 lines)
Lines 82-85 JumpPrevAction=&Previous Error Link Here
82
82
83
#LogAction
83
#LogAction
84
MSG_LogTab_name=IDE &Log File
84
MSG_LogTab_name=IDE &Log File
85
Actions/View/org-netbeans-core-actions-LogAction.instance=IDE &Log File
85
MSG_ShortLogTab_name=IDE Log File
86
MSG_ShortLogTab_name=IDE Log File
(-)a/openide.awt/nbproject/project.properties (-1 / +1 lines)
Lines 46-49 javadoc.arch=${basedir}/arch.xml Link Here
46
#javadoc.apichanges=${basedir}/api/apichanges.xml
46
#javadoc.apichanges=${basedir}/api/apichanges.xml
47
javadoc.apichanges=${basedir}/apichanges.xml
47
javadoc.apichanges=${basedir}/apichanges.xml
48
48
49
spec.version.base=7.2.0
49
spec.version.base=7.3.0
(-)a/openide.awt/nbproject/project.xml (+9 lines)
Lines 55-60 made subject to such option by the copyr Link Here
55
                    </run-dependency>
55
                    </run-dependency>
56
                </dependency>
56
                </dependency>
57
            </module-dependencies>
57
            </module-dependencies>
58
            <test-dependencies>
59
                <test-type>
60
                    <name>unit</name>
61
                    <test-dependency>
62
                        <code-name-base>org.openide.filesystems</code-name-base>
63
                        <compile-dependency/>
64
                    </test-dependency>
65
                </test-type>
66
            </test-dependencies>
58
            <public-packages>
67
            <public-packages>
59
                <package>org.openide.awt</package>
68
                <package>org.openide.awt</package>
60
            </public-packages>
69
            </public-packages>
(-)a/openide.awt/src/org/openide/awt/Actions.java (+43 lines)
Lines 66-71 import org.openide.util.Utilities; Link Here
66
import org.openide.util.Utilities;
66
import org.openide.util.Utilities;
67
import java.lang.ref.WeakReference;
67
import java.lang.ref.WeakReference;
68
import java.util.ArrayList;
68
import java.util.ArrayList;
69
import java.util.HashMap;
69
import java.util.Hashtable;
70
import java.util.Hashtable;
70
import java.util.Iterator;
71
import java.util.Iterator;
71
import java.util.Map;
72
import java.util.Map;
Lines 379-385 public class Actions extends Object { Link Here
379
380
380
        return result;
381
        return result;
381
    }
382
    }
383
    
384
    //
385
    // Factories 
386
    //
382
387
388
    
389
    /** Creates new action which is always enabled. 
390
     * This method can also be used from 
391
     * <a href="@org-openide-modules@/org/openide/modules/doc-files/api.html#how-layer">XML Layer</a> 
392
     * directly by following XML definition:
393
     * <pre>
394
     * &lt;file name="your-pkg-action-id.instance"&gt;
395
     *   &lt;attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/&gt;
396
     *   &lt;attr name="delegate" methodvalue="your.pkg.YourAction.factoryMethod"/&gt;
397
     *   &lt;attr name="SystemFileSystem.icon" stringvalue="your/pkg/YourComponent.png"/&gt;
398
     *   &lt;attr name="SystemFileSystem.localizingBundle" stringvalue="your.pkg.Bundle"/&gt;
399
     *   &lt;attr name="noIconInMenu" boolvalue="false"/&gt;
400
     * &lt;/file&gt;
401
     * </pre>
402
     *
403
     * 
404
     * @param delegate the task to perform when action is invoked
405
     * @param displayName the name of the action
406
     * @param iconBase the location to the actions icon
407
     * @param noIconInMenu true if this icon shall not have an item in menu
408
     * @since 7.3
409
     */
410
    public static Action alwaysEnabled(
411
        ActionListener delegate, String displayName, String iconBase, boolean noIconInMenu
412
    ) {
413
        HashMap<String,Object> map = new HashMap<String,Object>();
414
        map.put("delegate", delegate); // NOI18N
415
        map.put("displayName", displayName); // NOI18N
416
        map.put("iconBase", iconBase); // NOI18N
417
        map.put("noIconInMenu", noIconInMenu); // NOI18N
418
        return alwaysEnabled(map);
419
    }
420
    // for use from layers
421
    static Action alwaysEnabled(Map map) {
422
        return new AlwaysEnabledAction(map);
423
    }
424
425
    
383
    /** Extracts help from action.
426
    /** Extracts help from action.
384
     */
427
     */
385
    private static HelpCtx findHelp(Action a) {
428
    private static HelpCtx findHelp(Action a) {
(-)428419c1ab32 (+100 lines)
Added Link Here
1
package org.openide.awt;
2
3
import java.awt.EventQueue;
4
import java.awt.Image;
5
import java.awt.Toolkit;
6
import java.awt.event.ActionEvent;
7
import java.awt.event.ActionListener;
8
import java.net.URL;
9
import java.util.Map;
10
import javax.swing.AbstractAction;
11
import javax.swing.Action;
12
import javax.swing.Icon;
13
import javax.swing.KeyStroke;
14
import javax.swing.text.Keymap;
15
import org.openide.util.ImageUtilities;
16
import org.openide.util.Lookup;
17
18
/** Lazily initialized always enabled action
19
 *
20
 * @author Jaroslav Tulach <jtulach@netbeans.org>
21
 */
22
final class AlwaysEnabledAction extends AbstractAction {
23
24
    private Map map;
25
26
    public AlwaysEnabledAction(Map m) {
27
        super();
28
        this.map = m;
29
    }
30
31
    @Override
32
    public boolean isEnabled() {
33
        assert EventQueue.isDispatchThread();
34
        return true;
35
    }
36
37
    public void actionPerformed(ActionEvent e) {
38
        assert EventQueue.isDispatchThread();
39
        Object listener = map.get("delegate");
40
        if (!(listener instanceof ActionListener)) {
41
            throw new NullPointerException();
42
        }
43
        ((ActionListener) listener).actionPerformed(e);
44
    }
45
46
    @Override
47
    public Object getValue(String name) {
48
        return extractCommonAttribute(map, this, name);
49
    }
50
51
    static final Object extractCommonAttribute(Map fo, Action action, String name) {
52
        if (Action.NAME.equals(name)) {
53
            String actionName = (String) fo.get("displayName"); // NOI18N
54
            // NOI18N
55
            //return Actions.cutAmpersand(actionName);
56
            return actionName;
57
        }
58
        if (Action.MNEMONIC_KEY.equals(name)) {
59
            String actionName = (String) fo.get("displayName"); // NOI18N
60
            // NOI18N
61
            int position = Mnemonics.findMnemonicAmpersand(actionName);
62
63
            return position == -1 ? null : Character.valueOf(actionName.charAt(position + 1));
64
        }
65
        if (Action.SMALL_ICON.equals(name)) {
66
            Object icon = fo == null ? null : fo.get("iconBase"); // NOI18N
67
            if (icon instanceof Icon) {
68
                return (Icon) icon;
69
            }
70
            if (icon instanceof Image) {
71
                return ImageUtilities.image2Icon((Image)icon);
72
            }
73
            if (icon instanceof String) {
74
                return ImageUtilities.loadImage((String)icon);
75
            }
76
            if (icon instanceof URL) {
77
                return Toolkit.getDefaultToolkit().getImage((URL) icon);
78
            }
79
            Object image = fo.get("image"); // NOI18N
80
            if (image instanceof Image) {
81
                return ImageUtilities.image2Icon((Image)image);
82
            }
83
        }
84
        if ("iconBase".equals(name)) { // NOI18N
85
            return fo == null ? null : fo.get("iconBase"); // NOI18N
86
        }
87
        if ("noIconInMenu".equals(name)) { // NOI18N
88
            return fo == null ? null : fo.get("noIconInMenu"); // NOI18N
89
        }
90
        if (Action.ACCELERATOR_KEY.equals(name)) {
91
            Keymap map = Lookup.getDefault().lookup(Keymap.class);
92
            if (map != null) {
93
                KeyStroke[] arr = map.getKeyStrokesForAction(action);
94
                return arr.length > 0 ? arr[0] : null;
95
            }
96
        }
97
98
        return null;
99
    }
100
}
(-)428419c1ab32 (+3 lines)
Added Link Here
1
OpenIDE-Module: org.openide.awt.test
2
OpenIDE-Module-Layer: org/openide/awt/test-layer.xml
3
OpenIDE-Public-Packages: -
(-)428419c1ab32 (+136 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.openide.awt;
43
44
import java.awt.event.ActionListener;
45
import javax.swing.Action;
46
import org.netbeans.junit.NbTestCase;
47
import org.openide.filesystems.FileObject;
48
import org.openide.filesystems.FileSystem;
49
import org.openide.filesystems.Repository;
50
import org.openide.util.ContextAwareAction;
51
52
/**
53
 *
54
 * @author Jaroslav Tulach
55
 */
56
public class AlwaysEnabledActionTest extends NbTestCase {
57
    private FileObject folder;
58
    
59
    public AlwaysEnabledActionTest(String testName) {
60
        super(testName);
61
    }
62
    
63
    @Override
64
    protected void setUp() throws Exception {
65
        FileSystem fs = Repository.getDefault().getDefaultFileSystem();
66
        folder = fs.findResource("actions/support/test");
67
        assertNotNull("testing layer is loaded: ", folder);
68
    }
69
    
70
    @Override
71
    protected boolean runInEQ() {
72
        return true;
73
    }
74
    
75
    public void testIconIsCorrect() throws Exception {
76
        myListenerCounter = 0;
77
        myIconResourceCounter = 0;
78
        Action a = readAction("testIconIsCorrect.instance");
79
        
80
        assertNotNull("Action created", a);
81
        assertEquals("No myListener called", 0, myListenerCounter);
82
        assertEquals("No myIconURL called", 0, myIconResourceCounter);
83
        
84
        Object name = a.getValue(a.NAME);
85
        Object mnem = a.getValue(a.MNEMONIC_KEY);
86
        Object smallIcon = a.getValue(a.SMALL_ICON);
87
        //Object icon = a.getValue(a.ICON)
88
            
89
        assertEquals("Right localized name", "Icon &Name Action", name);
90
        assertEquals("Mnemonic is N", Character.valueOf('N'), mnem);
91
        assertNotNull("small icon present", smallIcon);
92
93
        assertEquals("once icon called", 1, myIconResourceCounter);
94
95
        
96
        Object base = a.getValue("iconBase"); 
97
        assertEquals("iconBase attribute is delegated", 2, myIconResourceCounter);
98
     
99
        assertTrue("Always enabled", a.isEnabled());
100
        a.setEnabled(false);
101
        assertTrue("Still Always enabled", a.isEnabled());
102
        
103
        
104
        assertEquals("No icon in menu", Boolean.TRUE, a.getValue("noIconInMenu"));
105
        
106
        if (a instanceof ContextAwareAction) {
107
            fail("Should not be context sensitive, otherwise it would have to implement equal correctly: " + a);
108
        }
109
    }
110
    
111
    private static int myListenerCounter;
112
    private static ActionListener myListener() {
113
        myListenerCounter++;
114
        return null;
115
    }
116
    private static int myIconResourceCounter;
117
    private static String myIconResource() {
118
        myIconResourceCounter++;
119
        return "/org/openide/awt/TestIcon.png";
120
    }
121
    
122
    
123
    private Action readAction(String fileName) throws Exception {
124
        FileObject fo = this.folder.getFileObject(fileName);
125
        assertNotNull("file " + fileName, fo);
126
        
127
        Object obj = fo.getAttribute("instanceCreate");
128
        assertNotNull("File object has not null instanceCreate attribute", obj);
129
        
130
        if (!(obj instanceof Action)) {
131
            fail("Object needs to be action: " + obj);
132
        }
133
        
134
        return (Action)obj;
135
    }
136
}
(-)428419c1ab32 (+43 lines)
Added Link Here
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
3
# Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
4
#
5
# The contents of this file are subject to the terms of either the GNU
6
# General Public License Version 2 only ("GPL") or the Common
7
# Development and Distribution License("CDDL") (collectively, the
8
# "License"). You may not use this file except in compliance with the
9
# License. You can obtain a copy of the License at
10
# http://www.netbeans.org/cddl-gplv2.html
11
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
12
# specific language governing permissions and limitations under the
13
# License.  When distributing the software, include this License Header
14
# Notice in each file and include the License file at
15
# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
16
# particular file as subject to the "Classpath" exception as provided
17
# by Sun in the GPL Version 2 section of the License file that
18
# accompanied this code. If applicable, add the following below the
19
# License Header, with the fields enclosed by brackets [] replaced by
20
# your own identifying information:
21
# "Portions Copyrighted [year] [name of copyright owner]"
22
#
23
# Contributor(s):
24
#
25
# The Original Software is NetBeans. The Initial Developer of the Original
26
# Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
27
# Microsystems, Inc. All Rights Reserved.
28
#
29
# If you wish your version of this file to be governed by only the CDDL
30
# or only the GPL Version 2, indicate your decision by adding
31
# "[Contributor] elects to include this software in this distribution
32
# under the [CDDL or GPL Version 2] license." If you do not indicate a
33
# single choice of license, a recipient has the option to distribute
34
# your version of this file under either the CDDL, the GPL Version 2 or
35
# to extend the choice of license to its licensees as provided above.
36
# However, if you add GPL Version 2 code and therefore, elected the GPL
37
# Version 2 license, then the option applies only if the new code is
38
# made subject to such option by the copyright holder.
39
40
41
actions/support/test/testIconIsCorrect.instance=Icon &Name Action
42
actions/support/test/testContext.instance=Open
43
(-)428419c1ab32 (+59 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
5
Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
7
8
The contents of this file are subject to the terms of either the GNU
9
General Public License Version 2 only ("GPL") or the Common
10
Development and Distribution License("CDDL") (collectively, the
11
"License"). You may not use this file except in compliance with the
12
License. You can obtain a copy of the License at
13
http://www.netbeans.org/cddl-gplv2.html
14
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
15
specific language governing permissions and limitations under the
16
License.  When distributing the software, include this License Header
17
Notice in each file and include the License file at
18
nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
19
particular file as subject to the "Classpath" exception as provided
20
by Sun in the GPL Version 2 section of the License file that
21
accompanied this code. If applicable, add the following below the
22
License Header, with the fields enclosed by brackets [] replaced by
23
your own identifying information:
24
"Portions Copyrighted [year] [name of copyright owner]"
25
26
Contributor(s):
27
28
The Original Software is NetBeans. The Initial Developer of the Original
29
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
30
Microsystems, Inc. All Rights Reserved.
31
32
If you wish your version of this file to be governed by only the CDDL
33
or only the GPL Version 2, indicate your decision by adding
34
"[Contributor] elects to include this software in this distribution
35
under the [CDDL or GPL Version 2] license." If you do not indicate a
36
single choice of license, a recipient has the option to distribute
37
your version of this file under either the CDDL, the GPL Version 2 or
38
to extend the choice of license to its licensees as provided above.
39
However, if you add GPL Version 2 code and therefore, elected the GPL
40
Version 2 license, then the option applies only if the new code is
41
made subject to such option by the copyright holder.
42
-->
43
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
44
45
<filesystem>
46
    <folder name="actions">
47
        <folder name="support">
48
            <folder name="test">
49
                <file name="testIconIsCorrect.instance">
50
                    <attr name='instanceCreate' methodvalue='org.openide.awt.Actions.alwaysEnabled'/>
51
                    <attr name='delegate' methodvalue='org.openide.awt.AlwaysEnabledActionTest.myListener'/>
52
                    <attr name='SystemFileSystem.localizingBundle' stringvalue='org.openide.awt.TestBundle'/>
53
                    <attr name='iconBase' methodvalue='org.openide.awt.AlwaysEnabledActionTest.myIconResource'/>
54
                    <attr name='noIconInMenu' boolvalue="true"/>
55
                </file>
56
            </folder>
57
        </folder>
58
    </folder> 
59
</filesystem>
(-)a/openide.filesystems/apichanges.xml (+17 lines)
Lines 46-51 made subject to such option by the copyr Link Here
46
        <apidef name="filesystems">Filesystems API</apidef>
46
        <apidef name="filesystems">Filesystems API</apidef>
47
    </apidefs>
47
    </apidefs>
48
    <changes> 	
48
    <changes> 	
49
        <change id="displayNameImage">
50
            <api name="filesystems"/>
51
            <summary>Attributes 'displayName' and 'image'</summary>
52
            <version major="7" minor="9"/>
53
            <date day="9" month="7" year="2008"/>
54
            <author login="jtulach"/>
55
            <compatibility addition="yes"/>
56
            <description>
57
                <p>
58
                    When using methodvalue in XML filesystem, one can add there
59
                    expect new values 'displayName' and 'image' available to methods
60
                    that accept <code>java.util.Map</code>.
61
                </p>
62
            </description>
63
            <class package="org.openide.filesystems" name="XMLFileSystem"/>
64
            <issue number="137709"/>
65
        </change>
49
        <change id="FileUtil.urlForArchiveOrDir.archiveOrDirForURL">
66
        <change id="FileUtil.urlForArchiveOrDir.archiveOrDirForURL">
50
            <api name="filesystems"/>
67
            <api name="filesystems"/>
51
            <summary>Added methods to interconvert URLs and traditional path entries</summary>
68
            <summary>Added methods to interconvert URLs and traditional path entries</summary>
(-)a/openide.filesystems/manifest.mf (-1 / +1 lines)
Lines 1-5 Manifest-Version: 1.0 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.filesystems
2
OpenIDE-Module: org.openide.filesystems
3
OpenIDE-Module-Specification-Version: 7.9
3
OpenIDE-Module-Specification-Version: 7.10
4
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
5
5
(-)a/openide.filesystems/src/org/openide/filesystems/XMLFileSystem.java (-1 / +4 lines)
Lines 146-152 import org.xml.sax.helpers.DefaultHandle Link Here
146
 * static Value methodName(Map<String,Object> attrs); // since 7.0
146
 * static Value methodName(Map<String,Object> attrs); // since 7.0
147
 * static Value methodName(Map<String,Object> attrs, String attrName); // since 7.0
147
 * static Value methodName(Map<String,Object> attrs, String attrName); // since 7.0
148
 * </pre>
148
 * </pre>
149
 * where <code>Value</code> can be any java type.
149
 * where <code>Value</code> can be any java type. Since version 7.9 the Map
150
 * attribute may also contain special values for keys <q>displayName</q> and
151
 * <q>image</q> representing display name of the {@link FileObject} and its image
152
 * respectively.
150
 *
153
 *
151
 *
154
 *
152
 * @author Radek Matous
155
 * @author Radek Matous
(-)a/openide.filesystems/src/org/openide/filesystems/XMLMapAttr.java (-3 / +50 lines)
Lines 40-45 Link Here
40
 */
40
 */
41
package org.openide.filesystems;
41
package org.openide.filesystems;
42
42
43
import java.awt.Toolkit;
43
import org.openide.util.SharedClassObject;
44
import org.openide.util.SharedClassObject;
44
import org.openide.util.Utilities;
45
import org.openide.util.Utilities;
45
import org.openide.util.io.NbMarshalledObject;
46
import org.openide.util.io.NbMarshalledObject;
Lines 53-58 import java.net.URL; Link Here
53
54
54
import java.util.*;
55
import java.util.*;
55
import org.openide.util.Exceptions;
56
import org.openide.util.Exceptions;
57
import org.openide.util.NbBundle;
56
58
57
59
58
/**
60
/**
Lines 338-343 final class XMLMapAttr implements Map { Link Here
338
        return map.containsValue(p1);
340
        return map.containsValue(p1);
339
    }
341
    }
340
342
343
    @Override
341
    public synchronized int hashCode() {
344
    public synchronized int hashCode() {
342
        return map.hashCode();
345
        return map.hashCode();
343
    }
346
    }
Lines 367-372 final class XMLMapAttr implements Map { Link Here
367
        return map.isEmpty();
370
        return map.isEmpty();
368
    }
371
    }
369
372
373
    @Override
370
    public synchronized boolean equals(Object p1) {
374
    public synchronized boolean equals(Object p1) {
371
        return map.equals(p1);
375
        return map.equals(p1);
372
    }
376
    }
Lines 982-987 final class XMLMapAttr implements Map { Link Here
982
            return index;
986
            return index;
983
        }
987
        }
984
988
989
        @Override
985
        public boolean equals(Object obj) {
990
        public boolean equals(Object obj) {
986
            if (obj instanceof Attr) {
991
            if (obj instanceof Attr) {
987
                Attr other = (Attr)obj;
992
                Attr other = (Attr)obj;
Lines 995-1000 final class XMLMapAttr implements Map { Link Here
995
            return false;
1000
            return false;
996
        }
1001
        }
997
1002
1003
        @Override
998
        public int hashCode() {
1004
        public int hashCode() {
999
            return 743 + keyIndex << 8 + value.hashCode();
1005
            return 743 + keyIndex << 8 + value.hashCode();
1000
        }
1006
        }
Lines 1140-1149 final class XMLMapAttr implements Map { Link Here
1140
            return fo.getAttribute(key);
1146
            return fo.getAttribute(key);
1141
        }
1147
        }
1142
1148
1149
        @Override
1143
        public Object remove(Object key) {
1150
        public Object remove(Object key) {
1144
            throw new UnsupportedOperationException();
1151
            throw new UnsupportedOperationException();
1145
        }
1152
        }
1146
1153
1154
        @Override
1147
        public Object put(String key, Object value) {
1155
        public Object put(String key, Object value) {
1148
            throw new UnsupportedOperationException();
1156
            throw new UnsupportedOperationException();
1149
        }
1157
        }
Lines 1158-1170 final class XMLMapAttr implements Map { Link Here
1158
        
1166
        
1159
        public Iterator<Map.Entry<String, Object>> iterator() {
1167
        public Iterator<Map.Entry<String, Object>> iterator() {
1160
            class Iter implements Iterator<Map.Entry<String, Object>> {
1168
            class Iter implements Iterator<Map.Entry<String, Object>> {
1169
                int fixed;
1161
                Enumeration<String> attrs = fo.getAttributes();
1170
                Enumeration<String> attrs = fo.getAttributes();
1162
                
1171
1163
                public boolean hasNext() {
1172
                public boolean hasNext() {
1164
                    return attrs.hasMoreElements();
1173
                    return fixed < 2 || attrs.hasMoreElements();
1165
                }
1174
                }
1166
                
1175
1167
                public Map.Entry<String, Object> next() {
1176
                public Map.Entry<String, Object> next() {
1177
                    if (fixed < 2) {
1178
                        return new LocEntry(fo, fixed++);
1179
                    }
1168
                    String s = attrs.nextElement();
1180
                    String s = attrs.nextElement();
1169
                    return new FOEntry(fo, s);
1181
                    return new FOEntry(fo, s);
1170
                }
1182
                }
Lines 1186-1191 final class XMLMapAttr implements Map { Link Here
1186
            return cnt;
1198
            return cnt;
1187
        }
1199
        }
1188
1200
1201
        @Override
1189
        public boolean remove(Object o) {
1202
        public boolean remove(Object o) {
1190
            throw new UnsupportedOperationException();
1203
            throw new UnsupportedOperationException();
1191
        }
1204
        }
Lines 1212-1215 final class XMLMapAttr implements Map { Link Here
1212
            throw new UnsupportedOperationException();
1225
            throw new UnsupportedOperationException();
1213
        }
1226
        }
1214
    } // end of FOEntry
1227
    } // end of FOEntry
1228
    private static final class LocEntry implements Map.Entry<String, Object> {
1229
        private FileObject fo;
1230
        private int type;
1231
1232
        private LocEntry(FileObject fo, int cnt) {
1233
            this.fo = fo;
1234
            this.type = cnt;
1235
        }
1236
1237
        public String getKey() {
1238
            return type == 0 ? "displayName" : "image"; // NOI18N
1239
        }
1240
1241
        public Object getValue() {
1242
            if (type == 0) {
1243
                String rb = (String) fo.getAttribute("SystemFileSystem.localizingBundle"); // NOI18N
1244
                if (rb == null) {
1245
                    return fo.getNameExt();
1246
                }
1247
                return NbBundle.getBundle(rb).getString(fo.getPath());
1248
            } else if (type == 1) {
1249
                URL u = (URL) fo.getAttribute("SystemFileSystem.icon"); // NOI18N
1250
                if (u != null) {
1251
                    return Toolkit.getDefaultToolkit().getImage(u);
1252
                }
1253
            } 
1254
            return null;
1255
        }
1256
        
1257
1258
        public Object setValue(Object value) {
1259
            throw new UnsupportedOperationException();
1260
        }
1261
    } // end of LocEntry
1215
}
1262
}
(-)a/openide.windows/apichanges.xml (+12 lines)
Lines 48-53 made subject to such option by the copyr Link Here
48
</apidefs>
48
</apidefs>
49
<changes>
49
<changes>
50
50
51
<change id="tc.open">
52
    <api name="winsys"/>
53
    <summary>TopComponent.openAction</summary>
54
    <version major="6" minor="24"/>
55
    <date day="8" month="7" year="2008"/>
56
    <author login="jtulach"/>
57
    <compatibility addition="yes" binary="compatible" source="compatible" semantic="compatible" deprecation="no" deletion="no" modification="no"/>
58
    <description>
59
        Adding new factory method that creates an action to open a <code>TopComponent</code>.
60
    </description>
61
    <issue number="136636"/>
62
</change>
51
<change id="winsys_customizations">
63
<change id="winsys_customizations">
52
    <api name="winsys"/>
64
    <api name="winsys"/>
53
    <summary>Added a group of resource bundle properties for customization
65
    <summary>Added a group of resource bundle properties for customization
(-)a/openide.windows/manifest.mf (-1 / +1 lines)
Lines 1-6 Manifest-Version: 1.0 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.windows
2
OpenIDE-Module: org.openide.windows
3
OpenIDE-Module-Specification-Version: 6.23
3
OpenIDE-Module-Specification-Version: 6.24
4
OpenIDE-Module-Localizing-Bundle: org/openide/windows/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/windows/Bundle.properties
5
AutoUpdate-Essential-Module: true
5
AutoUpdate-Essential-Module: true
6
6
(-)a/openide.windows/nbproject/project.xml (-15 / +15 lines)
Lines 47-53 made subject to such option by the copyr Link Here
47
            <code-name-base>org.openide.windows</code-name-base>
47
            <code-name-base>org.openide.windows</code-name-base>
48
            <module-dependencies>
48
            <module-dependencies>
49
                <dependency>
49
                <dependency>
50
                    <code-name-base>org.openide.util</code-name-base>
50
                    <code-name-base>org.openide.awt</code-name-base>
51
                    <build-prerequisite/>
51
                    <build-prerequisite/>
52
                    <compile-dependency/>
52
                    <compile-dependency/>
53
                    <run-dependency>
53
                    <run-dependency>
Lines 63-88 made subject to such option by the copyr Link Here
63
                    </run-dependency>
63
                    </run-dependency>
64
                </dependency>
64
                </dependency>
65
                <dependency>
65
                <dependency>
66
                    <code-name-base>org.openide.awt</code-name-base>
66
                    <code-name-base>org.openide.util</code-name-base>
67
                    <build-prerequisite/>
67
                    <build-prerequisite/>
68
                    <compile-dependency/>
68
                    <compile-dependency/>
69
                    <run-dependency>
69
                    <run-dependency>
70
                        <specification-version>6.2</specification-version>
70
                        <specification-version>7.15</specification-version>
71
                    </run-dependency>
71
                    </run-dependency>
72
                </dependency>
72
                </dependency>
73
            </module-dependencies>
73
            </module-dependencies>
74
          <test-dependencies>
74
            <test-dependencies>
75
              <test-type>
75
                <test-type>
76
                  <name>unit</name>
76
                    <name>unit</name>
77
                  <test-dependency>
77
                    <test-dependency>
78
                      <code-name-base>org.openide.windows</code-name-base>
78
                        <code-name-base>org.openide.windows</code-name-base>
79
                      <recursive/>
79
                        <recursive/>
80
                      <compile-dependency/>
80
                        <compile-dependency/>
81
                  </test-dependency>
81
                    </test-dependency>
82
              </test-type>
82
                </test-type>
83
              <test-type>
83
                <test-type>
84
                  <name>qa-functional</name>
84
                    <name>qa-functional</name>
85
              </test-type>
85
                </test-type>
86
            </test-dependencies>
86
            </test-dependencies>
87
            <public-packages>
87
            <public-packages>
88
                <package>org.openide.windows</package>
88
                <package>org.openide.windows</package>
(-)428419c1ab32 (+87 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.openide.windows;
41
42
import java.awt.EventQueue;
43
import java.awt.Image;
44
import java.awt.event.ActionEvent;
45
import java.util.Map;
46
import javax.swing.AbstractAction;
47
48
import org.openide.util.ImageUtilities;
49
50
/** Opens a top component.
51
 *
52
 * @author Jaroslav Tulach
53
 */
54
final class OpenComponentAction extends AbstractAction {
55
    private TopComponent component;
56
    private final Map<?,?> map;
57
58
    OpenComponentAction(TopComponent component, String displayName, Image image) {
59
        super(displayName);
60
        this.component = component;
61
        putValue(SMALL_ICON, ImageUtilities.image2Icon(image));
62
        map = null;
63
    }
64
    
65
    OpenComponentAction(Map<?,?> map) {
66
        super((String)map.get("displayName")); // NOI18N
67
        this.map = map;
68
        Image image = (Image)map.get("image"); // NOI18N
69
        if (image != null) {
70
            putValue(SMALL_ICON, ImageUtilities.image2Icon(image));
71
        }
72
    }
73
    
74
    private TopComponent getTopComponent() {
75
        assert EventQueue.isDispatchThread();
76
        if (component != null) {
77
            return component;
78
        }
79
        return component = (TopComponent)map.get("component"); // NOI18N
80
    }
81
82
    public void actionPerformed(ActionEvent e) {
83
        TopComponent win = getTopComponent();
84
        win.open();
85
        win.requestActive();
86
    }
87
}
(-)a/openide.windows/src/org/openide/windows/TopComponent.java (+27 lines)
Lines 65-70 import java.util.Arrays; Link Here
65
import java.util.Arrays;
65
import java.util.Arrays;
66
import java.util.Collection;
66
import java.util.Collection;
67
import java.util.List;
67
import java.util.List;
68
import java.util.Map;
68
import java.util.Set;
69
import java.util.Set;
69
import java.util.logging.Level;
70
import java.util.logging.Level;
70
import java.util.logging.LogRecord;
71
import java.util.logging.LogRecord;
Lines 535-540 public class TopComponent extends JCompo Link Here
535
        } else {
536
        } else {
536
            return actions;
537
            return actions;
537
        }
538
        }
539
    }
540
    
541
    /** Creates an action that opens and activates given <code>TopComponent</code>,
542
     * when invoked. This method can also be used from 
543
     * <a href="@org-openide-modules@/org/openide/modules/doc-files/api.html#how-layer">XML Layer</a> 
544
     * directly by following XML definition:
545
     * <pre>
546
     * &lt;file name="your-pkg-action-id.instance"&gt;
547
     *   &lt;attr name="instanceCreate" methodvalue="org.openide.windows.TopComponent.openAction"/&gt;
548
     *   &lt;attr name="component" methodvalue="your.pkg.YourComponent.factoryMethod"/&gt;
549
     *   &lt;attr name="SystemFileSystem.icon" stringvalue="your/pkg/YourComponent.png"/&gt;
550
     *   &lt;attr name="SystemFileSystem.localizingBundle" stringvalue="your/pkg/Bundle"/&gt;
551
     * &lt;/file&gt;
552
     * </pre>
553
     * 
554
     * @param component the component to open
555
     * @param displayName the display name of the action
556
     * @param image the image to associated with the action
557
     * 
558
     * @since 6.24
559
     */
560
    public static Action openAction(TopComponent component, String displayName, Image image) {
561
        return new OpenComponentAction(component, displayName, image);
562
    }
563
    static Action openAction(Map map) {
564
        return new OpenComponentAction(map);
538
    }
565
    }
539
566
540
    /** Set the close mode for the component.
567
    /** Set the close mode for the component.
(-)428419c1ab32 (+160 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.openide.windows;
41
42
import java.awt.Image;
43
import java.awt.event.ActionEvent;
44
import java.awt.image.BufferedImage;
45
import java.util.HashMap;
46
import java.util.Map;
47
import javax.swing.Action;
48
import javax.swing.Icon;
49
import org.netbeans.junit.NbTestCase;
50
51
/**
52
 *
53
 * @author Jaroslav Tulach
54
 */
55
public class OpenComponentActionTest extends NbTestCase {
56
    
57
    public OpenComponentActionTest(String testName) {
58
        super(testName);
59
    }
60
61
    @Override
62
    protected boolean runInEQ() {
63
        return true;
64
    }
65
    
66
    
67
68
    @Override
69
    protected void setUp() throws Exception {
70
        super.setUp();
71
        
72
        TC.instance = null;
73
    }
74
75
    @Override
76
    protected void tearDown() throws Exception {
77
        super.tearDown();
78
    }
79
80
    public void testMethodCallDirectly() {
81
        ActionEvent e = new ActionEvent(this, 0, "");
82
        TC tc = new TC();
83
        Image img = new BufferedImage(133, 133, BufferedImage.TYPE_INT_ARGB);
84
        Action instance = TopComponent.openAction(tc, "Ahoj", img);
85
        instance.actionPerformed(e);
86
        
87
        tc.close();
88
        
89
        assertEquals("Opened once", 1, tc.cntOpen);
90
        assertEquals("Activated once", 1, tc.cntRequest);
91
        
92
        Icon icon = (Icon) instance.getValue(Action.SMALL_ICON);
93
        assertEquals("Width", 133, icon.getIconWidth());
94
        assertEquals("Height", 133, icon.getIconHeight());
95
        assertEquals("Name", "Ahoj", instance.getValue(Action.NAME));
96
    }
97
98
    public void testMapInstantiation() {
99
        final Image img = new BufferedImage(133, 133, BufferedImage.TYPE_INT_ARGB);
100
        
101
        Map<String,Object> m = new HashMap<String,Object>() {
102
            @Override
103
            public Object get(Object key) {
104
                if ("component".equals(key)) {
105
                    return new TC();
106
                }
107
                if ("displayName".equals(key)) {
108
                    return "Ahoj";
109
                }
110
                if ("image".equals(key)) {
111
                    return img;
112
                }
113
                return null;
114
            }
115
        };
116
        
117
        ActionEvent e = new ActionEvent(this, 0, "");
118
        Action instance = TopComponent.openAction(m);
119
        
120
        assertNull("No instance yet", TC.instance);
121
        instance.actionPerformed(e);
122
        
123
        assertNotNull("Instance created", TC.instance);
124
        TC tc = TC.instance;
125
        tc.close();
126
        
127
        assertEquals("Opened once", 1, tc.cntOpen);
128
        assertEquals("Activated once", 1, tc.cntRequest);
129
        
130
        Icon icon = (Icon) instance.getValue(Action.SMALL_ICON);
131
        assertEquals("Width", 133, icon.getIconWidth());
132
        assertEquals("Height", 133, icon.getIconHeight());
133
        assertEquals("Name", "Ahoj", instance.getValue(Action.NAME));
134
    }
135
136
    
137
    public static final class TC extends TopComponent {
138
        static TC instance;
139
140
        int cntOpen;
141
        int cntRequest;
142
        
143
        public TC() {
144
            assertNull("No previous one", instance);
145
            instance = this;
146
        }
147
148
        @Override
149
        public void open() {
150
            super.open();
151
            cntOpen++;
152
        }
153
154
        @Override
155
        public void requestActive() {
156
            super.requestActive();
157
            cntRequest++;
158
        }
159
    }
160
}

Return to bug 137709