KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2004 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): Jerome Moroy, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.util.explorer.plugin.java.reflect.swing;
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.explorer.api.IconProvider;
35 import org.objectweb.util.explorer.core.common.lib.ClassResolver;
36
37
38 /**
39  * Provides an icon to represent <code>java.lang.Class</code> object.
40  *
41  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>,
42  * <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>
43  *
44  * @version 0.1
45  */

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

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

77     /**
78      * Default constructor
79      */

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

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

113     /* (non-Javadoc)
114      * @see org.objectweb.util.explorer.api.IconProvider#newIcon(java.lang.Object)
115      */

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