KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > swing > gui > lib > TreeBox


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.swing.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.fractal.api.Component;
35 import org.objectweb.fractal.api.NoSuchInterfaceException;
36 import org.objectweb.util.explorer.api.Entry;
37 import org.objectweb.util.explorer.api.Tree;
38 import org.objectweb.util.explorer.swing.api.Explorer;
39 import org.objectweb.util.explorer.swing.gui.api.ValidateReport;
40
41 /**
42  * This class represents the panel which displays a DynamicTree.
43  *
44  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
45  *
46  * @version 0.1
47  */

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

57     /** The Tree component. */
58     protected Component component_;
59     
60     /** The Tree interface of the Tree component. */
61     protected Tree treeItf_;
62
63     /** The Explorer interface of the Tree component. */
64     protected Explorer explorerItf_;
65     
66     /** TheJScrollPane associated to the tree */
67     protected JScrollPane JavaDoc scrollPane_;
68
69     //==================================================================
70
//
71
// Constructors.
72
//
73
//==================================================================
74

75     /**
76      * Default constructor
77      * @param tree The DynamicTree to use
78      */

79     public TreeBox(Component treeComponent) {
80         this(treeComponent,true);
81     }
82
83     /**
84      *
85      * @param tree The DynamicTree to use
86      * @param isMandatory If the value is mandatory : TRUE, else : FALSE
87      */

88     public TreeBox(Component treeComponent, boolean isMandatory) {
89         super(isMandatory);
90         initAttributes(treeComponent);
91         scrollPane_ = new JScrollPane JavaDoc(explorerItf_.getTree());
92         add(scrollPane_);
93     }
94
95     /**
96      * Invokes just before displaying.
97      */

98     public void preInitialize(){
99         if(explorerItf_!=null){
100             explorerItf_.setPopupEnabled(false);
101             explorerItf_.setDragAndDropEnabled(false);
102         }
103     }
104     
105     /**
106      * Invokes just before removing.
107      */

108     public void postInitialize(){
109         if(explorerItf_!=null){
110             explorerItf_.setPopupEnabled(true);
111             explorerItf_.setDragAndDropEnabled(true);
112         }
113     }
114
115     //==================================================================
116
//
117
// Internal methods.
118
//
119
//==================================================================
120

121     protected void initAttributes(org.objectweb.fractal.api.Component treeComponent){
122         component_ = treeComponent;
123         if(component_!=null){
124             try {
125                 treeItf_ = (Tree)component_.getFcInterface(Tree.TREE);
126                 explorerItf_ = (Explorer)component_.getFcInterface(Explorer.EXPLORER);
127             } catch (NoSuchInterfaceException e) {
128                 e.printStackTrace();
129             }
130         }
131     }
132     
133     // ==================================================================
134
//
135
// Public methods for ElementBox.
136
//
137
// ==================================================================
138

139     /**
140      * Validates the content of the ElementBox. Indicates if the different value are acceptables or not.
141      * @return The corresponding ValidateReport.
142      */

143     public ValidateReport validateBox(){
144         if(isMandatory_){
145             if(getObject()==null)
146                 return new DefaultValidateReport(false,"You must select a component");
147         }
148         return new DefaultValidateReport();
149     }
150     
151     /**
152      * Returns the Box contains by the ElementBox.
153      * @return The Box contains by the ElementBox.
154      */

155     public Box JavaDoc getBox(){
156         return this;
157     }
158
159     //==================================================================
160
//
161
// Public methods.
162
//
163
//==================================================================
164

165     /** Returns the chosen Object */
166     public Object JavaDoc getObject(){
167         Object JavaDoc o = null;
168         Entry entry = treeItf_.getSelectedEntry();
169         if (entry != null) {
170             o = entry.getValue();
171         }
172         return o;
173     }
174
175     /**
176      * Sets the preferred dimension of the JScrollPane.
177      * @param d The preferred dimension of the JScrollPane
178      */

179     public void setPreferredSize(Dimension JavaDoc d){
180         scrollPane_.setPreferredSize(d);
181     }
182
183 }
Popular Tags