import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class OffscreenImageDemo {

	public static Display myDisplay;
	public static boolean internalCall = false;

	public static void main(String[] args) {
		internalCall = true;
		myDisplay = new Display();
		OffscreenImageDemo id = new OffscreenImageDemo();
		id.runDemo(myDisplay);
	}
	
	public void runDemo(Display display) {
		myDisplay = display;
		Shell shell = new Shell(display);
		shell.setSize(100,100);
		shell.setText("OffScreen Image Demo");

		//load an image from a JPEG file
		Image img = new Image(display, 50,50);		

		//open the shell, so we can draw on it
		shell.open();

		//create a graphics context for the offscreen image
		GC imgGC = new GC(img);
			
		//draw a line onto the image in memory
		imgGC.drawLine(10, 20, 30, 40);
		
		//get a Graphics Context
		GC shellGC = new GC(shell);
		
		//draw the image to the screen
		shellGC.drawImage(img, 0, 0);

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		
		img.dispose();
		if (internalCall) display.dispose();

	}
	
}
