KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > timers > gui > UniformRandomTimerGui


1 // $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 $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.timers.gui;
20
21 import javax.swing.BorderFactory JavaDoc;
22 import javax.swing.Box JavaDoc;
23 import javax.swing.JComponent JavaDoc;
24 import javax.swing.JLabel JavaDoc;
25 import javax.swing.JOptionPane JavaDoc;
26 import javax.swing.JPanel JavaDoc;
27 import javax.swing.JTextField JavaDoc;
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 /**
37  * Implementation of a uniform random timer.
38  *
39  * @version $Id: UniformRandomTimerGui.java,v 1.15 2004/03/05 01:33:13 sebb Exp $
40  */

41 public class UniformRandomTimerGui extends AbstractTimerGui
42 {
43
44     private static final String JavaDoc DELAY_FIELD = "Delay Field";
45     private static final String JavaDoc RANGE_FIELD = "Range Field";
46
47     public static final String JavaDoc DEFAULT_DELAY = "0"; //TODO: make private?
48
public static final String JavaDoc DEFAULT_RANGE = "100.0";//TODO: make private?
49

50     private JTextField JavaDoc delayField;
51     private JTextField JavaDoc rangeField;
52
53     /**
54      * No-arg constructor.
55      */

56     public UniformRandomTimerGui()
57     {
58         init();
59     }
60
61     /**
62      * Handle an error.
63      *
64      * @param e the Exception that was thrown.
65      * @param thrower the JComponent that threw the Exception.
66      */

67     public static void error(Exception JavaDoc e, JComponent JavaDoc thrower)
68     {
69         JOptionPane.showMessageDialog(thrower, e, "Error", JOptionPane.ERROR_MESSAGE);
70     }
71
72     public String JavaDoc getLabelResource()
73     {
74         return "uniform_timer_title";
75     }
76
77     /**
78      * Create the test element underlying this GUI component.
79      *
80      * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
81      */

82     public TestElement createTestElement()
83     {
84         RandomTimer timer = new UniformRandomTimer();
85         modifyTestElement(timer);
86         return timer;
87     }
88
89     /**
90      * Modifies a given TestElement to mirror the data in the gui components.
91      * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
92      */

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     /**
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 JavaDoc threadDelayPropsPanel = new JPanel JavaDoc();
124         threadDelayPropsPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
125         threadDelayPropsPanel.setBorder(BorderFactory.createTitledBorder(JMeterUtils.getResString("thread_delay_properties")));
126
127         // DELAY DEVIATION
128
Box JavaDoc delayDevPanel = Box.createHorizontalBox();
129         delayDevPanel.add(new JLabel JavaDoc(JMeterUtils.getResString("uniform_timer_range")));
130         delayDevPanel.add(Box.createHorizontalStrut(5));
131
132         rangeField = new JTextField JavaDoc(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 JavaDoc avgDelayPanel = Box.createHorizontalBox();
141         avgDelayPanel.add(new JLabel JavaDoc(JMeterUtils.getResString("uniform_timer_delay")));
142         avgDelayPanel.add(Box.createHorizontalStrut(5));
143
144         delayField = new JTextField JavaDoc(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 }
167
Popular Tags