|
What this is
Other links
The source code// $Header: /home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/control/gui/ThroughputControllerGui.java,v 1.10 2004/03/05 01:32:37 sebb Exp $ /* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package org.apache.jmeter.control.gui; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.DefaultComboBoxModel; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import org.apache.jmeter.control.ThroughputController; import org.apache.jmeter.testelement.TestElement; import org.apache.jmeter.util.JMeterUtils; import org.apache.jorphan.gui.layout.VerticalLayout; /** * @version $Revision: 1.10 $ on $Date: 2004/03/05 01:32:37 $ */ public class ThroughputControllerGui extends AbstractControllerGui { private JComboBox styleBox; private int style; private JTextField throughput; private JCheckBox perthread; private boolean isPerThread = true; private String BYNUMBER_LABEL = JMeterUtils.getResString("throughput_control_bynumber_label"); private String BYPERCENT_LABEL = JMeterUtils.getResString("throughput_control_bypercent_label"); private String THROUGHPUT_LABEL = JMeterUtils.getResString("throughput_control_tplabel"); private String THROUGHPUT = "Througput Field"; private String PERTHREAD_LABEL = JMeterUtils.getResString("throughput_control_perthread_label"); public ThroughputControllerGui() { init(); } public TestElement createTestElement() { ThroughputController tc = new ThroughputController(); modifyTestElement(tc); return tc; } /** * Modifies a given TestElement to mirror the data in the gui components. * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement) */ public void modifyTestElement(TestElement tc) { configureTestElement(tc); ((ThroughputController) tc).setStyle(style); ((ThroughputController) tc).setPerThread(isPerThread); if (style == ThroughputController.BYNUMBER) { try { ((ThroughputController) tc).setMaxThroughput( Integer.parseInt(throughput.getText().trim())); } catch (NumberFormatException e) { ((ThroughputController) tc).setMaxThroughput( throughput.getText()); } } else { try { ((ThroughputController) tc).setPercentThroughput( Float.parseFloat(throughput.getText().trim())); } catch (NumberFormatException e) { ((ThroughputController) tc).setPercentThroughput( throughput.getText()); } } } public void configure(TestElement el) { super.configure(el); if (((ThroughputController) el).getStyle() == ThroughputController.BYNUMBER) { styleBox.getModel().setSelectedItem(BYNUMBER_LABEL); throughput.setText( String.valueOf(((ThroughputController) el).getMaxThroughput())); } else { styleBox.setSelectedItem(BYPERCENT_LABEL); throughput.setText( String.valueOf( ((ThroughputController) el).getPercentThroughput())); } perthread.setSelected(((ThroughputController) el).isPerThread()); } public String getLabelResource() { return "throughput_control_title"; } private void init() { setLayout( new VerticalLayout(5, VerticalLayout.LEFT, VerticalLayout.TOP)); setBorder(makeBorder()); add(makeTitlePanel()); DefaultComboBoxModel styleModel = new DefaultComboBoxModel(); styleModel.addElement(BYNUMBER_LABEL); styleModel.addElement(BYPERCENT_LABEL); styleBox = new JComboBox(styleModel); styleBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (((String) styleBox.getSelectedItem()) .equals(BYNUMBER_LABEL)) { style = ThroughputController.BYNUMBER; } else { style = ThroughputController.BYPERCENT; } } }); add(styleBox); // TYPE FIELD JPanel tpPanel = new JPanel(); JLabel tpLabel = new JLabel(THROUGHPUT_LABEL); tpPanel.add(tpLabel); // TEXT FIELD throughput = new JTextField(5); tpPanel.add(throughput); throughput.setName(THROUGHPUT); throughput.setText("1"); // throughput.addActionListener(this); tpPanel.add(throughput); add(tpPanel); // PERTHREAD FIELD perthread = new JCheckBox(PERTHREAD_LABEL, isPerThread); perthread.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { if (event.getStateChange() == ItemEvent.SELECTED) { isPerThread = true; } else { isPerThread = false; } } }); add(perthread); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.