Return-Path: Delivered-To: apmail-jakarta-avalon-cvs-archive@apache.org Received: (qmail 18463 invoked from network); 28 Apr 2002 17:04:22 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 28 Apr 2002 17:04:22 -0000 Received: (qmail 8026 invoked by uid 97); 28 Apr 2002 17:04:24 -0000 Delivered-To: qmlist-jakarta-archive-avalon-cvs@jakarta.apache.org Received: (qmail 7904 invoked by uid 97); 28 Apr 2002 17:04:23 -0000 Mailing-List: contact avalon-cvs-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list avalon-cvs@jakarta.apache.org Received: (qmail 7812 invoked by uid 97); 28 Apr 2002 17:04:23 -0000 Date: 28 Apr 2002 17:04:16 -0000 Message-ID: <20020428170416.56412.qmail@icarus.apache.org> From: leif@apache.org To: jakarta-avalon-excalibur-cvs@apache.org Subject: cvs commit: jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client AbstractTabularOptionDialog.java CreateSampleDialog.java AbstractOptionDialog.java ConnectDialog.java InstrumentClientFrame.java MenuBar.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N leif 02/04/28 10:04:16 Modified: instrument-client/src/java/org/apache/avalon/excalibur/instrument/client AbstractOptionDialog.java ConnectDialog.java InstrumentClientFrame.java MenuBar.java Added: instrument-client/src/java/org/apache/avalon/excalibur/instrument/client AbstractTabularOptionDialog.java CreateSampleDialog.java Log: Add the ability to add instrument samples at runtime. Revision Changes Path 1.3 +25 -6 jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/AbstractOptionDialog.java Index: AbstractOptionDialog.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/AbstractOptionDialog.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AbstractOptionDialog.java 3 Apr 2002 13:48:48 -0000 1.2 +++ AbstractOptionDialog.java 28 Apr 2002 17:04:15 -0000 1.3 @@ -22,12 +22,14 @@ import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; +import javax.swing.border.CompoundBorder; import javax.swing.border.EmptyBorder; +import javax.swing.border.EtchedBorder; /** * * @author Leif Mortenson - * @version CVS $Revision: 1.2 $ $Date: 2002/04/03 13:48:48 $ + * @version CVS $Revision: 1.3 $ $Date: 2002/04/28 17:04:15 $ * @since 4.1 */ public abstract class AbstractOptionDialog @@ -45,23 +47,37 @@ * Creates a new AbstractOptionDialog. * * @param frame Frame which owns the dialog. + * @param title Title for the dialog. * @param buttons List of buttons to display. */ - protected AbstractOptionDialog( JFrame frame, int buttons ) + protected AbstractOptionDialog( JFrame frame, String title, int buttons ) { - super( frame, true ); + super( frame, title, true ); JPanel contentPane = (JPanel)getContentPane(); contentPane.setLayout( new BorderLayout() ); contentPane.setBorder( new EmptyBorder( 5, 5, 5, 5 ) ); + JPanel backPane = new JPanel(); + backPane.setLayout( new BorderLayout() ); + backPane.setBorder( + new CompoundBorder( + new EmptyBorder( 0, 0, 5, 0 ), + new CompoundBorder( + new EtchedBorder( EtchedBorder.LOWERED ), + new EmptyBorder( 5, 5, 5, 5 ) + ) + ) + ); + contentPane.add( backPane, BorderLayout.CENTER ); + // Build the message - contentPane.add( new JLabel( getMessage(), SwingConstants.LEFT ), BorderLayout.NORTH ); + backPane.add( new JLabel( getMessage(), SwingConstants.LEFT ), BorderLayout.NORTH ); // Build the main panel JPanel mainPanel = getMainPanel(); - mainPanel.setBorder( new EmptyBorder( 5, 0, 5, 0 ) ); - contentPane.add( mainPanel, BorderLayout.CENTER ); + mainPanel.setBorder( new EmptyBorder( 5, 0, 0, 0 ) ); + backPane.add( mainPanel, BorderLayout.CENTER ); // Build the button panel @@ -112,6 +128,9 @@ setLocation( (int)( frameLocation.getX() + (frameSize.getWidth() - size.getWidth() ) / 2 ), (int)( frameLocation.getY() + (frameSize.getHeight() - size.getHeight() ) / 2 ) ); + + // Make the dialog a fixed size. + setResizable( false ); } /*--------------------------------------------------------------- 1.4 +42 -40 jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/ConnectDialog.java Index: ConnectDialog.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/ConnectDialog.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ConnectDialog.java 3 Apr 2002 13:48:48 -0000 1.3 +++ ConnectDialog.java 28 Apr 2002 17:04:15 -0000 1.4 @@ -7,14 +7,13 @@ */ package org.apache.avalon.excalibur.instrument.client; -import java.awt.FlowLayout; +import java.awt.Component; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JDialog; -import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; @@ -23,11 +22,11 @@ /** * * @author Leif Mortenson - * @version CVS $Revision: 1.3 $ $Date: 2002/04/03 13:48:48 $ + * @version CVS $Revision: 1.4 $ $Date: 2002/04/28 17:04:15 $ * @since 4.1 */ class ConnectDialog - extends AbstractOptionDialog + extends AbstractTabularOptionDialog { private JTextField m_hostField; private String m_host; @@ -44,7 +43,8 @@ */ ConnectDialog( InstrumentClientFrame frame ) { - super( frame, AbstractOptionDialog.BUTTON_OK | AbstractOptionDialog.BUTTON_CANCEL ); + super( frame, "Connect to Remote Instrument Manager", + AbstractOptionDialog.BUTTON_OK | AbstractOptionDialog.BUTTON_CANCEL ); } /*--------------------------------------------------------------- @@ -61,41 +61,6 @@ } /** - * Returns the main panel which makes up the guts of the dialog. - * - * @return The main panel. - */ - protected JPanel getMainPanel() - { - m_hostField = new JTextField(); - m_hostField.setColumns( 20 ); - m_portField = new JTextField(); - m_portField.setColumns( 6 ); - - JPanel panel = new JPanel(); - - panel.setLayout( new FlowLayout() ); - Box mainBox = Box.createVerticalBox(); - - Box hostBox = Box.createHorizontalBox(); - hostBox.add( new JLabel( "Host:" ) ); - hostBox.add( Box.createHorizontalStrut( 5 ) ); - hostBox.add( m_hostField ); - mainBox.add( hostBox ); - mainBox.add( Box.createVerticalStrut( 5 ) ); - - Box portBox = Box.createHorizontalBox(); - portBox.add( new JLabel( "Port:" ) ); - portBox.add( Box.createHorizontalStrut( 5 ) ); - portBox.add( m_portField ); - mainBox.add( portBox ); - - panel.add( mainBox ); - - return panel; - } - - /** * Goes through and validates the fields in the dialog. * * @return True if the fields were Ok. @@ -136,6 +101,43 @@ m_port = port; return true; + } + + /*--------------------------------------------------------------- + * AbstractTabularOptionDialog Methods + *-------------------------------------------------------------*/ + /** + * Returns an array of labels to use for the components returned from + * getMainPanelComponents(). + * + * @returns An array of labels. + */ + protected String[] getMainPanelLabels() + { + return new String[] + { + "Host:", + "Port:" + }; + } + + /** + * Returns an array of components to show in the main panel of the dialog. + * + * @returns An array of components. + */ + protected Component[] getMainPanelComponents() + { + m_hostField = new JTextField(); + m_hostField.setColumns( 20 ); + m_portField = new JTextField(); + m_portField.setColumns( 6 ); + + return new Component[] + { + m_hostField, + m_portField + }; } /*--------------------------------------------------------------- 1.6 +41 -2 jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/InstrumentClientFrame.java Index: InstrumentClientFrame.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/InstrumentClientFrame.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- InstrumentClientFrame.java 3 Apr 2002 13:48:48 -0000 1.5 +++ InstrumentClientFrame.java 28 Apr 2002 17:04:15 -0000 1.6 @@ -26,7 +26,7 @@ /** * * @author Leif Mortenson - * @version CVS $Revision: 1.5 $ $Date: 2002/04/03 13:48:48 $ + * @version CVS $Revision: 1.6 $ $Date: 2002/04/28 17:04:15 $ * @since 4.1 */ class InstrumentClientFrame @@ -394,7 +394,46 @@ } /** - * File-Exit callback. + * Instrument-CreateSample callback. */ + void instrumentCreateSample( final InstrumentManagerConnection connection, + final InstrumentableDescriptor instrumentableDescriptor, + final InstrumentDescriptor instrumentDescriptor ) + { + SwingUtilities.invokeLater( new Runnable() + { + public void run() + { + CreateSampleDialog dialog = + new CreateSampleDialog( InstrumentClientFrame.this, instrumentDescriptor ); + + dialog.setSampleDescription( "Each Second" ); + dialog.setInterval( 1000 ); + dialog.setSampleCount( 600 ); // 10 minutes of history + dialog.setLeaseTime( 600 ); + dialog.setMaintainLease( true ); + dialog.show(); + + if ( dialog.getAction() == CreateSampleDialog.BUTTON_OK ) + { + System.out.println( "New Sample: desc=" + dialog.getSampleDescription() + + ", interval=" + dialog.getInterval() + ", size=" + dialog.getSampleCount() + + ", lease=" + dialog.getLeaseTime() + ", type=" + dialog.getSampleType() ); + + InstrumentSampleDescriptor sampleDescriptor = + instrumentDescriptor.createInstrumentSample( + dialog.getSampleDescription(), + dialog.getInterval(), + dialog.getSampleCount(), + dialog.getLeaseTime(), + dialog.getSampleType() ); + + // Show a frame for the new sample + openInstrumentSampleFrame( connection, instrumentableDescriptor, + instrumentDescriptor, sampleDescriptor ); + } + } + } ); + } } 1.8 +63 -35 jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/MenuBar.java Index: MenuBar.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/MenuBar.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- MenuBar.java 4 Apr 2002 08:07:05 -0000 1.7 +++ MenuBar.java 28 Apr 2002 17:04:15 -0000 1.8 @@ -30,7 +30,7 @@ /** * * @author Leif Mortenson - * @version CVS $Revision: 1.7 $ $Date: 2002/04/04 08:07:05 $ + * @version CVS $Revision: 1.8 $ $Date: 2002/04/28 17:04:15 $ * @since 4.1 */ public class MenuBar @@ -253,10 +253,11 @@ Action action = item.getAction(); m_frame.openInstrumentManagerConnectionFrame( - (InstrumentManagerConnection)action.getValue( "connection" ) ); + (InstrumentManagerConnection)action.getValue + ( "InstrumentManagerConnection" ) ); } }; - detailAction.putValue( "connection", connection ); + detailAction.putValue( "InstrumentManagerConnection", connection ); JMenuItem detailItem = new JMenuItem( detailAction ); detailItem.setMnemonic( 'D' ); @@ -272,12 +273,12 @@ Action action = item.getAction(); InstrumentManagerConnection connection = - (InstrumentManagerConnection)action.getValue( "connection" ); + (InstrumentManagerConnection)action.getValue( "InstrumentManagerConnection" ); connection.delete(); } }; - deleteAction.putValue( "connection", connection ); + deleteAction.putValue( "InstrumentManagerConnection", connection ); JMenuItem deleteItem = new JMenuItem( deleteAction ); deleteItem.setMnemonic( 'I' ); @@ -431,45 +432,72 @@ boolean showAll = m_menuItemShowUnconfigured.getState(); + // Create Sample + Action createAction = new AbstractAction( "Create Sample..." ) + { + public void actionPerformed( ActionEvent event ) + { + JMenuItem item = (JMenuItem)event.getSource(); + Action action = item.getAction(); + + m_frame.instrumentCreateSample( + (InstrumentManagerConnection)action.getValue( "InstrumentManagerConnection" ), + (InstrumentableDescriptor)action.getValue( "InstrumentableDescriptor" ), + (InstrumentDescriptor)action.getValue( "InstrumentDescriptor" ) ); + } + }; + createAction.putValue( "InstrumentManagerConnection", connection ); + createAction.putValue( "InstrumentableDescriptor", instrumentableDescriptor ); + createAction.putValue( "InstrumentDescriptor", instrumentDescriptor ); + + JMenuItem createItem = new JMenuItem( createAction ); + createItem.setMnemonic( 'C' ); + instrumentMenu.add( createItem ); + try { InstrumentSampleDescriptor[] descriptors = instrumentDescriptor.getInstrumentSampleDescriptors(); - for( int i = 0; i < descriptors.length; i++ ) + if ( descriptors.length > 0 ) { - InstrumentSampleDescriptor descriptor = descriptors[ i ]; - - if( showAll || descriptor.isConfigured() ) + instrumentMenu.addSeparator(); + + for( int i = 0; i < descriptors.length; i++ ) { - String description = descriptor.getDescription(); - - Action action = new AbstractAction( description ) + InstrumentSampleDescriptor descriptor = descriptors[ i ]; + + if( showAll || descriptor.isConfigured() ) { - public void actionPerformed( ActionEvent event ) + String description = descriptor.getDescription(); + + Action action = new AbstractAction( description ) { - JMenuItem menu = (JMenuItem)event.getSource(); - Action action = menu.getAction(); - - m_frame.openInstrumentSampleFrame( - (InstrumentManagerConnection)action.getValue( - "InstrumentManagerConnection" ), - (InstrumentableDescriptor)action.getValue( - "InstrumentableDescriptor" ), - (InstrumentDescriptor)action.getValue( - "InstrumentDescriptor" ), - (InstrumentSampleDescriptor)action.getValue( - "InstrumentSampleDescriptor" ) ); - } - }; - action.putValue( "InstrumentManagerConnection", connection ); - action.putValue( "InstrumentableDescriptor", instrumentableDescriptor ); - action.putValue( "InstrumentDescriptor", instrumentDescriptor ); - action.putValue( "InstrumentSampleDescriptor", descriptor ); - - JMenuItem item = new JMenuItem( action ); - - instrumentMenu.add( item ); + public void actionPerformed( ActionEvent event ) + { + JMenuItem menu = (JMenuItem)event.getSource(); + Action action = menu.getAction(); + + m_frame.openInstrumentSampleFrame( + (InstrumentManagerConnection)action.getValue( + "InstrumentManagerConnection" ), + (InstrumentableDescriptor)action.getValue( + "InstrumentableDescriptor" ), + (InstrumentDescriptor)action.getValue( + "InstrumentDescriptor" ), + (InstrumentSampleDescriptor)action.getValue( + "InstrumentSampleDescriptor" ) ); + } + }; + action.putValue( "InstrumentManagerConnection", connection ); + action.putValue( "InstrumentableDescriptor", instrumentableDescriptor ); + action.putValue( "InstrumentDescriptor", instrumentDescriptor ); + action.putValue( "InstrumentSampleDescriptor", descriptor ); + + JMenuItem item = new JMenuItem( action ); + + instrumentMenu.add( item ); + } } } } 1.1 jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/AbstractTabularOptionDialog.java Index: AbstractTabularOptionDialog.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.excalibur.instrument.client; import java.awt.Component; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Point; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.border.EmptyBorder; /** * Creates a dialog which displays a table of labeled components to the user. * * @author Leif Mortenson * @version CVS $Revision: 1.1 $ $Date: 2002/04/28 17:04:15 $ * @since 4.1 */ public abstract class AbstractTabularOptionDialog extends AbstractOptionDialog { /*--------------------------------------------------------------- * Constructors *-------------------------------------------------------------*/ /** * Creates a new AbstractTabularOptionDialog. * * @param frame Frame which owns the dialog. * @param title Title for the dialog. * @param buttons List of buttons to display. */ protected AbstractTabularOptionDialog( JFrame frame, String title, int buttons ) { super( frame, title, buttons ); } /*--------------------------------------------------------------- * AbstractOptionDialog Methods *-------------------------------------------------------------*/ /** * Returns the main panel which makes up the guts of the dialog. * This implementaton builds a table of labeled components using * arrays returned by getMainPanelLabels() and getMainPanelComponents(); * * @return The main panel. */ protected JPanel getMainPanel() { String[] labels = getMainPanelLabels(); Component[] components = getMainPanelComponents(); JPanel panel = new JPanel(); GridBagLayout gbl = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); panel.setLayout( gbl ); for ( int i = 0; i < labels.length; i++ ) { addRow( panel, labels[i], components[i], gbl, gbc ); } return panel; } /*--------------------------------------------------------------- * Methods *-------------------------------------------------------------*/ /** * Returns an array of labels to use for the components returned from * getMainPanelComponents(). * * @returns An array of labels. */ protected abstract String[] getMainPanelLabels(); /** * Returns an array of components to show in the main panel of the dialog. * * @returns An array of components. */ protected abstract Component[] getMainPanelComponents(); /** * Adds a row to the panel consisting of a label and component, separated by * a 5 pixel spacer and followed by a 5 pixel high row between this and the * next row. * * @param panel Panel to which the row will be added. * @param label Text of the label for the component. * @param component Component which makes up the row. * @param gbl GridBagLayout which must have been set as the layour of the * panel. * @param gbc GridBagConstraints to use when laying out the row. */ private void addRow( JPanel panel, String label, Component component, GridBagLayout gbl, GridBagConstraints gbc ) { JLabel jLabel = new JLabel( label ); gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.EAST; gbl.setConstraints( jLabel, gbc ); panel.add( jLabel ); // Add a 5 pixel high spacer Component spacer = Box.createRigidArea( new Dimension( 5, 5 ) ); gbc.gridwidth = GridBagConstraints.RELATIVE; gbc.anchor = GridBagConstraints.WEST; gbl.setConstraints( spacer, gbc ); panel.add( spacer ); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.anchor = GridBagConstraints.WEST; gbl.setConstraints( component, gbc ); panel.add( component ); // Add a 5 pixel high spacer spacer = Box.createRigidArea( new Dimension( 5, 5 ) ); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.anchor = GridBagConstraints.WEST; gbl.setConstraints( spacer, gbc ); panel.add( spacer ); } } 1.1 jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/CreateSampleDialog.java Index: CreateSampleDialog.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.excalibur.instrument.client; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.Box; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; import javax.swing.SwingConstants; import org.apache.avalon.excalibur.instrument.manager.interfaces.InstrumentDescriptor; import org.apache.avalon.excalibur.instrument.manager.interfaces.InstrumentManagerClient; /** * * @author Leif Mortenson * @version CVS $Revision: 1.1 $ $Date: 2002/04/28 17:04:15 $ * @since 4.1 */ class CreateSampleDialog extends AbstractTabularOptionDialog { private InstrumentDescriptor m_instrumentDescriptor; private JTextField m_instrumentNameField; private JTextField m_instrumentDescriptionField; private JTextField m_sampleDescriptionField; private String m_sampleDescription; private JTextField m_intervalField; private long m_interval; private JTextField m_sizeField; private int m_size; private JTextField m_leaseTimeField; private long m_leaseTime; private JCheckBox m_maintainLeaseCheckBox; private Container m_sampleTypePanel; private ButtonGroup m_sampleTypeGroup; private int m_sampleType; private JRadioButton m_sampleTypeCounter; private JRadioButton m_sampleTypeMaximum; private JRadioButton m_sampleTypeMinimum; private JRadioButton m_sampleTypeMean; /*--------------------------------------------------------------- * Constructors *-------------------------------------------------------------*/ /** * Creates a new CreateSampleDialog. * * @param frame Frame which owns the dialog. */ CreateSampleDialog( InstrumentClientFrame frame, InstrumentDescriptor instrumentDescriptor ) { super( frame, "Create Instrument Sample", AbstractOptionDialog.BUTTON_OK | AbstractOptionDialog.BUTTON_CANCEL ); m_instrumentDescriptor = instrumentDescriptor; m_instrumentNameField.setText( m_instrumentDescriptor.getName() ); m_instrumentDescriptionField.setText( m_instrumentDescriptor.getDescription() ); buildSampleTypeComponent(); pack(); } /*--------------------------------------------------------------- * AbstractOptionDialog Methods *-------------------------------------------------------------*/ /** * Returns the message to show at the top of the dialog. * * @return The text of the message. */ protected String getMessage() { return "Please enter the parameters for the sample to be created."; } /** * Goes through and validates the fields in the dialog. * * @return True if the fields were Ok. */ protected boolean validateFields() { // Check the description. String description = m_sampleDescriptionField.getText().trim(); if ( description.length() == 0 ) { JOptionPane.showMessageDialog( this, "Please enter a valid description.", "Invalid description", JOptionPane.ERROR_MESSAGE ); return false; } m_sampleDescription = description; // Check the interval. boolean intervalOk = true; long interval = 0; try { interval = Long.parseLong( m_intervalField.getText().trim() ); } catch ( NumberFormatException e ) { intervalOk = false; } if ( ( interval < 100 ) || ( interval > 24 * 60 * 60 * 1000 ) ) { intervalOk = false; } if ( !intervalOk ) { JOptionPane.showMessageDialog( this, "Please enter a valid interval. (100ms - 24hrs, 86400000)", "Invalid interval", JOptionPane.ERROR_MESSAGE ); return false; } m_interval = interval; // Check the size. boolean sizeOk = true; int size = 0; try { size = Integer.parseInt( m_sizeField.getText().trim() ); } catch ( NumberFormatException e ) { sizeOk = false; } if ( ( size < 1 ) || ( size > 2048 ) ) { sizeOk = false; } if ( !sizeOk ) { JOptionPane.showMessageDialog( this, "Please enter a valid size. (1 - 2048)", "Invalid size", JOptionPane.ERROR_MESSAGE ); return false; } m_size = size; // Check the leaseTime. boolean leaseTimeOk = true; int leaseTime = 0; try { leaseTime = Integer.parseInt( m_leaseTimeField.getText().trim() ); } catch ( NumberFormatException e ) { leaseTimeOk = false; } if ( ( leaseTime < 60 ) || ( leaseTime > ( size * interval / 1000 ) + 86400 ) ) { leaseTimeOk = false; } if ( !leaseTimeOk ) { JOptionPane.showMessageDialog( this, "Please enter a valid lease time. Must be " + "between 1 minute (60) and 24 hours greater than the interval * size (" + ( ( size * interval / 1000 ) + 86400 ) + ")", "Invalid leaseTime", JOptionPane.ERROR_MESSAGE ); return false; } m_leaseTime = leaseTime * 1000L; // Store the sample type if ( m_sampleTypeCounter.isSelected() ) { m_sampleType = InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_COUNTER; } else if ( m_sampleTypeMaximum.isSelected() ) { m_sampleType = InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MAXIMUM; } else if ( m_sampleTypeMean.isSelected() ) { m_sampleType = InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MEAN; } else if ( m_sampleTypeMinimum.isSelected() ) { m_sampleType = InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MINIMUM; } else { // Should never get here. m_sampleType = -1; } return true; } /*--------------------------------------------------------------- * AbstractTabularOptionDialog Methods *-------------------------------------------------------------*/ /** * Returns an array of labels to use for the components returned from * getMainPanelComponents(). * * @returns An array of labels. */ protected String[] getMainPanelLabels() { return new String[] { "Instrument Name:", "Instrument Description:", "Sample Description:", "Sample Interval (milliseconds):", "Number of Samples:", "Lease Time (Seconds):", "Maintain Lease:", "Sample Type:" }; } /** * Returns an array of components to show in the main panel of the dialog. * * @returns An array of components. */ protected Component[] getMainPanelComponents() { m_instrumentNameField = new JTextField(); m_instrumentNameField.setColumns( 40 ); m_instrumentNameField.setEditable( false ); m_instrumentDescriptionField = new JTextField(); m_instrumentDescriptionField.setColumns( 40 ); m_instrumentDescriptionField.setEditable( false ); m_sampleDescriptionField = new JTextField(); m_sampleDescriptionField.setColumns( 40 ); m_intervalField = new JTextField(); m_intervalField.setColumns( 10 ); m_sizeField = new JTextField(); m_sizeField.setColumns( 4 ); m_leaseTimeField = new JTextField(); m_leaseTimeField.setColumns( 10 ); m_maintainLeaseCheckBox = new JCheckBox(); m_sampleTypePanel = Box.createVerticalBox(); return new Component[] { m_instrumentNameField, m_instrumentDescriptionField, m_sampleDescriptionField, m_intervalField, m_sizeField, m_leaseTimeField, m_maintainLeaseCheckBox, m_sampleTypePanel }; } /*--------------------------------------------------------------- * Methods *-------------------------------------------------------------*/ /** * Builds the sample type component. */ private void buildSampleTypeComponent() { m_sampleTypeGroup = new ButtonGroup(); m_sampleTypeCounter = new JRadioButton( "Count over each sample" ); m_sampleTypeMaximum = new JRadioButton( "Maximum value over each sample" ); m_sampleTypeMinimum = new JRadioButton( "Minumum value over each sample" ); m_sampleTypeMean = new JRadioButton( "Mean value over each sample" ); switch ( m_instrumentDescriptor.getType() ) { case InstrumentManagerClient.INSTRUMENT_TYPE_COUNTER: m_sampleTypePanel.add( m_sampleTypeCounter ); m_sampleTypeGroup.add( m_sampleTypeCounter ); m_sampleTypeCounter.setSelected( true ); m_sampleType = InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_COUNTER; break; case InstrumentManagerClient.INSTRUMENT_TYPE_VALUE: m_sampleTypePanel.add( m_sampleTypeMaximum ); m_sampleTypeGroup.add( m_sampleTypeMaximum ); m_sampleTypePanel.add( m_sampleTypeMinimum ); m_sampleTypeGroup.add( m_sampleTypeMinimum ); m_sampleTypePanel.add( m_sampleTypeMean ); m_sampleTypeGroup.add( m_sampleTypeMean ); m_sampleTypeMaximum.setSelected( true ); m_sampleType = InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MAXIMUM; break; default: // Unknown Type break; } } /** * Sets the initial sample description to be shown in the TextField. * * @param sampleDescription The initial sample description. */ void setSampleDescription( String sampleDescription ) { m_sampleDescription = sampleDescription; m_sampleDescriptionField.setText( sampleDescription ); } /** * Returns the sample description set in the dialog. * * @return The sample description. */ String getSampleDescription() { return m_sampleDescription; } /** * Sets the initial interval to be shown in the interval TextField. * * @param interval The initial interval. */ void setInterval( long interval ) { m_interval = interval; m_intervalField.setText( Long.toString( interval ) ); } /** * Returns the interval set in the dialog. * * @return The interval. */ long getInterval() { return m_interval; } /** * Sets the initial size to be shown in the size TextField. * * @param size The initial size. */ void setSampleCount( int size ) { m_size = size; m_sizeField.setText( Integer.toString( size ) ); } /** * Returns the size set in the dialog. * * @return The size. */ int getSampleCount() { return m_size; } /** * Sets the initial lease time to be shown in the lease time TextField. * * @param leaseTime The initial lease time. */ void setLeaseTime( long leaseTime ) { m_leaseTime = leaseTime; m_leaseTimeField.setText( Long.toString( leaseTime ) ); } /** * Returns the lease time set in the dialog. * * @return The lease time. */ long getLeaseTime() { return m_leaseTime; } /** * Sets the initial maintain lease flag to be shown in the maintain lease * CheckBox. * * @param maintainLease The initial maintain lease flag. */ void setMaintainLease( boolean maintainLease ) { m_maintainLeaseCheckBox.setSelected( maintainLease ); } /** * Returns the maintain lease flag set in the dialog. * * @return The maintain lease flag. */ boolean getMaintainLease() { return m_maintainLeaseCheckBox.isSelected(); } /** * Sets the initial size to be shown in the size TextField. * * @param size The initial size. */ void setSampleType( int type ) { m_sampleType = type; switch(type) { case InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_COUNTER: m_sampleTypeCounter.setSelected( true ); break; case InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MAXIMUM: m_sampleTypeMaximum.setSelected( true ); break; case InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MEAN: m_sampleTypeMean.setSelected( true ); break; case InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MINIMUM: m_sampleTypeMinimum.setSelected( true ); break; default: break; } } /** * Returns the type set in the dialog. * * @return The type. */ int getSampleType() { return m_sampleType; } } -- To unsubscribe, e-mail: For additional commands, e-mail: