KickJava   Java API By Example, From Geeks To Geeks.

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


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): Jérôme Moroy.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================*/

26
27 package org.objectweb.util.browser.core.panel;
28
29 /** To use the PanelFactory interface */
30 import java.util.Iterator JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 import org.objectweb.util.browser.api.Panel;
34 import org.objectweb.util.browser.core.api.PanelFactory;
35
36 /**
37  * Basic implementation for Panel factories.
38  *
39  *
40  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
41  * @version 0.1
42  *
43  */

44 public class DefaultPanelFactory
45     implements PanelFactory {
46
47     /** The Associated class */
48     protected Class JavaDoc class_ = null;
49
50     /** Indicates if this panel has to inherit panel from parents at the java type inheritance level. */
51     protected boolean inheritTypePanel_ = false;
52     
53     protected Vector JavaDoc subPanels_ = new Vector JavaDoc();
54
55     protected Panel createPanel(Object JavaDoc object){
56         if (class_ != null) {
57             try {
58                 return (Panel) class_.newInstance();
59             } catch (java.lang.InstantiationException JavaDoc e) {
60                 System.out.println(class_.getName() + " : Instanciation exception");
61             } catch (java.lang.IllegalAccessException JavaDoc e) {
62                 System.out.println(class_.getName() + " : Illegal access exception");
63             }
64         }
65         return null;
66     }
67
68     /**
69      * Return an JPanel associated to the param's object.
70      *
71      * @return The associated panel.
72      */

73     public Panel newPanel(Object JavaDoc object) {
74         if (subPanels_.size()>0){
75             DefaultCompositePanel compositePanel = new DefaultCompositePanel();
76             compositePanel.add(createPanel(object));
77             Iterator JavaDoc it = subPanels_.iterator();
78             while(it.hasNext()){
79                 compositePanel.add(((PanelFactory)it.next()).newPanel(object));
80             }
81             return compositePanel;
82         } else {
83             return createPanel(object);
84         }
85     }
86
87     /**
88      * Fixes the panel class to display
89      *
90      * @param theClass The class to instantiate
91      */

92     public void setClassName(Class JavaDoc theClass) {
93         class_ = theClass;
94     }
95
96     /**
97      * Fixes the inheritTypePanel value.
98      * @param inheritTypePanel true if this panel has to inherit panel from parents at the java type inheritance level
99      */

100     public void setInheritTypePanel(boolean inheritTypePanel){
101         inheritTypePanel_ = inheritTypePanel;
102     }
103     
104     /**
105      * Indicates if this panel has to inherit panel from parents at the java type inheritance level.
106      */

107     public boolean inheritTypePanel(){
108         return inheritTypePanel_;
109     }
110
111     /**
112      * Addes a PanelFactory
113      * @param panelFactory The PanelFactory to add.
114      */

115     public void addInheritPanelFactory(PanelFactory panelFactory){
116         subPanels_.add(panelFactory);
117     }
118 }
119
Popular Tags