KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > assertions > gui > BeanShellAssertionGui


1 // $Header: /home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/assertions/gui/BeanShellAssertionGui.java,v 1.4.2.1 2005/03/06 17:34:29 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.assertions.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.assertions.BeanShellAssertion;
31 import org.apache.jmeter.testelement.TestElement;
32 import org.apache.jmeter.util.JMeterUtils;
33
34 /**
35  * @version $Revision: 1.4.2.1 $ $Date: 2005/03/06 17:34:29 $
36  */

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

44
45     public BeanShellAssertionGui()
46     {
47         init();
48     }
49
50     public void configure(TestElement element)
51     {
52         scriptField.setText(element.getPropertyAsString(BeanShellAssertion.SCRIPT));
53         filename.setText(element.getPropertyAsString(BeanShellAssertion.FILENAME));
54         parameters.setText(element.getPropertyAsString(BeanShellAssertion.PARAMETERS));
55         super.configure(element);
56     }
57
58     public TestElement createTestElement()
59     {
60         BeanShellAssertion sampler = new BeanShellAssertion();
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(BeanShellAssertion.SCRIPT, scriptField.getText());
74         te.setProperty(BeanShellAssertion.FILENAME, filename.getText());
75         te.setProperty(BeanShellAssertion.PARAMETERS, parameters.getText());
76     }
77
78     public String JavaDoc getLabelResource()
79     {
80         return "bsh_assertion_title";
81     }
82
83     private JPanel JavaDoc createFilenamePanel()//TODO ought to be a FileChooser ...
84
{
85         JLabel JavaDoc label = new JLabel JavaDoc(JMeterUtils.getResString("bsh_script_file"));
86         
87         filename = new JTextField JavaDoc(10);
88         filename.setName(BeanShellAssertion.FILENAME);
89         label.setLabelFor(filename);
90
91         JPanel JavaDoc filenamePanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
92         filenamePanel.add(label, BorderLayout.WEST);
93         filenamePanel.add(filename, BorderLayout.CENTER);
94         return filenamePanel;
95     }
96
97     private JPanel JavaDoc createParameterPanel()
98     {
99         JLabel JavaDoc label = new JLabel JavaDoc(JMeterUtils.getResString("bsh_script_parameters"));
100
101         parameters = new JTextField JavaDoc(10);
102         parameters.setName(BeanShellAssertion.PARAMETERS);
103         label.setLabelFor(parameters);
104
105         JPanel JavaDoc parameterPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5,0));
106         parameterPanel.add(label,BorderLayout.WEST);
107         parameterPanel.add(parameters, BorderLayout.CENTER);
108         return parameterPanel;
109     }
110
111     private void init()
112     {
113         setLayout(new BorderLayout JavaDoc(0, 5));
114         setBorder(makeBorder());
115
116         Box JavaDoc box = Box.createVerticalBox();
117         box.add(makeTitlePanel());
118         box.add(createParameterPanel());
119         box.add(createFilenamePanel());
120         add(box,BorderLayout.NORTH);
121
122         JPanel JavaDoc panel = createScriptPanel();
123         add(panel, BorderLayout.CENTER);
124         // Don't let the input field shrink too much
125
add(
126             Box.createVerticalStrut(panel.getPreferredSize().height),
127             BorderLayout.WEST);
128     }
129
130
131     private JPanel JavaDoc createScriptPanel()
132     {
133         scriptField = new JTextArea JavaDoc();
134         scriptField.setRows(4);
135         scriptField.setLineWrap(true);
136         scriptField.setWrapStyleWord(true);
137
138         JLabel JavaDoc label = new JLabel JavaDoc(JMeterUtils.getResString("bsh_assertion_script"));
139         label.setLabelFor(scriptField);
140
141         JPanel JavaDoc panel = new JPanel JavaDoc(new BorderLayout JavaDoc());
142         panel.add(label, BorderLayout.NORTH);
143         panel.add(new JScrollPane JavaDoc(scriptField), BorderLayout.CENTER);
144
145         JTextArea JavaDoc explain = new JTextArea JavaDoc(
146                 JMeterUtils.getResString("bsh_assertion_script_variables"));
147         explain.setLineWrap(true);
148         explain.setEditable(false);
149         explain.setBackground(this.getBackground());
150         panel.add(explain, BorderLayout.SOUTH);
151
152         return panel;
153     }
154 }
155
Popular Tags