preferenceStore = new PreferenceStore( "g2gui.pref" ); myPrefs = new Preferences( preferenceStore ); splashShell = new Shell( shell, SWT.ON_TOP ); box = new MessageBox( shell, SWT.ICON_ERROR | SWT.OK ); waiterObject = new Object();  if (notProcessingLink){  progressBar = new ProgressBar( splashShell, SWT.NONE ); count = new int[] { 3 };   progressBar.setMaximum( count[0] ); label = new Label( splashShell, SWT.NONE ); label.setImage( G2GuiResources.getImage("splashScreen") ); FormLayout layout = new FormLayout(); splashShell.setLayout( layout ); formData = new FormData(); formData.left = new FormAttachment( 0, 5 ); formData.right = new FormAttachment( 100, -5 ); formData.bottom = new FormAttachment( 100, -5 ); progressBar.setLayoutData( formData ); splashShell.pack(); shellRect = splashShell.getBounds(); displayRect = display.getBounds(); int x = ( displayRect.width - shellRect.width ) / 2; int y = ( displayRect.height - shellRect.height ) / 2; splashShell.setLocation( x, y ); splashShell.open();  increaseBar( "Starting the model" ); }   try { myPrefs.initialize( preferenceStore ); } catch ( IOException e ) {System.out.println("failed"); }   if ( !( preferenceStore.getBoolean( "initialized" ) ) ) { splashShell.setVisible( false ); myPrefs.open( shell, null ); splashShell.setVisible( true ); } port = preferenceStore.getInt( "port" ); hostname = preferenceStore.getString( "hostname" ); username = preferenceStore.getString( "username" ); password = preferenceStore.getString( "password" );   socket = null; try { socketPool = new SocketPool( hostname, port ); socket = ( Socket ) socketPool.checkOut(); } catch ( UnknownHostException e ) { splashShell.dispose(); box.setText( G2GuiResources.getString( "G2_INVALID_ADDRESS") ); box.setMessage( G2GuiResources.getString( "G2_ILLEGAL_ADDRESS" ) ); box.open(); myPrefs.open( shell, null ); relaunchSelf(args); } catch ( IOException e ) { splashShell.dispose(); box.setText( G2GuiResources.getString( "G2_IOEXCEPTION") ); box.setMessage( G2GuiResources.getString( "G2_CORE_NOT_RUNNING" ) ); box.open(); myPrefs.open( shell, null ); relaunchSelf(args); }   boolean pushmode = ! notProcessingLink; core = new Core( socket, username, password, waiterObject, pushmode ); core.connect(); mldonkey = new Thread( core ); mldonkey.setDaemon( true ); mldonkey.start(); preferenceStore.setValue("initialized", true); try { preferenceStore.save(); } catch (IOException e2) {  }  while ( true ) {  synchronized ( waiterObject ) { try { waiterObject.wait(); } catch ( InterruptedException e1 ) { } }  if ( core.getBadPassword() ) { badPasswordHandling(args); }  else break; } if (notProcessingLink){ increaseBar( "Starting the view" );  MainTab g2gui = new MainTab( core, shell ); } else { shell.dispose(); display.dispose(); sendDownloadLink(args); } core.disconnect();
launch( args );
	public static void main( String[] args ) {				if ( containsLink(args) ) notProcessingLink = false;				/* initializing */				display = new Display();		shell = new Shell( display );				ImageRegistry reg = G2GuiResources.getImageRegistry();		reg.put("splashScreen", ImageDescriptor.createFromFile(G2Gui.class, "images/splash.png") );					preferenceStore = new PreferenceStore( "g2gui.pref" );			myPrefs = new Preferences( preferenceStore );		splashShell = new Shell( shell, SWT.ON_TOP );			box = new MessageBox( shell, SWT.ICON_ERROR | SWT.OK );		waiterObject = new Object();				if (notProcessingLink){										progressBar = new ProgressBar( splashShell, SWT.NONE );			count = new int[] { 3 };							/* build the splash */			progressBar.setMaximum( count[0] );			label = new Label( splashShell, SWT.NONE );			label.setImage( G2GuiResources.getImage("splashScreen") );			FormLayout layout = new FormLayout();			splashShell.setLayout( layout );			formData = new FormData();			formData.left = new FormAttachment( 0, 5 );			formData.right = new FormAttachment( 100, -5 );			formData.bottom = new FormAttachment( 100, -5 );			progressBar.setLayoutData( formData );			splashShell.pack();			shellRect = splashShell.getBounds();			displayRect = display.getBounds();			int x = ( displayRect.width - shellRect.width ) / 2;			int y = ( displayRect.height - shellRect.height ) / 2;			splashShell.setLocation( x, y );			splashShell.open(); //TODO disabled for developing						increaseBar( "Starting the model" );		}		/* load the preferences */		try {			myPrefs.initialize( preferenceStore );		}		catch ( IOException e ) {System.out.println("failed"); }					/* if the gui isnt set up yet launch the preference window */		if ( !( preferenceStore.getBoolean( "initialized" ) ) ) {								splashShell.setVisible( false );			myPrefs.open( shell, null );			splashShell.setVisible( true );		}		port = preferenceStore.getInt( "port" );				hostname = preferenceStore.getString( "hostname" );					username = preferenceStore.getString( "username" );					password = preferenceStore.getString( "password" );						/* create the socket connection to the core */		socket = null;		try {			socketPool = new SocketPool( hostname, port );			socket = ( Socket ) socketPool.checkOut();		}		catch ( UnknownHostException e ) {			splashShell.dispose();			box.setText( G2GuiResources.getString( "G2_INVALID_ADDRESS") );			box.setMessage( G2GuiResources.getString( "G2_ILLEGAL_ADDRESS" ) );			box.open();			myPrefs.open( shell, null );			relaunchSelf(args);		}		catch ( IOException e ) {			splashShell.dispose();			box.setText( G2GuiResources.getString( "G2_IOEXCEPTION") );			box.setMessage( G2GuiResources.getString( "G2_CORE_NOT_RUNNING" ) );			box.open();			myPrefs.open( shell, null );			relaunchSelf(args);		}				/* launch the model */		boolean pushmode = ! notProcessingLink;		core = new Core( socket, username, password, waiterObject, pushmode );		core.connect();		mldonkey = new Thread( core );		mldonkey.setDaemon( true );		mldonkey.start();		preferenceStore.setValue("initialized", true);		try {			preferenceStore.save();		} catch (IOException e2) {					}				while ( true ) {			/* wait as long as the core tells us to continue */			synchronized ( waiterObject ) {				try {					waiterObject.wait();				}				catch ( InterruptedException e1 ) { }			}			/* did the core receive "bad password" */			if ( core.getBadPassword() ) {				badPasswordHandling(args);			}			/* user/pass was valid, leave the loop */			else				break;		}		if (notProcessingLink){			increaseBar( "Starting the view" ); 						/* launch the view */				MainTab g2gui = new MainTab( core, shell );		}		else {			shell.dispose();			display.dispose();						sendDownloadLink(args);		}		core.disconnect();	}