1 2 23 24 package net.fenyo.gnetwatch.GUI; 25 26 import java.net.UnknownHostException ; 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 48 49 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 [] dscp = new String [] { 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 156 public DialogIPOptions(final GUI gui, final Shell parent) { 157 super(parent, 0); 158 this.gui = gui; 159 } 160 161 166 public int getTOS() { 167 return tos; 168 } 169 170 175 public int getPortSrc() { 176 return port_src; 177 } 178 179 183 public int getPortDst() { 184 return port_dst; 185 } 186 187 192 public int getPDUMaxSize() { 193 return pdu_max_size; 194 } 195 196 201 public void setTOS(final int tos) { 202 this.tos = tos; 203 } 204 205 210 public void setPortSrc(final int port_src) { 211 this.port_src = port_src; 212 } 213 214 219 public void setPortDst(final int port_dst) { 220 this.port_dst = port_dst; 221 } 222 223 228 public void setPDUMaxSize(final int pdu_max_size) { 229 this.pdu_max_size = pdu_max_size; 230 } 231 232 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 244 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 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 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 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 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 |