KickJava   Java API By Example, From Geeks To Geeks.

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


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, Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================*/

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

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

57     /** The associated JPanel */
58     protected JPanel JavaDoc panel_ = null;
59
60     /** The box added into the JPanel */
61     protected Box JavaDoc box_ = null;
62
63     // ==================================================================
64
//
65
// Constructors.
66
//
67
// ==================================================================
68

69     /**
70      * Empty constructor
71      */

72     public ContextPanel() {
73         panel_ = new JPanel JavaDoc();
74         panel_.setBackground(Color.white);
75         box_ = Box.createVerticalBox();
76         panel_.add(box_);
77     }
78
79     // ==================================================================
80
//
81
// No internal method.
82
//
83
// ==================================================================
84

85     // ==================================================================
86
//
87
// Public methods for ViewPanel interface.
88
//
89
// ==================================================================
90

91     /**
92      * Invokes just after instanciation
93      */

94     public void selected(TreeView treeView) {
95         Context context = (Context) treeView.getSelectedEntry().getValue();
96         if (context != null) {
97             Entry[] entries = context.getEntries();
98             for (int i = 0; i < entries.length; i++) {
99                 Entry entry = entries[i];
100                 String JavaDoc text = entry.getValue().toString();
101                 JTextField JavaDoc textField = new JTextField JavaDoc(text);
102                 textField.setEditable(false);
103                 textField.setBackground(Color.white);
104                 textField.setBorder(new TitledBorder JavaDoc(null, entry.getName().toString(), TitledBorder.LEFT, TitledBorder.TOP));
105                 box_.add(textField);
106             }
107         }
108     }
109
110     /**
111      * Provides the panel to display
112      * @return The panel to display
113      */

114     public JPanel JavaDoc getPanel(){
115         return panel_;
116     }
117
118     /**
119      * Invokes just before removing
120      */

121     public void unselected(TreeView treeView) {
122     }
123
124 }
125
Popular Tags