FileDocCategorySizeDatePackage
NatTestWindow.javaAPI DocAzureus 3.0.3.48875Wed Nov 29 11:15:30 GMT 2006org.gudy.azureus2.ui.swt.nat

NatTestWindow

public class NatTestWindow extends Object

Fields Summary
org.eclipse.swt.widgets.Display
display
org.eclipse.swt.widgets.Button
bTest
org.eclipse.swt.widgets.Button
bApply
org.eclipse.swt.widgets.Button
bCancel
org.eclipse.swt.custom.StyledText
textResults
Checker
checker
int
serverTCPListenPort
Constructors Summary
public NatTestWindow()

    serverTCPListenPort = COConfigurationManager.getIntParameter( "TCP.Listen.Port" );
    
    final Shell shell = ShellFactory.createShell(SWT.BORDER | SWT.TITLE | SWT.CLOSE);        
    shell.setText(MessageText.getString("configureWizard.nat.title"));
	if(! Constants.isOSX) {
		shell.setImage(ImageRepository.getImage("azureus"));
	}

    display = shell.getDisplay();
    
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    shell.setLayout(layout);

    Composite panel = new Composite(shell, SWT.NULL);
    GridData gridData = new GridData(GridData.VERTICAL_ALIGN_CENTER | GridData.FILL_HORIZONTAL);
    panel.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 3;
    panel.setLayout(layout);

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

    label = new Label(panel, SWT.NULL);
    label = new Label(panel, SWT.NULL);
    label = new Label(panel, SWT.NULL);
    label = new Label(panel, SWT.NULL);
    Messages.setLanguageText(label, "configureWizard.nat.server.tcp_listen_port");

    final Text textServerTCPListen = new Text(panel, SWT.BORDER);
    gridData = new GridData();    
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalAlignment = SWT.FILL;
    textServerTCPListen.setLayoutData(gridData);
    textServerTCPListen.setText("" + 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) {
        final int TCPListenPort = Integer.parseInt(textServerTCPListen.getText());
        serverTCPListenPort = TCPListenPort;
      }
    });

   

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

    textResults = new StyledText(panel, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP );
    gridData = new GridData();
    gridData.widthHint = 400;
    gridData.heightHint = 100;
    gridData.grabExcessVerticalSpace = true;
    gridData.verticalAlignment = SWT.FILL;
    gridData.horizontalSpan = 3;
    textResults.setLayoutData(gridData);
    textResults.setBackground(panel.getDisplay().getSystemColor(SWT.COLOR_WHITE));

    bTest.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event event) {
        bTest.setEnabled(false);
        textResults.setText("");
        
        checker = new Checker(serverTCPListenPort);
        checker.start();
      }
    });
        
        
    bApply = new Button(panel,SWT.PUSH);
    bApply.setText(MessageText.getString("Button.apply"));
    gridData = new GridData();
    gridData.widthHint = 70;
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalAlignment = SWT.RIGHT;
    gridData.horizontalSpan = 2;
    bApply.setLayoutData(gridData);
    
    
    bApply.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event event) {
	   	int	old_tcp 	= COConfigurationManager.getIntParameter( "TCP.Listen.Port" );
	   	int	old_udp 	= COConfigurationManager.getIntParameter( "UDP.Listen.Port" );
	   	int	old_udp2 	= COConfigurationManager.getIntParameter( "UDP.NonData.Listen.Port" );
    	
        COConfigurationManager.setParameter("TCP.Listen.Port",serverTCPListenPort);
        
        if ( old_tcp == old_udp ){
        	COConfigurationManager.setParameter("UDP.Listen.Port",serverTCPListenPort);
        }
        if ( old_tcp == old_udp2 ){
        	COConfigurationManager.setParameter("UDP.NonData.Listen.Port",serverTCPListenPort);
        }

        COConfigurationManager.save();
        
        shell.close();
      }
    });
    
    bCancel = new Button(panel,SWT.PUSH);
    bCancel.setText(MessageText.getString("Button.cancel"));
    gridData = new GridData();
    gridData.widthHint = 70;
    bCancel.setLayoutData(gridData);
    bCancel.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event event) {
        shell.close();
      }      
    });
    
	shell.setDefaultButton( bApply );
	
	shell.addListener(SWT.Traverse, new Listener() {	
		public void handleEvent(Event e) {
			if ( e.character == SWT.ESC){
				shell.close();
			}
		}
	});
	
    shell.pack();
    Utils.centreWindow(shell);
    shell.open();
  
Methods Summary
public voidprintMessage(java.lang.String message)

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