FileDocCategorySizeDatePackage
NatPanel.javaAPI DocAzureus 3.0.3.410279Thu Jan 18 10:55:40 GMT 2007org.gudy.azureus2.ui.swt.config.wizard

NatPanel

public class NatPanel extends org.gudy.azureus2.ui.swt.wizard.AbstractWizardPanel
author
Olivier

Fields Summary
org.eclipse.swt.custom.StyledText
textResults
Checker
checker
org.eclipse.swt.widgets.Button
bTest
org.eclipse.swt.widgets.Button
bCancel
Constructors Summary
public NatPanel(ConfigureWizard wizard, org.gudy.azureus2.ui.swt.wizard.IWizardPanel previous)

    super(wizard, previous);
  
Methods Summary
private voidenableNext()

    Display display = wizard.getDisplay();
    if (display == null || display.isDisposed())
      return;
    display.asyncExec(new AERunnable(){
      public void runSupport() {
      	if (bTest == null || bTest.isDisposed()) {
      		return;
      	}
      	
      	if (wizard.getCurrentPanel().equals(this)) {
      		return;
      	}

        wizard.setNextEnabled(true);
        bTest.setEnabled(true);
        bCancel.setEnabled(false);
      }
    });
  
public org.gudy.azureus2.ui.swt.wizard.IWizardPanelgetNextPanel()

    return new FilePanel(((ConfigureWizard)wizard),this);
  
public booleanisNextEnabled()

    return true;
  
public voidprintMessage(java.lang.String message)

    Display display = wizard.getDisplay();
    if (display == null || display.isDisposed())
      return;
    display.asyncExec(new AERunnable() {
      public void runSupport() {
        if (textResults == null || textResults.isDisposed())
          return;
        textResults.append(message);
      }
    });
  
public voidshow()

    wizard.setTitle(MessageText.getString("configureWizard.nat.title"));
    //wizard.setCurrentInfo(MessageText.getString("configureWizard.nat.hint"));
    Composite rootPanel = wizard.getPanel();
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    rootPanel.setLayout(layout);

    Composite panel = new Composite(rootPanel, SWT.NULL);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    panel.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 4;
    panel.setLayout(layout);

    Label label = new Label(panel, SWT.WRAP);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 4;
    label.setLayoutData(gridData);
    Messages.setLanguageText(label, "configureWizard.nat.message");

    label = new Label(panel, SWT.NULL);
    gridData = new GridData();
    gridData.horizontalSpan = 4;
    label.setLayoutData(gridData);
    
    
    label = new Label(panel, SWT.NULL);
    gridData = new GridData();
    label.setLayoutData(gridData);
    Messages.setLanguageText(label, "configureWizard.nat.server.tcp_listen_port");

    final Text textServerTCPListen = new Text(panel, SWT.BORDER);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 80;
    textServerTCPListen.setLayoutData(gridData);
    textServerTCPListen.setText("" + ((ConfigureWizard) wizard).serverTCPListenPort);
    textServerTCPListen.addListener(SWT.Verify, new Listener() {
      public void handleEvent(Event e) {
        String text = e.text;
        char[] chars = new char[text.length()];
        text.getChars(0, chars.length, chars, 0);
        for (int i = 0; i < chars.length; i++) {
          if (!('0" <= chars[i] && chars[i] <= '9")) {
            e.doit = false;
            return;
          }
        }
      }
    });
    textServerTCPListen.addListener(SWT.Modify, new Listener() {
      public void handleEvent(Event e) {
      	try {
	        final int TCPListenPort = Integer.parseInt(textServerTCPListen.getText());
	        ((ConfigureWizard) wizard).serverTCPListenPort = TCPListenPort;
      	} catch (NumberFormatException ex) {
      		// ignore
      	}
      }
    });

    /*
    label = new Label(panel, SWT.NULL);
    Messages.setLanguageText(label, "configureWizard.nat.serverhigh");

    final Text textServerHigh = new Text(panel, SWT.BORDER);
    gridData = new GridData();
    gridData.widthHint = 100;
    textServerHigh.setLayoutData(gridData);
    textServerHigh.setText("" + ((ConfigureWizard) wizard).serverMaxPort);
    textServerHigh.addListener(SWT.Verify, new Listener() {
      public void handleEvent(Event e) {
        String text = e.text;
        char[] chars = new char[text.length()];
        text.getChars(0, chars.length, chars, 0);
        for (int i = 0; i < chars.length; i++) {
          if (!('0' <= chars[i] && chars[i] <= '9')) {
            e.doit = false;
            return;
          }
        }
      }
    });
    textServerHigh.addListener(SWT.Modify, new Listener() {
      public void handleEvent(Event e) {
        int highPort = 0;
        try{
          highPort = Integer.parseInt(textServerHigh.getText());
        } catch(Exception ignore) { }
        ((ConfigureWizard) wizard).serverMaxPort = highPort;
      }
    });

    final Button sharePort = new Button(panel,SWT.CHECK);
    sharePort.setSelection(((ConfigureWizard)wizard).serverSharePort);
    sharePort.addListener(SWT.Selection,new Listener() {
    	public void handleEvent(Event arg0) {
    		((ConfigureWizard)wizard).serverSharePort = sharePort.getSelection();
    		textServerHigh.setEnabled(!((ConfigureWizard)wizard).serverSharePort);
    	}
    });
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
    sharePort.setLayoutData(gridData);
    
	label = new Label(panel,SWT.NULL);
	Messages.setLanguageText(label, "configureWizard.nat.sharePort");
	 
    textServerHigh.setEnabled(!((ConfigureWizard)wizard).serverSharePort);
    */

    bTest = new Button(panel, SWT.PUSH);
    Messages.setLanguageText(bTest, "configureWizard.nat.test");
    gridData = new GridData();
    gridData.widthHint = 70;
    bTest.setLayoutData(gridData);

    bCancel = new Button(panel, SWT.PUSH);
    Messages.setLanguageText(bCancel, "Button.cancel");
    gridData = new GridData();
    gridData.widthHint = 70;
    bCancel.setLayoutData(gridData);
    bCancel.setEnabled(false);

    textResults = new StyledText(panel, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP );
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.heightHint = 70;
    gridData.horizontalSpan = 4;
    textResults.setLayoutData(gridData);
    textResults.setBackground(panel.getDisplay().getSystemColor(SWT.COLOR_WHITE));

    bTest.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event event) {
        wizard.setNextEnabled(false);
        bTest.setEnabled(false);
        bCancel.setEnabled(true);
        textResults.setText("");
        ConfigureWizard cw = (ConfigureWizard) wizard;
        
        //int lowPort = cw.serverMinPort;
        //int highPort = cw.serverSharePort?cw.serverMinPort:cw.serverMaxPort;
        int TCPListenPort = cw.serverTCPListenPort;
        checker = new Checker(TCPListenPort);
        checker.start();
      }
    });

    bCancel.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event event) {
        if (checker != null)
          checker.stopIt();
        bCancel.setEnabled(false);
      }
    });