KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/java/org/apache/jmeter/protocol/java/control/gui/BSFSamplerGui.java,v 1.4 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.BSFSampler;
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  *
37  * @version $Revision: 1.4 $ $Date: 2004/03/05 01:38:42 $
38  */

39 public class BSFSamplerGui extends AbstractSamplerGui
40 {
41     private JTextArea JavaDoc scriptField;
42     private JTextField JavaDoc langField;// Language TODO should this be a drop-down list?
43
private JTextField JavaDoc filename;// script file name (if present)
44
private JTextField JavaDoc parameters;// parameters to pass to script file (or script)
45

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

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