KickJava   Java API By Example, From Geeks To Geeks.

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


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.Field JavaDoc;
30 import java.lang.reflect.Modifier JavaDoc;
31
32 import javax.swing.Icon JavaDoc;
33 import javax.swing.ImageIcon JavaDoc;
34
35 import org.objectweb.util.explorer.api.IconProvider;
36 import org.objectweb.util.explorer.core.common.lib.ClassResolver;
37
38 /**
39  * Provides an icon to represent <code>java.lang.reflect.Field</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 FieldIconProvider
47     implements IconProvider {
48
49     //==================================================================
50
//
51
// Internal states.
52
//
53
//==================================================================
54

55     /** The icons to use for public field. */
56     protected static Icon JavaDoc publicField_, publicStaticField_, publicFinalField_, publicStaticFinalField_;
57     
58     /** The icons to use for protected field. */
59     protected static Icon JavaDoc protectedField_, protectedStaticField_, protectedFinalField_, protectedStaticFinalField_;
60     
61     /** The icons to use for package field. */
62     protected static Icon JavaDoc packageField_, packageStaticField_, packageFinalField_, packageStaticFinalField_;
63
64     /** The icons to use for private field. */
65     protected static Icon JavaDoc privateField_, privateFinalField_;
66
67     //==================================================================
68
//
69
// Constructor.
70
//
71
//==================================================================
72

73     /**
74      * Default constructor
75      */

76     public FieldIconProvider(){
77         publicField_ = new ImageIcon JavaDoc(ClassResolver.getResource("publicField.png"));
78         publicStaticField_ = new ImageIcon JavaDoc(ClassResolver.getResource("publicStaticField.png"));
79         publicFinalField_ = new ImageIcon JavaDoc(ClassResolver.getResource("publicFinalField.png"));
80         publicStaticFinalField_ = new ImageIcon JavaDoc(ClassResolver.getResource("publicStaticFinalField.png"));
81         protectedField_ = new ImageIcon JavaDoc(ClassResolver.getResource("protectedField.png"));
82         protectedStaticField_ = new ImageIcon JavaDoc(ClassResolver.getResource("protectedStaticField.png"));
83         protectedFinalField_ = new ImageIcon JavaDoc(ClassResolver.getResource("protectedFinalField.png"));
84         protectedStaticFinalField_ = new ImageIcon JavaDoc(ClassResolver.getResource("protectedStaticFinalField.png"));
85         privateField_ = new ImageIcon JavaDoc(ClassResolver.getResource("privateField.png"));
86         privateFinalField_ = new ImageIcon JavaDoc(ClassResolver.getResource("privateFinalField.png"));
87         packageField_ = new ImageIcon JavaDoc(ClassResolver.getResource("packageField.png"));
88         packageStaticField_ = new ImageIcon JavaDoc(ClassResolver.getResource("packageStaticField.png"));
89         packageFinalField_ = new ImageIcon JavaDoc(ClassResolver.getResource("packageFinalField.png"));
90         packageStaticFinalField_ = new ImageIcon JavaDoc(ClassResolver.getResource("packageStaticFinalField.png"));
91     }
92
93     //==================================================================
94
//
95
// No internal method.
96
//
97
//==================================================================
98

99     //==================================================================
100
//
101
// Public methods for IconProvider interface.
102
//
103
//==================================================================
104

105     /* (non-Javadoc)
106      * @see org.objectweb.util.explorer.api.IconProvider#newIcon(java.lang.Object)
107      */

108     public Object JavaDoc
109     newIcon(Object JavaDoc object){
110         Field JavaDoc field_ = (Field JavaDoc)object;
111         int modifier = field_.getModifiers();
112         if (Modifier.isPrivate(modifier)){
113             if (Modifier.isFinal(modifier))
114                 return privateFinalField_;
115             else
116                 return privateField_;
117         } else if (Modifier.isProtected(modifier)){
118             if (Modifier.isStatic(modifier) && Modifier.isFinal(modifier))
119                 return protectedStaticFinalField_;
120             else if (Modifier.isStatic(modifier))
121                 return protectedStaticField_;
122             else if (Modifier.isFinal(modifier))
123                 return protectedFinalField_;
124             else
125                 return protectedField_;
126         } else if (Modifier.isPublic(modifier)){
127             if (Modifier.isStatic(modifier) && Modifier.isFinal(modifier))
128                 return publicStaticFinalField_;
129             else if (Modifier.isStatic(modifier))
130                 return publicStaticField_;
131             else if (Modifier.isFinal(modifier))
132                 return publicFinalField_;
133             else
134                 return publicField_;
135         } else if (!Modifier.isPrivate(modifier) && !Modifier.isProtected(modifier) && !Modifier.isPublic(modifier)) {
136             if (Modifier.isStatic(modifier) && Modifier.isFinal(modifier))
137                 return packageStaticFinalField_;
138             else if (Modifier.isStatic(modifier))
139                 return packageStaticField_;
140             else if (Modifier.isFinal(modifier))
141                 return packageFinalField_;
142             else
143                 return packageField_;
144         } else {
145             return null;
146         }
147     }
148     
149 }
Popular Tags