001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.protocol.tcp.config.gui;
020:
021: import java.awt.BorderLayout;
022:
023: import javax.swing.JCheckBox;
024: import javax.swing.JLabel;
025: import javax.swing.JPanel;
026: import javax.swing.JTextArea;
027: import javax.swing.JTextField;
028:
029: import org.apache.jmeter.config.ConfigTestElement;
030: import org.apache.jmeter.config.gui.AbstractConfigGui;
031: import org.apache.jmeter.gui.util.VerticalPanel;
032: import org.apache.jmeter.protocol.tcp.sampler.TCPSampler;
033: import org.apache.jmeter.testelement.TestElement;
034: import org.apache.jmeter.util.JMeterUtils;
035:
036: public class TCPConfigGui extends AbstractConfigGui {
037: private final static String SERVER = "server"; //$NON-NLS-1$
038:
039: private final static String RE_USE_CONNECTION = "reUseConnection"; //$NON-NLS-1$
040:
041: private final static String PORT = "port"; //$NON-NLS-1$
042:
043: // NOTUSED yet private final static String FILENAME = "filename";
044: // //$NON-NLS-1$
045: private final static String TIMEOUT = "timeout"; //$NON-NLS-1$
046:
047: private final static String NODELAY = "nodelay"; //$NON-NLS-1$
048:
049: private final static String REQUEST = "request"; //$NON-NLS-1$
050:
051: private JTextField server;
052:
053: private JCheckBox reUseConnection;
054:
055: private JTextField port;
056:
057: // NOTUSED yet private JTextField filename;
058: private JTextField timeout;
059:
060: private JCheckBox setNoDelay;
061:
062: private JTextArea requestData;
063:
064: private boolean displayName = true;
065:
066: public TCPConfigGui() {
067: this (true);
068: }
069:
070: public TCPConfigGui(boolean displayName) {
071: this .displayName = displayName;
072: init();
073: }
074:
075: public String getLabelResource() {
076: return "tcp_config_title"; // $NON-NLS-1$
077: }
078:
079: public void configure(TestElement element) {
080: super .configure(element);
081: server.setText(element.getPropertyAsString(TCPSampler.SERVER));
082: // Default to original behaviour, i.e. re-use connection
083: reUseConnection.setSelected(element.getPropertyAsBoolean(
084: TCPSampler.RE_USE_CONNECTION, true));
085: port.setText(element.getPropertyAsString(TCPSampler.PORT));
086: // filename.setText(element.getPropertyAsString(TCPSampler.FILENAME));
087: timeout
088: .setText(element
089: .getPropertyAsString(TCPSampler.TIMEOUT));
090: setNoDelay.setSelected(element
091: .getPropertyAsBoolean(TCPSampler.NODELAY));
092: requestData.setText(element
093: .getPropertyAsString(TCPSampler.REQUEST));
094: }
095:
096: public TestElement createTestElement() {
097: ConfigTestElement element = new ConfigTestElement();
098: modifyTestElement(element);
099: return element;
100: }
101:
102: /**
103: * Modifies a given TestElement to mirror the data in the gui components.
104: *
105: * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
106: */
107: public void modifyTestElement(TestElement element) {
108: configureTestElement(element);
109: element.setProperty(TCPSampler.SERVER, server.getText());
110: element.setProperty(TCPSampler.RE_USE_CONNECTION,
111: reUseConnection.isSelected());
112: element.setProperty(TCPSampler.PORT, port.getText());
113: // element.setProperty(TCPSampler.FILENAME, filename.getText());
114: element
115: .setProperty(TCPSampler.NODELAY, setNoDelay
116: .isSelected());
117: element.setProperty(TCPSampler.TIMEOUT, timeout.getText());
118: element.setProperty(TCPSampler.REQUEST, requestData.getText());
119: }
120:
121: /**
122: * Implements JMeterGUIComponent.clearGui
123: */
124: public void clearGui() {
125: super .clearGui();
126:
127: server.setText(""); //$NON-NLS-1$
128: port.setText(""); //$NON-NLS-1$
129: timeout.setText(""); //$NON-NLS-1$
130: requestData.setText(""); //$NON-NLS-1$
131: reUseConnection.setSelected(true);
132: setNoDelay.setSelected(false);
133: }
134:
135: private JPanel createTimeoutPanel() {
136: JLabel label = new JLabel(JMeterUtils
137: .getResString("tcp_timeout")); // $NON-NLS-1$
138:
139: timeout = new JTextField(10);
140: timeout.setName(TIMEOUT);
141: label.setLabelFor(timeout);
142:
143: JPanel timeoutPanel = new JPanel(new BorderLayout(5, 0));
144: timeoutPanel.add(label, BorderLayout.WEST);
145: timeoutPanel.add(timeout, BorderLayout.CENTER);
146: return timeoutPanel;
147: }
148:
149: private JPanel createNoDelayPanel() {
150: JLabel label = new JLabel(JMeterUtils
151: .getResString("tcp_nodelay")); // $NON-NLS-1$
152:
153: setNoDelay = new JCheckBox();
154: setNoDelay.setName(NODELAY);
155: label.setLabelFor(setNoDelay);
156:
157: JPanel nodelayPanel = new JPanel(new BorderLayout(5, 0));
158: nodelayPanel.add(label, BorderLayout.WEST);
159: nodelayPanel.add(setNoDelay, BorderLayout.CENTER);
160: return nodelayPanel;
161: }
162:
163: private JPanel createServerPanel() {
164: JLabel label = new JLabel(JMeterUtils.getResString("server")); // $NON-NLS-1$
165:
166: server = new JTextField(10);
167: server.setName(SERVER);
168: label.setLabelFor(server);
169:
170: JPanel serverPanel = new JPanel(new BorderLayout(5, 0));
171: serverPanel.add(label, BorderLayout.WEST);
172: serverPanel.add(server, BorderLayout.CENTER);
173: return serverPanel;
174: }
175:
176: private JPanel createClosePortPanel() {
177: JLabel label = new JLabel(JMeterUtils
178: .getResString("reuseconnection")); //$NON-NLS-1$
179:
180: reUseConnection = new JCheckBox("", true);
181: reUseConnection.setName(RE_USE_CONNECTION);
182: label.setLabelFor(reUseConnection);
183:
184: JPanel closePortPanel = new JPanel(new BorderLayout(5, 0));
185: closePortPanel.add(label, BorderLayout.WEST);
186: closePortPanel.add(reUseConnection, BorderLayout.CENTER);
187: return closePortPanel;
188: }
189:
190: private JPanel createPortPanel() {
191: JLabel label = new JLabel(JMeterUtils.getResString("tcp_port")); //$NON-NLS-1$
192:
193: port = new JTextField(10);
194: port.setName(PORT);
195: label.setLabelFor(port);
196:
197: JPanel PortPanel = new JPanel(new BorderLayout(5, 0));
198: PortPanel.add(label, BorderLayout.WEST);
199: PortPanel.add(port, BorderLayout.CENTER);
200: return PortPanel;
201: }
202:
203: private JPanel createRequestPanel() {
204: JLabel reqLabel = new JLabel(JMeterUtils
205: .getResString("tcp_request_data")); // $NON-NLS-1$
206: requestData = new JTextArea(3, 0);
207: requestData.setLineWrap(true);
208: requestData.setName(REQUEST);
209: reqLabel.setLabelFor(requestData);
210:
211: JPanel reqDataPanel = new JPanel(new BorderLayout(5, 0));
212: reqDataPanel.add(reqLabel, BorderLayout.WEST);
213: reqDataPanel.add(requestData, BorderLayout.CENTER);
214: return reqDataPanel;
215:
216: }
217:
218: // private JPanel createFilenamePanel()//Not used yet
219: // {
220: //
221: // JLabel label = new JLabel(JMeterUtils.getResString("file_to_retrieve")); // $NON-NLS-1$
222: //
223: // filename = new JTextField(10);
224: // filename.setName(FILENAME);
225: // label.setLabelFor(filename);
226: //
227: // JPanel filenamePanel = new JPanel(new BorderLayout(5, 0));
228: // filenamePanel.add(label, BorderLayout.WEST);
229: // filenamePanel.add(filename, BorderLayout.CENTER);
230: // return filenamePanel;
231: // }
232:
233: private void init() {
234: setLayout(new BorderLayout(0, 5));
235:
236: if (displayName) {
237: setBorder(makeBorder());
238: add(makeTitlePanel(), BorderLayout.NORTH);
239: }
240:
241: VerticalPanel mainPanel = new VerticalPanel();
242: mainPanel.add(createServerPanel());
243: mainPanel.add(createClosePortPanel());
244: mainPanel.add(createPortPanel());
245: mainPanel.add(createTimeoutPanel());
246: mainPanel.add(createNoDelayPanel());
247: mainPanel.add(createRequestPanel());
248:
249: // mainPanel.add(createFilenamePanel());
250: add(mainPanel, BorderLayout.CENTER);
251: }
252: }
|