KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > core > panel > DefaultAssociatedPanel


1 /*===========================================================================
2
3 ObjectWeb Naming Context Framework
4 Copyright (C) 2002 USTL - LIFL - GOAL
5 Contact: architecture@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.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================*/

26
27 package org.objectweb.util.browser.core.panel;
28
29 /** The Java API's imports */
30 import javax.swing.JPanel JavaDoc;
31 import java.awt.Color JavaDoc;
32 import java.lang.reflect.Method JavaDoc;
33 import java.lang.reflect.Field JavaDoc;
34 import javax.swing.BoxLayout JavaDoc;
35 import javax.swing.Box JavaDoc;
36 import javax.swing.border.TitledBorder JavaDoc;
37
38 /** The Console's imports */
39 import org.objectweb.util.browser.api.TreeView;
40 import org.objectweb.util.browser.api.Panel;
41
42 /**
43  * Intropection Panel.
44  *
45  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
46  * @version 0.1
47  */

48 public class DefaultAssociatedPanel
49     implements Panel JavaDoc {
50
51     // ==================================================================
52
//
53
// Internal states.
54
//
55
// ==================================================================
56

57     protected TreeView treeView_;
58
59     protected Object JavaDoc object_;
60     
61     protected JPanel JavaDoc panel_;
62
63     // ==================================================================
64
//
65
// Constructors.
66
//
67
// ==================================================================
68

69     /**
70      * Empty constructor
71      */

72     public DefaultAssociatedPanel() {
73         panel_ = new JPanel JavaDoc();
74         panel_.setBackground(Color.white);
75         panel_.setLayout(new BoxLayout JavaDoc(panel_, BoxLayout.Y_AXIS));
76     }
77     
78     // ==================================================================
79
//
80
// No internal method.
81
//
82
// ==================================================================
83

84     protected JPanel JavaDoc addMethods() {
85         JPanel JavaDoc methodsPanel = new JPanel JavaDoc();
86         methodsPanel.setBackground(Color.white);
87         methodsPanel.setBorder(new TitledBorder JavaDoc(null, " Methods ", TitledBorder.CENTER, TitledBorder.TOP));
88         Box JavaDoc box = Box.createVerticalBox();
89         Method JavaDoc[] methods = object_.getClass().getDeclaredMethods();
90         for (int i = 0; i < methods.length; i++) {
91             box.add(new MethodGUI(methods[i], treeView_));
92         }
93         methodsPanel.add(box);
94         return methodsPanel;
95     }
96
97     protected JPanel JavaDoc addFields() {
98         JPanel JavaDoc fieldsPanel = new JPanel JavaDoc();
99         fieldsPanel.setBackground(Color.white);
100         fieldsPanel.setBorder(new TitledBorder JavaDoc(null, " Attributes ", TitledBorder.CENTER, TitledBorder.TOP));
101         Box JavaDoc box = Box.createVerticalBox();
102         Field JavaDoc[] fields = object_.getClass().getFields();
103         for (int i = 0; i < fields.length; i++) {
104             box.add(new FieldGUI(fields[i], object_));
105         }
106         fieldsPanel.add(box);
107         return fieldsPanel;
108     }
109
110     // ==================================================================
111
//
112
// Public methods for ViewPanel interface.
113
//
114
// ==================================================================
115

116     /**
117      * Invokes just after instanciation
118      */

119     public void selected(TreeView treeView) {
120         treeView_ = treeView;
121         object_ = treeView_.getSelectedObject();
122         if (object_ != null) {
123             panel_.add(addFields());
124             panel_.add(addMethods());
125         }
126     }
127
128     /**
129      * Provides the panel to display
130      * @return The panel to display
131      */

132     public JPanel JavaDoc getPanel(){
133         return panel_;
134     }
135
136     
137     /**
138      * Invokes just before removing
139      */

140     public void unselected(TreeView treeView) {
141     }
142
143 }
144
Popular Tags