KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Header: /home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/timers/gui/ConstantTimerGui.java,v 1.12 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.Box JavaDoc;
22 import javax.swing.JComponent JavaDoc;
23 import javax.swing.JLabel JavaDoc;
24 import javax.swing.JOptionPane JavaDoc;
25 import javax.swing.JTextField JavaDoc;
26
27 import org.apache.jmeter.testelement.TestElement;
28 import org.apache.jmeter.timers.ConstantTimer;
29 import org.apache.jmeter.util.JMeterUtils;
30 import org.apache.jorphan.gui.layout.VerticalLayout;
31
32 /**
33  * The GUI for ConstantTimer.
34  *
35  * @version $Revision: 1.12 $ on $Date: 2004/03/05 01:33:13 $
36  */

37 public class ConstantTimerGui extends AbstractTimerGui
38 {
39     /**
40      * The default value for the delay.
41      */

42     private static final String JavaDoc DEFAULT_DELAY = "300";
43
44     private static final String JavaDoc DELAY_FIELD = "Delay Field";
45
46     private JTextField JavaDoc delayField;
47
48     /**
49      * No-arg constructor.
50      */

51     public ConstantTimerGui()
52     {
53         init();
54     }
55
56     /**
57      * Handle an error.
58      *
59      * @param e the Exception that was thrown.
60      * @param thrower the JComponent that threw the Exception.
61      */

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

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

88     public void modifyTestElement(TestElement timer)
89     {
90         this.configureTestElement(timer);
91         ((ConstantTimer) timer).setDelay(delayField.getText());
92     }
93
94     /**
95      * Configure this GUI component from the underlying TestElement.
96      *
97      * @see org.apache.jmeter.gui.JMeterGUIComponent#configure(TestElement)
98      */

99     public void configure(TestElement el)
100     {
101         super.configure(el);
102         delayField.setText(((ConstantTimer) el).getDelay());
103     }
104
105     /**
106      * Initialize this component.
107      */

108     private void init()
109     {
110         setLayout(new VerticalLayout(5, VerticalLayout.LEFT, VerticalLayout.TOP));
111
112         setBorder(makeBorder());
113         add(makeTitlePanel());
114
115         Box JavaDoc delayPanel = Box.createHorizontalBox();
116         JLabel JavaDoc delayLabel = new JLabel JavaDoc(JMeterUtils.getResString("constant_timer_delay"));
117         delayPanel.add(delayLabel);
118
119         delayField = new JTextField JavaDoc(6);
120         delayField.setText(DEFAULT_DELAY);
121         delayField.setName(DELAY_FIELD);
122         delayPanel.add(delayField);
123         add(delayPanel);
124     }
125     /* (non-Javadoc)
126      * @see org.apache.jmeter.gui.JMeterGUIComponent#clear()
127      */

128     public void clear()
129     {
130         delayField.setText(DEFAULT_DELAY);
131         super.clear();
132     }
133 }
134
Popular Tags