KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > fenyo > gnetwatch > GUI > DialogHTTPOptions


1
2 /*
3  * GNetWatch
4  * Copyright 2006, 2007 Alexandre Fenyo
5  * gnetwatch@fenyo.net
6  *
7  * This file is part of GNetWatch.
8  *
9  * GNetWatch is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * GNetWatch is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with GNetWatch; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22  */

23
24 package net.fenyo.gnetwatch.GUI;
25
26 import java.net.UnknownHostException JavaDoc;
27
28 import net.fenyo.gnetwatch.AlgorithmException;
29 import net.fenyo.gnetwatch.GenericTools;
30 import net.fenyo.gnetwatch.targets.TargetIPv4Subnet;
31
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34
35 import org.eclipse.swt.*;
36 import org.eclipse.swt.widgets.*;
37 import org.eclipse.swt.layout.*;
38 import org.eclipse.swt.custom.*;
39 import org.eclipse.swt.events.*;
40 import org.eclipse.swt.graphics.*;
41 import org.eclipse.swt.browser.*;
42
43 /**
44  * This class manages the "IP options" dialog.
45  * @author Alexandre Fenyo
46  * @version $Id: DialogHTTPOptions.java,v 1.1 2007/03/07 22:08:27 fenyo Exp $
47  */

48
49 /*
50  * port src
51  * port dst
52  * DSCP
53  * taille des paquets (cf. setSendBufferSize()) pdu max size
54  *
55  * proxy yes/no
56  * proxy host
57  * proxy port
58  * URL
59  * reconnect after each GET yes/no
60  * number of parallel sessions
61  */

