KickJava   Java API By Example, From Geeks To Geeks.

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


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: DialogIPOptions.java,v 1.13 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 DialogIPOptions extends Dialog {
64   private static Log log = LogFactory.getLog(DialogIPOptions.class);
65
66   private final GUI gui;
67
68   private final int bglevel = 100;
69
70   private String JavaDoc [] dscp = new String JavaDoc [] {
71       "000000 - CS0 - default",
72       "000001",
73       "000010",
74       "000011",
75       "000100",
76       "000101",
77       "000110",
78       "000111",
79       "001000 - CS1",
80       "001001",
81       "001010 - AF11",
82       "001011",
83       "001100 - AF12",
84       "001101",
85       "001110 - AF13",
86       "001111",
87       "010000 - CS2",
88       "010001",
89       "010010 - AF21",
90       "010011",
91       "010100 - AF22",
92       "010101",
93       "010110 - AF23",
94       "010111",
95       "011000 - CS3",
96       "011001",
97       "011010 - AF31",
98       "011011",
99       "011100 - AF32",
100       "011101",
101       "011110 - AF33",
102       "011111",
103       "100000 - CS4",
104       "100001",
105       "100010 - AF41",
106       "100011",
107       "100100 - AF42",
108       "100101",
109       "100110 - AF43",
110       "100111",
111       "101000 - CS5",
112       "101001",
113       "101010",
114       "101011",
115       "101100",
116       "101101",
117       "101110 - EF",
118       "101111",
119       "110000 - CS6",
120       "110001",
121       "110010",
122       "110011",
123       "110100",
124       "110101",
125       "110110",
126       "110111",
127       "111000 - CS7",
128       "111001",
129       "111010",
130       "111011",
131       "111100",
132       "111101",
133       "111110",
134       "111111",
135   };
136
137   private GridLayout layout = null;
138   private Composite groups_composite = null;
139   private Composite bottom_composite = null;
140   private RowLayout groups_composite_layout = null;
141   private RowLayout bottom_composite_layout = null;
142   private GridData groups_composite_grid_data = null;
143   private Group group_network_parameters = null;
144   private GridLayout group_network_parameters_layout = null;
145
146   private int tos = 0;
147   private int port_src = 10000;
148   private int port_dst = 10000;
149   private int pdu_max_size = 1400;
150
151   /**
152    * Constructor.
153    * @param gui current GUI instance.
154    * @param parent parent shell.
155    */

156   public DialogIPOptions(final GUI gui, final Shell parent) {
157     super(parent, 0);
158     this.gui = gui;
159   }
160
161   /**
162    * Gets the IP type of service.
163    * @param none.
164    * @return int type of service.
165    */

166   public int getTOS() {
167     return tos;
168   }
169
170   /**
171    * Gets the source port.
172    * @param none.
173    * @return int source port.
174    */

175   public int getPortSrc() {
176     return port_src;
177   }
178
179   /**
180    * Gets the destination port.
181    * @return int destination port.
182    */

183   public int getPortDst() {
184     return port_dst;
185   }
186
187   /**
188    * Gets the PDU maximum size.
189    * @param none.
190    * @return int PDU maximum size.
191    */

192   public int getPDUMaxSize() {
193     return pdu_max_size;
194   }
195
196   /**
197    * Sets the type of service.
198    * @param tos type of service.
199    * @return void.
200    */

201   public void setTOS(final int tos) {
202     this.tos = tos;
203   }
204
205   /**
206    * Sets the source port.
207    * @param port_src source port.
208    * @return void.
209    */

210   public void setPortSrc(final int port_src) {
211     this.port_src = port_src;
212   }
213
214   /**
215    * Sets the destination port.
216    * @param port_dst destination port.
217    * @return void.
218    */

219   public void setPortDst(final int port_dst) {
220     this.port_dst = port_dst;
221   }
222
223   /**
224    * Sets the PDU maximum size.
225    * @param pdu_max_size PDU maximum size.
226    * @return void.
227    */

228   public void setPDUMaxSize(final int pdu_max_size) {
229     this.pdu_max_size = pdu_max_size;
230   }
231
232   /**
233    * Displays the dialog.
234    * @param none.
235    * @return void.
236    */

237   public void open() {
238     final Shell parent = getParent();
239     final Display display = parent.getDisplay();
240     final Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
241     shell.setText(gui.getConfig().getString("gnetwatch_ip_options"));
242 // shell.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
243

244     // Your code goes here (widget creation, set result, etc).
245
// Composite for groups at left
246
layout = new GridLayout();
247     layout.numColumns = 1;
248     layout.marginHeight = 2;
249     layout.marginWidth = 2;
250     layout.verticalSpacing = 1;
251     shell.setLayout(layout);
252
253     groups_composite = new Composite(shell, SWT.FLAT);
254     groups_composite_layout = new RowLayout(SWT.VERTICAL);
255     groups_composite_layout.fill = true;
256     groups_composite_layout.marginTop = 0;
257     groups_composite_layout.marginBottom = 0;
258     groups_composite.setLayout(groups_composite_layout);
259     groups_composite_grid_data = new GridData(GridData.FILL_VERTICAL);
260     groups_composite.setLayoutData(groups_composite_grid_data);
261
262     // Group for network parameters
263

264     group_network_parameters = new Group(groups_composite, SWT.SHADOW_ETCHED_IN);
265     group_network_parameters_layout = new GridLayout();
266     group_network_parameters_layout.numColumns = 2;
267     group_network_parameters.setLayout(group_network_parameters_layout);
268     group_network_parameters.setText(gui.getConfig().getString("network_parameters"));
269
270     // RFC 3260
271
final Label label_tos = new Label(group_network_parameters, SWT.SHADOW_IN);
272     label_tos.setText(gui.getConfig().getString("dscp_name"));
273     label_tos.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
274     final Combo ctos = new Combo(group_network_parameters, SWT.SHADOW_IN | SWT.READ_ONLY);
275     ctos.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
276     for (final String JavaDoc tos : dscp) ctos.add(tos);
277     ctos.setText(dscp[tos]);
278
279     final Label label_packet_size = new Label(group_network_parameters, SWT.SHADOW_IN);
280     label_packet_size.setText(gui.getConfig().getString("pdu_max_size"));
281     label_packet_size.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
282     final Spinner packet_size = new Spinner(group_network_parameters, SWT.WRAP);
283     packet_size.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
284     packet_size.setMinimum(0);
285     packet_size.setMaximum(10000);
286     packet_size.setSelection(this.pdu_max_size);
287
288     final Label label_port_src = new Label(group_network_parameters, SWT.SHADOW_IN);
289     label_port_src.setText(gui.getConfig().getString("source_port"));
290     label_port_src.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
291     final Spinner port_src = new Spinner(group_network_parameters, SWT.WRAP);
292     port_src.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
293     port_src.setMinimum(1);
294     port_src.setMaximum(65535);
295     port_src.setSelection(this.port_src);
296
297     final Label label_port_dst = new Label(group_network_parameters, SWT.SHADOW_IN);
298     label_port_dst.setText(gui.getConfig().getString("destination_port"));
299     label_port_dst.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
300     final Spinner port_dst = new Spinner(group_network_parameters, SWT.WRAP);
301     port_dst.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
302     port_dst.setMinimum(0);
303     port_dst.setMaximum(65535);
304     port_dst.setSelection(this.port_dst);
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 DialogIPOptions _this = this;
329     button_ok.addSelectionListener(new SelectionListener() {
330       public void widgetDefaultSelected(SelectionEvent e) {
331         _this.tos = ctos.getSelectionIndex();
332         _this.port_src = port_src.getSelection();
333         _this.port_dst = port_dst.getSelection();
334         _this.pdu_max_size = packet_size.getSelection();
335
336         shell.dispose();
337       }
338
339       public void widgetSelected(SelectionEvent e) {
340         widgetDefaultSelected(e);
341       }
342     });
343
344
345     final Button button_cancel = new Button(bottom_composite, SWT.PUSH);
346     button_cancel.setText(gui.getConfig().getString("cancel"));
347     button_cancel.addSelectionListener(new SelectionListener() {
348       public void widgetDefaultSelected(SelectionEvent e) {
349         shell.dispose();
350       }
351
352       public void widgetSelected(SelectionEvent e) {
353         widgetDefaultSelected(e);
354       }
355     });
356
357     shell.pack(true);
358     shell.open();
359     while (!shell.isDisposed())
360       if (!display.readAndDispatch()) display.sleep();
361   }
362 }
363
Popular Tags