KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > examples > sampler > gui > ExampleSamplerGui


1 // $Header: /home/cvs/jakarta-jmeter/src/examples/org/apache/jmeter/examples/sampler/gui/ExampleSamplerGui.java,v 1.2 2004/03/06 01:08:22 sebb Exp $
2
/*
3  * Copyright 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
20 /*
21  * Example Sampler GUI (non-beans version)
22  */

23  
24 package org.apache.jmeter.examples.sampler.gui;
25
26 import java.awt.BorderLayout JavaDoc;
27 import java.awt.Component JavaDoc;
28
29 import javax.swing.JLabel JavaDoc;
30 import javax.swing.JPanel JavaDoc;
31 import javax.swing.JTextField JavaDoc;
32
33 import org.apache.jmeter.examples.sampler.ExampleSampler;
34 import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
35 import org.apache.jmeter.testelement.TestElement;
36 import org.apache.jmeter.util.JMeterUtils;
37
38 /**
39  * Example Sampler (non-Bean version)
40  *
41  * This class is responsible for ensuring that the Sampler data is
42  * kept in step with the GUI.
43  *
44  * The GUI class is not invoked in non-GUI mode, so it should not
45  * perform any additional setup that a test would need at run-time
46  *
47  * @version $Revision: 1.2 $ $Date: 2004/03/06 01:08:22 $
48  */

49 public class ExampleSamplerGui extends AbstractSamplerGui
50 {
51
52     private JTextField JavaDoc data;
53         
54     public ExampleSamplerGui()
55     {
56         init();
57     }
58
59     /* (non-Javadoc)
60      * @see org.apache.jmeter.gui.JMeterGUIComponent#getStaticLabel()
61      */

62     public String JavaDoc getLabelResource()
63     {
64         return "example_title";
65     }
66
67     /* (non-Javadoc)
68      * Copy the data from the test element to the GUI
69      *
70      * @see org.apache.jmeter.gui.JMeterGUIComponent#configure(org.apache.jmeter.testelement.TestElement)
71      */

72     public void configure(TestElement element)
73     {
74         data.setText(element.getPropertyAsString(ExampleSampler.DATA));
75         super.configure(element);
76     }
77
78     /* (non-Javadoc)
79      * Create the corresponding Test Element and set up its data
80      *
81      * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
82      */

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

94     public void modifyTestElement(TestElement te)
95     {
96         te.clear();
97         configureTestElement(te);
98         te.setProperty(ExampleSampler.DATA,data.getText());
99     }
100
101
102     /*
103      * Helper method to set up the GUI screen
104      */

105     private void init()
106     {
107         // Standard setup
108
setLayout(new BorderLayout JavaDoc(0, 5));
109         setBorder(makeBorder());
110         add(makeTitlePanel(),BorderLayout.NORTH); // Add the standard title
111

112         // Specific setup
113
add(createDataPanel(),BorderLayout.CENTER);
114     }
115
116     /*
117      * Create a data input text field
118      *
119      * @return the panel for entering the data
120      */

121     private Component JavaDoc createDataPanel()
122     {
123         JLabel JavaDoc label = new JLabel JavaDoc(JMeterUtils.getResString("example_data"));
124         
125         data = new JTextField JavaDoc(10);
126         data.setName(ExampleSampler.DATA);
127         label.setLabelFor(data);
128
129         JPanel JavaDoc dataPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
130         dataPanel.add(label, BorderLayout.WEST);
131         dataPanel.add(data, BorderLayout.CENTER);
132
133         return dataPanel;
134     }
135 }
Popular Tags