KickJava   Java API By Example, From Geeks To Geeks.

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


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.Method 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.Method</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 MethodIconProvider
47     implements IconProvider {
48
49     //==================================================================
50
//
51
// Internal states.
52
//
53
//==================================================================
54

55     /** The icons to use for public method. */
56     protected static Icon JavaDoc publicMethod_, publicAbstractMethod_, publicStaticMethod_, publicFinalMethod_, publicStaticFinalMethod_;
57     
58     /** The icons to use for protected method. */
59     protected static Icon JavaDoc protectedMethod_, protectedAbstractMethod_, protectedStaticMethod_, protectedFinalMethod_, protectedStaticFinalMethod_;
60
61     /** The icons to use for package class. */
62     protected static Icon JavaDoc packageMethod_, packageAbstractMethod_, packageStaticMethod_, packageFinalMethod_, packageStaticFinalMethod_;
63     
64     /** The icons to use for private method. */
65     protected static Icon JavaDoc privateMethod_, privateFinalMethod_;
66
67     //==================================================================
68
//
69
// Constructor.
70
//
71
//==================================================================
72

73     /**
74      * Default constructor
75      */

76     public MethodIconProvider(){
77         publicMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("publicMethod.png"));
78         publicAbstractMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("publicAbstractMethod.png"));
79         publicStaticMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("publicStaticMethod.png"));
80         publicFinalMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("publicFinalMethod.png"));
81         publicStaticFinalMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("publicStaticFinalMethod.png"));
82         protectedMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("protectedMethod.png"));
83         protectedAbstractMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("protectedAbstractMethod.png"));
84         protectedStaticMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("protectedStaticMethod.png"));
85         protectedFinalMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("protectedFinalMethod.png"));
86         protectedStaticFinalMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("protectedStaticFinalMethod.png"));
87         privateMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("privateMethod.png"));
88         privateFinalMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("privateFinalMethod.png"));
89         packageMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("packageMethod.png"));
90         packageAbstractMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("packageAbstractMethod.png"));
91         packageStaticMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("packageStaticMethod.png"));
92         packageFinalMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("packageFinalMethod.png"));
93         packageStaticFinalMethod_ = new ImageIcon JavaDoc(ClassResolver.getResource("packageStaticFinalMethod.png"));
94     }
95
96     //==================================================================
97
//
98
// No internal method.
99
//
100
//==================================================================
101

102     //==================================================================
103
//
104
// Public methods for IconProvider interface.
105
//
106
//==================================================================
107

108     /**
109      * Return an <code>javax.swing.Icon</code> according to the given object.
110      *
111      * @param object The object to compute the associated icon.
112      *
113      * @return The icon according to the given object.
114      */

115     public Icon JavaDoc
116     newIcon(Object JavaDoc object){
117         Method JavaDoc method_ = (Method JavaDoc)object;
118         int modifier = method_.getModifiers();
119         if (Modifier.isPrivate(modifier)){
120             if (Modifier.isFinal(modifier))
121                 return privateFinalMethod_;
122             else
123                 return privateMethod_;
124         } else if (Modifier.isProtected(modifier)){
125             if (Modifier.isAbstract(modifier))
126                 return protectedAbstractMethod_;
127             else if (Modifier.isStatic(modifier) && Modifier.isFinal(modifier))
128                 return protectedStaticFinalMethod_;
129             else if (Modifier.isStatic(modifier))
130                 return protectedStaticMethod_;
131             else if (Modifier.isFinal(modifier))
132                 return protectedFinalMethod_;
133             else
134                 return protectedMethod_;
135         } else if (Modifier.isPublic(modifier)){
136             if (Modifier.isAbstract(modifier))
137                 return publicAbstractMethod_;
138             else if (Modifier.isStatic(modifier) && Modifier.isFinal(modifier))
139                 return publicStaticFinalMethod_;
140             else if (Modifier.isStatic(modifier))
141                 return publicStaticMethod_;
142             else if (Modifier.isFinal(modifier))
143                 return publicFinalMethod_;
144             else
145                 return publicMethod_;
146         } else if (!Modifier.isPrivate(modifier) && !Modifier.isProtected(modifier) && !Modifier.isPublic(modifier)){
147             if (Modifier.isAbstract(modifier))
148                 return packageAbstractMethod_;
149             else if (Modifier.isStatic(modifier) && Modifier.isFinal(modifier))
150                 return packageStaticFinalMethod_;
151             else if (Modifier.isStatic(modifier))
152                 return packageStaticMethod_;
153             else if (Modifier.isFinal(modifier))
154                 return packageFinalMethod_;
155             else
156                 return packageMethod_;
157         } else {
158             return null;
159         }
160     }
161     
162 }
Popular Tags