KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > ui > nodes > elements > IconResolver


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  */

20
21 package org.netbeans.modules.java.ui.nodes.elements;
22
23 import java.lang.reflect.Modifier JavaDoc;
24 import org.netbeans.jmi.javamodel.*;
25
26 /**
27  *
28  * @author Jan Becicka
29  */

30 public class IconResolver implements IconStrings {
31
32     private static String JavaDoc getIconBaseForMethod(int modif) {
33         if (Modifier.isStatic(modif)) {
34             // static method...
35
if (Modifier.isPrivate(modif))
36                 return METHOD_ST_PRIVATE;
37             else if (Modifier.isProtected(modif))
38                 return METHOD_ST_PROTECTED;
39             else if (Modifier.isPublic(modif))
40                 return METHOD_ST_PUBLIC;
41             else
42                 return METHOD_ST_PACKAGE;
43         }
44         else {
45             // non-static method...
46
if (Modifier.isPrivate(modif))
47                 return METHOD_PRIVATE;
48             else if (Modifier.isProtected(modif))
49                 return METHOD_PROTECTED;
50             else if (Modifier.isPublic(modif))
51                 return METHOD_PUBLIC;
52             else
53                 return METHOD_PACKAGE;
54         }
55     }
56     
57     public static String JavaDoc getIconBaseForMethod(Method m) {
58         return getIconBaseForMethod(m.getModifiers());
59     }
60     
61     public static String JavaDoc getIconBaseForAttribute(Attribute a) {
62         return getIconBaseForMethod(a.getModifiers());
63     }
64     
65     public static String JavaDoc getIconBaseForVariable(Variable v) {
66         return FIELD_PRIVATE;
67     }
68     
69     public static String JavaDoc getIconBaseForField(Field f) {
70         int modif = f.getModifiers();
71         if (!Modifier.isStatic(modif)) {
72             // non-static field...
73
if (Modifier.isPrivate(modif))
74                 return FIELD_PRIVATE;
75             else if (Modifier.isProtected(modif))
76                 return FIELD_PROTECTED;
77             else if (Modifier.isPublic(modif))
78                 return FIELD_PUBLIC;
79             else
80                 return FIELD_PACKAGE;
81         }
82         else {
83             // static field...
84
if (Modifier.isPrivate(modif))
85                 return FIELD_ST_PRIVATE;
86             else if (Modifier.isProtected(modif))
87                 return FIELD_ST_PROTECTED;
88             else if (Modifier.isPublic(modif))
89                 return FIELD_ST_PUBLIC;
90             else
91                 return FIELD_ST_PACKAGE;
92         }
93     }
94     
95     public static String JavaDoc getIconBaseForInitializer(Initializer i) {
96         return Modifier.isStatic(i.getModifiers())? INITIALIZER_ST : INITIALIZER;
97     }
98     
99     public static String JavaDoc getIconBaseForJavaClass(JavaClass c) {
100         return c.isInterface()? INTERFACE : CLASS;
101     }
102
103     public static String JavaDoc getIconBaseForConstructor(Constructor c) {
104         int modif = c.getModifiers();
105         if (Modifier.isPrivate(modif))
106             return CONSTRUCTOR_PRIVATE;
107         else if (Modifier.isProtected(modif))
108             return CONSTRUCTOR_PROTECTED;
109         else if (Modifier.isPublic(modif))
110             return CONSTRUCTOR_PUBLIC;
111         else
112             return CONSTRUCTOR_PACKAGE;
113     }
114     
115     public static String JavaDoc getIconBase(Feature f) {
116         if (f instanceof Method)
117             return getIconBaseForMethod((Method) f);
118         if (f instanceof Field)
119             return getIconBaseForField((Field) f);
120         if (f instanceof Constructor)
121             return getIconBaseForConstructor((Constructor) f);
122         if (f instanceof Initializer)
123             return getIconBaseForInitializer((Initializer) f);
124         if (f instanceof JavaClass)
125             return getIconBaseForJavaClass((JavaClass) f);
126         if (f instanceof Attribute)
127             return getIconBaseForAttribute((Attribute) f);
128         if (f instanceof AnnotationType)
129             return ANNOTATION_TYPE;
130         if (f instanceof EnumConstant)
131             return ENUM_CONSTANT;
132         if (f instanceof JavaEnum)
133             return ENUM;
134         throw new IllegalArgumentException JavaDoc("Unknown Feature"); // NOI18N
135
}
136 }
137
Popular Tags