KickJava   Java API By Example, From Geeks To Geeks.

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


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.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.browser.api.IconProvider;
36 import org.objectweb.util.browser.core.common.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     /**
106      * Return an <code>javax.swing.Icon</code> according to the given object.
107      *
108      * @param object The object to compute the associated icon.
109      *
110      * @return The icon according to the given object.
111      */

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