KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > phoenix > components > kernel > beanshell > BeanShellGUI


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.phoenix.components.kernel.beanshell;
9
10 import bsh.EvalError;
11 import bsh.Interpreter;
12 import bsh.util.JConsole;
13 import java.awt.BorderLayout JavaDoc;
14 import java.awt.Dimension JavaDoc;
15 import java.awt.event.ActionEvent JavaDoc;
16 import java.awt.event.ActionListener JavaDoc;
17 import javax.swing.JFrame JavaDoc;
18 import javax.swing.JMenu JavaDoc;
19 import javax.swing.JMenuBar JavaDoc;
20 import javax.swing.JMenuItem JavaDoc;
21 import javax.swing.JPanel JavaDoc;
22 import org.apache.avalon.phoenix.interfaces.Kernel;
23
24 /**
25  * @author Paul Hammant <a HREF="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
26  * @version $Revision: 1.3 $
27  */

28 public class BeanShellGUI
29     extends JPanel JavaDoc
30     implements ActionListener JavaDoc
31 {
32     private JConsole m_jConsole;
33
34     private Interpreter m_interpreter;
35
36     private Thread JavaDoc m_thread;
37
38     private JFrame JavaDoc m_frame;
39
40     /**
41      * Construct a BeanShellGUI with a handle on the Kernel.
42      */

43     public BeanShellGUI( Kernel kernel )
44     {
45         setPreferredSize( new Dimension JavaDoc( 600, 480 ) );
46
47         m_jConsole = new JConsole();
48
49         this.setLayout( new BorderLayout JavaDoc() );
50         this.add( m_jConsole, BorderLayout.CENTER );
51
52         m_interpreter = new Interpreter( m_jConsole );
53         try
54         {
55             m_interpreter.set( "phoenix-kernel", kernel );
56         }
57         catch( EvalError ee )
58         {
59             ee.printStackTrace();
60         }
61     }
62
63     /**
64      * Initialize after construction.
65      *
66      */

67     public void init()
68     {
69         m_frame = new JFrame JavaDoc( "BeanShell - Phoenix management" );
70         m_frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
71         m_frame.getContentPane().add( this, BorderLayout.CENTER );
72
73         JMenuBar JavaDoc menubar = new JMenuBar JavaDoc();
74         JMenu JavaDoc menu = new JMenu JavaDoc( "File" );
75         JMenuItem JavaDoc mi = new JMenuItem JavaDoc( "Close" );
76
77         mi.addActionListener( this );
78         menu.add( mi );
79         menubar.add( menu );
80
81         m_frame.setJMenuBar( menubar );
82
83         m_thread = new Thread JavaDoc( m_interpreter );
84
85         m_thread.start();
86         m_frame.setVisible( true );
87         m_frame.pack();
88     }
89
90     /**
91      * Method actionPerformed by the menu options.
92      *
93      * @param event the action event.
94      *
95      */

96     public void actionPerformed( final ActionEvent JavaDoc event )
97     {
98         final String JavaDoc command = event.getActionCommand();
99
100         if( command.equals( "Close" ) )
101         {
102             m_thread.interrupt();
103             m_frame.dispose();
104         }
105     }
106 }
107
Popular Tags