hammant 01/11/04 00:31:54 Modified: apps/db/src/java/org/apache/avalon/db/test TestGUI.java Log: Test GUI now hand crafted. Revision Changes Path 1.3 +139 -385 jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/test/TestGUI.java Index: TestGUI.java =================================================================== RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/test/TestGUI.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TestGUI.java 2001/11/03 04:26:21 1.2 +++ TestGUI.java 2001/11/04 08:31:54 1.3 @@ -7,419 +7,173 @@ */ package org.apache.avalon.db.test; -import java.awt.*; -import java.util.StringTokenizer; -import java.util.Vector; +import javax.swing.*; + import java.sql.Connection; import java.sql.DriverManager; import java.sql.Driver; import java.sql.ResultSet; import java.sql.Statement; -import javax.swing.*; +import java.sql.SQLException; + +import java.awt.*; +import java.awt.event.*; + import org.apache.avalon.db.driver.AvalonDBDriver; /** - * Little GUI for AvalonDB Testing. Only socket connection in the - * moment. Code was mostly generated from IBM'S Dark Age :)) + * TestGUI for testing the AvalonDB. * * @author Gerhard Froehlich <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> */ -public class TestGUI extends JFrame { - private JPanel ivjAvalonDBClientPane = null; - private JPanel ivjJFrameContentPane = null; - private JPanel ivjJPanel1 = null; - private JScrollPane ivjJScrollPane1 = null; - private JScrollPane ivjJScrollPane2 = null; - private JTextField ivjConnectTextField = null; - private JTextArea ivjInputTextArea = null; - private JTextArea ivjOutputTextArea = null; +public class TestGUI { private Connection con = null; + private final JButton execute = new JButton("Execute"); + private final JButton connect = new JButton("Connect"); + private final JButton test = new JButton("test"); + private final JTextArea inputArea = new JTextArea(); + private final JTextArea outputArea = new JTextArea(); + private final JTextField connectField = new JTextField(); + private final JScrollPane inputAreaScrollPane = new JScrollPane(); + private final JScrollPane outputAreaScrollPane = new JScrollPane(); - class IvjEventHandler implements java.awt.event.ActionListener { - public void actionPerformed(java.awt.event.ActionEvent e) { - if (e.getSource() == TestGUI.this.getExecuteButton()) - connEtoC1(e); - if (e.getSource() == TestGUI.this.getConnectButton()) - connEtoC2(e); - } - } - private JButton ivjConnectButton = null; - IvjEventHandler ivjEventHandler = new IvjEventHandler(); - private JButton ivjExecuteButton = null; - - /** - * TestGUI constructor comment. - */ public TestGUI() { - super(); - try { - Driver driver = (Driver)Class.forName("org.apache.avalon.db.driver.AvalonDBDriver").newInstance(); - DriverManager.registerDriver(driver); - } catch (Exception e) { - handleException(e); - } - initialize(); - } - - /** - * TestGUI constructor comment. - * @param title java.lang.String - */ - public TestGUI(String title) { - super(title); - } - - /** - * Comment - */ - public void connectButton_ActionPerformed(java.awt.event.ActionEvent actionEvent) { - return; + setupDBDriver(); } - /** - * connEtoC1: (ExecuteButton.action.actionPerformed(java.awt.event.ActionEvent) --> TestGUI.executeButton_ActionPerformed(Ljava.awt.event.ActionEvent;)V) - * @param arg1 java.awt.event.ActionEvent - */ - /* WARNING: THIS METHOD WILL BE REGENERATED. */ - private void connEtoC1(java.awt.event.ActionEvent arg1) { - try { - if(con != null) { - Statement statement = con.createStatement(); - ResultSet rs = statement.executeQuery(ivjInputTextArea.getText()); - //TODO rs processing - } else { - ivjOutputTextArea.setText("No connection"); + public Component createComponents() { + + outputArea.setEditable(false); + inputAreaScrollPane.setViewportView(inputArea); + outputAreaScrollPane.setViewportView(outputArea); + + connect.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + if(!connectField.getText().equals("")) { + System.out.println("Fired JDBC connect!"); + con = DriverManager.getConnection(connectField.getText(),null); + outputArea.setText("Connection established!"); + } else { + outputArea.setText("Please insert JDBC URL!"); + } + } catch (Exception ex) { + handleException(ex); + } } - this.executeButton_ActionPerformed(arg1); - } catch (Throwable ivjExc) { - handleException(ivjExc); - } - } + }); + - /** - * connEtoC2: (ConnectButton.action.actionPerformed(java.awt.event.ActionEvent) --> TestGUI.connectButton_ActionPerformed(Ljava.awt.event.ActionEvent;)V) - * @param arg1 java.awt.event.ActionEvent - */ - /* WARNING: THIS METHOD WILL BE REGENERATED. */ - private void connEtoC2(java.awt.event.ActionEvent arg1) { - try { - if(!ivjConnectTextField.getText().equals("")) { - System.out.println("Fired JDBC connect!"); - con = DriverManager.getConnection(ivjConnectTextField.getText(),null); - ivjOutputTextArea.setText("Connection established!"); - } else { - ivjOutputTextArea.setText("Please insert JDBC URL!"); + execute.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if(con != null) { + try { + Statement statement = con.createStatement(); + ResultSet rs = statement.executeQuery(inputArea.getText()); + } catch (SQLException slqe) { + handleException(slqe); + } + //TODO rs processing + } else { + outputArea.setText("No connection!"); + } } - this.connectButton_ActionPerformed(arg1); - } catch (Throwable ivjExc) { - ivjOutputTextArea.setText("Connection not established!"); - handleException(ivjExc); - } - } + }); - /** - * Comment - */ - public void executeButton_ActionPerformed(java.awt.event.ActionEvent actionEvent) { - return; + JPanel pane = new JPanel(); + pane.setBorder(BorderFactory.createEmptyBorder( + 5, //top + 5, //left + 5, //bottom + 5) //right + + ); + GridBagLayout gridbag = new GridBagLayout(); + GridBagConstraints c = new GridBagConstraints(); + pane.setLayout(gridbag); + c.fill = GridBagConstraints.HORIZONTAL; + + //Connect Text Field + c.gridx = 0; + c.gridy = 0; + c.ipadx = 250; + c.ipady = 8; + gridbag.setConstraints(connectField, c); + pane.add(connectField); + + c.gridx = 1; + c.gridy = 0; + c.ipadx = 0; + c.ipady = 0; + gridbag.setConstraints(connect, c); + pane.add(connect); + + c.gridx = 2; + c.gridy = 0; + c.ipadx = 0; + c.ipady = 0; + gridbag.setConstraints(execute, c); + pane.add(execute); + + c.gridx = 0; + c.gridy = 1; + c.gridwidth = 3; + c.ipadx = 300; + c.ipady = 100; + c.insets = new Insets(2,0,0,0); + gridbag.setConstraints(inputAreaScrollPane, c); + pane.add(inputAreaScrollPane); + + c.gridx = 0; + c.gridy = 2; + c.gridwidth = 3; + c.insets = new Insets(2,0,0,0); + c.ipadx = 300; + c.ipady = 100; + gridbag.setConstraints(outputAreaScrollPane, c); + pane.add(outputAreaScrollPane); + return pane; } - /** - * Return the AvalonDBClientPane property value. - * @return javax.swing.JPanel - */ - /* WARNING: THIS METHOD WILL BE REGENERATED. */ - private JPanel getAvalonDBClientPane() { - if (ivjAvalonDBClientPane == null) { - try { - ivjAvalonDBClientPane = new JPanel(); - ivjAvalonDBClientPane.setName("AvalonDBClientPane"); - ivjAvalonDBClientPane.setLayout(null); - getAvalonDBClientPane().add(getJPanel1(), getJPanel1().getName()); - // user code begin {1} - // user code end - } catch (Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjAvalonDBClientPane; + public static void main(String args[]) { + //Set the Look and Feel + try { + UIManager.setLookAndFeel( + UIManager.getCrossPlatformLookAndFeelClassName()); + } catch (Exception e) { } + + JFrame frame = new JFrame("TestGUI"); + TestGUI app = new TestGUI(); + Component contents = app.createComponents(); + frame.getContentPane().add(contents, BorderLayout.CENTER); + + //Finish setting up the frame, and show it. + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + frame.pack(); + frame.setSize(450, 330); + frame.setVisible(true); + frame.setResizable(false); } - /** - * Return the JButton1 property value. - * @return javax.swing.JButton - */ - /* WARNING: THIS METHOD WILL BE REGENERATED. */ - private JButton getConnectButton() { - if (ivjConnectButton == null) { - try { - ivjConnectButton = new JButton(); - ivjConnectButton.setName("ConnectButton"); - ivjConnectButton.setText("Connect"); - ivjConnectButton.setBounds(208, 15, 85, 25); - // user code begin {1} - // user code end - } catch (Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjConnectButton; + private void setupDBDriver() { + try { + Driver driver = (Driver)Class.forName("org.apache.avalon.db.driver.AvalonDBDriver").newInstance(); + DriverManager.registerDriver(driver); + } catch (Exception e) { + handleException(e); + } } - /** - * Return the JButton2 property value. - * @return javax.swing.JButton - */ - /* WARNING: THIS METHOD WILL BE REGENERATED. */ - private JButton getExecuteButton() { - if (ivjExecuteButton == null) { - try { - ivjExecuteButton = new JButton(); - ivjExecuteButton.setName("ExecuteButton"); - ivjExecuteButton.setText("Execute"); - ivjExecuteButton.setBounds(301, 14, 85, 25); - // user code begin {1} - // user code end - } catch (Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjExecuteButton; - } - /** - * Return the JFrameContentPane property value. - * @return javax.swing.JPanel - */ - /* WARNING: THIS METHOD WILL BE REGENERATED. */ - private JPanel getJFrameContentPane() { - if (ivjJFrameContentPane == null) { - try { - ivjJFrameContentPane = new JPanel(); - ivjJFrameContentPane.setName("JFrameContentPane"); - ivjJFrameContentPane.setLayout(new BorderLayout()); - getJFrameContentPane().add(getAvalonDBClientPane(), "Center"); - // user code begin {1} - // user code end - } catch (Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjJFrameContentPane; - } - /** - * Return the JPanel1 property value. - * @return javax.swing.JPanel - */ - /* WARNING: THIS METHOD WILL BE REGENERATED. */ - private JPanel getJPanel1() { - if (ivjJPanel1 == null) { - try { - ivjJPanel1 = new JPanel(); - ivjJPanel1.setName("JPanel1"); - ivjJPanel1.setLayout(null); - ivjJPanel1.setBounds(1, 2, 462, 326); - getJPanel1().add(getJScrollPane1(), getJScrollPane1().getName()); - getJPanel1().add(getJScrollPane2(), getJScrollPane2().getName()); - getJPanel1().add(getConnectTextField(), getConnectTextField().getName()); - getJPanel1().add(getConnectButton(), getConnectButton().getName()); - getJPanel1().add(getExecuteButton(), getExecuteButton().getName()); - // user code begin {1} - // user code end - } catch (Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjJPanel1; - } - - /** - * Return the JScrollPane1 property value. - * @return javax.swing.JScrollPane - */ - /* WARNING: THIS METHOD WILL BE REGENERATED. */ - private JScrollPane getJScrollPane1() { - if (ivjJScrollPane1 == null) { - try { - ivjJScrollPane1 = new JScrollPane(); - ivjJScrollPane1.setName("JScrollPane1"); - ivjJScrollPane1.setBounds(4, 180, 458, 126); - getJScrollPane1().setViewportView(getOutputTextArea()); - // user code begin {1} - // user code end - } catch (Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjJScrollPane1; - } - - /** - * Return the JScrollPane2 property value. - * @return javax.swing.JScrollPane - */ - /* WARNING: THIS METHOD WILL BE REGENERATED. */ - private JScrollPane getJScrollPane2() { - if (ivjJScrollPane2 == null) { - try { - ivjJScrollPane2 = new JScrollPane(); - ivjJScrollPane2.setName("JScrollPane2"); - ivjJScrollPane2.setBounds(5, 44, 457, 130); - getJScrollPane2().setViewportView(getInputTextArea()); - // user code begin {1} - // user code end - } catch (Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjJScrollPane2; - } - - - - - /** - * Called whenever the part throws an exception. - * @param exception java.lang.Throwable - */ private void handleException(Throwable exception) { - - /* Uncomment the following lines to print uncaught exceptions to stdout */ - System.out.println("--------- UNCAUGHT EXCEPTION ---------"); + System.out.println("--------- UNCAUGHT EXCEPTION ---------"); exception.printStackTrace(System.out); - } - /** - * Initializes connections - * @exception java.lang.Exception The exception description. - */ - /* WARNING: THIS METHOD WILL BE REGENERATED. */ - private void initConnections() throws Exception { - // user code begin {1} - // user code end - getExecuteButton().addActionListener(ivjEventHandler); - getConnectButton().addActionListener(ivjEventHandler); - } - /** - * Initialize the class. - */ - /* WARNING: THIS METHOD WILL BE REGENERATED. */ - private void initialize() { - try { - // user code begin {1} - // user code end - setName("TestGUI"); - setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - setResizable(false); - setSize(469, 370); - setTitle("TestGUI"); - setContentPane(getJFrameContentPane()); - initConnections(); - } catch (Throwable ivjExc) { - handleException(ivjExc); - } - // user code begin {2} - // user code end - } - /** - * Starts the application. - * @param args an array of command-line arguments - */ - public static void main(String[] args) { - try { - /* Set native look and feel */ - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - /* Create the frame */ - TestGUI aAvalonDBClient = new TestGUI(); - /* Add a windowListener for the windowClosedEvent */ - aAvalonDBClient.addWindowListener(new java.awt.event.WindowAdapter() { - public void windowClosed(java.awt.event.WindowEvent e) { - System.exit(0); - } - }); - aAvalonDBClient.setVisible(true); - } catch (Throwable exception) { - System.err.println("Exception occurred in main() of TestGUI"); - exception.printStackTrace(System.out); - } - } - - /** - * Return the JTextField1 property value. - * @return javax.swing.JTextField - */ - /* WARNING: THIS METHOD WILL BE REGENERATED. */ - private JTextField getConnectTextField() { - if (ivjConnectTextField == null) { - try { - ivjConnectTextField = new JTextField(); - ivjConnectTextField.setName("ConnectTextField"); - ivjConnectTextField.setBounds(6, 19, 186, 20); - // user code begin {1} - // user code end - } catch (Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjConnectTextField; - } - - /** - * Return the JTextArea1 property value. - * @return javax.swing.JTextArea - */ - /* WARNING: THIS METHOD WILL BE REGENERATED. */ - private JTextArea getInputTextArea() { - if (ivjInputTextArea == null) { - try { - ivjInputTextArea = new JTextArea(); - ivjInputTextArea.setName("InputTextArea"); - ivjInputTextArea.setBounds(-12, 0, 463, 127); - // user code begin {1} - // user code end - } catch (Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjInputTextArea; - } - /** - * Return the JTextArea2 property value. - * @return javax.swing.JTextArea - */ - /* WARNING: THIS METHOD WILL BE REGENERATED. */ - private JTextArea getOutputTextArea() { - if (ivjOutputTextArea == null) { - try { - ivjOutputTextArea = new JTextArea(); - ivjOutputTextArea.setName("OutputTextArea"); - ivjOutputTextArea.setBounds(0, 0, 425, 123); - ivjOutputTextArea.setEditable(false); - // user code begin {1} - // user code end - } catch (Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjOutputTextArea; + outputArea.setText("--------- UNCAUGHT EXCEPTION ---------" + "\n" + + exception + + "\n" + exception.getMessage()); } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>