KickJava   Java API By Example, From Geeks To Geeks.

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


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;
28
29 import java.awt.event.ItemEvent JavaDoc;
30 import java.awt.event.ItemListener JavaDoc;
31
32 import javax.swing.BorderFactory JavaDoc;
33 import javax.swing.Box JavaDoc;
34 import javax.swing.BoxLayout JavaDoc;
35 import javax.swing.JCheckBox JavaDoc;
36 import javax.swing.JPanel JavaDoc;
37
38 import org.objectweb.util.explorer.swing.gui.api.ValidateReport;
39 import org.objectweb.util.explorer.swing.gui.lib.AbstractElementBox;
40 import org.objectweb.util.explorer.swing.gui.lib.DefaultValidateReport;
41
42
43 /**
44  *
45  *
46  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>,
47  * <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>
48  *
49  * @version 0.1
50  */

51 public class ClassVisibilityBox
52     extends AbstractElementBox {
53
54     //==================================================================
55
//
56
// Internal states.
57
//
58
//==================================================================
59

60     protected ClassVisibilityConfig oldConfig_, newConfig_;
61
62
63     //==================================================================
64
//
65
// Constructor.
66
//
67
//==================================================================
68

69     /**
70      * Constructor with params
71      */

72     public ClassVisibilityBox() {
73         this(null);
74     }
75
76     public ClassVisibilityBox(ClassVisibilityConfig config) {
77         super(true);
78         
79         if(config!=null)
80             oldConfig_ = config;
81         else
82             oldConfig_ = new ClassVisibilityConfig();
83         newConfig_ = (ClassVisibilityConfig)oldConfig_.clone();
84         
85         Box JavaDoc mainBox = Box.createVerticalBox();
86         
87         Box JavaDoc treeInheritanceBox = Box.createHorizontalBox();
88         treeInheritanceBox.add(Box.createHorizontalGlue());
89         JPanel JavaDoc treeInheritancePanel = createHorizontalPanel("Tree Inheritance");
90         treeInheritancePanel.add(createCheckBox("Tree inheritance", ClassVisibilityConfig.TREE_INHERITANCE));
91         treeInheritancePanel.add(createCheckBox("Flat view", ClassVisibilityConfig.FLAT_VIEW));
92         treeInheritanceBox.add(treeInheritancePanel);
93         treeInheritanceBox.add(Box.createHorizontalGlue());
94         
95         mainBox.add(treeInheritanceBox);
96         
97         mainBox.add(Box.createVerticalStrut(10));
98         
99         Box JavaDoc classVisibilityBox = Box.createHorizontalBox();
100         
101         classVisibilityBox.add(Box.createHorizontalGlue());
102         
103         JPanel JavaDoc attributesPanel = createVerticalPanel("Attributes");
104         attributesPanel.add(createCheckBox("public", ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.PUBLIC));
105         attributesPanel.add(createCheckBox("protected", ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.PROTECTED));
106         attributesPanel.add(createCheckBox("private", ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.PRIVATE));
107         attributesPanel.add(createCheckBox("package", ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.PACKAGE));
108         attributesPanel.add(createCheckBox("static", ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.STATIC));
109         attributesPanel.add(createCheckBox("final", ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.FINAL));
110         attributesPanel.add(createCheckBox("display the type", ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.TYPE));
111         attributesPanel.add(createCheckBox("display declaring class", ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.DECLARING_CLASS));
112         classVisibilityBox.add(attributesPanel);
113         
114         classVisibilityBox.add(Box.createHorizontalStrut(10));
115
116         JPanel JavaDoc methodsPanel = createVerticalPanel("Methods");
117         methodsPanel.add(createCheckBox("public", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.PUBLIC));
118         methodsPanel.add(createCheckBox("protected", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.PROTECTED));
119         methodsPanel.add(createCheckBox("private", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.PRIVATE));
120         methodsPanel.add(createCheckBox("package", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.PACKAGE));
121         methodsPanel.add(createCheckBox("static", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.STATIC));
122         methodsPanel.add(createCheckBox("final", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.FINAL));
123         methodsPanel.add(createCheckBox("abstract", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.ABSTRACT));
124         methodsPanel.add(createCheckBox("display the params", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.PARAMS));
125         methodsPanel.add(createCheckBox("display the return type", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.RETURN_TYPE));
126         methodsPanel.add(createCheckBox("display declaring class", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.DECLARING_CLASS));
127         classVisibilityBox.add(methodsPanel);
128
129         classVisibilityBox.add(Box.createHorizontalStrut(10));
130
131         JPanel JavaDoc innerClassPanel = createVerticalPanel("Inner Classes");
132         innerClassPanel.add(createCheckBox("public", ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.PUBLIC));
133         innerClassPanel.add(createCheckBox("protected", ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.PROTECTED));
134         innerClassPanel.add(createCheckBox("private", ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.PRIVATE));
135         innerClassPanel.add(createCheckBox("package", ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.PACKAGE));
136         innerClassPanel.add(createCheckBox("static", ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.STATIC));
137         innerClassPanel.add(createCheckBox("final", ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.FINAL));
138         innerClassPanel.add(createCheckBox("abstract", ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.ABSTRACT));
139         innerClassPanel.add(createCheckBox("display declaring class", ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.DECLARING_CLASS));
140         classVisibilityBox.add(innerClassPanel);
141         
142         classVisibilityBox.add(Box.createHorizontalGlue());
143         
144         mainBox.add(classVisibilityBox);
145         
146         add(mainBox);
147     }
148
149     //==================================================================
150
//
151
// Internal methods.
152
//
153
//==================================================================
154

155     protected JPanel JavaDoc createVerticalPanel(String JavaDoc title){
156         JPanel JavaDoc panel = new JPanel JavaDoc();
157         panel.setBorder(BorderFactory.createTitledBorder(title));
158         panel.setLayout(new BoxLayout JavaDoc(panel, BoxLayout.Y_AXIS));
159         panel.setAlignmentY(TOP_ALIGNMENT);
160         panel.setAlignmentX(LEFT_ALIGNMENT);
161         return panel;
162     }
163
164     protected JPanel JavaDoc createHorizontalPanel(String JavaDoc title){
165         JPanel JavaDoc panel = new JPanel JavaDoc();
166         panel.setBorder(BorderFactory.createTitledBorder(title));
167         panel.setLayout(new BoxLayout JavaDoc(panel, BoxLayout.X_AXIS));
168         panel.setAlignmentY(TOP_ALIGNMENT);
169         panel.setAlignmentX(LEFT_ALIGNMENT);
170         return panel;
171     }
172
173     protected JCheckBox JavaDoc createCheckBox(String JavaDoc label, String JavaDoc name){
174         JCheckBox JavaDoc checkBox = new JCheckBox JavaDoc(label);
175         checkBox.setSelected(newConfig_.get(name));
176         checkBox.addItemListener(new ChangeState(name, checkBox));
177         return checkBox;
178     }
179
180     //==================================================================
181
//
182
// Public methods for ElementBox interface.
183
//
184
//==================================================================
185

186     /* (non-Javadoc)
187      * @see org.objectweb.util.explorer.swing.gui.api.ElementBox#validateBox()
188      */

189     public ValidateReport validateBox() {
190         return new DefaultValidateReport();
191     }
192
193     //==================================================================
194
//
195
// Public methods.
196
//
197
//==================================================================
198

199     public ClassVisibilityConfig getConfig(){
200         return newConfig_;
201     }
202     
203     //==================================================================
204
//
205
// Inner classes.
206
//
207
//==================================================================
208

209     private final class ChangeState
210         implements ItemListener JavaDoc {
211     
212         protected String JavaDoc state_;
213         protected JCheckBox JavaDoc checkBox_;
214         
215         public ChangeState(String JavaDoc state, JCheckBox JavaDoc checkBox){
216             state_ = state;
217             checkBox_ = checkBox;
218         }
219        
220         public void itemStateChanged(ItemEvent JavaDoc e) {
221             newConfig_.put(state_, checkBox_.isSelected());
222         }
223
224     }
225     
226 }
227
228     
Popular Tags