1 18 19 package org.apache.jmeter.protocol.http.config.gui; 20 21 22 import java.awt.BorderLayout ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.io.File ; 26 27 import javax.swing.BorderFactory ; 28 import javax.swing.BoxLayout ; 29 import javax.swing.JButton ; 30 import javax.swing.JFileChooser ; 31 import javax.swing.JLabel ; 32 import javax.swing.JPanel ; 33 import javax.swing.JTextField ; 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 46 public class MultipartUrlConfigGui 47 extends UrlConfigGui 48 implements ActionListener 49 { 50 51 private JTextField filenameField; 52 private JTextField paramNameField; 53 private JTextField mimetypeField; 54 55 private static String FILENAME = "filename"; 56 private static String BROWSE = "browse"; 57 private static String PARAMNAME = "paramname"; 58 private static String 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 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 getLabelResource() 94 { 95 return "url_multipart_config_title"; 96 } 97 98 public void updateGui() 99 {} 100 101 public void actionPerformed(ActionEvent e) 102 { 103 String name = e.getActionCommand(); 104 105 if (name.equals(BROWSE)) 106 { 107 JFileChooser chooser = FileDialoger.promptToOpenFile(); 108 109 if (chooser == null) 110 { 111 return; 112 } 113 File 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 ()); 125 126 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 JPanel webRequestPanel = new JPanel (); 137 webRequestPanel.setLayout( 138 new BoxLayout (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 getFilePanel() 154 { 155 JPanel 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 createFileMimeTypePanel() 169 { 170 mimetypeField = new JTextField (15); 171 mimetypeField.setName(MIMETYPE); 172 173 JLabel mimetypeLabel = 174 new JLabel (JMeterUtils.getResString("send_file_mime_label")); 175 mimetypeLabel.setLabelFor(mimetypeField); 176 JPanel mimePanel = new JPanel (new BorderLayout (5, 0)); 177 mimePanel.add(mimetypeLabel, BorderLayout.WEST); 178 mimePanel.add(mimetypeField, BorderLayout.CENTER); 179 return mimePanel; 180 } 181 182 private JPanel createFileParamNamePanel() 183 { 184 paramNameField = new JTextField (15); 185 paramNameField.setName(PARAMNAME); 186 187 JLabel paramNameLabel = 188 new JLabel (JMeterUtils.getResString("send_file_param_name_label")); 189 paramNameLabel.setLabelFor(paramNameField); 190 191 JPanel paramNamePanel = new JPanel (new BorderLayout (5, 0)); 192 paramNamePanel.add(paramNameLabel, BorderLayout.WEST); 193 paramNamePanel.add(paramNameField, BorderLayout.CENTER); 194 return paramNamePanel; 195 } 196 197 private JPanel createFilenamePanel() 198 { 199 filenameField = new JTextField (15); 200 filenameField.setName(FILENAME); 201 202 JLabel filenameLabel = 203 new JLabel (JMeterUtils.getResString("send_file_filename_label")); 204 filenameLabel.setLabelFor(filenameField); 205 206 JButton browseFileButton = 207 new JButton (JMeterUtils.getResString("send_file_browse")); 208 browseFileButton.setActionCommand(BROWSE); 209 browseFileButton.addActionListener(this); 210 211 212 JPanel filenamePanel = new JPanel (new BorderLayout (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 222 public void clear() 223 { 224 super.clear(); 226 filenameField.setText(""); 227 mimetypeField.setText(""); 228 paramNameField.setText(""); 229 } 230 } 231 | Popular Tags |