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

(-)projectapi/apichanges.xml (+17 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
        <change id="ProjectIconAnnotator">
111
            <api name="general"/>
112
            <summary>Added <code>ProjectIconAnnotator</code></summary>
113
            <version major="1" minor="33"/>
114
            <date day="22" month="6" year="2010"/>
115
            <author login="jbecicka"/>
116
            <compatibility addition="yes" />
117
            <description>
118
                <p>
119
                    A mechanism for changing the project node icon.
120
                    You can use it for example to add a badge to the project's icon.
121
                </p>
122
            </description>
123
            <class package="org.netbeans.spi.project" name="ProjectIconAnnotator"/>
124
            <issue number="171516"/>
125
        </change>
126
110
        <change id="MoveOrRenameOperationImplementation">
127
        <change id="MoveOrRenameOperationImplementation">
111
            <api name="general"/>
128
            <api name="general"/>
112
            <summary>Added <code>MoveOrRenameOperationImplementation</code></summary>
129
            <summary>Added <code>MoveOrRenameOperationImplementation</code></summary>
(-)projectapi/manifest.mf (-1 / +1 lines)
Lines 1-7 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.projectapi/1
2
OpenIDE-Module: org.netbeans.modules.projectapi/1
3
OpenIDE-Module-Install: org/netbeans/modules/projectapi/Installer.class
3
OpenIDE-Module-Install: org/netbeans/modules/projectapi/Installer.class
4
OpenIDE-Module-Specification-Version: 1.32
4
OpenIDE-Module-Specification-Version: 1.33
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties
6
OpenIDE-Module-Layer: org/netbeans/modules/projectapi/layer.xml
6
OpenIDE-Module-Layer: org/netbeans/modules/projectapi/layer.xml
7
7
(-)projectapi/src/org/netbeans/api/project/ProjectUtils.java (-4 / +70 lines)
Lines 44-50 Link Here
44
44
45
package org.netbeans.api.project;
45
package org.netbeans.api.project;
46
46
47
import java.beans.PropertyChangeEvent;
48
import org.netbeans.spi.project.ProjectIconAnnotator;
49
import java.awt.Image;
47
import java.beans.PropertyChangeListener;
50
import java.beans.PropertyChangeListener;
51
import java.beans.PropertyChangeSupport;
48
import java.io.IOException;
52
import java.io.IOException;
49
import java.util.HashMap;
53
import java.util.HashMap;
50
import java.util.Map;
54
import java.util.Map;
Lines 64-71 Link Here
64
import org.openide.filesystems.FileStateInvalidException;
68
import org.openide.filesystems.FileStateInvalidException;
65
import org.openide.filesystems.FileUtil;
69
import org.openide.filesystems.FileUtil;
66
import org.openide.util.ImageUtilities;
70
import org.openide.util.ImageUtilities;
71
import org.openide.util.Lookup;
67
import org.openide.util.Mutex;
72
import org.openide.util.Mutex;
68
import org.openide.util.Parameters;
73
import org.openide.util.Parameters;
74
import org.openide.util.WeakListeners;
69
75
70
/**
76
/**
71
 * Utility methods to get information about {@link Project}s.
77
 * Utility methods to get information about {@link Project}s.
Lines 87-97 Link Here
87
     */
93
     */
88
    public static ProjectInformation getInformation(Project p) {
94
    public static ProjectInformation getInformation(Project p) {
89
        ProjectInformation pi = p.getLookup().lookup(ProjectInformation.class);
95
        ProjectInformation pi = p.getLookup().lookup(ProjectInformation.class);
90
        if (pi != null) {
96
        if (pi == null) {
91
            return pi;
97
            pi = new BasicInformation(p);
92
        } else {
93
            return new BasicInformation(p);
94
        }
98
        }
99
        ProjectInformation retVal = new AnnotateIconProxyProjectInformation(p, pi);
100
        return retVal;
95
    }
101
    }
96
    
102
    
97
    /**
103
    /**
Lines 254-259 Link Here
254
        
260
        
255
    }
261
    }
256
    
262
    
263
    private static final class AnnotateIconProxyProjectInformation implements ProjectInformation {
264
265
        private final ProjectInformation pinfo;
266
        private final Icon icon;
267
        private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
268
        private final PropertyChangeListener listener = new PropertyChangeListener() {
269
270
            @Override
271
            public void propertyChange(PropertyChangeEvent evt) {
272
                pcs.firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue());
273
            }
274
        };
275
276
        public AnnotateIconProxyProjectInformation(Project p, ProjectInformation pi) {
277
            this.pinfo = pi;
278
            this.pinfo.addPropertyChangeListener(WeakListeners.propertyChange(listener, pinfo));
279
            if (pi.getIcon() != null) {
280
                Image _icon = ImageUtilities.icon2Image(pi.getIcon());
281
                for (ProjectIconAnnotator pa : Lookup.getDefault().lookupAll(ProjectIconAnnotator.class)) {
282
                    _icon = pa.annotateIcon(p, _icon, false);
283
                }
284
                icon = ImageUtilities.image2Icon(_icon);
285
            } else {
286
                icon = null;
287
            }
288
        }
289
290
        @Override
291
        public String getName() {
292
            return pinfo.getName();
293
        }
294
295
        @Override
296
        public String getDisplayName() {
297
            return pinfo.getDisplayName();
298
        }
299
300
        @Override
301
        public Icon getIcon() {
302
            return icon;
303
        }
304
305
        @Override
306
        public Project getProject() {
307
            return pinfo.getProject();
308
        }
309
310
        @Override
311
        public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
312
            pcs.addPropertyChangeListener(listener);
313
        }
314
315
        @Override
316
        public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
317
            pcs.removePropertyChangeListener(listener);
318
        }
319
320
    }
321
322
    
257
    /**
323
    /**
258
     * Find a way of storing extra configuration in a project.
324
     * Find a way of storing extra configuration in a project.
259
     * If the project's {@linkplain Project#getLookup lookup} does not provide an instance,
325
     * If the project's {@linkplain Project#getLookup lookup} does not provide an instance,
(-)projectapi/src/org/netbeans/spi/project/ProjectIconAnnotator.java (+89 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.spi.project;
46
47
import java.awt.Image;
48
import org.netbeans.api.project.Project;
49
50
/**
51
 * <p>The interface provides a mechanism for changing the project node icon.
52
 * You can use it for example to add a badge to the project's icon. Class implementing this
53
 * interface should be registered using {@link org.openide.util.lookup.ServiceProvider}.</p>
54
 * <pre>
55
 * &#64;ServiceProvider(service=ProjectIconAnnotator.class)
56
 * public class SampleProjectIconAnnotator implements ProjectIconAnnotator {
57
 *
58
 *   private static final Image badgeOpened = ImageUtilities.loadImage("org/samplepath/opened-badge.png");
59
 *   private static final Image badgeClosed = ImageUtilities.loadImage("org/samplepath/closed-badge.png");
60
 *   private static final String tooltip = "Sample tooltip."
61
 *
62
 *   Image annotateIcon(Project p, Image original, boolean openedNode) {
63
 *       original = ImageUtilities.addToolTipToImage(original, tooltip);
64
 *       if (openedNode) {
65
 *           original = ImageUtilities.mergeImages(original, badgeOpened, 16, 0);
66
 *       } else {
67
 *           original = ImageUtilities.mergeImages(original, badgeClosed, 16, 0);
68
 *       }
69
 *       return original;
70
 *   }
71
 *
72
 * }
73
 * </pre>
74
 * @author petrdvorak
75
 * @since 1.33
76
 */
77
public interface ProjectIconAnnotator {
78
79
    /**
80
     * Returns image representing annotated project icon. Return {@code original} if you do not
81
     * intend to change the original icon (i.e. you just add a tooltip to the image).
82
     * @param p Project whose icon is to be annotated
83
     * @param original Image with the original icon
84
     * @param openedNode Flag indicating if the node that uses the icon is in opened state or not
85
     * @return Annotated project icon
86
     */
87
    public Image annotateIcon(Project p, Image original, boolean openedNode);
88
89
}
(-)projectapi/test/unit/src/org/netbeans/api/project/ProjectIconAnnotatorTest.java (+116 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.api.project;
46
47
import java.io.IOException;
48
import org.netbeans.spi.project.ProjectIconAnnotator;
49
import java.awt.Image;
50
import javax.swing.Icon;
51
import org.junit.Test;
52
import org.netbeans.junit.NbTestCase;
53
import org.openide.filesystems.FileObject;
54
import org.openide.util.ImageUtilities;
55
import org.openide.util.test.MockLookup;
56
57
/**
58
 *
59
 * @author petrdvorak
60
 */
61
public class ProjectIconAnnotatorTest extends NbTestCase {
62
63
    public ProjectIconAnnotatorTest() {
64
        super("== ProjectIconAnnotatorTest ==");
65
    }
66
67
    final static Image icon1 = ImageUtilities.loadImage("org/netbeans/api/project/resources/icon-1.png");
68
69
    private FileObject scratch;
70
    private FileObject goodproject;
71
    private ProjectManager pm;
72
73
    @Override
74
    protected void setUp() throws Exception {
75
        super.setUp();
76
        scratch = TestUtil.makeScratchDir(this);
77
        goodproject = scratch.createFolder("good");
78
        goodproject.createFolder("testproject");
79
        MockLookup.setInstances(TestUtil.testProjectFactory(), new ProjectIconAnnotatorImpl());
80
        pm = ProjectManager.getDefault();
81
        pm.reset();
82
83
    }
84
85
    @Override
86
    protected void tearDown() throws Exception {
87
        scratch = null;
88
        goodproject = null;
89
        pm = null;
90
        super.tearDown();
91
    }
92
93
94
    /**
95
     * Test of annotateIcon method, of class ProjectIconAnnotator.
96
     */
97
    @Test
98
    public void testAnnotateIcon() throws IOException {
99
        Project p = pm.findProject(goodproject);
100
        ProjectInformation pi = ProjectUtils.getInformation(p);
101
        Icon img = pi.getIcon();
102
        assertEquals("Annotated image height should be 8", img.getIconHeight(), 8);
103
        assertEquals("Annotated image width should be 8", img.getIconWidth(), 8);
104
    }
105
106
    public static final class ProjectIconAnnotatorImpl implements ProjectIconAnnotator {
107
108
        public ProjectIconAnnotatorImpl() {
109
        }
110
111
        public Image annotateIcon(Project p, Image original, boolean openedNode) {
112
            return icon1;
113
        }
114
    }
115
116
}
(-)projectui/nbproject/project.xml (-1 / +1 lines)
Lines 91-97 Link Here
91
                    <compile-dependency/>
91
                    <compile-dependency/>
92
                    <run-dependency>
92
                    <run-dependency>
93
                        <release-version>1</release-version>
93
                        <release-version>1</release-version>
94
                        <specification-version>1.17</specification-version>
94
                        <specification-version>1.33</specification-version>
95
                    </run-dependency>
95
                    </run-dependency>
96
                </dependency>
96
                </dependency>
97
                <dependency>
97
                <dependency>
(-)projectui/src/org/netbeans/modules/project/ui/ProjectsRootNode.java (+13 lines)
Lines 72-77 Link Here
72
import javax.swing.event.ChangeListener;
72
import javax.swing.event.ChangeListener;
73
import org.netbeans.api.project.FileOwnerQuery;
73
import org.netbeans.api.project.FileOwnerQuery;
74
import org.netbeans.api.project.Project;
74
import org.netbeans.api.project.Project;
75
import org.netbeans.spi.project.ProjectIconAnnotator;
75
import org.netbeans.api.project.ProjectManager;
76
import org.netbeans.api.project.ProjectManager;
76
import org.netbeans.api.project.ProjectUtils;
77
import org.netbeans.api.project.ProjectUtils;
77
import org.netbeans.api.project.SourceGroup;
78
import org.netbeans.api.project.SourceGroup;
Lines 772-778 Link Here
772
                } catch (FileStateInvalidException e) {
773
                } catch (FileStateInvalidException e) {
773
                    LOG.log(Level.INFO, null, e);
774
                    LOG.log(Level.INFO, null, e);
774
                }
775
                }
