1 18 19 package org.apache.jmeter.control.gui; 20 21 import java.awt.BorderLayout ; 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 25 import javax.swing.Box ; 26 import javax.swing.JLabel ; 27 import javax.swing.JPanel ; 28 import javax.swing.JTextField ; 29 30 import org.apache.jmeter.control.RunTime; 31 import org.apache.jmeter.testelement.TestElement; 32 import org.apache.jmeter.util.JMeterUtils; 33 34 41 42 public class RunTimeGui 43 extends AbstractControllerGui 44 implements ActionListener 45 { 46 50 private JTextField seconds; 51 52 53 58 private boolean displayName = true; 59 60 61 private static final String SECONDS = "Seconds Field"; 62 63 66 public RunTimeGui() 67 { 68 this(true); 69 } 70 71 80 public RunTimeGui(boolean displayName) 81 { 82 this.displayName = displayName; 83 init(); 84 setState(1); 85 } 86 87 95 public void configure(TestElement element) 96 { 97 super.configure(element); 98 if (element instanceof RunTime) 99 { 100 setState(((RunTime) element).getRuntimeString()); 101 } 102 else 103 { 104 setState(1); 105 } 106 } 107 108 109 public TestElement createTestElement() 110 { 111 RunTime lc = new RunTime(); 112 modifyTestElement(lc); 113 return lc; 114 } 115 116 117 public void modifyTestElement(TestElement lc) 118 { 119 configureTestElement(lc); 120 if (lc instanceof RunTime) 121 { 122 if (seconds.getText().length() > 0) 123 { 124 ((RunTime) lc).setRuntime(seconds.getText()); 125 } 126 else 127 { 128 ((RunTime) lc).setRuntime(0); 129 } 130 } 131 } 132 133 139 public void actionPerformed(ActionEvent event) 140 { 141 seconds.setEnabled(true); 142 } 143 144 public String getLabelResource() 145 { 146 return "runtime_controller_title"; 147 } 148 149 152 private void init() 153 { 154 160 if (displayName) 162 { 163 setLayout(new BorderLayout (0, 5)); 164 setBorder(makeBorder()); 165 add(makeTitlePanel(), BorderLayout.NORTH); 166 167 JPanel mainPanel = new JPanel (new BorderLayout ()); 168 mainPanel.add(createLoopCountPanel(), BorderLayout.NORTH); 169 add(mainPanel, BorderLayout.CENTER); 170 } 171 else 172 { 173 setLayout(new BorderLayout ()); 175 add(createLoopCountPanel(), BorderLayout.NORTH); 176 } 177 } 178 179 185 private JPanel createLoopCountPanel() 186 { 187 JPanel loopPanel = new JPanel (new BorderLayout (5, 0)); 188 189 JLabel secondsLabel = 191 new JLabel (JMeterUtils.getResString("runtime_seconds")); 192 loopPanel.add(secondsLabel, BorderLayout.WEST); 193 194 JPanel loopSubPanel = new JPanel (new BorderLayout (5, 0)); 195 196 seconds = new JTextField ("60", 5); 198 secondsLabel.setLabelFor(seconds); 199 loopSubPanel.add(seconds, BorderLayout.CENTER); 200 201 loopPanel.add(loopSubPanel,BorderLayout.CENTER); 202 203 loopPanel.add( 204 Box.createHorizontalStrut( 205 secondsLabel.getPreferredSize().width 206 + seconds.getPreferredSize().width), 207 BorderLayout.NORTH); 208 209 return loopPanel; 210 } 211 212 221 private void setState(String secsCount) 222 { 223 seconds.setText(secsCount); 224 seconds.setEnabled(true); 225 } 226 227 234 private void setState(long secsCount) 235 { 236 seconds.setEnabled(true); 237 seconds.setText("" + secsCount); 238 } 239 } 240 | Popular Tags |