KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > retouche > navigation > Icons


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.retouche.navigation;
20
21 import java.awt.Image JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
26 import javax.swing.Icon JavaDoc;
27 import javax.swing.ImageIcon JavaDoc;
28 import org.netbeans.api.gsf.ElementKind;
29 import org.netbeans.api.gsf.Modifier;
30 import org.openide.util.Utilities;
31
32
33 /**
34  * This file is originally from Retouche, the Java Support
35  * infrastructure in NetBeans. I have modified the file as little
36  * as possible to make merging Retouche fixes back as simple as
37  * possible.
38  *
39  * @todo Perhaps include icons from http://xdesign-tools.czech.sun.com/visualdesign/prehled/index.html
40  * @author phrebejk
41  */

42 public final class Icons {
43     private static final String JavaDoc ICON_BASE = "org/netbeans/modules/retouche/source/resources/icons/";
44     private static final String JavaDoc GIF_EXTENSION = ".gif";
45     private static final String JavaDoc PNG_EXTENSION = ".png";
46     private static final String JavaDoc WAIT = ICON_BASE + "wait" + PNG_EXTENSION;
47     private static final Map JavaDoc<String JavaDoc, Icon JavaDoc> icons = new HashMap JavaDoc<String JavaDoc, Icon JavaDoc>();
48
49     /** Creates a new instance of Icons */
50     private Icons() {
51     }
52
53     public static Icon JavaDoc getBusyIcon() {
54         Image JavaDoc img = Utilities.loadImage(WAIT);
55
56         if (img == null) {
57             return null;
58         } else {
59             return new ImageIcon JavaDoc(img);
60         }
61     }
62
63     public static Icon JavaDoc getMethodIcon() {
64         // TODO - consider modifiers
65
Image JavaDoc img =
66             Utilities.loadImage(ICON_BASE + "method" + "Public" + PNG_EXTENSION);
67
68         if (img == null) {
69             return null;
70         } else {
71             return new ImageIcon JavaDoc(img);
72         }
73     }
74
75     public static Icon JavaDoc getFieldIcon() {
76         // TODO - consider modifiers
77
Image JavaDoc img =
78             Utilities.loadImage(ICON_BASE + "field" + "Public" + PNG_EXTENSION);
79
80         if (img == null) {
81             return null;
82         } else {
83             return new ImageIcon JavaDoc(img);
84         }
85     }
86
87     public static Icon JavaDoc getClassIcon() {
88         Image JavaDoc img = Utilities.loadImage(ICON_BASE + "class" + PNG_EXTENSION);
89
90         if (img == null) {
91             return null;
92         } else {
93             return new ImageIcon JavaDoc(img);
94         }
95     }
96
97     public static Icon JavaDoc getModuleIcon() {
98         Image JavaDoc img =
99             Utilities.loadImage(ICON_BASE + "package" + GIF_EXTENSION);
100
101         if (img == null) {
102             return null;
103         } else {
104             return new ImageIcon JavaDoc(img);
105         }
106     }
107
108     public static ImageIcon JavaDoc getElementIcon( ElementKind elementKind, Collection JavaDoc<Modifier> modifiers ) {
109     
110         if ( modifiers == null ) {
111             modifiers = Collections.<Modifier>emptyList();
112         }
113     
114         Image JavaDoc img = null;
115     
116         switch( elementKind ) {
117             //case PACKAGE:
118
case MODULE:
119                 img = Utilities.loadImage( ICON_BASE + "package" + GIF_EXTENSION );
120                 break;
121 // case ENUM:
122
// img = Utilities.loadImage( ICON_BASE + "enum" + PNG_EXTENSION );
123
// break;
124
// case ANNOTATION_TYPE:
125
// img = Utilities.loadImage( ICON_BASE + "annotation" + PNG_EXTENSION );
126
// break;
127
case CLASS:
128                 img = Utilities.loadImage( ICON_BASE + "class" + PNG_EXTENSION );
129                 break;
130 // case INTERFACE:
131
// img = Utilities.loadImage( ICON_BASE + "interface" + PNG_EXTENSION );
132
// break;
133
case VARIABLE:
134             case ATTRIBUTE:
135             case FIELD:
136                 img = Utilities.loadImage( getIconName( ICON_BASE + "field", PNG_EXTENSION, modifiers ) );
137                 break;
138 // case ENUM_CONSTANT:
139
// img = Utilities.loadImage( ICON_BASE + "constant" + PNG_EXTENSION );
140
// break;
141
case CONSTANT:
142                 img = Utilities.loadImage(ICON_BASE + "constant" + PNG_EXTENSION );
143                 break;
144             case CONSTRUCTOR:
145                 img = Utilities.loadImage( getIconName( ICON_BASE + "constructor", PNG_EXTENSION, modifiers ) );
146                 break;
147 // case STATIC_INIT:
148
// img = Utilities.loadImage( getIconName( ICON_BASE + "initializer", PNG_EXTENSION, modifiers ) );
149
// break;
150
case METHOD:
151                 img = Utilities.loadImage( getIconName( ICON_BASE + "method", PNG_EXTENSION, modifiers ) );
152                 break;
153             default:
154                 img = null;
155         }
156     
157         return img == null ? null : new ImageIcon JavaDoc (img);
158     }
159         
160         // Private Methods ---------------------------------------------------------
161
private static String JavaDoc getIconName(String JavaDoc typeName, String JavaDoc extension, Collection JavaDoc<Modifier> modifiers) {
162             
163             StringBuffer JavaDoc fileName = new StringBuffer JavaDoc( typeName );
164             
165             if (modifiers.contains(Modifier.STATIC)) {
166                 fileName.append( "Static" );
167             }
168             if (modifiers.contains(Modifier.PROTECTED)) {
169                 return fileName.append( "Protected" ).append( extension ).toString();
170             }
171             if (modifiers.contains(Modifier.PRIVATE)) {
172                 return fileName.append( "Private" ).append( extension ).toString();
173             }
174             // Assume it's public
175
return fileName.append( "Public" ).append( extension ).toString();
176             //return fileName.append( "Package" ).append( extension ).toString();
177
//return fileName.append(extension).toString();
178

179         }
180         
181 }
182
Popular Tags