KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swing > BasicSwingConsole


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 swing;
28
29 import java.awt.BorderLayout JavaDoc;
30 import java.util.Vector JavaDoc;
31
32 import javax.swing.JFrame JavaDoc;
33 import javax.swing.JSplitPane JavaDoc;
34
35 import org.objectweb.fractal.adl.ADLException;
36 import org.objectweb.fractal.adl.Factory;
37 import org.objectweb.fractal.adl.FactoryFactory;
38 import org.objectweb.fractal.api.Component;
39 import org.objectweb.fractal.api.NoSuchInterfaceException;
40 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
41 import org.objectweb.fractal.util.Fractal;
42 import org.objectweb.util.explorer.api.Tree;
43 import org.objectweb.util.explorer.core.common.api.ContextContainer;
44 import org.objectweb.util.explorer.core.common.lib.DefaultContextContainer;
45 import org.objectweb.util.explorer.parser.api.ParserConfiguration;
46 import org.objectweb.util.explorer.swing.api.Explorer;
47 import org.objectweb.util.explorer.swing.api.StatusBar;
48 import org.objectweb.util.explorer.swing.api.ViewPanel;
49 import org.objectweb.util.explorer.swing.lib.DefaultTreePanel;
50 import org.objectweb.util.trace.TraceSystem;
51
52
53 /**
54  * This class builds a example console built on top of the Explorer Framework.
55  * This console allows us to manage various Java Object such as <code>java.util.List</code>.
56  *
57  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>,
58  * <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>
59  *
60  * @version 0.1
61  */

62 public class BasicSwingConsole {
63
64     public BasicSwingConsole(String JavaDoc configFile){
65         
66         try {
67             // Creates a Fractal Explorer instance.
68
Factory f = FactoryFactory.getFactory(FactoryFactory.FRACTAL_BACKEND);
69             Component explorer = (Component)f.newComponent("swing.SwingFractalExplorer",null);
70             Fractal.getLifeCycleController(explorer).startFc();
71
72             // Loads the configuration file.
73
ParserConfiguration parser = (ParserConfiguration)explorer.getFcInterface(ParserConfiguration.PARSER_CONFIGURATION);
74             parser.addPropertyFile(configFile);
75             parser.parse();
76         
77             // Populates the tree.
78
Tree treeItf = (Tree)explorer.getFcInterface(Tree.TREE);
79             treeItf.addEntry("Java Properties", System.getProperties());
80             ContextContainer contextContainer = new DefaultContextContainer();
81             contextContainer.addEntry("Object 1", new Object JavaDoc());
82             contextContainer.addEntry("Object 2", new Object JavaDoc());
83             treeItf.addEntry("Context", contextContainer);
84             treeItf.addEntry("Vector", new Vector JavaDoc());
85
86             // Configures the main frame.
87
Explorer explorerItf = (Explorer)explorer.getFcInterface(Explorer.EXPLORER);
88             ViewPanel viewPanelItf = (ViewPanel)explorer.getFcInterface(ViewPanel.VIEW_PANEL);
89             StatusBar statusBar = (StatusBar)explorer.getFcInterface(StatusBar.STATUS_BAR);
90             JFrame JavaDoc frame = new JFrame JavaDoc("Explorer GUI");
91             frame.getContentPane().setLayout(new BorderLayout JavaDoc());
92             frame.getContentPane().add(new JSplitPane JavaDoc(
93                     JSplitPane.HORIZONTAL_SPLIT,
94                     true,
95                     new DefaultTreePanel(explorerItf.getTree()),
96                     viewPanelItf.getViewPanel()), BorderLayout.CENTER);
97             frame.getContentPane().add(statusBar.getStatusBar(), BorderLayout.SOUTH);
98             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
99             frame.pack();
100             frame.setVisible(true);
101             
102         } catch (ADLException e) {
103             e.printStackTrace();
104         } catch (IllegalLifeCycleException e) {
105             e.printStackTrace();
106         } catch (NoSuchInterfaceException e) {
107             e.printStackTrace();
108         }
109         
110     }
111
112     public static void main(String JavaDoc[] args){
113         TraceSystem.setLevel("debug");
114         if(args.length != 0) {
115             new BasicSwingConsole(args[0]);
116         } else {
117             TraceSystem.get("explorer").debug("No available argument!");
118         }
119     }
120
121 }
122
Popular Tags