KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xam > ui > customizer > FolderNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.xam.ui.customizer;
21
22 import java.awt.Image JavaDoc;
23 import org.openide.filesystems.FileObject;
24 import org.openide.filesystems.Repository;
25 import org.openide.loaders.DataObject;
26 import org.openide.loaders.DataObjectNotFoundException;
27 import org.openide.nodes.AbstractNode;
28 import org.openide.nodes.Children;
29 import org.openide.nodes.Node;
30 import org.openide.util.NbBundle;
31
32 /**
33  * An abstract node that uses a file folder icon. Ideally the icon is
34  * taken from the Node delegate of DataFolder, if it is available.
35  * Otherwise a default icon is used.
36  *
37  * @author Nathan Fiedler
38  */

39 public class FolderNode extends AbstractNode {
40     /** The source for our folder icons. */
41     private static Node iconSource;
42
43     static {
44         FileObject fobj = Repository.getDefault().getDefaultFileSystem().getRoot();
45         try {
46             DataObject dobj = DataObject.find(fobj);
47             iconSource = dobj.getNodeDelegate();
48         } catch (DataObjectNotFoundException donfe) {
49             // In this case, we have our default icons, which are not
50
// platform-conformant, but they are better than nothing.
51
}
52     }
53
54     public FolderNode(Children children) {
55         super(children);
56     }
57
58     public Image JavaDoc getIcon(int type) {
59         if (iconSource != null) {
60             return iconSource.getIcon(type);
61         } else {
62             String JavaDoc url = NbBundle.getMessage(FolderNode.class,
63                     "IMG_FolderNode_Closed");
64             return org.openide.util.Utilities.loadImage(url);
65         }
66     }
67
68     public Image JavaDoc getOpenedIcon(int type) {
69         if (iconSource != null) {
70             return iconSource.getOpenedIcon(type);
71         } else {
72             String JavaDoc url = NbBundle.getMessage(FolderNode.class,
73                     "IMG_FolderNode_Opened");
74             return org.openide.util.Utilities.loadImage(url);
75         }
76     }
77 }
78
Popular Tags