import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class SplashDemo {

	public static Display myDisplay;
	public static boolean internalCall = false;

	public static void main(String[] args) {
		internalCall = true;
		myDisplay = new Display();
		SplashDemo sd = new SplashDemo();
		sd.runDemo(myDisplay);	
	}
	
	public void runDemo(Display display) {
		myDisplay = display;
		Shell shell = new Shell(display, SWT.NO_TRIM);
		shell.setText("Splash Demo");
		
		//load the image into memory
		Image image = new Image(display, "splash.jpg");

		//get the image data
		ImageData imdata = image.getImageData();

		//set the shell just large enough to hold the image				
		shell.setSize(imdata.width, imdata.height);

		//get the bounds of the display to centre the shell on the screen
		Rectangle r = display.getBounds();
		int shellX = (r.width - imdata.width) / 2;
		int shellY = (r.height - imdata.height) / 2;
		shell.setLocation(shellX, shellY);
		
		//time to display the splash screen, in milliseconds
		final int SLEEP_TIME = 4000;	

		//open the shell, and draw the image
		shell.open();
		GC gc = new GC(shell);
		gc.drawImage(image, 0, 0);				

		//sleep for the required amount of time
		try {
			Thread.sleep(SLEEP_TIME);
		} catch (InterruptedException e) {
		}

		//dispose of the image, shell, display
		image.dispose();
		shell.dispose();
		if (internalCall) display.dispose();		
	}
}
