KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > tcp > config > gui > TCPConfigGui


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/config/gui/TCPConfigGui.java,v 1.4.2.3 2004/06/12 20:30:03 sebb Exp $
2
/*
3  * Copyright 2003-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.protocol.tcp.config.gui;
20 import java.awt.BorderLayout JavaDoc;
21
22 import javax.swing.JCheckBox JavaDoc;
23 import javax.swing.JLabel JavaDoc;
24 import javax.swing.JPanel JavaDoc;
25 import javax.swing.JTextArea JavaDoc;
26 import javax.swing.JTextField JavaDoc;
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 /**
37  * @version $Revision: 1.4.2.3 $ $Date: 2004/06/12 20:30:03 $
38  */

39 public class TCPConfigGui extends AbstractConfigGui
40 {
41     private final static String JavaDoc SERVER = "server"; //$NON-NLS-1$
42
private final static String JavaDoc PORT = "port"; //$NON-NLS-1$
43
private final static String JavaDoc FILENAME = "filename"; //$NON-NLS-1$
44
private final static String JavaDoc TIMEOUT = "timeout"; //$NON-NLS-1$
45
private final static String JavaDoc NODELAY = "nodelay"; //$NON-NLS-1$
46
private final static String JavaDoc REQUEST = "request"; //$NON-NLS-1$
47

48     private JTextField JavaDoc server;
49     private JTextField JavaDoc port;
50     //NOTUSED yet private JTextField filename;
51
private JTextField JavaDoc timeout;
52     private JCheckBox JavaDoc setNoDelay;
53
54     private JTextArea JavaDoc 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 JavaDoc 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         //filename.setText(element.getPropertyAsString(TCPSampler.FILENAME));
80
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     /**
93      * Modifies a given TestElement to mirror the data in the gui components.
94      * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
95      */

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.FILENAME, filename.getText());
102
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 JavaDoc createTimeoutPanel()
108     {
109         JLabel JavaDoc label = new JLabel JavaDoc(JMeterUtils.getResString("tcp_timeout"));
110
111         timeout = new JTextField JavaDoc(10);
112         timeout.setName(TIMEOUT);
113         label.setLabelFor(timeout);
114
115         JPanel JavaDoc timeoutPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
116         timeoutPanel.add(label, BorderLayout.WEST);
117         timeoutPanel.add(timeout, BorderLayout.CENTER);
118         return timeoutPanel;
119     }
120
121     private JPanel JavaDoc createNoDelayPanel()
122     {
123         JLabel JavaDoc label = new JLabel JavaDoc(JMeterUtils.getResString("tcp_nodelay"));
124
125         setNoDelay = new JCheckBox JavaDoc();
126         setNoDelay.setName(NODELAY);
127         label.setLabelFor(setNoDelay);
128
129         JPanel JavaDoc nodelayPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
130         nodelayPanel.add(label, BorderLayout.WEST);
131         nodelayPanel.add(setNoDelay, BorderLayout.CENTER);
132         return nodelayPanel;
133     }
134
135     private JPanel JavaDoc createServerPanel()
136     {
137         JLabel JavaDoc label = new JLabel JavaDoc(JMeterUtils.getResString("server"));
138
139         server = new JTextField JavaDoc(10);
140         server.setName(SERVER);
141         label.setLabelFor(server);
142
143         JPanel JavaDoc serverPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
144         serverPanel.add(label, BorderLayout.WEST);
145         serverPanel.add(server, BorderLayout.CENTER);
146         return serverPanel;
147     }
148
149     private JPanel JavaDoc createPortPanel()
150     {
151         JLabel JavaDoc label = new JLabel JavaDoc(JMeterUtils.getResString("tcp_port"));
152
153         port = new JTextField JavaDoc(10);
154         port.setName(PORT);
155         label.setLabelFor(port);
156
157         JPanel JavaDoc PortPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
158         PortPanel.add(label, BorderLayout.WEST);
159         PortPanel.add(port, BorderLayout.CENTER);
160         return PortPanel;
161     }
162
163     private JPanel JavaDoc createRequestPanel()
164     {
165         JLabel JavaDoc reqLabel = new JLabel JavaDoc(JMeterUtils.getResString("tcp_request_data"));
166         requestData = new JTextArea JavaDoc(3,0);
167         requestData.setLineWrap(true);
168         requestData.setName(REQUEST);
169         reqLabel.setLabelFor(requestData);
170     
171         JPanel JavaDoc reqDataPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
172         reqDataPanel.add(reqLabel, BorderLayout.WEST);
173         reqDataPanel.add(requestData, BorderLayout.CENTER);
174         return reqDataPanel;
175
176     }
177 // private JPanel createFilenamePanel()//Not used yet
178
// {
179
//
180
// JLabel label = new JLabel(JMeterUtils.getResString("file_to_retrieve"));
181
//
182
// filename = new JTextField(10);
183
// filename.setName(FILENAME);
184
// label.setLabelFor(filename);
185
//
186
// JPanel filenamePanel = new JPanel(new BorderLayout(5, 0));
187
// filenamePanel.add(label, BorderLayout.WEST);
188
// filenamePanel.add(filename, BorderLayout.CENTER);
189
// return filenamePanel;
190
// }
191

192     private void init()
193     {
194         setLayout(new BorderLayout JavaDoc(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         //mainPanel.add(createFilenamePanel());
210
add(mainPanel, BorderLayout.CENTER);
211     }
212 }
213
Popular Tags