KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > swing > Main


1 /*===========================================================================
2
3 ObjectWeb Explorer Framework
4 Copyright (C) 2000-2005 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): Philippe Merle, Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================
26 $Id: Main.java,v 1.2 2005/07/06 15:36:02 moroy Exp $
27 ===========================================================================*/

28
29 package test.swing;
30
31 import java.awt.BorderLayout JavaDoc;
32 import java.awt.Dimension JavaDoc;
33 import java.util.HashMap JavaDoc;
34
35 import javax.swing.JFrame JavaDoc;
36 import javax.swing.JSplitPane JavaDoc;
37
38 import org.objectweb.fractal.adl.ADLException;
39 import org.objectweb.fractal.adl.Factory;
40 import org.objectweb.fractal.adl.FactoryFactory;
41 import org.objectweb.fractal.api.Component;
42 import org.objectweb.fractal.api.NoSuchInterfaceException;
43 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
44 import org.objectweb.fractal.util.Fractal;
45 import org.objectweb.util.explorer.api.Tree;
46 import org.objectweb.util.explorer.core.common.api.ContextContainer;
47 import org.objectweb.util.explorer.core.common.lib.DefaultContextContainer;
48 import org.objectweb.util.explorer.parser.api.ParserConfiguration;
49 import org.objectweb.util.explorer.swing.api.Explorer;
50 import org.objectweb.util.explorer.swing.api.StatusBar;
51 import org.objectweb.util.explorer.swing.api.ViewPanel;
52 import org.objectweb.util.explorer.swing.lib.DefaultTreePanel;
53
54 import test.Calculate;
55
56 /**
57  * This class defines a console in order to test the Explorer Framework features.
58  *
59  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
60  * @version 0.1
61  */

62 public class Main
63      extends JFrame JavaDoc
64 {
65
66     /**
67      * Populates the tree
68      */

69     protected void populateTree(Tree tree) {
70         tree.addEntry("Java Properties", System.getProperties());
71         Calculate c = new Calculate();
72         ContextContainer contextContainer_ = new DefaultContextContainer();
73         contextContainer_.addEntry("Calculate", c);
74         tree.addEntry("Test", contextContainer_, 1);
75         tree.addEntry("Object", new Object JavaDoc(), 1);
76         tree.addEntry("Calculatrice", new Calculate());
77         tree.addEntry("HashMap class", HashMap JavaDoc.class);
78     }
79
80     /**
81      * Default constructor
82      */

83     public Main(String JavaDoc explorerPropertyFile) {
84         super("Explorer GUI");
85
86         try {
87             // Creates a Fractal Explorer instance.
88
Factory f = FactoryFactory.getFactory(FactoryFactory.FRACTAL_BACKEND);
89             Component explorer = (Component)f.newComponent("test.swing.SwingFractalExplorer",null);
90             Fractal.getLifeCycleController(explorer).startFc();
91
92             // Loads the configuration file.
93
ParserConfiguration parser = (ParserConfiguration)explorer.getFcInterface(ParserConfiguration.PARSER_CONFIGURATION);
94             parser.addPropertyFile(explorerPropertyFile);
95             parser.parse();
96         
97             // Populates the tree.
98
populateTree((Tree)explorer.getFcInterface(Tree.TREE));
99
100             // Configures the main frame.
101
Explorer explorerItf = (Explorer)explorer.getFcInterface(Explorer.EXPLORER);
102             ViewPanel viewPanelItf = (ViewPanel)explorer.getFcInterface(ViewPanel.VIEW_PANEL);
103             StatusBar statusBar = (StatusBar)explorer.getFcInterface(StatusBar.STATUS_BAR);
104             JFrame JavaDoc frame = new JFrame JavaDoc("Explorer GUI");
105             frame.getContentPane().setLayout(new BorderLayout JavaDoc());
106             frame.getContentPane().add(new JSplitPane JavaDoc(
107                     JSplitPane.HORIZONTAL_SPLIT,
108                     true,
109                     new DefaultTreePanel(explorerItf.getTree()),
110                     viewPanelItf.getViewPanel()), BorderLayout.CENTER);
111             frame.getContentPane().add(statusBar.getStatusBar(), BorderLayout.SOUTH);
112             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
113             frame.pack();
114
115             // Centers the frame
116
Dimension JavaDoc screenSize =
117                 java.awt.Toolkit.getDefaultToolkit().getScreenSize();
118             setLocation(
119                 (screenSize.width - getWidth()) / 2,
120                 (screenSize.height - getHeight()) / 2);
121             
122             frame.setVisible(true);
123             
124         } catch (ADLException e) {
125             e.printStackTrace();
126         } catch (IllegalLifeCycleException e) {
127             e.printStackTrace();
128         } catch (NoSuchInterfaceException e) {
129             e.printStackTrace();
130         }
131     }
132
133     public static void main(String JavaDoc[] args) {
134         new Main("resources/config/demoConfig.xml");
135     }
136
137 }
138
139
140
141
Popular Tags