KickJava   Java API By Example, From Geeks To Geeks.

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


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.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.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.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     /* (non-Javadoc)
109      * @see org.objectweb.util.explorer.api.IconProvider#newIcon(java.lang.Object)
110      */

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