KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > http > config > gui > MultipartUrlConfigGui


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/MultipartUrlConfigGui.java,v 1.12 2004/03/21 01:21:34 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.protocol.http.config.gui;
20
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.io.File JavaDoc;
26
27 import javax.swing.BorderFactory JavaDoc;
28 import javax.swing.BoxLayout JavaDoc;
29 import javax.swing.JButton JavaDoc;
30 import javax.swing.JFileChooser JavaDoc;
31 import javax.swing.JLabel JavaDoc;
32 import javax.swing.JPanel JavaDoc;
33 import javax.swing.JTextField JavaDoc;
34
35 import org.apache.jmeter.gui.util.FileDialoger;
36 import org.apache.jmeter.gui.util.VerticalPanel;
37 import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
38 import org.apache.jmeter.testelement.TestElement;
39 import org.apache.jmeter.util.JMeterUtils;
40
41
42 /**
43  * @author Michael Stover
44  * @version $Revision: 1.12 $
45  */

46 public class MultipartUrlConfigGui
47     extends UrlConfigGui
48     implements ActionListener JavaDoc
49 {
50
51     private JTextField JavaDoc filenameField;
52     private JTextField JavaDoc paramNameField;
53     private JTextField JavaDoc mimetypeField;
54
55     private static String JavaDoc FILENAME = "filename";
56     private static String JavaDoc BROWSE = "browse";
57     private static String JavaDoc PARAMNAME = "paramname";
58     private static String JavaDoc MIMETYPE = "mimetype";
59
60     public MultipartUrlConfigGui()
61     {
62         super();
63     }
64
65     public TestElement createTestElement()
66     {
67         TestElement ce = super.createTestElement();
68
69         configureTestElement(ce);
70         ce.setProperty(HTTPSampler.MIMETYPE, mimetypeField.getText());
71         ce.setProperty(HTTPSampler.FILE_NAME, filenameField.getText());
72         ce.setProperty(HTTPSampler.FILE_FIELD, paramNameField.getText());
73         return ce;
74     }
75
76 // does not appear to be used
77
// public void configureSampler(HTTPSampler sampler)
78
// {
79
// sampler.setMimetype(mimetypeField.getText());
80
// sampler.setFileField(paramNameField.getText());
81
// sampler.setFilename(filenameField.getText());
82
// super.configureSampler(sampler);
83
// }
84

85     public void configure(TestElement el)
86     {
87         super.configure(el);
88         mimetypeField.setText(el.getPropertyAsString(HTTPSampler.MIMETYPE));
89         filenameField.setText(el.getPropertyAsString(HTTPSampler.FILE_NAME));
90         paramNameField.setText(el.getPropertyAsString(HTTPSampler.FILE_FIELD));
91     }
92
93     public String JavaDoc getLabelResource()
94     {
95         return "url_multipart_config_title";
96     }
97
98     public void updateGui()
99     {}
100
101     public void actionPerformed(ActionEvent JavaDoc e)
102     {
103         String JavaDoc name = e.getActionCommand();
104
105         if (name.equals(BROWSE))
106         {
107             JFileChooser JavaDoc chooser = FileDialoger.promptToOpenFile();
108
109             if (chooser == null)
110             {
111                 return;
112             }
113             File JavaDoc file = chooser.getSelectedFile();
114
115             if (file != null)
116             {
117                 filenameField.setText(file.getPath());
118             }
119         }
120     }
121
122     protected void init()
123     {
124         this.setLayout(new BorderLayout JavaDoc());
125
126         // WEB SERVER PANEL
127
VerticalPanel webServerPanel = new VerticalPanel();
128         webServerPanel.setBorder(
129             BorderFactory.createTitledBorder(
130                 BorderFactory.createEtchedBorder(),
131                 JMeterUtils.getResString("web_server")));
132         webServerPanel.add(getDomainPanel());
133         webServerPanel.add(getPortPanel());
134
135         // WEB REQUEST PANEL
136
JPanel JavaDoc webRequestPanel = new JPanel JavaDoc();
137         webRequestPanel.setLayout(
138             new BoxLayout JavaDoc(webRequestPanel, BoxLayout.Y_AXIS));
139         webRequestPanel.setBorder(
140             BorderFactory.createTitledBorder(
141                 BorderFactory.createEtchedBorder(),
142                 JMeterUtils.getResString("web_request")));
143         
144         webRequestPanel.add(getProtocolAndMethodPanel());
145         webRequestPanel.add(getPathPanel());
146         webRequestPanel.add(getParameterPanel());
147         webRequestPanel.add(getFilePanel());
148         
149         this.add(webServerPanel, BorderLayout.NORTH);
150         this.add(webRequestPanel, BorderLayout.CENTER);
151     }
152
153     protected JPanel JavaDoc getFilePanel()
154     {
155         JPanel JavaDoc filePanel = new VerticalPanel();
156         filePanel.setBorder(
157             BorderFactory.createTitledBorder(
158                 BorderFactory.createEtchedBorder(),
159                 JMeterUtils.getResString("send_file")));
160
161         filePanel.add(createFilenamePanel());
162         filePanel.add(createFileParamNamePanel());
163         filePanel.add(createFileMimeTypePanel());
164
165         return filePanel;
166     }
167
168     private JPanel JavaDoc createFileMimeTypePanel()
169     {
170         mimetypeField = new JTextField JavaDoc(15);
171         mimetypeField.setName(MIMETYPE);
172
173         JLabel JavaDoc mimetypeLabel =
174             new JLabel JavaDoc(JMeterUtils.getResString("send_file_mime_label"));
175         mimetypeLabel.setLabelFor(mimetypeField);
176         JPanel JavaDoc mimePanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
177         mimePanel.add(mimetypeLabel, BorderLayout.WEST);
178         mimePanel.add(mimetypeField, BorderLayout.CENTER);
179         return mimePanel;
180     }
181
182     private JPanel JavaDoc createFileParamNamePanel()
183     {
184         paramNameField = new JTextField JavaDoc(15);
185         paramNameField.setName(PARAMNAME);
186
187         JLabel JavaDoc paramNameLabel =
188             new JLabel JavaDoc(JMeterUtils.getResString("send_file_param_name_label"));
189         paramNameLabel.setLabelFor(paramNameField);
190
191         JPanel JavaDoc paramNamePanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
192         paramNamePanel.add(paramNameLabel, BorderLayout.WEST);
193         paramNamePanel.add(paramNameField, BorderLayout.CENTER);
194         return paramNamePanel;
195     }
196
197     private JPanel JavaDoc createFilenamePanel()
198     {
199         filenameField = new JTextField JavaDoc(15);
200         filenameField.setName(FILENAME);
201
202         JLabel JavaDoc filenameLabel =
203             new JLabel JavaDoc(JMeterUtils.getResString("send_file_filename_label"));
204         filenameLabel.setLabelFor(filenameField);
205
206         JButton JavaDoc browseFileButton =
207             new JButton JavaDoc(JMeterUtils.getResString("send_file_browse"));
208         browseFileButton.setActionCommand(BROWSE);
209         browseFileButton.addActionListener(this);
210         
211
212         JPanel JavaDoc filenamePanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
213         filenamePanel.add(filenameLabel, BorderLayout.WEST);
214         filenamePanel.add(filenameField, BorderLayout.CENTER);
215         filenamePanel.add(browseFileButton, BorderLayout.EAST);
216         return filenamePanel;
217     }
218     
219     /* (non-Javadoc)
220      * @see org.apache.jmeter.protocol.http.config.gui.UrlConfigGui#clear()
221      */

222     public void clear()
223     {
224         // TODO Auto-generated method stub
225
super.clear();
226         filenameField.setText("");
227         mimetypeField.setText("");
228         paramNameField.setText("");
229     }
230 }
231
Popular Tags