Source Code Cross Referenced for BeanShellFrame.java in  » Science » Cougaar12_4 » org » cougaar » tutorials » bsh » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.tutorials.bsh 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* *************************************************************************
002:         *
003:         * <rrl>
004:         * =========================================================================
005:         *                                  LEGEND
006:         *
007:         * Use, duplication, or disclosure by the Government is as set forth in the
008:         * Rights in technical data noncommercial items clause DFAR 252.227-7013 and
009:         * Rights in noncommercial computer software and noncommercial computer
010:         * software documentation clause DFAR 252.227-7014, with the exception of
011:         * third party software known as Sun Microsystems' Java Runtime Environment
012:         * (JRE), Quest Software's JClass, Oracle's JDBC, and JGoodies which are
013:         * separately governed under their commercial licenses.  Refer to the
014:         * license directory for information regarding the open source packages used
015:         * by this software.
016:         *
017:         * Copyright 2006 by BBNT Solutions, LLC.
018:         * =========================================================================
019:         * </rrl>
020:         *
021:         * $Id: BeanShellFrame.java,v 1.1 2007/06/20 19:13:13 jzinky Exp $
022:         *
023:         * ************************************************************************/
024:
025:        package org.cougaar.tutorials.bsh;
026:
027:        import java.awt.BorderLayout;
028:        import java.awt.event.ActionEvent;
029:        import java.awt.event.ActionListener;
030:
031:        import javax.swing.JButton;
032:        import javax.swing.JFrame;
033:        import javax.swing.JPanel;
034:
035:        import bsh.EvalError;
036:        import bsh.Interpreter;
037:        import bsh.util.JConsole;
038:
039:        /**
040:         * A frame containing a Bean Shell console.  Unfortunately, I can't
041:         * figure out how to gracefully stop the interpreter.  That means it
042:         * might be best to hold on to the frame, redisplaying it as needed.
043:         *
044:         * @version $Revision: 1.1 $ on $Date: 2007/06/20 19:13:13 $
045:         */
046:        public class BeanShellFrame extends JFrame {
047:
048:            /** The Bean Shell console window. */
049:            private JConsole console;
050:
051:            /** The Bean Shell interpreter. */
052:            private Interpreter interpreter;
053:
054:            /**
055:             * Constructs a new Bean Shell Frame.  The frame consists of a
056:             * bean shell console and a close button.  The default size is 500
057:             * x 300.
058:             */
059:            public BeanShellFrame() {
060:                this ("Bean Shell");
061:            }
062:
063:            /**
064:             * Constructs a new Bean Shell Frame.  The frame consists of a
065:             * bean shell console and a close button.  The default size is 500
066:             * x 300.
067:             */
068:            public BeanShellFrame(String title) {
069:                super (title);
070:                console = new JConsole();
071:                interpreter = new Interpreter(console);
072:                init(interpreter);
073:
074:                getContentPane().setLayout(new BorderLayout());
075:                getContentPane().add(console, BorderLayout.CENTER);
076:                JPanel buttonPanel = makeButtonPanel();
077:                if (buttonPanel != null) {
078:                    getContentPane().add(buttonPanel, BorderLayout.SOUTH);
079:                }
080:                setSize(700, 600);
081:            }
082:
083:            /**
084:             * Performs any desired initializations on the Bean Shell
085:             * Interpreter.  This method can be overridden in extending
086:             * classes to perform additional initializations on the
087:             * interpreter.
088:             *
089:             * @param i the bean shell interpreter
090:             */
091:            protected void init(Interpreter i) {
092:                try {
093:                    i.set("bsh.system.shutdownOnExit", false);
094:                    i.eval("show();");
095:                } catch (EvalError e) {
096:                    // Do nothing, our inits didn't work out.
097:                    System.out.println("BeanShellFrame.init failure: ");
098:                    e.printStackTrace();
099:                }
100:            }
101:
102:            /**
103:             * Creates the button panel on the frame.  The default is a close
104:             * button.  Extending classes can create a more compilcated button
105:             * panel if desired by overriding this method.
106:             */
107:            protected JPanel makeButtonPanel() {
108:                JButton closeButton = new JButton("Close");
109:                closeButton.addActionListener(new ActionListener() {
110:                    public void actionPerformed(ActionEvent e) {
111:                        setVisible(false);
112:                    }
113:                });
114:
115:                JPanel buttonPanel = new JPanel();
116:                buttonPanel.add(closeButton);
117:                return buttonPanel;
118:            }
119:
120:            /**
121:             * Import a class or package into the interpreter
122:             * 
123:             * @param path the fully qualified class or package name
124:             **/
125:            public void interpreterImport(String path) {
126:                try {
127:                    interpreter.eval("import " + path);
128:                } catch (EvalError e) {
129:                    throw new RuntimeException(e);
130:                }
131:            }
132:
133:            /**
134:             * Sets the bean shell variable <code>var</code> to
135:             * <code>obj</code> in the bean shell interpreter of this frame.
136:             *
137:             * @param var the bean shell variable to set
138:             * @param obj the value of the beans shell variable
139:             * <code>var</code>
140:             */
141:            public void set(String var, Object obj) {
142:                try {
143:                    interpreter.set(var, obj);
144:                } catch (EvalError e) {
145:                    throw new RuntimeException(e);
146:                }
147:            }
148:
149:            /**
150:             * Runs this interpreter in the current thread.  I don't think
151:             * this method will ever return because of limitations in the bean
152:             * shell interpreter API.
153:             */
154:            public void run() {
155:                interpreter.run();
156:            }
157:
158:            /**
159:             * Runs this interpreter in its own thread.
160:             */
161:            public void runInThread() {
162:                new Thread(interpreter).start();
163:            }
164:
165:            public static void main(String[] argv) {
166:                BeanShellFrame bsf = new BeanShellFrame();
167:                bsf.setTitle("Bean Shell");
168:                bsf.pack();
169:                bsf.setVisible(true);
170:                bsf.run();
171:            }
172:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.