001: /*
002: * GNetWatch
003: * Copyright 2006, 2007 Alexandre Fenyo
004: * gnetwatch@fenyo.net
005: *
006: * This file is part of GNetWatch.
007: *
008: * GNetWatch is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License as published by
010: * the Free Software Foundation; either version 2 of the License, or
011: * (at your option) any later version.
012: *
013: * GNetWatch is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with GNetWatch; if not, write to the Free Software
020: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
021: */
022:
023: package net.fenyo.gnetwatch.GUI;
024:
025: import java.net.UnknownHostException;
026:
027: import net.fenyo.gnetwatch.AlgorithmException;
028: import net.fenyo.gnetwatch.GenericTools;
029: import net.fenyo.gnetwatch.targets.TargetIPv4Subnet;
030:
031: import org.apache.commons.logging.Log;
032: import org.apache.commons.logging.LogFactory;
033:
034: import org.eclipse.swt.*;
035: import org.eclipse.swt.widgets.*;
036: import org.eclipse.swt.layout.*;
037: import org.eclipse.swt.custom.*;
038: import org.eclipse.swt.events.*;
039: import org.eclipse.swt.graphics.*;
040: import org.eclipse.swt.browser.*;
041:
042: /**
043: * This class manages the "IP options" dialog.
044: * @author Alexandre Fenyo
045: * @version $Id: DialogHTTPOptions.java,v 1.1 2007/03/07 22:08:27 fenyo Exp $
046: */
047:
048: /*
049: * port src
050: * port dst
051: * DSCP
052: * taille des paquets (cf. setSendBufferSize()) pdu max size
053: *
054: * proxy yes/no
055: * proxy host
056: * proxy port
057: * URL
058: * reconnect after each GET yes/no
059: * number of parallel sessions
060: */
061:
062: public class DialogHTTPOptions extends Dialog {
063: private static Log log = LogFactory.getLog(DialogHTTPOptions.class);
064:
065: private final GUI gui;
066:
067: private final int bglevel = 100;
068:
069: private GridLayout layout = null;
070: private Composite groups_composite = null;
071: private Composite bottom_composite = null;
072: private RowLayout groups_composite_layout = null;
073: private RowLayout bottom_composite_layout = null;
074: private GridData groups_composite_grid_data = null;
075: private Group group_network_parameters = null;
076: private GridLayout group_network_parameters_layout = null;
077:
078: Label label = null;
079: Label label_port = null;
080:
081: private boolean use_proxy = false;
082: private String proxy_host = "";
083: private int proxy_port = 3128;
084: private String URL = "";
085: // private boolean reconnect = false;
086: private int nparallel = 1;
087:
088: /**
089: * Constructor.
090: * @param gui current GUI instance.
091: * @param parent parent shell.
092: */
093: public DialogHTTPOptions(final GUI gui, final Shell parent) {
094: super (parent, 0);
095: this .gui = gui;
096: }
097:
098: /**
099: * Checks that we use a proxy.
100: * @param none.
101: * @return boolean true if using a proxy.
102: */
103: public boolean getUseProxy() {
104: return use_proxy;
105: }
106:
107: /**
108: * Gets the proxy name.
109: * @param none.
110: * @return String proxy name.
111: */
112: public String getProxyHost() {
113: return proxy_host;
114: }
115:
116: /**
117: * Gets the TCP proxy port.
118: * @param none.
119: * @return int TCP proxy port.
120: */
121: public int getProxyPort() {
122: return proxy_port;
123: }
124:
125: /**
126: * Gets the URL to connect to.
127: * @param none.
128: * @return String URL to connect to.
129: */
130: public String getURL() {
131: return URL;
132: }
133:
134: /**
135: * Checks that we should reconnect after each HTTP transaction.
136: * @param none.
137: * @return boolean true if we should reconnect after each HTTP transaction.
138: */
139: /*
140: public boolean getReconnect() {
141: return reconnect;
142: }
143: */
144:
145: /**
146: * Returns the number of concurrent HTTP sessions.
147: * @param none.
148: * @return int number of concurrent HTTP sessions.
149: */
150: public int getNParallel() {
151: return nparallel;
152: }
153:
154: /**
155: * Sets it to true to use a proxy.
156: * @param use_proxy true to use a proxy.
157: * @return void.
158: */
159: public void setUseProxy(final boolean use_proxy) {
160: this .use_proxy = use_proxy;
161: }
162:
163: /**
164: * Sets the proxy host name.
165: * @param proxy_host proxy host name.
166: * @return void.
167: */
168: public void setProxyHost(final String proxy_host) {
169: this .proxy_host = proxy_host;
170: }
171:
172: /**
173: * Sets the proxy TCP port.
174: * @param proxy_port proxy TCP port.
175: * @return void.
176: */
177: public void setProxyPort(final int proxy_port) {
178: this .proxy_port = proxy_port;
179: }
180:
181: /**
182: * Sets the destination URL.
183: * @param URL destination URL.
184: * @return void.
185: */
186: public void setURL(final String URL) {
187: this .URL = URL;
188: }
189:
190: /**
191: * Sets it to true to reconnect after each transaction.
192: * @param reconnect true to reconnect after each transaction.
193: * @return void.
194: */
195: /*
196: public void setReconnect(final boolean reconnect) {
197: this.reconnect = reconnect;
198: }
199: */
200:
201: /**
202: * Sets the number of concurrent HTTP transactions.
203: * @param nparallel number of concurrent transactions.
204: * @return void.
205: */
206: public void setNParallel(final int nparallel) {
207: this .nparallel = nparallel;
208: }
209:
210: /**
211: * Displays the dialog.
212: * @param none.
213: * @return void.
214: */
215: public void open() {
216: final Shell parent = getParent();
217: final Display display = parent.getDisplay();
218: final Shell shell = new Shell(parent, SWT.DIALOG_TRIM
219: | SWT.APPLICATION_MODAL);
220: shell
221: .setText(gui.getConfig().getString(
222: "gnetwatch_ip_options"));
223: // shell.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
224:
225: // Your code goes here (widget creation, set result, etc).
226: // Composite for groups at left
227: layout = new GridLayout();
228: layout.numColumns = 1;
229: layout.marginHeight = 2;
230: layout.marginWidth = 2;
231: layout.verticalSpacing = 1;
232: shell.setLayout(layout);
233:
234: groups_composite = new Composite(shell, SWT.FLAT);
235: groups_composite_layout = new RowLayout(SWT.VERTICAL);
236: groups_composite_layout.fill = true;
237: groups_composite_layout.marginTop = 0;
238: groups_composite_layout.marginBottom = 0;
239: groups_composite.setLayout(groups_composite_layout);
240: groups_composite_grid_data = new GridData(
241: GridData.FILL_VERTICAL);
242: groups_composite.setLayoutData(groups_composite_grid_data);
243:
244: // Group for HTTP parameters
245:
246: group_network_parameters = new Group(groups_composite,
247: SWT.SHADOW_ETCHED_IN);
248: group_network_parameters_layout = new GridLayout();
249: group_network_parameters_layout.numColumns = 2;
250: group_network_parameters
251: .setLayout(group_network_parameters_layout);
252: group_network_parameters.setText(gui.getConfig().getString(
253: "http_parameters"));
254:
255: final Label label2 = new Label(group_network_parameters,
256: SWT.SHADOW_IN);
257: label2.setText("URL");
258: label2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
259: final Text group_URL_value = new Text(group_network_parameters,
260: SWT.SINGLE);
261: group_URL_value
262: .setLayoutData(new GridData(
263: GridData.HORIZONTAL_ALIGN_END
264: | GridData.FILL_VERTICAL));
265: group_URL_value.setBackground(new Color(display, bglevel,
266: bglevel, bglevel));
267: group_URL_value.setForeground(display
268: .getSystemColor(SWT.COLOR_WHITE));
269: group_URL_value.setText(URL);
270: final GC gc = new GC(group_URL_value);
271: ((GridData) (group_URL_value.getLayoutData())).widthHint = gc
272: .stringExtent(" ").x;
273:
274: label = new Label(group_network_parameters, SWT.SHADOW_IN);
275: label.setText(gui.getConfig().getString("proxy_host"));
276: label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
277: final Text group_proxyhost_value = new Text(
278: group_network_parameters, SWT.SINGLE);
279: group_proxyhost_value
280: .setLayoutData(new GridData(
281: GridData.HORIZONTAL_ALIGN_END
282: | GridData.FILL_VERTICAL));
283: group_proxyhost_value.setBackground(new Color(display, bglevel,
284: bglevel, bglevel));
285: group_proxyhost_value.setForeground(display
286: .getSystemColor(SWT.COLOR_WHITE));
287: group_proxyhost_value.setText(proxy_host);
288: ((GridData) (group_proxyhost_value.getLayoutData())).widthHint = gc
289: .stringExtent(" ").x;
290:
291: label_port = new Label(group_network_parameters, SWT.SHADOW_IN);
292: label_port.setText(gui.getConfig().getString("proxy_port"));
293: label_port
294: .setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
295: final Spinner group_port_value = new Spinner(
296: group_network_parameters, SWT.WRAP);
297: group_port_value
298: .setLayoutData(new GridData(
299: GridData.HORIZONTAL_ALIGN_END
300: | GridData.FILL_VERTICAL));
301: group_port_value.setMinimum(1);
302: group_port_value.setMaximum(65535);
303: group_port_value.setSelection(this .proxy_port);
304: ((GridData) (group_port_value.getLayoutData())).widthHint = gc
305: .stringExtent(" ").x;
306:
307: final Label label_nparallel = new Label(
308: group_network_parameters, SWT.SHADOW_IN);
309: label_nparallel.setText(gui.getConfig().getString("nparallel"));
310: label_nparallel.setLayoutData(new GridData(
311: GridData.FILL_HORIZONTAL));
312: final Spinner group_parallel_value = new Spinner(
313: group_network_parameters, SWT.WRAP);
314: group_parallel_value
315: .setLayoutData(new GridData(
316: GridData.HORIZONTAL_ALIGN_END
317: | GridData.FILL_VERTICAL));
318: group_parallel_value.setMinimum(1);
319: group_parallel_value.setMaximum(1000);
320: group_parallel_value.setSelection(this .nparallel);
321: ((GridData) (group_parallel_value.getLayoutData())).widthHint = gc
322: .stringExtent(" ").x;
323:
324: final Label label_useproxy = new Label(
325: group_network_parameters, SWT.SHADOW_IN);
326: label_useproxy.setText(gui.getConfig().getString("use_proxy"));
327: label_useproxy.setLayoutData(new GridData(
328: GridData.FILL_HORIZONTAL));
329: final Button group_useproxy_value = new Button(
330: group_network_parameters, SWT.CHECK);
331: group_useproxy_value.setSelection(use_proxy);
332: group_useproxy_value
333: .setLayoutData(new GridData(
334: GridData.HORIZONTAL_ALIGN_END
335: | GridData.FILL_VERTICAL));
336:
337: /*
338: final Label label_reconnect = new Label(group_network_parameters, SWT.SHADOW_IN);
339: label_reconnect.setText(gui.getConfig().getString("reconnect"));
340: label_reconnect.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
341: final Button group_reconnect_value = new Button(group_network_parameters, SWT.CHECK);
342: group_reconnect_value.setSelection(reconnect);
343: group_reconnect_value.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL));
344: */
345:
346: // bottom buttons
347: bottom_composite = new Composite(shell, SWT.FLAT);
348: bottom_composite_layout = new RowLayout();
349: bottom_composite_layout.fill = true;
350: bottom_composite_layout.marginTop = 0;
351: bottom_composite_layout.marginBottom = 0;
352: bottom_composite_layout.wrap = false;
353: bottom_composite_layout.pack = false;
354: bottom_composite_layout.justify = true;
355: bottom_composite_layout.type = SWT.HORIZONTAL;
356: bottom_composite_layout.marginLeft = 5;
357: bottom_composite_layout.marginTop = 5;
358: bottom_composite_layout.marginRight = 5;
359: bottom_composite_layout.marginBottom = 5;
360: bottom_composite_layout.spacing = 0;
361: bottom_composite.setLayout(bottom_composite_layout);
362: final GridData bottom_composite_grid_data = new GridData(
363: GridData.FILL_HORIZONTAL);
364: bottom_composite.setLayoutData(bottom_composite_grid_data);
365:
366: final Button button_ok = new Button(bottom_composite, SWT.PUSH);
367: button_ok.setText("Ok");
368: final DialogHTTPOptions _this = this ;
369: button_ok.addSelectionListener(new SelectionListener() {
370: public void widgetDefaultSelected(SelectionEvent e) {
371: _this .use_proxy = group_useproxy_value.getSelection();
372: _this .proxy_host = group_proxyhost_value.getText();
373: _this .proxy_port = group_port_value.getSelection();
374: _this .URL = group_URL_value.getText();
375: _this .nparallel = group_parallel_value.getSelection();
376: _this .use_proxy = group_useproxy_value.getSelection();
377: // _this.reconnect = group_reconnect_value.getSelection();
378:
379: shell.dispose();
380: }
381:
382: public void widgetSelected(SelectionEvent e) {
383: widgetDefaultSelected(e);
384: }
385: });
386:
387: final Button button_cancel = new Button(bottom_composite,
388: SWT.PUSH);
389: button_cancel.setText(gui.getConfig().getString("cancel"));
390: button_cancel.addSelectionListener(new SelectionListener() {
391: public void widgetDefaultSelected(SelectionEvent e) {
392: shell.dispose();
393: }
394:
395: public void widgetSelected(SelectionEvent e) {
396: widgetDefaultSelected(e);
397: }
398: });
399:
400: group_useproxy_value
401: .addSelectionListener(new SelectionListener() {
402: public void widgetDefaultSelected(
403: final SelectionEvent e) {
404: widgetSelected(e);
405: }
406:
407: public void widgetSelected(final SelectionEvent e) {
408: group_proxyhost_value
409: .setEnabled(group_useproxy_value
410: .getSelection());
411: label.setEnabled(group_useproxy_value
412: .getSelection());
413: label_port.setEnabled(group_useproxy_value
414: .getSelection());
415: group_port_value
416: .setEnabled(group_useproxy_value
417: .getSelection());
418: }
419: });
420:
421: group_proxyhost_value.setEnabled(getUseProxy());
422: label.setEnabled(getUseProxy());
423: label_port.setEnabled(getUseProxy());
424: group_port_value.setEnabled(getUseProxy());
425:
426: shell.pack(true);
427: shell.open();
428: while (!shell.isDisposed())
429: if (!display.readAndDispatch())
430: display.sleep();
431: }
432: }
|