1 18 19 package org.apache.jmeter.protocol.java.control.gui; 20 21 import java.awt.BorderLayout ; 22 23 import javax.swing.Box ; 24 import javax.swing.JLabel ; 25 import javax.swing.JPanel ; 26 import javax.swing.JScrollPane ; 27 import javax.swing.JTextArea ; 28 import javax.swing.JTextField ; 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 39 public class BSFSamplerGui extends AbstractSamplerGui 40 { 41 private JTextArea scriptField; 42 private JTextField langField; private JTextField filename; private JTextField parameters; 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 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 getLabelResource() 80 { 81 return "bsf_sampler_title"; 82 } 83 84 private void init() 85 { 86 setLayout(new BorderLayout (0, 5)); 87 setBorder(makeBorder()); 88 89 Box 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 panel = createScriptPanel(); 97 add(panel, BorderLayout.CENTER); 98 add( 100 Box.createVerticalStrut(panel.getPreferredSize().height), 101 BorderLayout.WEST); 102 } 103 104 private JPanel createParameterPanel() 105 { 106 JLabel label = new JLabel (JMeterUtils.getResString("bsf_script_parameters")); 107 108 parameters = new JTextField (10); 109 parameters.setName(BSFSampler.PARAMETERS); 110 label.setLabelFor(parameters); 111 112 JPanel parameterPanel = new JPanel (new BorderLayout (5,0)); 113 parameterPanel.add(label,BorderLayout.WEST); 114 parameterPanel.add(parameters, BorderLayout.CENTER); 115 return parameterPanel; 116 } 117 118 119 private JPanel createFilenamePanel() { 121 JLabel label = new JLabel (JMeterUtils.getResString("bsf_script_file")); 122 123 filename = new JTextField (10); 124 filename.setName(BSFSampler.FILENAME); 125 label.setLabelFor(filename); 126 127 JPanel filenamePanel = new JPanel (new BorderLayout (5, 0)); 128 filenamePanel.add(label, BorderLayout.WEST); 129 filenamePanel.add(filename, BorderLayout.CENTER); 130 return filenamePanel; 131 } 132 133 private JPanel createLanguagePanel() 134 { 135 JLabel label = new JLabel (JMeterUtils.getResString("bsf_script_language")); 136 137 langField = new JTextField (10); 138 langField.setName(BSFSampler.LANGUAGE); 139 label.setLabelFor(langField); 140 141 JPanel langPanel = new JPanel (new BorderLayout (5,0)); 142 langPanel.add(label,BorderLayout.WEST); 143 langPanel.add(langField, BorderLayout.CENTER); 144 return langPanel; 145 } 146 147 148 149 private JPanel createScriptPanel() 150 { 151 scriptField = new JTextArea (); 152 scriptField.setRows(4); 153 scriptField.setLineWrap(true); 154 scriptField.setWrapStyleWord(true); 155 156 JLabel label = new JLabel (JMeterUtils.getResString("bsf_script")); 157 label.setLabelFor(scriptField); 158 159 JPanel panel = new JPanel (new BorderLayout ()); 160 panel.add(label, BorderLayout.NORTH); 161 panel.add(new JScrollPane (scriptField), BorderLayout.CENTER); 162 return panel; 163 } 164 } 165 | Popular Tags |