KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > gui > lib > TreeBox


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
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): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.util.browser.gui.lib;
28
29 import java.awt.Dimension JavaDoc;
30
31 import javax.swing.Box JavaDoc;
32 import javax.swing.JScrollPane JavaDoc;
33
34 import org.objectweb.util.browser.api.Entry;
35 import org.objectweb.util.browser.api.Wrapper;
36 import org.objectweb.util.browser.gui.api.ValidateReport;
37 import org.objectweb.util.browser.core.common.DynamicTree;
38
39 /**
40  * This class represents the panel which displays a DynamicTree.
41  *
42  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
43  *
44  * @version 0.1
45  */

46 public class TreeBox
47     extends AbstractElementBox {
48
49     //==================================================================
50
//
51
// Internal state.
52
//
53
//==================================================================
54

55     /** The tree to display */
56     protected DynamicTree tree_;
57     
58     /** TheJScrollPane associated to the tree */
59     protected JScrollPane JavaDoc scrollPane_;
60
61     //==================================================================
62
//
63
// Constructors.
64
//
65
//==================================================================
66

67     /**
68      * Default constructor
69      * @param tree The DynamicTree to use
70      */

71     public TreeBox(DynamicTree tree) {
72         this(tree,true);
73     }
74
75     /**
76      *
77      * @param tree The DynamicTree to use
78      * @param isMandatory If the value is mandatory : TRUE, else : FALSE
79      */

80     public TreeBox(DynamicTree tree, boolean isMandatory) {
81         super(isMandatory);
82         tree_ = tree;
83         scrollPane_ = new JScrollPane JavaDoc(tree_);
84         add(scrollPane_);
85     }
86
87     /**
88      * Invokes just before displaying.
89      */

90     public void preInitialize(){
91         if(tree_!=null){
92             tree_.setPopupEnabled(false);
93             tree_.setDragAndDropEnabled(false);
94         }
95     }
96     
97     /**
98      * Invokes just before removing.
99      */

100     public void postInitialize(){
101         if(tree_!=null){
102             tree_.setPopupEnabled(true);
103             tree_.setDragAndDropEnabled(true);
104         }
105     }
106
107     //==================================================================
108
//
109
// Internal methods.
110
//
111
//==================================================================
112

113     // ==================================================================
114
//
115
// Public methods for ElementBox.
116
//
117
// ==================================================================
118

119     /**
120      * Validates the content of the ElementBox. Indicates if the different value are acceptables or not.
121      * @return The corresponding ValidateReport.
122      */

123     public ValidateReport validateBox(){
124         if(isMandatory_){
125             if(getObject()==null)
126                 return new DefaultValidateReport(false,"You must select a component");
127         }
128         return new DefaultValidateReport();
129     }
130     
131     /**
132      * Returns the Box contains by the ElementBox.
133      * @return The Box contains by the ElementBox.
134      */

135     public Box JavaDoc getBox(){
136         return this;
137     }
138
139     //==================================================================
140
//
141
// Public methods.
142
//
143
//==================================================================
144

145     /** Returns the chosen Object */
146     public Object JavaDoc getObject(){
147         Object JavaDoc o = null;
148         Entry entry = tree_.getSelectedEntry();
149             if (entry != null) {
150                 o = entry.getValue();
151                 if (o!=null && Wrapper.class.isAssignableFrom(o.getClass()))
152                     return ((Wrapper)o).getWrapped();
153             }
154         return o;
155     }
156
157     /**
158      * Sets the preferred dimension of the JScrollPane.
159      * @param d The preferred dimension of the JScrollPane
160      */

161     public void setPreferredSize(Dimension JavaDoc d){
162         scrollPane_.setPreferredSize(d);
163     }
164
165 }
Popular Tags