KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Header: /home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/timers/gui/GaussianRandomTimerGui.java,v 1.14 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 java.awt.Dimension JavaDoc;
22
23 import javax.swing.BorderFactory JavaDoc;
24 import javax.swing.Box JavaDoc;
25 import javax.swing.JComponent JavaDoc;
26 import javax.swing.JLabel JavaDoc;
27 import javax.swing.JOptionPane JavaDoc;
28 import javax.swing.JPanel JavaDoc;
29 import javax.swing.JTextField JavaDoc;
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 /**
39  * Implementation of a gaussian random timer.
40  *
41  * @version $Revision: 1.14 $ last updated $Date: 2004/03/05 01:33:13 $
42  */

43 public class GaussianRandomTimerGui extends AbstractTimerGui
44 {
45
46     private static final String JavaDoc DELAY_FIELD = "Delay Field";
47     private static final String JavaDoc RANGE_FIELD = "Range Field";
48
49     public static final String JavaDoc DEFAULT_DELAY = "300";
50     public static final String JavaDoc DEFAULT_RANGE = "100.0";
51
52     private JTextField JavaDoc delayField;
53     private JTextField JavaDoc rangeField;
54
55     /**
56      * No-arg constructor.
57      */

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

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

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

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     /**
98      * Configure this GUI component from the underlying TestElement.
99      *
100      * @see org.apache.jmeter.gui.JMeterGUIComponent#configure(TestElement)
101      */

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 JavaDoc getLabelResource()
110     {
111         return "gaussian_timer_title";
112     }
113
114     /**
115      * Initialize this component.
116      */

117     private void init()
118     {
119         setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
120         setBorder(makeBorder());
121
122         add(makeTitlePanel());
123
124         JPanel JavaDoc threadDelayPropsPanel = new JPanel JavaDoc();
125         threadDelayPropsPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
126         threadDelayPropsPanel.setBorder(BorderFactory.createTitledBorder(JMeterUtils.getResString("thread_delay_properties")));
127
128         // DELAY DEVIATION
129
Box JavaDoc delayDevPanel = Box.createHorizontalBox();
130         delayDevPanel.add(new JLabel JavaDoc(JMeterUtils.getResString("gaussian_timer_range")));
131         delayDevPanel.add(Box.createHorizontalStrut(5));
132
133         rangeField = new JTextField JavaDoc(6);
134         rangeField.setText(DEFAULT_RANGE);
135         rangeField.setName(RANGE_FIELD);
136         delayDevPanel.add(rangeField);
137
138         threadDelayPropsPanel.add(delayDevPanel);
139
140         // AVG DELAY
141
Box JavaDoc avgDelayPanel = Box.createHorizontalBox();
142         avgDelayPanel.add(new JLabel JavaDoc(JMeterUtils.getResString("gaussian_timer_delay")));
143         avgDelayPanel.add(Box.createHorizontalStrut(5));
144
145         delayField = new JTextField JavaDoc(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 JavaDoc(threadDelayPropsPanel.getMaximumSize().width, threadDelayPropsPanel.getPreferredSize().height));
152         add(threadDelayPropsPanel);
153
154         // Set the initial focus to the delay field
155
new FocusRequester(rangeField);
156     }
157
158     /* (non-Javadoc)
159      * @see org.apache.jmeter.gui.JMeterGUIComponent#clear()
160      */

161     public void clear()
162     {
163         rangeField.setText(DEFAULT_RANGE);
164         delayField.setText(DEFAULT_DELAY);
165         super.clear();
166     }
167 }
168
Popular Tags