KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > plugin > java > reflect > ClassIconProvider


1 /*====================================================================
2
3 Objectweb Browser Framework
4 Copyright (C) 2000-2003 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle, Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.util.browser.plugin.java.reflect;
28
29 import java.lang.reflect.Modifier JavaDoc;
30
31 import javax.swing.Icon JavaDoc;
32 import javax.swing.ImageIcon JavaDoc;
33
34 import org.objectweb.util.browser.api.IconProvider;
35 import org.objectweb.util.browser.core.common.ClassResolver;
36
37 /**
38  * Provides an icon to represent <code>java.lang.Class</code> object.
39  *
40  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>,
41  * <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>
42  *
43  * @version 0.1
44  */

45 public class ClassIconProvider
46     implements IconProvider {
47
48     //==================================================================
49
//
50
// Internal states.
51
//
52
//==================================================================
53

54     /** The icons to use for interface. */
55     protected static Icon JavaDoc interface_;
56
57     /** The icons to use for public class. */
58     protected static Icon JavaDoc publicClass_, publicAbstractClass_, publicStaticClass_, publicFinalClass_, publicStaticFinalClass_;
59     
60     /** The icons to use for protected class. */
61     protected static Icon JavaDoc protectedClass_, protectedAbstractClass_, protectedStaticClass_, protectedFinalClass_, protectedStaticFinalClass_;
62
63     /** The icons to use for package class. */
64     protected static Icon JavaDoc packageClass_, packageAbstractClass_, packageStaticClass_, packageFinalClass_, packageStaticFinalClass_;
65     
66     /** The icons to use for private class. */
67     protected static Icon JavaDoc privateClass_, privateFinalClass_;
68
69
70     //==================================================================
71
//
72
// Constructor.
73
//
74
//==================================================================
75

76     /**
77      * Default constructor
78      */

79     public ClassIconProvider(){
80         interface_ = new ImageIcon JavaDoc(ClassResolver.getResource("interface.png"));
81         publicClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("publicClass.png"));
82         publicAbstractClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("publicAbstractClass.png"));
83         publicStaticClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("publicStaticClass.png"));
84         publicFinalClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("publicFinalClass.png"));
85         publicStaticFinalClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("publicStaticFinalClass.png"));
86         protectedClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("protectedClass.png"));
87         protectedAbstractClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("protectedAbstractClass.png"));
88         protectedStaticClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("protectedStaticClass.png"));
89         protectedFinalClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("protectedFinalClass.png"));
90         protectedStaticFinalClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("protectedStaticFinalClass.png"));
91         privateClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("privateClass.png"));
92         privateFinalClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("privateFinalClass.png"));
93         packageClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("packageClass.png"));
94         packageAbstractClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("packageAbstractClass.png"));
95         packageStaticClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("packageStaticClass.png"));
96         packageFinalClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("packageFinalClass.png"));
97         packageStaticFinalClass_ = new ImageIcon JavaDoc(ClassResolver.getResource("packageStaticFinalClass.png"));
98     }
99
100     //==================================================================
101
//
102
// No internal method.
103
//
104
//==================================================================
105

106     //==================================================================
107
//
108
// Public methods for IconProvider interface.
109
//
110
//==================================================================
111

112     /**
113      * Return an <code>javax.swing.Icon</code> according to the given object.
114      *
115      * @param object The object to compute the associated icon.
116      *
117      * @return The icon according to the given object.
118      */

119     public Icon JavaDoc
120     newIcon(Object JavaDoc object){
121         Class JavaDoc theClass = (Class JavaDoc)object;
122         int modifier = theClass.getModifiers();
123         if (Modifier.isInterface(modifier)) {
124             return interface_;
125         } else if (Modifier.isPrivate(modifier)){
126             if (Modifier.isFinal(modifier))
127                 return privateFinalClass_;
128             else
129                 return privateClass_;
130         } else if (Modifier.isProtected(modifier)){
131             if (Modifier.isAbstract(modifier))
132                 return protectedAbstractClass_;
133             else if (Modifier.isStatic(modifier) && Modifier.isFinal(modifier))
134                 return protectedStaticFinalClass_;
135             else if (Modifier.isStatic(modifier))
136                 return protectedStaticClass_;
137             else if (Modifier.isFinal(modifier))
138                 return protectedFinalClass_;
139             else
140                 return protectedClass_;
141         } else if (Modifier.isPublic(modifier)){
142             if (Modifier.isAbstract(modifier))
143                 return publicAbstractClass_;
144             else if (Modifier.isStatic(modifier) && Modifier.isFinal(modifier))
145                 return publicStaticFinalClass_;
146             else if (Modifier.isStatic(modifier))
147                 return publicStaticClass_;
148             else if (Modifier.isFinal(modifier))
149                 return publicFinalClass_;
150             else
151                 return publicClass_;
152         } else if (!Modifier.isPrivate(modifier) && !Modifier.isProtected(modifier) && !Modifier.isPublic(modifier)){
153             if (Modifier.isAbstract(modifier))
154                 return packageAbstractClass_;
155             else if (Modifier.isStatic(modifier) && Modifier.isFinal(modifier))
156                 return packageStaticFinalClass_;
157             else if (Modifier.isStatic(modifier))
158                 return packageStaticClass_;
159             else if (Modifier.isFinal(modifier))
160                 return packageFinalClass_;
161             else
162                 return packageClass_;
163         } else
164             return null;
165         
166     }
167     
168 }
Popular Tags