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: DialogIPOptions.java,v 1.13 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 DialogIPOptions extends Dialog {
063: private static Log log = LogFactory.getLog(DialogIPOptions.class);
064:
065: private final GUI gui;
066:
067: private final int bglevel = 100;
068:
069: private String[] dscp = new String[] { "000000 - CS0 - default",
070: "000001", "000010", "000011", "000100", "000101", "000110",
071: "000111", "001000 - CS1", "001001", "001010 - AF11",
072: "001011", "001100 - AF12", "001101", "001110 - AF13",
073: "001111", "010000 - CS2", "010001", "010010 - AF21",
074: "010011", "010100 - AF22", "010101", "010110 - AF23",
075: "010111", "011000 - CS3", "011001", "011010 - AF31",
076: "011011", "011100 - AF32", "011101", "011110 - AF33",
077: "011111", "100000 - CS4", "100001", "100010 - AF41",
078: "100011", "100100 - AF42", "100101", "100110 - AF43",
079: "100111", "101000 - CS5", "101001", "101010", "101011",
080: "101100", "101101", "101110 - EF", "101111",
081: "110000 - CS6", "110001", "110010", "110011", "110100",
082: "110101", "110110", "110111", "111000 - CS7", "111001",
083: "111010", "111011", "111100", "111101", "111110", "111111", };
084:
085: private GridLayout layout = null;
086: private Composite groups_composite = null;
087: private Composite bottom_composite = null;
088: private RowLayout groups_composite_layout = null;
089: private RowLayout bottom_composite_layout = null;
090: private GridData groups_composite_grid_data = null;
091: private Group group_network_parameters = null;
092: private GridLayout group_network_parameters_layout = null;
093:
094: private int tos = 0;
095: private int port_src = 10000;
096: private int port_dst = 10000;
097: private int pdu_max_size = 1400;
098:
099: /**
100: * Constructor.
101: * @param gui current GUI instance.
102: * @param parent parent shell.
103: */
104: public DialogIPOptions(final GUI gui, final Shell parent) {
105: super (parent, 0);
106: this .gui = gui;
107: }
108:
109: /**
110: * Gets the IP type of service.
111: * @param none.
112: * @return int type of service.
113: */
114: public int getTOS() {
115: return tos;
116: }
117:
118: /**
119: * Gets the source port.
120: * @param none.
121: * @return int source port.
122: */
123: public int getPortSrc() {
124: return port_src;
125: }
126:
127: /**
128: * Gets the destination port.
129: * @return int destination port.
130: */
131: public int getPortDst() {
132: return port_dst;
133: }
134:
135: /**
136: * Gets the PDU maximum size.
137: * @param none.
138: * @return int PDU maximum size.
139: */
140: public int getPDUMaxSize() {
141: return pdu_max_size;
142: }
143:
144: /**
145: * Sets the type of service.
146: * @param tos type of service.
147: * @return void.
148: */
149: public void setTOS(final int tos) {
150: this .tos = tos;
151: }
152:
153: /**
154: * Sets the source port.
155: * @param port_src source port.
156: * @return void.
157: */
158: public void setPortSrc(final int port_src) {
159: this .port_src = port_src;
160: }
161:
162: /**
163: * Sets the destination port.
164: * @param port_dst destination port.
165: * @return void.
166: */
167: public void setPortDst(final int port_dst) {
168: this .port_dst = port_dst;
169: }
170:
171: /**
172: * Sets the PDU maximum size.
173: * @param pdu_max_size PDU maximum size.
174: * @return void.
175: */
176: public void setPDUMaxSize(final int pdu_max_size) {
177: this .pdu_max_size = pdu_max_size;
178: }
179:
180: /**
181: * Displays the dialog.
182: * @param none.
183: * @return void.
184: */
185: public void open() {
186: final Shell parent = getParent();
187: final Display display = parent.getDisplay();
188: final Shell shell = new Shell(parent, SWT.DIALOG_TRIM
189: | SWT.APPLICATION_MODAL);
190: shell
191: .setText(gui.getConfig().getString(
192: "gnetwatch_ip_options"));
193: // shell.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
194:
195: // Your code goes here (widget creation, set result, etc).
196: // Composite for groups at left
197: layout = new GridLayout();
198: layout.numColumns = 1;
199: layout.marginHeight = 2;
200: layout.marginWidth = 2;
201: layout.verticalSpacing = 1;
202: shell.setLayout(layout);
203:
204: groups_composite = new Composite(shell, SWT.FLAT);
205: groups_composite_layout = new RowLayout(SWT.VERTICAL);
206: groups_composite_layout.fill = true;
207: groups_composite_layout.marginTop = 0;
208: groups_composite_layout.marginBottom = 0;
209: groups_composite.setLayout(groups_composite_layout);
210: groups_composite_grid_data = new GridData(
211: GridData.FILL_VERTICAL);
212: groups_composite.setLayoutData(groups_composite_grid_data);
213:
214: // Group for network parameters
215:
216: group_network_parameters = new Group(groups_composite,
217: SWT.SHADOW_ETCHED_IN);
218: group_network_parameters_layout = new GridLayout();
219: group_network_parameters_layout.numColumns = 2;
220: group_network_parameters
221: .setLayout(group_network_parameters_layout);
222: group_network_parameters.setText(gui.getConfig().getString(
223: "network_parameters"));
224:
225: // RFC 3260
226: final Label label_tos = new Label(group_network_parameters,
227: SWT.SHADOW_IN);
228: label_tos.setText(gui.getConfig().getString("dscp_name"));
229: label_tos.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
230: final Combo ctos = new Combo(group_network_parameters,
231: SWT.SHADOW_IN | SWT.READ_ONLY);
232: ctos.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
233: for (final String tos : dscp)
234: ctos.add(tos);
235: ctos.setText(dscp[tos]);
236:
237: final Label label_packet_size = new Label(
238: group_network_parameters, SWT.SHADOW_IN);
239: label_packet_size.setText(gui.getConfig().getString(
240: "pdu_max_size"));
241: label_packet_size.setLayoutData(new GridData(
242: GridData.FILL_HORIZONTAL));
243: final Spinner packet_size = new Spinner(
244: group_network_parameters, SWT.WRAP);
245: packet_size
246: .setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
247: packet_size.setMinimum(0);
248: packet_size.setMaximum(10000);
249: packet_size.setSelection(this .pdu_max_size);
250:
251: final Label label_port_src = new Label(
252: group_network_parameters, SWT.SHADOW_IN);
253: label_port_src
254: .setText(gui.getConfig().getString("source_port"));
255: label_port_src.setLayoutData(new GridData(
256: GridData.FILL_HORIZONTAL));
257: final Spinner port_src = new Spinner(group_network_parameters,
258: SWT.WRAP);
259: port_src.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
260: port_src.setMinimum(1);
261: port_src.setMaximum(65535);
262: port_src.setSelection(this .port_src);
263:
264: final Label label_port_dst = new Label(
265: group_network_parameters, SWT.SHADOW_IN);
266: label_port_dst.setText(gui.getConfig().getString(
267: "destination_port"));
268: label_port_dst.setLayoutData(new GridData(
269: GridData.FILL_HORIZONTAL));
270: final Spinner port_dst = new Spinner(group_network_parameters,
271: SWT.WRAP);
272: port_dst.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
273: port_dst.setMinimum(0);
274: port_dst.setMaximum(65535);
275: port_dst.setSelection(this .port_dst);
276:
277: // bottom buttons
278:
279: bottom_composite = new Composite(shell, SWT.FLAT);
280: bottom_composite_layout = new RowLayout();
281: bottom_composite_layout.fill = true;
282: bottom_composite_layout.marginTop = 0;
283: bottom_composite_layout.marginBottom = 0;
284: bottom_composite_layout.wrap = false;
285: bottom_composite_layout.pack = false;
286: bottom_composite_layout.justify = true;
287: bottom_composite_layout.type = SWT.HORIZONTAL;
288: bottom_composite_layout.marginLeft = 5;
289: bottom_composite_layout.marginTop = 5;
290: bottom_composite_layout.marginRight = 5;
291: bottom_composite_layout.marginBottom = 5;
292: bottom_composite_layout.spacing = 0;
293: bottom_composite.setLayout(bottom_composite_layout);
294: final GridData bottom_composite_grid_data = new GridData(
295: GridData.FILL_HORIZONTAL);
296: bottom_composite.setLayoutData(bottom_composite_grid_data);
297:
298: final Button button_ok = new Button(bottom_composite, SWT.PUSH);
299: button_ok.setText("Ok");
300: final DialogIPOptions _this = this ;
301: button_ok.addSelectionListener(new SelectionListener() {
302: public void widgetDefaultSelected(SelectionEvent e) {
303: _this .tos = ctos.getSelectionIndex();
304: _this .port_src = port_src.getSelection();
305: _this .port_dst = port_dst.getSelection();
306: _this .pdu_max_size = packet_size.getSelection();
307:
308: shell.dispose();
309: }
310:
311: public void widgetSelected(SelectionEvent e) {
312: widgetDefaultSelected(e);
313: }
314: });
315:
316: final Button button_cancel = new Button(bottom_composite,
317: SWT.PUSH);
318: button_cancel.setText(gui.getConfig().getString("cancel"));
319: button_cancel.addSelectionListener(new SelectionListener() {
320: public void widgetDefaultSelected(SelectionEvent e) {
321: shell.dispose();
322: }
323:
324: public void widgetSelected(SelectionEvent e) {
325: widgetDefaultSelected(e);
326: }
327: });
328:
329: shell.pack(true);
330: shell.open();
331: while (!shell.isDisposed())
332: if (!display.readAndDispatch())
333: display.sleep();
334: }
335: }
|