KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > interpreter > lib > swing > PanelInterpreter


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.interpreter.lib.swing;
27
28 import java.util.Map JavaDoc;
29
30 import org.objectweb.util.explorer.api.Panel;
31 import org.objectweb.util.explorer.api.Table;
32 import org.objectweb.util.explorer.api.Tree;
33 import org.objectweb.util.explorer.core.code.api.Code;
34 import org.objectweb.util.explorer.core.common.api.Description;
35 import org.objectweb.util.explorer.core.panel.api.CompositePanelDescription;
36 import org.objectweb.util.explorer.core.panel.api.PanelDescription;
37 import org.objectweb.util.explorer.core.panel.api.TableDescription;
38 import org.objectweb.util.explorer.interpreter.api.DescriptionInterpreter;
39 import org.objectweb.util.explorer.interpreter.lib.AbstractDescriptionInterpreter;
40 import org.objectweb.util.explorer.resolver.api.PropertyResolver;
41 import org.objectweb.util.explorer.swing.panel.BasicCompositePanel;
42 import org.objectweb.util.explorer.swing.panel.BasicTablePanel;
43
44 /**
45  *
46  *
47  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>,
48  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>.
49  *
50  * @version 0.1
51  */

52 public class PanelInterpreter
53      extends AbstractDescriptionInterpreter
54 {
55
56     //==================================================================
57
//
58
// Internal States.
59
//
60
// ==================================================================
61

62     // ==================================================================
63
//
64
// Constructors.
65
//
66
// ==================================================================
67

68     // ==================================================================
69
//
70
// Internal methods.
71
//
72
// ==================================================================
73

74     protected Panel createPanel(TableDescription table, Map JavaDoc params){
75         Code tableCode = getCodeProvider().getCode(table.getCodeDescription());
76         if(tableCode!=null && tableCode.isInstanceOf(Table.class)){
77             BasicTablePanel p = new BasicTablePanel();
78             p.setTable((Table)tableCode.createInstance());
79             p.setPropertyResolver((PropertyResolver)params.get(PropertyResolver.PROPERTY_RESOLVER));
80             p.setDescriptionInterpreter((DescriptionInterpreter)params.get(DescriptionInterpreter.DESCRIPTION_INTERPRETER));
81             p.setTree((Tree)params.get(Tree.TREE));
82             return p;
83         } else {
84             getTrace().warn(tableCode + " is not assignable from Table!");
85             return null;
86         }
87     }
88     
89     protected Panel createPanel(PanelDescription panel){
90         Code panelCode = getCodeProvider().getCode(panel.getCodeDescription());
91         if(panelCode!=null && panelCode.isInstanceOf(Panel.class)){
92             return (Panel)panelCode.createInstance();
93         } else {
94             getTrace().warn(panelCode + " is not assignable from Panel!");
95             return null;
96         }
97     }
98     
99     protected Panel createPanel(CompositePanelDescription panel, Map JavaDoc params){
100         BasicCompositePanel compositePanel = new BasicCompositePanel();
101         PanelDescription[] panelDescs = panel.getPanelDescriptions();
102         for (int i = 0; i < panelDescs.length; i++) {
103             PanelDescription panelDesc = panelDescs[i];
104             if (PanelDescription.TABLE.equals(panelDesc.getPanelType())) {
105                 compositePanel.add(createPanel((TableDescription)panelDesc, params));
106             } else if (PanelDescription.PANEL.equals(panelDesc.getPanelType())) {
107                 compositePanel.add(createPanel((PanelDescription)panelDesc));
108             } else {
109                 compositePanel.add(createPanel((CompositePanelDescription)panelDesc));
110             }
111         }
112         return compositePanel;
113     }
114         
115     // ==================================================================
116
//
117
// Public methods for DescriptionInterpreter interface.
118
//
119
// ==================================================================
120

121     /* (non-Javadoc)
122      * @see org.objectweb.util.explorer.interpreter.api.DescriptionInterpreter#interprete(org.objectweb.util.explorer.core.common.api.Description, java.lang.Object)
123      */

124     public Object JavaDoc interprete(Description description, Object JavaDoc params) {
125         return createPanel((CompositePanelDescription)description, (Map JavaDoc)params);
126     }
127
128 }
129
Popular Tags