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 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 proxy_host = ""; 84 private int proxy_port = 3128; 85 private String URL = ""; 86 private int nparallel = 1; 88 89 94 public DialogHTTPOptions(final GUI gui, final Shell parent) { 95 super(parent, 0); 96 this.gui = gui; 97 } 98 99 104 public boolean getUseProxy() { 105 return use_proxy; 106 } 107 108 113 public String getProxyHost() { 114 return proxy_host; 115 } 116 117 122 public int getProxyPort() { 123 return proxy_port; 124 } 125 126 131 public String getURL() { 132 return URL; 133 } 134 135 140 145 146 151 public int getNParallel() { 152 return nparallel; 153 } 154 155 160 public void setUseProxy(final boolean use_proxy) { 161 this.use_proxy = use_proxy; 162 } 163 164 169 public void setProxyHost(final String proxy_host) { 170 this.proxy_host = proxy_host; 171 } 172 173 178 public void setProxyPort(final int proxy_port) { 179 this.proxy_port = proxy_port; 180 } 181 182 187 public void setURL(final String URL) { 188 this.URL = URL; 189 } 190 191 196 201 202 207 public void setNParallel(final int nparallel) { 208 this.nparallel = nparallel; 209 } 210 211 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 223 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 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 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 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 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 |