import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class ColorFontDemo {

	public static Display myDisplay;
	public static boolean internalCall = false;

	public static void main(String[] args) {
		internalCall = true;
		myDisplay = new Display();
		ColorFontDemo gcd = new ColorFontDemo();
		gcd.runDemo(myDisplay);
	}

	public void runDemo(Display display) {
		myDisplay = display;
		Shell shell = new Shell(display);
		shell.setSize(200, 240);
		shell.setText("Color Font Demo");

		shell.addPaintListener(new PaintListener() {
			public void paintControl(PaintEvent e) {
				//get the GC, and a reference to the display
				GC gc = e.gc;
				Display d = e.widget.getDisplay();

				//create a custom colour, with RGB values
				Color color = new Color(d, 120, 42, 105);
				gc.setForeground(color);

				//create a Font object of font Arial,
				//set it to point size 24 and style BOLD and ITALIC
				Font font = new Font(d, "Arial", 24, SWT.BOLD | SWT.ITALIC);
				gc.setFont(font);

				//draw some text
				gc.drawString("Text", 20, 20);

				//make sure to dispose of the color and font
				color.dispose();
				font.dispose();
			}
		});

		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}

		if (internalCall) display.dispose();

	}

}
