public AddFriend( final CoreCommunication core ) { shell = new Shell( SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL );  Rectangle parentBounds = desktop.getActiveShell().getBounds();  int tlx = parentBounds.x + (parentBounds.width / 2) - ( width / 2); int tly = parentBounds.y + (parentBounds.height / 2) - ( height / 2);  tlx = Math.min( (desktop.getClientArea().width - width), Math.max( 0, tlx) ); tly = Math.min( (desktop.getClientArea().height - height), Math.max( 0, tly) );  shell.setBounds( tlx, tly , width, height );  shell.setImage( G2GuiResources.getImage( "ProgramIcon" ) ); shell.setText( G2GuiResources.getString( "FR_MENU_ADD_BY_IP" ) ); GridLayout gridLayout = CGridLayout.createGL( 2, 5, 5, 10, 5, false ); shell.setLayout( gridLayout );  Label hostLabel = new Label( shell, SWT.NONE ); hostLabel.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_END ) ); hostLabel.setText( G2GuiResources.getString( "FR_ADD_HOST" ) + ":" );  final Text host = new Text( shell, SWT.BORDER ); host.setText( "192.168.1.1" ); host.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );  Label portLabel = new Label( shell, SWT.NONE ); portLabel.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_END ) ); portLabel.setText( G2GuiResources.getString( "FR_ADD_PORT" ) + ":" );  final Text port = new Text( shell, SWT.BORDER ); port.setText( "4662" ); port.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );  Button okButton = new Button( shell, SWT.NONE ); okButton.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); okButton.setText( G2GuiResources.getString( "BTN_OK" ) ); okButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent s ) { String string = "afr " + host.getText() + " " + port.getText(); Message consoleMessage = new EncodeMessage( Message.S_CONSOLEMSG, string ); consoleMessage.sendMessage( core ); consoleMessage = null; shell.close(); } } );  Button cancelButton = new Button( shell, SWT.NONE ); cancelButton.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); cancelButton.setText( G2GuiResources.getString( "BTN_CANCEL" ) ); cancelButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent s ) { shell.close(); } } ); shell.pack(); shell.open();
public AddFriend(Shell parentShell, CoreCommunication core) { super(parentShell); this.core = core;
    public AddFriend( final CoreCommunication core ) {        shell = new Shell( SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL );				Rectangle parentBounds = desktop.getActiveShell().getBounds();		        int tlx = parentBounds.x + (parentBounds.width / 2) - ( width / 2);		int tly = parentBounds.y + (parentBounds.height / 2) - ( height / 2);		tlx = Math.min( (desktop.getClientArea().width - width), Math.max( 0, tlx) );		tly = Math.min( (desktop.getClientArea().height - height), Math.max( 0, tly) );		shell.setBounds( tlx, tly , width, height );        shell.setImage( G2GuiResources.getImage( "ProgramIcon" ) );        shell.setText( G2GuiResources.getString( "FR_MENU_ADD_BY_IP" ) );        GridLayout gridLayout = CGridLayout.createGL( 2, 5, 5, 10, 5, false );        shell.setLayout( gridLayout );        Label hostLabel = new Label( shell, SWT.NONE );        hostLabel.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_END ) );        hostLabel.setText( G2GuiResources.getString( "FR_ADD_HOST" ) + ":" );        final Text host = new Text( shell, SWT.BORDER );        host.setText( "192.168.1.1" );        host.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );        Label portLabel = new Label( shell, SWT.NONE );        portLabel.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_END ) );        portLabel.setText( G2GuiResources.getString( "FR_ADD_PORT" ) + ":" );        final Text port = new Text( shell, SWT.BORDER );        port.setText( "4662" );        port.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );        Button okButton = new Button( shell, SWT.NONE );        okButton.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );        okButton.setText( G2GuiResources.getString( "BTN_OK" ) );        okButton.addSelectionListener( new SelectionAdapter() {                public void widgetSelected( SelectionEvent s ) {                    String string = "afr " + host.getText() + " " + port.getText();                    Message consoleMessage = new EncodeMessage( Message.S_CONSOLEMSG, string );                    consoleMessage.sendMessage( core );                    consoleMessage = null;                    shell.close();                }            } );        Button cancelButton = new Button( shell, SWT.NONE );        cancelButton.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );        cancelButton.setText( G2GuiResources.getString( "BTN_CANCEL" ) );        cancelButton.addSelectionListener( new SelectionAdapter() {                public void widgetSelected( SelectionEvent s ) {                    shell.close();                }            } );        shell.pack();        shell.open();    }