e.g. Calendar Search Help
You must enter a value before pressing Search
jmeter

Class: org.apache.jmeter.timers.gui.UniformRandomTimerGui   ©

 OK to copy?
001 // $Header: /home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/timers/gui/UniformRandomTimerGui.java,v 1.15 2004/03/05 01:33:13 sebb Exp $
002 /*
003  * Copyright 2001-2004 The Apache Software Foundation.
004  *
005  * Licensed under the Apache License, Version 2.0 (the "License");
006  * you may not use this file except in compliance with the License.
007  * You may obtain a copy of the License at
008  *
009  *   http://www.apache.org/licenses/LICENSE-2.0
010  *
011  * Unless required by applicable law or agreed to in writing, software
012  * distributed under the License is distributed on an "AS IS" BASIS,
013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014  * See the License for the specific language governing permissions and
015  * limitations under the License.
016  * 
017 */
018 
019 package org.apache.jmeter.timers.gui;
020 
021 import javax.swing.BorderFactory;
022 import javax.swing.Box;
023 import javax.swing.JComponent;
024 import javax.swing.JLabel;
025 import javax.swing.JOptionPane;
026 import javax.swing.JPanel;
027 import javax.swing.JTextField;
028 
029 import org.apache.jmeter.gui.util.FocusRequester;
030 import org.apache.jmeter.testelement.TestElement;
031 import org.apache.jmeter.timers.RandomTimer;
032 import org.apache.jmeter.timers.UniformRandomTimer;
033 import org.apache.jmeter.util.JMeterUtils;
034 import org.apache.jorphan.gui.layout.VerticalLayout;
035 
036 /**
037  * Implementation of a uniform random timer.
038  *
039  * @version $Id: UniformRandomTimerGui.java,v 1.15 2004/03/05 01:33:13 sebb Exp $
040  */
041 public class UniformRandomTimerGui extends AbstractTimerGui
042 {
043 
044     private static final String DELAY_FIELD = "Delay Field";
045     private static final String RANGE_FIELD = "Range Field";
046 
047     public static final String DEFAULT_DELAY = "0"; //TODO: make private?
048     public static final String DEFAULT_RANGE = "100.0";//TODO: make private?
049 
050     private JTextField delayField;
051     private JTextField rangeField;
052 
053     /**
054      * No-arg constructor.
055      */
056     public UniformRandomTimerGui()
057     {
058         init();
059     }
060 
061     /**
062      * Handle an error.
063      *
064      * @param e the Exception that was thrown.
065      * @param thrower the JComponent that threw the Exception.
066      */
067     public static void error(Exception e, JComponent thrower)
068     {
069         JOptionPane.showMessageDialog(thrower, e, "Error", JOptionPane.ERROR_MESSAGE);
070     }
071 
072     public String getLabelResource()
073     {
074         return "uniform_timer_title";
075     }
076 
077     /**
078      * Create the test element underlying this GUI component.
079      * 
080      * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
081      */
082     public TestElement createTestElement()
083     {
084         RandomTimer timer = new UniformRandomTimer();
085         modifyTestElement(timer);
086         return timer;
087     }
088 
089     /**
090      * Modifies a given TestElement to mirror the data in the gui components.
091      * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
092      */
093     public void modifyTestElement(TestElement timer)
094     {
095         this.configureTestElement(timer);
096         ((RandomTimer) timer).setDelay(delayField.getText());
097         ((RandomTimer) timer).setRange(rangeField.getText());
098     }
099 
100     /**
101      * Configure this GUI component from the underlying TestElement.
102      * 
103      * @see org.apache.jmeter.gui.JMeterGUIComponent#configure(TestElement)
104      */
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     /**
113      * Initialize this component.
114      */
115     private void init()
116     {
117         setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
118         setBorder(makeBorder());
119 
120         add(makeTitlePanel());
121 
122         // THREAD DELAY PROPERTIES
123         JPanel threadDelayPropsPanel = new JPanel();
124         threadDelayPropsPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
Rate125         threadDelayPropsPanel.setBorder(BorderFactory.createTitledBorder(JMeterUtils.getResString("thread_delay_properties")));
126 
127         // DELAY DEVIATION
128         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         // AVG DELAY
140         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         // Set the initial focus to the range field
154         new FocusRequester(rangeField);
155     }
156 
157     /* (non-Javadoc)
158      * @see org.apache.jmeter.gui.JMeterGUIComponent#clear()
159      */
160     public void clear()
161     {
162         rangeField.setText(DEFAULT_RANGE);
163         delayField.setText(DEFAULT_DELAY);
164         super.clear();
165     }
166 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
125 0% of 0