Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ScriptingPanel.java

00001 /*
00002  * ScriptingInterface.java
00003  *
00004  * Created on 28 November 2002, 14:34
00005  */
00006 
00007 package TestGUI;
00008 import org.apache.bsf.*;
00009 import GuiComponents.scripting.*;
00010 import GuiComponents.Console.*;
00011 import javax.swing.*;
00012 
00017 public class ScriptingPanel extends javax.swing.JPanel {
00018     
00020     public ScriptingPanel(MyJPanel parent) {        
00021         initComponents();
00022         initManager(parent);
00023     }
00024     
00030     private void initComponents() {//GEN-BEGIN:initComponents
00031         java.awt.GridBagConstraints gridBagConstraints;
00032         
00033         jButtonPanel = new javax.swing.JPanel();
00034         bBeanShell = new javax.swing.JButton();
00035         bJython = new javax.swing.JButton();
00036         jLabel1 = new javax.swing.JLabel();
00037         jLabel2 = new javax.swing.JLabel();
00038         
00039         setLayout(new java.awt.BorderLayout());
00040         
00041         jButtonPanel.setLayout(new java.awt.GridBagLayout());
00042                         
00043         bBeanShell.setText("BeanShell");
00044         bBeanShell.addActionListener(new java.awt.event.ActionListener() {
00045             public void actionPerformed(java.awt.event.ActionEvent evt) {
00046                 bBeanShellActionPerformed(evt);
00047             }
00048         });
00049         
00050         gridBagConstraints = new java.awt.GridBagConstraints();
00051         gridBagConstraints.gridx = 0;
00052         gridBagConstraints.gridy = 2;
00053         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
00054         gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00055         jButtonPanel.add(bBeanShell, gridBagConstraints);
00056         
00057         bJython.setText("Jython");
00058         bJython.addActionListener(new java.awt.event.ActionListener() {
00059             public void actionPerformed(java.awt.event.ActionEvent evt) {
00060                 bJythonActionPerformed(evt);
00061             }
00062         });
00063         
00064         gridBagConstraints = new java.awt.GridBagConstraints();
00065         gridBagConstraints.gridx = 0;
00066         gridBagConstraints.gridy = 4;
00067         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
00068         gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00069         jButtonPanel.add(bJython, gridBagConstraints);
00070         
00071         jLabel1.setText("Create new scripting console...");
00072         gridBagConstraints = new java.awt.GridBagConstraints();
00073         gridBagConstraints.gridx = 0;
00074         gridBagConstraints.gridy = 0;
00075         gridBagConstraints.gridwidth = 2;
00076         gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00077         jButtonPanel.add(jLabel1, gridBagConstraints);
00078         
00079         gridBagConstraints = new java.awt.GridBagConstraints();
00080         gridBagConstraints.gridx = 2;
00081         gridBagConstraints.gridy = 5;
00082         gridBagConstraints.weightx = 1.0;
00083         gridBagConstraints.weighty = 1.0;
00084         jButtonPanel.add(jLabel2, gridBagConstraints);
00085         
00086         add(jButtonPanel, java.awt.BorderLayout.CENTER);
00087         
00088     }//GEN-END:initComponents
00089 
00090     private void bJythonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bJythonActionPerformed
00091         addNewConsole(ScriptingInterface.instance().getJythonInterpreter(), "Jython");
00092     }//GEN-LAST:event_bJythonActionPerformed
00093     
00094     private void initManager(MyJPanel parent) {        
00095         try {
00096             ScriptingInterface.instance().getManager().declareBean("Panel", parent, parent.getClass());            
00097         } catch (BSFException be) {
00098             System.err.println("Error initializing manager: " + be);
00099         }
00100     }
00101     
00102     private void bBeanShellActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBeanShellActionPerformed
00103         addNewConsole(ScriptingInterface.instance().getBeanShellInterpreter(), "BeanShell");
00104     }//GEN-LAST:event_bBeanShellActionPerformed
00105     
00109     protected boolean addNewConsole(Interpreter interpreter, String suffix) {    
00110         if (interpreter == null) {
00111             MyJPanel.getMessageArea().append("Can only have 1 scripting window open at once\n");
00112             return false;
00113         }       
00114         JFrame frame = new JFrame();
00115         frame.addWindowListener(new java.awt.event.WindowAdapter() {
00116             public void windowClosing(java.awt.event.WindowEvent evt) {
00117                 System.out.println("Closing window");
00118                 evt.getWindow().hide();
00119                 evt.getWindow().dispose();
00120                 
00121             }
00122         });
00123 
00124         JScrollPane scroll = new JScrollPane();
00125         scroll.setViewportView(interpreter.getConsole());
00126         frame.getContentPane().add(scroll);  
00127         frame.setTitle("Scripting Window:" + suffix);
00128         frame.show();
00129         frame.setSize(800, 500);        
00130         
00131         return true;
00132     }
00133         
00134     // Variables declaration - do not modify//GEN-BEGIN:variables
00135     private javax.swing.JButton bBeanShell;
00136     private javax.swing.JButton bJython;
00137     private javax.swing.JPanel jButtonPanel;
00138     private javax.swing.JLabel jLabel1;
00139     private javax.swing.JLabel jLabel2;
00140     // End of variables declaration//GEN-END:variables   
00141 }

Generated on Thu Jul 15 09:55:48 2004 for SCT DAQ/DCS Software - Java by doxygen 1.3.5