1 18 19 20 23 24 package org.apache.jmeter.examples.sampler.gui; 25 26 import java.awt.BorderLayout ; 27 import java.awt.Component ; 28 29 import javax.swing.JLabel ; 30 import javax.swing.JPanel ; 31 import javax.swing.JTextField ; 32 33 import org.apache.jmeter.examples.sampler.ExampleSampler; 34 import org.apache.jmeter.samplers.gui.AbstractSamplerGui; 35 import org.apache.jmeter.testelement.TestElement; 36 import org.apache.jmeter.util.JMeterUtils; 37 38 49 public class ExampleSamplerGui extends AbstractSamplerGui 50 { 51 52 private JTextField data; 53 54 public ExampleSamplerGui() 55 { 56 init(); 57 } 58 59 62 public String getLabelResource() 63 { 64 return "example_title"; 65 } 66 67 72 public void configure(TestElement element) 73 { 74 data.setText(element.getPropertyAsString(ExampleSampler.DATA)); 75 super.configure(element); 76 } 77 78 83 public TestElement createTestElement() 84 { 85 ExampleSampler sampler = new ExampleSampler(); 86 modifyTestElement(sampler); 87 return sampler; 88 } 89 90 94 public void modifyTestElement(TestElement te) 95 { 96 te.clear(); 97 configureTestElement(te); 98 te.setProperty(ExampleSampler.DATA,data.getText()); 99 } 100 101 102 105 private void init() 106 { 107 setLayout(new BorderLayout (0, 5)); 109 setBorder(makeBorder()); 110 add(makeTitlePanel(),BorderLayout.NORTH); 112 add(createDataPanel(),BorderLayout.CENTER); 114 } 115 116 121 private Component createDataPanel() 122 { 123 JLabel label = new JLabel (JMeterUtils.getResString("example_data")); 124 125 data = new JTextField (10); 126 data.setName(ExampleSampler.DATA); 127 label.setLabelFor(data); 128 129 JPanel dataPanel = new JPanel (new BorderLayout (5, 0)); 130 dataPanel.add(label, BorderLayout.WEST); 131 dataPanel.add(data, BorderLayout.CENTER); 132 133 return dataPanel; 134 } 135 } | Popular Tags |