KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > swing > lib > DefaultViewPanel


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 package org.objectweb.util.explorer.swing.lib;
27
28 import java.awt.Dimension JavaDoc;
29 import java.awt.GridLayout JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Map JavaDoc;
32
33 import javax.swing.JPanel JavaDoc;
34 import javax.swing.JScrollPane JavaDoc;
35
36 import org.objectweb.fractal.api.NoSuchInterfaceException;
37 import org.objectweb.util.explorer.api.Panel;
38 import org.objectweb.util.explorer.api.Tree;
39 import org.objectweb.util.explorer.api.TreeView;
40 import org.objectweb.util.explorer.core.common.api.Description;
41 import org.objectweb.util.explorer.core.common.api.ExplorerConstants;
42 import org.objectweb.util.explorer.core.common.api.Synchronization;
43 import org.objectweb.util.explorer.core.common.lib.BindingFeature;
44 import org.objectweb.util.explorer.interpreter.api.DescriptionInterpreter;
45 import org.objectweb.util.explorer.resolver.api.PropertyResolver;
46 import org.objectweb.util.explorer.swing.api.ViewPanel;
47 import org.objectweb.util.explorer.swing.panel.WhitePanel;
48
49 /**
50  *
51  *
52  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>,
53  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>.
54  *
55  * @version 0.1
56  */

57 public class DefaultViewPanel
58      extends BindingFeature
59   implements Synchronization, ViewPanel
60 {
61
62     //==================================================================
63
//
64
// Internal States.
65
//
66
// ==================================================================
67

68     protected JPanel JavaDoc viewPanel_ = null;
69     protected Panel JavaDoc userPanel_ = null;
70     protected Panel JavaDoc whitePanel_ = null;
71     protected TreeView currentTreeView_ = null;
72     
73     // ==================================================================
74
//
75
// Constructors.
76
//
77
// ==================================================================
78

79     public DefaultViewPanel(){
80         whitePanel_ = new WhitePanel();
81         viewPanel_ = new JPanel JavaDoc();
82         viewPanel_.setLayout(new GridLayout JavaDoc(1, 0));
83         viewPanel_.setPreferredSize(new Dimension JavaDoc(400, 500));
84         //viewPanel_.add(new JScrollPane((JPanel)whitePanel_.getPanel()));
85
viewPanel_.add((JPanel JavaDoc)whitePanel_.getPanel());
86     }
87     
88     // ==================================================================
89
//
90
// Internal methods.
91
//
92
// ==================================================================
93

94     /**
95      * Provides the PropertyResolver to use.
96      */

97     protected PropertyResolver getPropertyResolver() {
98         try {
99             return (PropertyResolver)lookupFc(PropertyResolver.PROPERTY_RESOLVER);
100         } catch (NoSuchInterfaceException e) {
101             getTrace().warn(PropertyResolver.PROPERTY_RESOLVER + ": interface not found!");
102             return null;
103         }
104     }
105
106     /**
107      * Provides the descriptionInterpreter to use.
108      */

109     protected DescriptionInterpreter getDescriptionInterpreter() {
110         try {
111             return (DescriptionInterpreter)lookupFc(DescriptionInterpreter.DESCRIPTION_INTERPRETER);
112         } catch (NoSuchInterfaceException e) {
113             getTrace().warn(DescriptionInterpreter.DESCRIPTION_INTERPRETER + ": interface not found!");
114             return null;
115         }
116     }
117
118     /**
119      * Provides the tree interface to use.
120      */

121     protected Tree getTree() {
122         try {
123             return (Tree)lookupFc(Tree.TREE);
124         } catch (NoSuchInterfaceException e) {
125             getTrace().warn(Tree.TREE + ": interface not found!");
126             return null;
127         }
128     }
129         
130     /**
131      * Fixes the panel associated to the selected node
132      */

133     protected void setViewPanel(Panel JavaDoc newPanel) {
134         viewPanel_.removeAll();
135         userPanel_ = newPanel;
136         viewPanel_.add(new JScrollPane JavaDoc((JPanel JavaDoc)userPanel_.getPanel()));
137         viewPanel_.revalidate();
138     }
139     
140     // ==================================================================
141
//
142
// Public methods for BindingFeature abstract class.
143
//
144
// ==================================================================
145

146     /* (non-Javadoc)
147      * @see org.objectweb.util.explorer.core.common.lib.BindingFeature#clientFc()
148      */

149     public String JavaDoc[] clientFc() {
150         return new String JavaDoc[]{Tree.TREE, PropertyResolver.PROPERTY_RESOLVER,DescriptionInterpreter.DESCRIPTION_INTERPRETER};
151     }
152
153     // ==================================================================
154
//
155
// Public methods for Synchronization interface.
156
//
157
// ==================================================================
158

159     /* (non-Javadoc)
160      * @see org.objectweb.util.explorer.core.code.api.Synchronization#refresh(org.objectweb.util.explorer.api.Entry)
161      */

162     public void refresh(TreeView treeView) {
163         if(userPanel_!=null && currentTreeView_!=null){
164             userPanel_.unselected(currentTreeView_);
165         }
166         if(treeView!=null){
167             Description desc = getPropertyResolver().resolve(ExplorerConstants.PANEL_PROPERTY, treeView.getSelectedEntry());
168             // TODO: Temporary methods until a dynamic fractal assembly is returned by the "interprete" method.
169
Map JavaDoc map = new HashMap JavaDoc();
170             map.put(PropertyResolver.PROPERTY_RESOLVER, getPropertyResolver());
171             map.put(DescriptionInterpreter.DESCRIPTION_INTERPRETER, getDescriptionInterpreter());
172             map.put(Tree.TREE, getTree());
173             Panel JavaDoc p = (Panel JavaDoc)getDescriptionInterpreter().interprete(desc, map);
174             if(p!=null){
175                 currentTreeView_ = treeView;
176                 p.selected(treeView);
177                 setViewPanel(p);
178             } else {
179                 userPanel_ = null;
180                 setViewPanel(whitePanel_);
181             }
182         }
183     }
184
185     // ==================================================================
186
//
187
// Public methods for ViewPanel interface.
188
//
189
// ==================================================================
190

191     /**
192      * Provides the view panel
193      * @return
194      */

195     public JPanel JavaDoc getViewPanel(){
196         return viewPanel_;
197     }
198     
199 }
200
201
Popular Tags