khammond 01/09/27 06:18:21 Modified: src/org/apache/jmeter/threads/gui ThreadGroupGui.java Log: Clean up GUI. Revision Changes Path 1.9 +264 -205 jakarta-jmeter/src/org/apache/jmeter/threads/gui/ThreadGroupGui.java Index: ThreadGroupGui.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/threads/gui/ThreadGroupGui.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- ThreadGroupGui.java 2001/08/31 00:46:45 1.8 +++ ThreadGroupGui.java 2001/09/27 13:18:21 1.9 @@ -1,205 +1,264 @@ -/* - * ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache JMeter" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact [EMAIL PROTECTED] - * - * 5. Products derived from this software may not be called "Apache", - * "Apache JMeter", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - */ -package org.apache.jmeter.threads.gui; - -import javax.swing.*; -import java.awt.event.*; - -import org.apache.jmeter.gui.*; -import org.apache.jmeter.threads.ThreadGroup; -import org.apache.jmeter.util.JMeterUtils; - -/************************************************************ - * Title: JMeter Description: Copyright: Copyright (c) 2000 Company: Apache - * - *@author Michael Stover - *@created $Date: 2001/08/31 00:46:45 $ - *@version 1.0 - ***********************************************************/ - -public class ThreadGroupGui extends JPanel implements ModelSupported, KeyListener -{ - - ThreadGroup model; - LoopControlPanel loopPanel; - - private JLabel nameLabel = new JLabel(JMeterUtils.getResString("name")); - private JTextField nameInput = new JTextField(30); - private JLabel threadLabel = new JLabel(JMeterUtils.getResString("number_of_threads")); - private JLabel rampLabel = new JLabel(JMeterUtils.getResString("ramp_up")); - private JTextField threadInput = new JTextField(5); - private JTextField rampInput = new JTextField(5); - private final static String THREAD_NAME = "Number Threads"; - private final static String RAMP_NAME = "Ramp-Up"; - - /************************************************************ - * !ToDo (Constructor description) - ***********************************************************/ - public ThreadGroupGui() - { - } - - /************************************************************ - * !ToDo (Method description) - * - *@param model !ToDo (Parameter description) - ***********************************************************/ - public void setModel(Object model) - { - this.model = (ThreadGroup)model; - init(); - } - - /************************************************************ - * !ToDo (Method description) - ***********************************************************/ - public void updateGui() - { - if (model != null) - { - nameInput.setText(model.getName()); - threadInput.setText("" + model.getNumThreads()); - rampInput.setText("" + model.getRampUp()); - loopPanel.updateGui(); - } - } - - /************************************************************ - * !ToDo (Method description) - * - *@return !ToDo (Return description) - ***********************************************************/ - public JPanel createControllerPanel() - { - loopPanel = new LoopControlPanel(false); - loopPanel.setModel(model.getSamplerController()); - return loopPanel; - } - - /************************************************************ - * !ToDo (Method description) - * - *@param e !ToDo (Parameter description) - ***********************************************************/ - public void keyReleased(KeyEvent e) - { - String field = e.getComponent().getName(); - if (field.equals(NAME_FIELD)) - { - model.setName(nameInput.getText()); - } - else if (field.equals(THREAD_NAME)) - { - model.setNumThreads(Integer.parseInt(threadInput.getText())); - } - else if (field.equals(RAMP_NAME)) - { - try - { - model.setRampUp(Integer.parseInt(rampInput.getText())); - } - catch (NumberFormatException nfe) - { - // Ignore - only set value if valid - } - } - - } - - /************************************************************ - * !ToDo (Method description) - * - *@param e !ToDo (Parameter description) - ***********************************************************/ - public void keyTyped(KeyEvent e) - { - } - - /************************************************************ - * !ToDo (Method description) - * - *@param e !ToDo (Parameter description) - ***********************************************************/ - public void keyPressed(KeyEvent e) - { - } - - private void init() - { - nameInput.addKeyListener(this); - threadInput.addKeyListener(this); - rampInput.addKeyListener(this); - nameInput.setName(NAME_FIELD); - threadInput.setName(THREAD_NAME); - rampInput.setName(RAMP_NAME); - this.setLayout(new VerticalLayout(2, VerticalLayout.LEFT, VerticalLayout.TOP)); - JPanel namePanel = new JPanel(); - namePanel.add(nameLabel); - namePanel.add(nameInput); - this.add(namePanel); - - JPanel threadPanel = new JPanel(); - threadPanel.add(threadLabel); - threadPanel.add(threadInput); - this.add(threadPanel); - - JPanel rampPanel = new JPanel(); - rampPanel.add(rampLabel); - rampPanel.add(rampInput); - this.add(rampPanel); - - this.add(createControllerPanel()); - } -} +/* + * ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache JMeter" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact [EMAIL PROTECTED] + * + * 5. Products derived from this software may not be called "Apache", + * "Apache JMeter", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ +package org.apache.jmeter.threads.gui; + +import javax.swing.*; +import java.awt.event.*; +import javax.swing.border.*; +import javax.swing.table.*; +import java.awt.*; +import javax.swing.text.*; + +import org.apache.jmeter.gui.*; +import org.apache.jmeter.threads.ThreadGroup; +import org.apache.jmeter.util.JMeterUtils; + +/************************************************************ + * Title: JMeter Description: Copyright: Copyright (c) 2000 Company: Apache + * + *@author Michael Stover + *@created $Date: 2001/09/27 13:18:21 $ + *@version 1.0 + ***********************************************************/ + +public class ThreadGroupGui extends JPanel implements ModelSupported, KeyListener +{ + ThreadGroup model; + LoopControlPanel loopPanel; + + private JTextField threadInput; + private JTextField rampInput; + + private final static String THREAD_NAME = "Thread Field"; + private final static String RAMP_NAME = "Ramp Up Field"; + + /************************************************************ + * !ToDo (Constructor description) + ***********************************************************/ + public ThreadGroupGui() + { + } + + /************************************************************ + * !ToDo (Method description) + * + *@param model !ToDo (Parameter description) + ***********************************************************/ + public void setModel(Object model) + { + this.model = (ThreadGroup)model; + init(); + } + + /************************************************************ + * !ToDo (Method description) + ***********************************************************/ + public void updateGui() + { + if (model != null) + { + threadInput.setText("" + model.getNumThreads()); + rampInput.setText("" + model.getRampUp()); + loopPanel.updateGui(); + } + } + + /************************************************************ + * !ToDo (Method description) + * + *@return !ToDo (Return description) + ***********************************************************/ + public JPanel createControllerPanel() + { + loopPanel = new LoopControlPanel(false); + loopPanel.setModel(model.getSamplerController()); + return loopPanel; + } + + /************************************************************ + * !ToDo (Method description) + * + *@param e !ToDo (Parameter description) + ***********************************************************/ + public void keyReleased(KeyEvent e) + { + String field = e.getComponent().getName(); + if (field.equals(THREAD_NAME)) + { + try + { + model.setNumThreads(Integer.parseInt(threadInput.getText())); + } + catch (NumberFormatException nfe) + { + if (threadInput.getText().length() > 0) + { + JOptionPane.showMessageDialog(this, "You must enter a valid number", + "Invalid data", JOptionPane.WARNING_MESSAGE); + model.setNumThreads(model.getDefaultNumThreads()); + + // Right now, the cleanest thing to do is simply clear the + // entire text field. We do not want to set the text to + // the default because that would be confusing to the user. + // For example, the user typed "5t" instead of "56". After + // the user closes the error dialog, the text would change + // from "5t" to "1". A litle confusing. If anything, it + // should display just "5". Future enhancement... + threadInput.setText(""); + } + else + { + model.setNumThreads(model.getDefaultNumThreads()); + } + } + } + else if (field.equals(RAMP_NAME)) + { + try + { + model.setRampUp(Integer.parseInt(rampInput.getText())); + } + catch (NumberFormatException nfe) + { + if (rampInput.getText().length() > 0) + { + JOptionPane.showMessageDialog(this, "You must enter a valid number", + "Invalid data", JOptionPane.WARNING_MESSAGE); + model.setRampUp(model.getDefaultRampUp()); + rampInput.setText(""); + } + else + { + model.setRampUp(model.getDefaultRampUp()); + } + } + } + } + + /************************************************************ + * !ToDo (Method description) + * + *@param e !ToDo (Parameter description) + ***********************************************************/ + public void keyTyped(KeyEvent e) + { + } + + /************************************************************ + * !ToDo (Method description) + * + *@param e !ToDo (Parameter description) + ***********************************************************/ + public void keyPressed(KeyEvent e) + { + } + + private void init() + { + this.setLayout(new VerticalLayout(5, VerticalLayout.LEFT, VerticalLayout.TOP)); + + // MAIN PANEL + JPanel mainPanel = new JPanel(); + Border margin = new EmptyBorder(10, 10, 5, 10); + mainPanel.setBorder(margin); + mainPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT)); + + // TITLE + JLabel panelTitleLabel = new JLabel(JMeterUtils.getResString("thread_group_title")); + Font curFont = panelTitleLabel.getFont(); + int curFontSize = curFont.getSize(); + curFontSize += 4; + panelTitleLabel.setFont(new Font(curFont.getFontName(), curFont.getStyle(), curFontSize)); + mainPanel.add(panelTitleLabel); + + // NAME + NamePanel namePanel = new NamePanel(model); + mainPanel.add(namePanel); + + // THREAD PROPERTIES + JPanel threadPropsPanel = new JPanel(); + margin = new EmptyBorder(5, 10, 10, 10); + threadPropsPanel.setLayout(new VerticalLayout(0, VerticalLayout.LEFT)); + threadPropsPanel.setBorder(new CompoundBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), JMeterUtils.getResString("thread_delay_properties")), margin)); + + // NUMBER OF THREADS + JPanel threadPanel = new JPanel(); + JLabel threadLabel = new JLabel(JMeterUtils.getResString("number_of_threads")); + threadPanel.add(threadLabel); + threadInput = new JTextField(5); + threadInput.addKeyListener(this); + threadInput.setName(THREAD_NAME); + threadPanel.add(threadInput); + threadPropsPanel.add(threadPanel); + new FocusRequester(threadInput); + + // RAMP-UP + JPanel rampPanel = new JPanel(); + JLabel rampLabel = new JLabel(JMeterUtils.getResString("ramp_up")); + rampPanel.add(rampLabel); + rampInput = new JTextField(5); + rampInput.setName(RAMP_NAME); + rampInput.addKeyListener(this); + rampPanel.add(rampInput); + threadPropsPanel.add(rampPanel); + + // LOOP COUNT + threadPropsPanel.add(createControllerPanel()); + + mainPanel.add(threadPropsPanel); + + this.add(mainPanel); + } +}
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
