1 18 19 package org.apache.jmeter.timers.gui; 20 21 import java.awt.Dimension ; 22 23 import javax.swing.BorderFactory ; 24 import javax.swing.Box ; 25 import javax.swing.JComponent ; 26 import javax.swing.JLabel ; 27 import javax.swing.JOptionPane ; 28 import javax.swing.JPanel ; 29 import javax.swing.JTextField ; 30 31 import org.apache.jmeter.gui.util.FocusRequester; 32 import org.apache.jmeter.testelement.TestElement; 33 import org.apache.jmeter.timers.GaussianRandomTimer; 34 import org.apache.jmeter.timers.RandomTimer; 35 import org.apache.jmeter.util.JMeterUtils; 36 import org.apache.jorphan.gui.layout.VerticalLayout; 37 38 43 public class GaussianRandomTimerGui extends AbstractTimerGui 44 { 45 46 private static final String DELAY_FIELD = "Delay Field"; 47 private static final String RANGE_FIELD = "Range Field"; 48 49 public static final String DEFAULT_DELAY = "300"; 50 public static final String DEFAULT_RANGE = "100.0"; 51 52 private JTextField delayField; 53 private JTextField rangeField; 54 55 58 public GaussianRandomTimerGui() 59 { 60 init(); 61 } 62 63 69 public static void error(Exception e, JComponent thrower) 70 { 71 JOptionPane.showMessageDialog(thrower, e, "Error", JOptionPane.ERROR_MESSAGE); 72 } 73 74 79 public TestElement createTestElement() 80 { 81 RandomTimer timer = new GaussianRandomTimer(); 82 modifyTestElement(timer); 83 return timer; 84 } 85 86 90 public void modifyTestElement(TestElement timer) 91 { 92 this.configureTestElement(timer); 93 ((RandomTimer) timer).setDelay(delayField.getText()); 94 ((RandomTimer) timer).setRange(rangeField.getText()); 95 } 96 97 102 public void configure(TestElement el) 103 { 104 super.configure(el); 105 delayField.setText(el.getPropertyAsString(RandomTimer.DELAY)); 106 rangeField.setText(el.getPropertyAsString(RandomTimer.RANGE)); 107 } 108 109 public String getLabelResource() 110 { 111 return "gaussian_timer_title"; 112 } 113 114 117 private void init() 118 { 119 setLayout(new VerticalLayout(5, VerticalLayout.LEFT)); 120 setBorder(makeBorder()); 121 122 add(makeTitlePanel()); 123 124 JPanel threadDelayPropsPanel = new JPanel (); 125 threadDelayPropsPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT)); 126 threadDelayPropsPanel.setBorder(BorderFactory.createTitledBorder(JMeterUtils.getResString("thread_delay_properties"))); 127 128 Box delayDevPanel = Box.createHorizontalBox(); 130 delayDevPanel.add(new JLabel (JMeterUtils.getResString("gaussian_timer_range"))); 131 delayDevPanel.add(Box.createHorizontalStrut(5)); 132 133 rangeField = new JTextField (6); 134 rangeField.setText(DEFAULT_RANGE); 135 rangeField.setName(RANGE_FIELD); 136 delayDevPanel.add(rangeField); 137 138 threadDelayPropsPanel.add(delayDevPanel); 139 140 Box avgDelayPanel = Box.createHorizontalBox(); 142 avgDelayPanel.add(new JLabel (JMeterUtils.getResString("gaussian_timer_delay"))); 143 avgDelayPanel.add(Box.createHorizontalStrut(5)); 144 145 delayField = new JTextField (6); 146 delayField.setText(DEFAULT_DELAY); 147 delayField.setName(DELAY_FIELD); 148 avgDelayPanel.add(delayField); 149 150 threadDelayPropsPanel.add(avgDelayPanel); 151 threadDelayPropsPanel.setMaximumSize(new Dimension (threadDelayPropsPanel.getMaximumSize().width, threadDelayPropsPanel.getPreferredSize().height)); 152 add(threadDelayPropsPanel); 153 154 new FocusRequester(rangeField); 156 } 157 158 161 public void clear() 162 { 163 rangeField.setText(DEFAULT_RANGE); 164 delayField.setText(DEFAULT_DELAY); 165 super.clear(); 166 } 167 } 168 | Popular Tags |