776
                Project p = getLookup().lookup(Project.class);
777
                if (p != null) {
778
                    for (ProjectIconAnnotator pa : Lookup.getDefault().lookupAll(ProjectIconAnnotator.class)) {
779
                        img = pa.annotateIcon(p, img, false);
775
            }
780
            }
781
                }
782
            }
776
783
777
            return img;
784
            return img;
778
        }
785
        }
Lines 787-793 Link Here
787
                } catch (FileStateInvalidException e) {
794
                } catch (FileStateInvalidException e) {
788
                    LOG.log(Level.INFO, null, e);
795
                    LOG.log(Level.INFO, null, e);
789
                }
796
                }
797
                Project p = getLookup().lookup(Project.class);
798
                if (p != null) {
799
                    for (ProjectIconAnnotator pa : Lookup.getDefault().lookupAll(ProjectIconAnnotator.class)) {
800
                        img = pa.annotateIcon(p, img, true);
790
            }
801
            }
802
                }
803
            }
791
804
792
            return img;
805
            return img;
793
        }
806
        }
(-)projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectRootNodeIconTest.java (+173 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.modules.project.ui;
46
47
import java.awt.Graphics;
48
import java.awt.Image;
49
import java.awt.image.ImageObserver;
50
import java.awt.image.ImageProducer;
51
import java.beans.BeanInfo;
52
import java.io.IOException;
53
import java.util.Arrays;
54
import java.util.Collection;
55
import java.util.HashSet;
56
import java.util.Set;
57
import java.util.TreeSet;
58
import org.netbeans.api.project.Project;
59
import org.netbeans.spi.project.ProjectIconAnnotator;
60
import org.netbeans.junit.MockServices;
61
import org.netbeans.junit.NbTestCase;
62
import org.netbeans.modules.project.ui.actions.TestSupport.TestProject;
63
import org.openide.filesystems.FileObject;
64
import org.openide.filesystems.FileStatusEvent;
65
import org.openide.filesystems.FileSystem;
66
import org.openide.filesystems.FileSystem.HtmlStatus;
67
import org.openide.filesystems.FileUtil;
68
import org.openide.filesystems.MultiFileSystem;
69
import org.openide.nodes.AbstractNode;
70
import org.openide.nodes.Children;
71
import org.openide.util.ImageUtilities;
72
import org.openide.util.Lookup;
73
import org.openide.util.lookup.Lookups;
74
75
/**
76
 *
77
 * @author petrdvorak
78
 */
79
public class ProjectRootNodeIconTest extends NbTestCase {
80
81
    public ProjectRootNodeIconTest() {
82
        super("ProjectRootNodeIconTest");
83
    }
84
85
    final static Image icon1 = ImageUtilities.loadImage("org/netbeans/modules/project/ui/resources/icon-1.png");
86
    final static Image icon2 = ImageUtilities.loadImage("org/netbeans/modules/project/ui/resources/icon-2.png");
87
    final static Image icon3 = ImageUtilities.loadImage("org/netbeans/modules/project/ui/resources/icon-3.png");
88
89
    @Override
90
    protected void setUp() throws Exception {
91
    }
92
93
    @Override
94
    protected void tearDown() throws Exception {
95
        super.tearDown();
96
    }
97
98
    public void testIconAnnotated() throws IOException, Exception {
99
        class BadgedImage extends Image {
100
            final Image original;
101
            BadgedImage(Image original) {this.original = original;}
102
            public @Override int getWidth(ImageObserver observer) {return original.getWidth(observer);}
103
            public @Override int getHeight(ImageObserver observer) {return original.getHeight(observer);}
104
            public @Override ImageProducer getSource() {return original.getSource();}
105
            public @Override Graphics getGraphics() {return original.getGraphics();}
106
            public @Override Object getProperty(String name, ImageObserver observer) {return original.getProperty(name, observer);}
107
            public @Override void flush() {original.flush();}
108
        }
109
        class TestFS extends MultiFileSystem {
110
            String nameBadge = "";
111
            String htmlBadge = "";
112
            boolean badging;
113
            Set<? extends FileObject> badgedFiles;
114
            TestFS() throws Exception {
115
                super(new FileSystem[] {FileUtil.createMemoryFileSystem()});
116
            }
117
            public @Override Status getStatus() {
118
                return new HtmlStatus() {
119
                    public String annotateName(String name, Set<? extends FileObject> files) {
120
                        badgedFiles = files;
121
                        return name + nameBadge;
122
                    }
123
                    public String annotateNameHtml(String name, Set<? extends FileObject> files) {
124
                        badgedFiles = files;
125
                        return name + htmlBadge;
126
                    }
127
                    public Image annotateIcon(Image icon, int iconType, Set<? extends FileObject> files) {
128
                        badgedFiles = files;
129
                        return badging ? new BadgedImage(icon) : icon;
130
                    }
131
                };
132
            }
133
            void fireChange(boolean icon, boolean name, FileObject... files) {
134
                fireFileStatusChanged(new FileStatusEvent(this, new HashSet<FileObject>(Arrays.asList(files)), icon, name));
135
            }
136
        }
137
        TestFS fs = new TestFS();
138
        FileObject root = fs.getRoot();
139
        Project prj = new TestProject(root, null);
140
        assertNotNull(prj);
141
        MockServices.setServices(ProjectIconAnnotatorImpl.class);
142
        Collection<? extends ProjectIconAnnotator> lookupAll = Lookup.getDefault().lookupAll(ProjectIconAnnotator.class);
143
        System.setProperty("test.nodelay", "true");
144
        ProjectsRootNode.BadgingNode node = new ProjectsRootNode.BadgingNode(null, new ProjectsRootNode.ProjectChildren.Pair(prj),
145
                new AbstractNode(Children.LEAF, Lookups.singleton(prj)) {
146
                    public @Override String getDisplayName() {return "Prj";}
147
                    public @Override String getHtmlDisplayName() {return "Prj";}
148
                }, false, true);
149
        Set<FileObject> fos = new TreeSet<FileObject>();
150
        fos.add(prj.getProjectDirectory());
151
        node.setFiles(fos);
152
        Image img = node.getIcon(BeanInfo.ICON_COLOR_16x16);
153
        assertTrue("Icon is not the same as 'icon3'", img.equals(icon3));
154
        assertFalse("Icon is the same as 'icon2'", img.equals(icon2));
155
        img = node.getOpenedIcon(BeanInfo.ICON_COLOR_16x16);
156
        assertTrue("Icon is not the same as 'icon2'", img.equals(icon2));
157
        assertFalse("Icon is the same as 'icon3'", img.equals(icon3));
158
    }
159
160
    public static final class ProjectIconAnnotatorImpl implements ProjectIconAnnotator {
161
162
        public ProjectIconAnnotatorImpl() {
163
        }
164
165
        public Image annotateIcon(Project p, Image original, boolean openedNode) {
166
            if (openedNode)
167
                return icon2;
168
            else
169
                return icon3;
170
        }
171
    }
172
173
}

Return to bug 171516