1 18 19 package org.apache.jmeter.protocol.tcp.config.gui; 20 import java.awt.BorderLayout ; 21 22 import javax.swing.JCheckBox ; 23 import javax.swing.JLabel ; 24 import javax.swing.JPanel ; 25 import javax.swing.JTextArea ; 26 import javax.swing.JTextField ; 27 28 import org.apache.jmeter.config.ConfigTestElement; 29 import org.apache.jmeter.config.gui.AbstractConfigGui; 30 import org.apache.jmeter.gui.util.VerticalPanel; 31 import org.apache.jmeter.protocol.tcp.sampler.TCPSampler; 32 import org.apache.jmeter.testelement.TestElement; 33 import org.apache.jmeter.util.JMeterUtils; 34 import org.apache.jorphan.util.JOrphanUtils; 35 36 39 public class TCPConfigGui extends AbstractConfigGui 40 { 41 private final static String SERVER = "server"; private final static String PORT = "port"; private final static String FILENAME = "filename"; private final static String TIMEOUT = "timeout"; private final static String NODELAY = "nodelay"; private final static String REQUEST = "request"; 48 private JTextField server; 49 private JTextField port; 50 private JTextField timeout; 52 private JCheckBox setNoDelay; 53 54 private JTextArea requestData; 55 56 private boolean displayName = true; 57 58 public TCPConfigGui() 59 { 60 this(true); 61 } 62 63 public TCPConfigGui(boolean displayName) 64 { 65 this.displayName = displayName; 66 init(); 67 } 68 69 public String getLabelResource() 70 { 71 return "tcp_config_title"; 72 } 73 74 public void configure(TestElement element) 75 { 76 super.configure(element); 77 server.setText(element.getPropertyAsString(TCPSampler.SERVER)); 78 port.setText(element.getPropertyAsString(TCPSampler.PORT)); 79 timeout.setText(element.getPropertyAsString(TCPSampler.TIMEOUT)); 81 setNoDelay.setSelected(element.getPropertyAsBoolean(TCPSampler.NODELAY)); 82 requestData.setText(element.getPropertyAsString(TCPSampler.REQUEST)); 83 } 84 85 public TestElement createTestElement() 86 { 87 ConfigTestElement element = new ConfigTestElement(); 88 modifyTestElement(element); 89 return element; 90 } 91 92 96 public void modifyTestElement(TestElement element) 97 { 98 configureTestElement(element); 99 element.setProperty(TCPSampler.SERVER, server.getText()); 100 element.setProperty(TCPSampler.PORT, port.getText()); 101 element.setProperty(TCPSampler.NODELAY, JOrphanUtils.booleanToString(setNoDelay.isSelected())); 103 element.setProperty(TCPSampler.TIMEOUT, timeout.getText()); 104 element.setProperty(TCPSampler.REQUEST, requestData.getText()); 105 } 106 107 private JPanel createTimeoutPanel() 108 { 109 JLabel label = new JLabel (JMeterUtils.getResString("tcp_timeout")); 110 111 timeout = new JTextField (10); 112 timeout.setName(TIMEOUT); 113 label.setLabelFor(timeout); 114 115 JPanel timeoutPanel = new JPanel (new BorderLayout (5, 0)); 116 timeoutPanel.add(label, BorderLayout.WEST); 117 timeoutPanel.add(timeout, BorderLayout.CENTER); 118 return timeoutPanel; 119 } 120 121 private JPanel createNoDelayPanel() 122 { 123 JLabel label = new JLabel (JMeterUtils.getResString("tcp_nodelay")); 124 125 setNoDelay = new JCheckBox (); 126 setNoDelay.setName(NODELAY); 127 label.setLabelFor(setNoDelay); 128 129 JPanel nodelayPanel = new JPanel (new BorderLayout (5, 0)); 130 nodelayPanel.add(label, BorderLayout.WEST); 131 nodelayPanel.add(setNoDelay, BorderLayout.CENTER); 132 return nodelayPanel; 133 } 134 135 private JPanel createServerPanel() 136 { 137 JLabel label = new JLabel (JMeterUtils.getResString("server")); 138 139 server = new JTextField (10); 140 server.setName(SERVER); 141 label.setLabelFor(server); 142 143 JPanel serverPanel = new JPanel (new BorderLayout (5, 0)); 144 serverPanel.add(label, BorderLayout.WEST); 145 serverPanel.add(server, BorderLayout.CENTER); 146 return serverPanel; 147 } 148 149 private JPanel createPortPanel() 150 { 151 JLabel label = new JLabel (JMeterUtils.getResString("tcp_port")); 152 153 port = new JTextField (10); 154 port.setName(PORT); 155 label.setLabelFor(port); 156 157 JPanel PortPanel = new JPanel (new BorderLayout (5, 0)); 158 PortPanel.add(label, BorderLayout.WEST); 159 PortPanel.add(port, BorderLayout.CENTER); 160 return PortPanel; 161 } 162 163 private JPanel createRequestPanel() 164 { 165 JLabel reqLabel = new JLabel (JMeterUtils.getResString("tcp_request_data")); 166 requestData = new JTextArea (3,0); 167 requestData.setLineWrap(true); 168 requestData.setName(REQUEST); 169 reqLabel.setLabelFor(requestData); 170 171 JPanel reqDataPanel = new JPanel (new BorderLayout (5, 0)); 172 reqDataPanel.add(reqLabel, BorderLayout.WEST); 173 reqDataPanel.add(requestData, BorderLayout.CENTER); 174 return reqDataPanel; 175 176 } 177 192 private void init() 193 { 194 setLayout(new BorderLayout (0, 5)); 195 196 if (displayName) 197 { 198 setBorder(makeBorder()); 199 add(makeTitlePanel(), BorderLayout.NORTH); 200 } 201 202 VerticalPanel mainPanel = new VerticalPanel(); 203 mainPanel.add(createServerPanel()); 204 mainPanel.add(createPortPanel()); 205 mainPanel.add(createTimeoutPanel()); 206 mainPanel.add(createNoDelayPanel()); 207 mainPanel.add(createRequestPanel()); 208 209 add(mainPanel, BorderLayout.CENTER); 211 } 212 } 213 | Popular Tags |