62
63 public class DialogHTTPOptions extends Dialog {
64   private static Log log = LogFactory.getLog(DialogHTTPOptions.class);
65
66   private final GUI gui;
67
68   private final int bglevel = 100;
69
70   private GridLayout layout = null;
71   private Composite groups_composite = null;
72   private Composite bottom_composite = null;
73   private RowLayout groups_composite_layout = null;
74   private RowLayout bottom_composite_layout = null;
75   private GridData groups_composite_grid_data = null;
76   private Group group_network_parameters = null;
77   private GridLayout group_network_parameters_layout = null;
78
79   Label label = null;
80   Label label_port = null;
81
82   private boolean use_proxy = false;
83   private String JavaDoc proxy_host = "";
84   private int proxy_port = 3128;
85   private String JavaDoc URL = "";
86   // private boolean reconnect = false;
87
private int nparallel = 1;
88
89   /**
90    * Constructor.
91    * @param gui current GUI instance.
92    * @param parent parent shell.
93    */

94   public DialogHTTPOptions(final GUI gui, final Shell parent) {
95     super(parent, 0);
96     this.gui = gui;
97   }
98
99   /**
100    * Checks that we use a proxy.
101    * @param none.
102    * @return boolean true if using a proxy.
103    */

104   public boolean getUseProxy() {
105     return use_proxy;
106   }
107
108   /**
109    * Gets the proxy name.
110    * @param none.
111    * @return String proxy name.
112    */

113   public String JavaDoc getProxyHost() {
114     return proxy_host;
115   }
116
117   /**
118    * Gets the TCP proxy port.
119    * @param none.
120    * @return int TCP proxy port.
121    */

122   public int getProxyPort() {
123     return proxy_port;
124   }
125
126   /**
127    * Gets the URL to connect to.
128    * @param none.
129    * @return String URL to connect to.
130    */

131   public String JavaDoc getURL() {
132     return URL;
133   }
134
135   /**
136    * Checks that we should reconnect after each HTTP transaction.
137    * @param none.
138    * @return boolean true if we should reconnect after each HTTP transaction.
139    */

140 /*
141   public boolean getReconnect() {
142     return reconnect;
143   }
144 */

145
146   /**
147    * Returns the number of concurrent HTTP sessions.
148    * @param none.
149    * @return int number of concurrent HTTP sessions.
150    */

151   public int getNParallel() {
152     return nparallel;
153   }
154
155   /**
156    * Sets it to true to use a proxy.
157    * @param use_proxy true to use a proxy.
158    * @return void.
159    */

160   public void setUseProxy(final boolean use_proxy) {
161     this.use_proxy = use_proxy;
162   }
163
164   /**
165    * Sets the proxy host name.
166    * @param proxy_host proxy host name.
167    * @return void.
168    */

169   public void setProxyHost(final String JavaDoc proxy_host) {
170     this.proxy_host = proxy_host;
171   }
172
173   /**
174    * Sets the proxy TCP port.
175    * @param proxy_port proxy TCP port.
176    * @return void.
177    */

178   public void setProxyPort(final int proxy_port) {
179     this.proxy_port = proxy_port;
180   }
181
182   /**
183    * Sets the destination URL.
184    * @param URL destination URL.
185    * @return void.
186    */

187   public void setURL(final String JavaDoc URL) {
188     this.URL = URL;
189   }
190
191   /**
192    * Sets it to true to reconnect after each transaction.
193    * @param reconnect true to reconnect after each transaction.
194    * @return void.
195    */

196 /*
197   public void setReconnect(final boolean reconnect) {
198     this.reconnect = reconnect;
199   }
200 */

201
202   /**
203    * Sets the number of concurrent HTTP transactions.
204    * @param nparallel number of concurrent transactions.
205    * @return void.
206    */

207   public void setNParallel(final int nparallel) {
208     this.nparallel = nparallel;
209   }
210
211   /**
212    * Displays the dialog.
213    * @param none.
214    * @return void.
215    */

216   public void open() {
217     final Shell parent = getParent();
218     final Display display = parent.getDisplay();
219     final Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
220     shell.setText(gui.getConfig().getString("gnetwatch_ip_options"));
221 // shell.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
222

223     // Your code goes here (widget creation, set result, etc).
224
// Composite for groups at left
225
layout = new GridLayout();
226     layout.numColumns = 1;
227     layout.marginHeight = 2;
228     layout.marginWidth = 2;
229     layout.verticalSpacing = 1;
230     shell.setLayout(layout);
231
232     groups_composite = new Composite(shell, SWT.FLAT);
233     groups_composite_layout = new RowLayout(SWT.VERTICAL);
234     groups_composite_layout.fill = true;
235     groups_composite_layout.marginTop = 0;
236     groups_composite_layout.marginBottom = 0;
237     groups_composite.setLayout(groups_composite_layout);
238     groups_composite_grid_data = new GridData(GridData.FILL_VERTICAL);
239     groups_composite.setLayoutData(groups_composite_grid_data);
240
241     // Group for HTTP parameters
242

243     group_network_parameters = new Group(groups_composite, SWT.SHADOW_ETCHED_IN);
244     group_network_parameters_layout = new GridLayout();
245     group_network_parameters_layout.numColumns = 2;
246     group_network_parameters.setLayout(group_network_parameters_layout);
247     group_network_parameters.setText(gui.getConfig().getString("http_parameters"));
248
249     final Label label2 = new Label(group_network_parameters, SWT.SHADOW_IN);
250     label2.setText("URL");
251     label2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
252     final Text group_URL_value = new Text(group_network_parameters, SWT.SINGLE);
253     group_URL_value.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL));
254     group_URL_value.setBackground(new Color(display, bglevel, bglevel, bglevel));
255     group_URL_value.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
256     group_URL_value.setText(URL);
257     final GC gc = new GC(group_URL_value);
258     ((GridData) (group_URL_value.getLayoutData())).widthHint = gc.stringExtent(" ").x;
259
260     label = new Label(group_network_parameters, SWT.SHADOW_IN);
261     label.setText(gui.getConfig().getString("proxy_host"));
262     label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
263     final Text group_proxyhost_value = new Text(group_network_parameters, SWT.SINGLE);
264     group_proxyhost_value.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL));
265     group_proxyhost_value.setBackground(new Color(display, bglevel, bglevel, bglevel));
266     group_proxyhost_value.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
267     group_proxyhost_value.setText(proxy_host);
268     ((GridData) (group_proxyhost_value.getLayoutData())).widthHint = gc.stringExtent(" ").x;
269
270     label_port = new Label(group_network_parameters, SWT.SHADOW_IN);
271     label_port.setText(gui.getConfig().getString("proxy_port"));
272     label_port.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
273     final Spinner group_port_value = new Spinner(group_network_parameters, SWT.WRAP);
274     group_port_value.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL));
275     group_port_value.setMinimum(1);
276     group_port_value.setMaximum(65535);
277     group_port_value.setSelection(this.proxy_port);
278     ((GridData) (group_port_value.getLayoutData())).widthHint = gc.stringExtent(" ").x;
279
280     final Label label_nparallel = new Label(group_network_parameters, SWT.SHADOW_IN);
281     label_nparallel.setText(gui.getConfig().getString("nparallel"));
282     label_nparallel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
283     final Spinner group_parallel_value = new Spinner(group_network_parameters, SWT.WRAP);
284     group_parallel_value.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL));
285     group_parallel_value.setMinimum(1);
286     group_parallel_value.setMaximum(1000);
287     group_parallel_value.setSelection(this.nparallel);
288     ((GridData) (group_parallel_value.getLayoutData())).widthHint = gc.stringExtent(" ").x;
289
290     final Label label_useproxy = new Label(group_network_parameters, SWT.SHADOW_IN);
291     label_useproxy.setText(gui.getConfig().getString("use_proxy"));
292     label_useproxy.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
293     final Button group_useproxy_value = new Button(group_network_parameters, SWT.CHECK);
294     group_useproxy_value.setSelection(use_proxy);
295     group_useproxy_value.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL));
296
297     /*
298     final Label label_reconnect = new Label(group_network_parameters, SWT.SHADOW_IN);
299     label_reconnect.setText(gui.getConfig().getString("reconnect"));
300     label_reconnect.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
301     final Button group_reconnect_value = new Button(group_network_parameters, SWT.CHECK);
302     group_reconnect_value.setSelection(reconnect);
303     group_reconnect_value.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL));
304     */

