29package com.jogamp.opengl.test.junit.jogl.swt;
31import java.lang.reflect.InvocationTargetException;
33import org.eclipse.swt.SWT;
34import org.eclipse.swt.events.PaintEvent;
35import org.eclipse.swt.events.PaintListener;
36import org.eclipse.swt.graphics.Color;
37import org.eclipse.swt.graphics.Rectangle;
38import org.eclipse.swt.layout.FillLayout;
39import org.eclipse.swt.layout.GridData;
40import org.eclipse.swt.layout.GridLayout;
41import org.eclipse.swt.widgets.Canvas;
42import org.eclipse.swt.widgets.Composite;
43import org.eclipse.swt.widgets.Display;
44import org.eclipse.swt.widgets.Shell;
45import org.eclipse.swt.widgets.Text;
46import org.junit.Assert;
47import org.junit.Assume;
48import org.junit.BeforeClass;
50import org.junit.FixMethodOrder;
51import org.junit.runners.MethodSorters;
53import com.jogamp.common.os.Platform;
54import com.jogamp.junit.util.JunitTracer;
55import com.jogamp.nativewindow.swt.SWTAccessor;
56import com.jogamp.opengl.test.junit.util.MiscUtils;
57import com.jogamp.opengl.test.junit.util.UITestCase;
65@FixMethodOrder(MethodSorters.NAME_ASCENDING)
68 static int duration = 250;
70 Display display =
null;
72 Composite composite =
null;
76 if( Platform.getOSType() == Platform.OSType.MACOS ) {
80 JunitTracer.setTestSupported(
false);
85 protected void init() throws InterruptedException, InvocationTargetException {
88 display =
new Display();
89 Assert.assertNotNull( display );
91 shell =
new Shell( display );
92 Assert.assertNotNull( shell );
93 shell.setLayout(
new GridLayout(3,
false) );
94 shell.setBackground(
new Color(display, 0, 0, 255));
95 new Text(shell, SWT.NONE).setText(
"1");
96 new Text(shell, SWT.NONE).setText(
"2");
97 new Text(shell, SWT.NONE).setText(
"3");
98 new Text(shell, SWT.NONE).setText(
"4");
99 composite =
new Composite( shell, SWT.NO_BACKGROUND );
100 composite.setLayout(
new FillLayout() );
101 composite.setBackground(
new Color(display, 0, 255, 0));
102 final GridData gd =
new GridData (GridData.FILL, GridData.FILL,
true ,
true );
103 composite.setLayoutData(gd);
104 new Text(shell, SWT.NONE).setText(
"6");
105 new Text(shell, SWT.NONE).setText(
"7");
106 new Text(shell, SWT.NONE).setText(
"8");
107 new Text(shell, SWT.NONE).setText(
"9");
108 Assert.assertNotNull( composite );
112 protected void release() throws InterruptedException, InvocationTargetException {
113 Assert.assertNotNull( display );
114 Assert.assertNotNull( shell );
115 Assert.assertNotNull( composite );
129 protected void runTest() throws InterruptedException, InvocationTargetException {
131 final Canvas canvas[] = {
null };
135 canvas[0] =
new Canvas (composite, SWT.NONE);
136 canvas[0].setBackground(
new Color(display, 255, 255, 255));
137 canvas[0].setForeground(
new Color(display, 255, 0, 0));
138 canvas[0].addPaintListener (
new PaintListener() {
139 public void paintControl(
final PaintEvent e) {
140 final Rectangle r = canvas[0].getClientArea();
141 e.gc.fillRectangle(0, 0, r.width, r.height);
142 e.gc.drawRectangle(50, 50, r.width-100, r.height-100);
143 e.gc.drawString(
"I am a Canvas", r.width/2, r.height/2);
147 }
catch (
final Exception e) {
148 System.err.println(e.getMessage());
150 shell.setText( getClass().getName() );
151 shell.setBounds( 0, 0, 700, 700 );
158 final long lStartTime = System.currentTimeMillis();
159 final long lEndTime = lStartTime + duration;
161 while( (System.currentTimeMillis() < lEndTime) && !composite.isDisposed() ) {
164 if( !display.readAndDispatch() ) {
168 }
catch (
final InterruptedException e) { }
177 catch(
final Throwable throwable ) {
178 throwable.printStackTrace();
179 Assume.assumeNoException( throwable );
187 public void test() throws InterruptedException, InvocationTargetException {
191 public static void main(
final String args[]) {
192 for(
int i=0; i<args.length; i++) {
193 if(args[i].equals(
"-time")) {
static void invokeOnOSTKThread(final boolean blocking, final Runnable runnable)
Runs the specified action in an SWT compatible OS toolkit thread, which is:
static long getWindowHandle(final Control swtControl)
static void printInfo(final PrintStream out, final Display d)
Tests SWTAccessor#getWindowHandle(org.eclipse.swt.widgets.Control) on a basic simple SWT window.
static void main(final String args[])
static int atoi(final String str, final int def)