1 18 19 package org.apache.jmeter.timers.gui; 20 21 import javax.swing.BorderFactory ; 22 import javax.swing.Box ; 23 import javax.swing.JComponent ; 24 import javax.swing.JLabel ; 25 import javax.swing.JOptionPane ; 26 import javax.swing.JPanel ; 27 import javax.swing.JTextField ; 28 29 import org.apache.jmeter.gui.util.FocusRequester; 30 import org.apache.jmeter.testelement.TestElement; 31 import org.apache.jmeter.timers.RandomTimer; 32 import org.apache.jmeter.timers.UniformRandomTimer; 33 import org.apache.jmeter.util.JMeterUtils; 34 import org.apache.jorphan.gui.layout.VerticalLayout; 35 36 41 public class UniformRandomTimerGui extends AbstractTimerGui 42 { 43 44 private static final String DELAY_FIELD = "Delay Field"; 45 private static final String RANGE_FIELD = "Range Field"; 46 47 public static final String DEFAULT_DELAY = "0"; public static final String DEFAULT_RANGE = "100.0"; 50 private JTextField delayField; 51 private JTextField rangeField; 52 53 56 public UniformRandomTimerGui() 57 { 58 init(); 59 } 60 61 67 public static void error(Exception e, JComponent thrower) 68 { 69 JOptionPane.showMessageDialog(thrower, e, "Error", JOptionPane.ERROR_MESSAGE); 70 } 71 72 public String getLabelResource() 73 { 74 return "uniform_timer_title"; 75 } 76 77 82 public TestElement createTestElement() 83 { 84 RandomTimer timer = new UniformRandomTimer(); 85 modifyTestElement(timer); 86 return timer; 87 } 88 89 93 public void modifyTestElement(TestElement timer) 94 { 95 this.configureTestElement(timer); 96 ((RandomTimer) timer).setDelay(delayField.getText()); 97 ((RandomTimer) timer).setRange(rangeField.getText()); 98 } 99 100 105 public void configure(TestElement el) 106 { 107 super.configure(el); 108 delayField.setText(el.getPropertyAsString(RandomTimer.DELAY)); 109 rangeField.setText(el.getPropertyAsString(RandomTimer.RANGE)); 110 } 111 112 115 private void init() 116 { 117 setLayout(new VerticalLayout(5, VerticalLayout.LEFT)); 118 setBorder(makeBorder()); 119 120 add(makeTitlePanel()); 121 122 JPanel threadDelayPropsPanel = new JPanel (); 124 threadDelayPropsPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT)); 125 threadDelayPropsPanel.setBorder(BorderFactory.createTitledBorder(JMeterUtils.getResString("thread_delay_properties"))); 126 127 Box delayDevPanel = Box.createHorizontalBox(); 129 delayDevPanel.add(new JLabel (JMeterUtils.getResString("uniform_timer_range"))); 130 delayDevPanel.add(Box.createHorizontalStrut(5)); 131 132 rangeField = new JTextField (6); 133 rangeField.setText(DEFAULT_RANGE); 134 rangeField.setName(RANGE_FIELD); 135 delayDevPanel.add(rangeField); 136 137 threadDelayPropsPanel.add(delayDevPanel); 138 139 Box avgDelayPanel = Box.createHorizontalBox(); 141 avgDelayPanel.add(new JLabel (JMeterUtils.getResString("uniform_timer_delay"))); 142 avgDelayPanel.add(Box.createHorizontalStrut(5)); 143 144 delayField = new JTextField (6); 145 delayField.setText(DEFAULT_DELAY); 146 delayField.setName(DELAY_FIELD); 147 avgDelayPanel.add(delayField); 148 149 threadDelayPropsPanel.add(avgDelayPanel); 150 151 add(threadDelayPropsPanel); 152 153 new FocusRequester(rangeField); 155 } 156 157 160 public void clear() 161 { 162 rangeField.setText(DEFAULT_RANGE); 163 delayField.setText(DEFAULT_DELAY); 164 super.clear(); 165 } 166 } 167 | Popular Tags |