305
306     // bottom buttons
307

308     bottom_composite = new Composite(shell, SWT.FLAT);
309     bottom_composite_layout = new RowLayout();
310     bottom_composite_layout.fill = true;
311     bottom_composite_layout.marginTop = 0;
312     bottom_composite_layout.marginBottom = 0;
313     bottom_composite_layout.wrap = false;
314     bottom_composite_layout.pack = false;
315     bottom_composite_layout.justify = true;
316     bottom_composite_layout.type = SWT.HORIZONTAL;
317     bottom_composite_layout.marginLeft = 5;
318     bottom_composite_layout.marginTop = 5;
319     bottom_composite_layout.marginRight = 5;
320     bottom_composite_layout.marginBottom = 5;
321     bottom_composite_layout.spacing = 0;
322     bottom_composite.setLayout(bottom_composite_layout);
323     final GridData bottom_composite_grid_data = new GridData(GridData.FILL_HORIZONTAL);
324     bottom_composite.setLayoutData(bottom_composite_grid_data);
325
326     final Button button_ok = new Button(bottom_composite, SWT.PUSH);
327     button_ok.setText("Ok");
328     final DialogHTTPOptions _this = this;
329     button_ok.addSelectionListener(new SelectionListener() {
330       public void widgetDefaultSelected(SelectionEvent e) {
331         _this.use_proxy = group_useproxy_value.getSelection();
332         _this.proxy_host = group_proxyhost_value.getText();
333         _this.proxy_port = group_port_value.getSelection();
334         _this.URL = group_URL_value.getText();
335         _this.nparallel = group_parallel_value.getSelection();
336         _this.use_proxy = group_useproxy_value.getSelection();
337         // _this.reconnect = group_reconnect_value.getSelection();
338

339         shell.dispose();
340       }
341
342       public void widgetSelected(SelectionEvent e) {
343         widgetDefaultSelected(e);
344       }
345     });
346
347
348     final Button button_cancel = new Button(bottom_composite, SWT.PUSH);
349     button_cancel.setText(gui.getConfig().getString("cancel"));
350     button_cancel.addSelectionListener(new SelectionListener() {
351       public void widgetDefaultSelected(SelectionEvent e) {
352         shell.dispose();
353       }
354
355       public void widgetSelected(SelectionEvent e) {
356         widgetDefaultSelected(e);
357       }
358     });
359
360     group_useproxy_value.addSelectionListener(new SelectionListener() {
361       public void widgetDefaultSelected(final SelectionEvent e) {
362         widgetSelected(e);
363       }
364       public void widgetSelected(final SelectionEvent e) {
365         group_proxyhost_value.setEnabled(group_useproxy_value.getSelection());
366         label.setEnabled(group_useproxy_value.getSelection());
367         label_port.setEnabled(group_useproxy_value.getSelection());
368         group_port_value.setEnabled(group_useproxy_value.getSelection());
369       }
370     });
371
372     group_proxyhost_value.setEnabled(getUseProxy());
373     label.setEnabled(getUseProxy());
374     label_port.setEnabled(getUseProxy());
375     group_port_value.setEnabled(getUseProxy());
376
377     shell.pack(true);
378     shell.open();
379     while (!shell.isDisposed())
380       if (!display.readAndDispatch()) display.sleep();
381   }
382 }
383
Popular Tags