KickJava   Java API By Example, From Geeks To Geeks.

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


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.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.browser.gui.api.ValidateReport;
39 import org.objectweb.util.browser.gui.lib.AbstractElementBox;
40 import org.objectweb.util.browser.gui.lib.DefaultValidateReport;
41
42 /**
43  *
44  *
45  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>,
46  * <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>
47  *
48  * @version 0.1
49  */

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

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

68     /**
69      * Constructor with params
70      */

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

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

185     public ValidateReport validateBox() {
186         return new DefaultValidateReport();
187     }
188
189     //==================================================================
190
//
191
// Public methods.
192
//
193
//==================================================================
194

195     public ClassVisibilityConfig getConfig(){
196         return newConfig_;
197     }
198     
199     //==================================================================
200
//
201
// Inner classes.
202
//
203
//==================================================================
204

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