1 18 19 package org.apache.jmeter.control.gui; 20 21 import java.awt.event.ActionEvent ; 22 import java.awt.event.ActionListener ; 23 import java.awt.event.ItemEvent ; 24 import java.awt.event.ItemListener ; 25 26 import javax.swing.DefaultComboBoxModel ; 27 import javax.swing.JCheckBox ; 28 import javax.swing.JComboBox ; 29 import javax.swing.JLabel ; 30 import javax.swing.JPanel ; 31 import javax.swing.JTextField ; 32 33 import org.apache.jmeter.control.ThroughputController; 34 import org.apache.jmeter.testelement.TestElement; 35 import org.apache.jmeter.util.JMeterUtils; 36 import org.apache.jorphan.gui.layout.VerticalLayout; 37 38 41 public class ThroughputControllerGui extends AbstractControllerGui 42 { 43 private JComboBox styleBox; 44 private int style; 45 private JTextField throughput; 46 private JCheckBox perthread; 47 private boolean isPerThread = true; 48 49 private String BYNUMBER_LABEL = 50 JMeterUtils.getResString("throughput_control_bynumber_label"); 51 private String BYPERCENT_LABEL = 52 JMeterUtils.getResString("throughput_control_bypercent_label"); 53 private String THROUGHPUT_LABEL = 54 JMeterUtils.getResString("throughput_control_tplabel"); 55 private String THROUGHPUT = "Througput Field"; 56 private String PERTHREAD_LABEL = 57 JMeterUtils.getResString("throughput_control_perthread_label"); 58 59 public ThroughputControllerGui() 60 { 61 init(); 62 } 63 64 public TestElement createTestElement() 65 { 66 ThroughputController tc = new ThroughputController(); 67 modifyTestElement(tc); 68 return tc; 69 } 70 71 75 public void modifyTestElement(TestElement tc) 76 { 77 configureTestElement(tc); 78 ((ThroughputController) tc).setStyle(style); 79 ((ThroughputController) tc).setPerThread(isPerThread); 80 if (style == ThroughputController.BYNUMBER) 81 { 82 try 83 { 84 ((ThroughputController) tc).setMaxThroughput( 85 Integer.parseInt(throughput.getText().trim())); 86 } 87 catch (NumberFormatException e) 88 { 89 ((ThroughputController) tc).setMaxThroughput( 90 throughput.getText()); 91 } 92 } 93 else 94 { 95 try 96 { 97 ((ThroughputController) tc).setPercentThroughput( 98 Float.parseFloat(throughput.getText().trim())); 99 } 100 catch (NumberFormatException e) 101 { 102 ((ThroughputController) tc).setPercentThroughput( 103 throughput.getText()); 104 } 105 } 106 } 107 108 public void configure(TestElement el) 109 { 110 super.configure(el); 111 if (((ThroughputController) el).getStyle() 112 == ThroughputController.BYNUMBER) 113 { 114 styleBox.getModel().setSelectedItem(BYNUMBER_LABEL); 115 throughput.setText( 116 String.valueOf(((ThroughputController) el).getMaxThroughput())); 117 } 118 else 119 { 120 styleBox.setSelectedItem(BYPERCENT_LABEL); 121 throughput.setText( 122 String.valueOf( 123 ((ThroughputController) el).getPercentThroughput())); 124 } 125 perthread.setSelected(((ThroughputController) el).isPerThread()); 126 } 127 128 public String getLabelResource() 129 { 130 return "throughput_control_title"; 131 } 132 133 private void init() 134 { 135 setLayout( 136 new VerticalLayout(5, VerticalLayout.LEFT, VerticalLayout.TOP)); 137 setBorder(makeBorder()); 138 add(makeTitlePanel()); 139 140 DefaultComboBoxModel styleModel = new DefaultComboBoxModel (); 141 styleModel.addElement(BYNUMBER_LABEL); 142 styleModel.addElement(BYPERCENT_LABEL); 143 styleBox = new JComboBox (styleModel); 144 styleBox.addActionListener(new ActionListener () 145 { 146 public void actionPerformed(ActionEvent e) 147 { 148 if (((String ) styleBox.getSelectedItem()) 149 .equals(BYNUMBER_LABEL)) 150 { 151 style = ThroughputController.BYNUMBER; 152 } 153 else 154 { 155 style = ThroughputController.BYPERCENT; 156 } 157 } 158 }); 159 add(styleBox); 160 161 JPanel tpPanel = new JPanel (); 163 JLabel tpLabel = new JLabel (THROUGHPUT_LABEL); 164 tpPanel.add(tpLabel); 165 166 throughput = new JTextField (5); 168 tpPanel.add(throughput); 169 throughput.setName(THROUGHPUT); 170 throughput.setText("1"); 171 tpPanel.add(throughput); 173 add(tpPanel); 174 175 perthread = new JCheckBox (PERTHREAD_LABEL, isPerThread); 177 perthread.addItemListener(new ItemListener () 178 { 179 public void itemStateChanged(ItemEvent event) 180 { 181 if (event.getStateChange() == ItemEvent.SELECTED) 182 { 183 isPerThread = true; 184 } 185 else 186 { 187 isPerThread = false; 188 } 189 } 190 }); 191 add(perthread); 192 } 193 } 194 | Popular Tags |