KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swing > ReflectorSwingConsole


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: ReflectorSwingConsole.java,v 1.2 2005/07/06 15:36:01 moroy Exp $
27 ====================================================================*/

28
29 package swing;
30 import java.awt.BorderLayout JavaDoc;
31 import java.io.File JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.net.MalformedURLException JavaDoc;
34 import java.util.jar.JarFile JavaDoc;
35
36 import javax.swing.JFrame JavaDoc;
37 import javax.swing.JSplitPane JavaDoc;
38
39 import org.objectweb.fractal.adl.ADLException;
40 import org.objectweb.fractal.adl.Factory;
41 import org.objectweb.fractal.adl.FactoryFactory;
42 import org.objectweb.fractal.api.Component;
43 import org.objectweb.fractal.api.NoSuchInterfaceException;
44 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
45 import org.objectweb.fractal.util.Fractal;
46 import org.objectweb.util.explorer.api.Tree;
47 import org.objectweb.util.explorer.parser.api.ParserConfiguration;
48 import org.objectweb.util.explorer.plugin.java.reflect.JarFileStructure;
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 import org.objectweb.util.trace.TraceSystem;
54
55 /**
56  * This class builds a example console built on top of the Explorer Framework.
57  * This console allows us to browse a standalone Java archive.
58  *
59  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>,
60  * <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>
61  *
62  * @version 0.1
63  */

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