KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > java > control > gui > BeanShellSamplerGui


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/java/org/apache/jmeter/protocol/java/control/gui/BeanShellSamplerGui.java,v 1.9 2004/03/05 01:38:42 sebb Exp $
2
/*
3  * Copyright 2003-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.protocol.java.control.gui;
20
21 import java.awt.BorderLayout JavaDoc;
22
23 import javax.swing.Box JavaDoc;
24 import javax.swing.JLabel JavaDoc;
25 import javax.swing.JPanel JavaDoc;
26 import javax.swing.JScrollPane JavaDoc;
27 import javax.swing.JTextArea JavaDoc;
28 import javax.swing.JTextField JavaDoc;
29
30 import org.apache.jmeter.protocol.java.sampler.BeanShellSampler;
31 import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
32 import org.apache.jmeter.testelement.TestElement;
33 import org.apache.jmeter.util.JMeterUtils;
34
35 /**
36  * @version $Revision: 1.9 $ $Date: 2004/03/05 01:38:42 $
37  */

38 public class BeanShellSamplerGui extends AbstractSamplerGui
39 {
40     
41     private JTextField JavaDoc filename;// script file name (if present)
42
private JTextField JavaDoc parameters;// parameters to pass to script file (or script)
43
private JTextArea JavaDoc scriptField;// script area
44

45
46     public BeanShellSamplerGui()
47     {
48         init();
49     }
50
51     public void configure(TestElement element)
52     {
53         scriptField.setText(element.getPropertyAsString(BeanShellSampler.SCRIPT));
54         filename.setText(element.getPropertyAsString(BeanShellSampler.FILENAME));
55         parameters.setText(element.getPropertyAsString(BeanShellSampler.PARAMETERS));
56         super.configure(element);
57     }
58
59     public TestElement createTestElement()
60     {
61         BeanShellSampler sampler = new BeanShellSampler();
62         modifyTestElement(sampler);
63         return sampler;
64     }
65
66     /**
67      * Modifies a given TestElement to mirror the data in the gui components.
68      * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
69      */

70     public void modifyTestElement(TestElement te)
71     {
72         te.clear();
73         this.configureTestElement(te);
74         te.setProperty(BeanShellSampler.SCRIPT, scriptField.getText());
75         te.setProperty(BeanShellSampler.FILENAME, filename.getText());
76         te.setProperty(BeanShellSampler.PARAMETERS, parameters.getText());
77     }
78
79     public String JavaDoc getLabelResource()
80     {
81         return "bsh_sampler_title";
82     }
83
84     
85
86     private JPanel JavaDoc createFilenamePanel()//TODO ought to be a FileChooser ...
87
{
88         JLabel JavaDoc label = new JLabel JavaDoc(JMeterUtils.getResString("bsh_script_file"));
89         
90         filename = new JTextField JavaDoc(10);
91         filename.setName(BeanShellSampler.FILENAME);
92         label.setLabelFor(filename);
93
94         JPanel JavaDoc filenamePanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
95         filenamePanel.add(label, BorderLayout.WEST);
96         filenamePanel.add(filename, BorderLayout.CENTER);
97         return filenamePanel;
98     }
99
100     private JPanel JavaDoc createParameterPanel()
101     {
102         JLabel JavaDoc label = new JLabel JavaDoc(JMeterUtils.getResString("bsh_script_parameters"));
103
104         parameters = new JTextField JavaDoc(10);
105         parameters.setName(BeanShellSampler.PARAMETERS);
106         label.setLabelFor(parameters);
107
108         JPanel JavaDoc parameterPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5,0));
109         parameterPanel.add(label,BorderLayout.WEST);
110         parameterPanel.add(parameters, BorderLayout.CENTER);
111         return parameterPanel;
112     }
113
114     private void init()
115     {
116         setLayout(new BorderLayout JavaDoc(0, 5));
117         setBorder(makeBorder());
118
119         Box JavaDoc box = Box.createVerticalBox();
120         box.add(makeTitlePanel());
121         box.add(createParameterPanel());
122         box.add(createFilenamePanel());
123         add(box,BorderLayout.NORTH);
124
125         JPanel JavaDoc panel = createScriptPanel();
126         add(panel, BorderLayout.CENTER);
127         // Don't let the input field shrink too much
128
add(
129             Box.createVerticalStrut(panel.getPreferredSize().height),
130             BorderLayout.WEST);
131     }
132
133
134     private JPanel JavaDoc createScriptPanel()
135     {
136         scriptField = new JTextArea JavaDoc();
137         scriptField.setRows(4);
138         scriptField.setLineWrap(true);
139         scriptField.setWrapStyleWord(true);
140
141         JLabel JavaDoc label = new JLabel JavaDoc(JMeterUtils.getResString("bsh_script"));
142         label.setLabelFor(scriptField);
143
144         JPanel JavaDoc panel = new JPanel JavaDoc(new BorderLayout JavaDoc());
145         panel.add(label, BorderLayout.NORTH);
146         panel.add(new JScrollPane JavaDoc(scriptField), BorderLayout.CENTER);
147         return panel;
148     }
149 }
150
Popular Tags