1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
/**
* Copyright 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of JogAmp Community.
*/
package com.jogamp.test.junit.newt.parenting;
import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Test;
import java.awt.Button;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Label;
import javax.media.opengl.*;
import javax.media.nativewindow.*;
import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.FPSAnimator;
import com.jogamp.newt.*;
import com.jogamp.newt.event.*;
import com.jogamp.newt.opengl.*;
import com.jogamp.newt.awt.NewtCanvasAWT;
import java.io.IOException;
import com.jogamp.test.junit.util.*;
import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
public class TestParenting03bAWT extends UITestCase {
static Dimension size;
static long durationPerTest = 800;
static long waitAdd2nd = 500;
static GLCapabilities glCaps;
@BeforeClass
public static void initClass() {
GLProfile.initSingleton(true);
size = new Dimension(400,200);
glCaps = new GLCapabilities(null);
}
@Test
public void testWindowParenting1AWTTwoNewtChilds01() throws InterruptedException, InvocationTargetException {
testWindowParenting1AWTTwoNewtChilds();
}
public void testWindowParenting1AWTTwoNewtChilds() throws InterruptedException, InvocationTargetException {
int x = 0;
int y = 0;
NEWTEventFiFo eventFifo = new NEWTEventFiFo();
GLWindow glWindow1 = GLWindow.create(glCaps);
glWindow1.enablePerfLog(true);
glWindow1.setUndecorated(true);
NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1);
newtCanvasAWT1.setPreferredSize(size);
GLEventListener demo1 = new Gears(1);
setDemoFields(demo1, glWindow1, false);
glWindow1.addGLEventListener(demo1);
final NewtCanvasAWT f_newtCanvasAWT1 = newtCanvasAWT1;
final GLWindow f_glWindow1 = glWindow1;
glWindow1.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
if(e.getKeyChar()=='d') {
f_glWindow1.setUndecorated(!f_glWindow1.isUndecorated());
} else if(e.getKeyChar()=='f') {
f_glWindow1.setFullscreen(!f_glWindow1.isFullscreen());
} else if(e.getKeyChar()=='r') {
if(f_glWindow1.getParent()==null) {
System.err.println("XXX glWin1 -> home");
f_glWindow1.reparentWindow(f_newtCanvasAWT1.getNativeWindow());
} else {
System.err.println("XXX glWin1 -> TOP");
f_glWindow1.reparentWindow(null);
}
}
}
});
GLAnimatorControl animator1 = new Animator(glWindow1);
animator1.start();
GLWindow glWindow2 = GLWindow.create(glCaps);
glWindow2.enablePerfLog(true);
glWindow2.setUndecorated(true);
NewtCanvasAWT newtCanvasAWT2 = new NewtCanvasAWT(glWindow2);
newtCanvasAWT2.setPreferredSize(size);
GLEventListener demo2 = new Gears(1);
setDemoFields(demo2, glWindow2, false);
glWindow2.addGLEventListener(demo2);
final NewtCanvasAWT f_newtCanvasAWT2 = newtCanvasAWT2;
final GLWindow f_glWindow2 = glWindow2;
glWindow2.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
if(e.getKeyChar()=='d') {
f_glWindow2.setUndecorated(!f_glWindow2.isUndecorated());
} else if(e.getKeyChar()=='f') {
f_glWindow2.setFullscreen(!f_glWindow2.isFullscreen());
} else if(e.getKeyChar()=='r') {
if(f_glWindow2.getParent()==null) {
System.err.println("XXX glWin2 -> home");
f_glWindow2.reparentWindow(f_newtCanvasAWT2.getNativeWindow());
} else {
System.err.println("XXX glWin2 -> TOP");
f_glWindow2.reparentWindow(null);
}
}
}
});
GLAnimatorControl animator2 = new Animator(glWindow2);
animator2.start();
Container cont1 = new Container();
cont1.setLayout(new BorderLayout());
cont1.add(newtCanvasAWT1, BorderLayout.CENTER);
cont1.setVisible(true);
final Container f_cont1 = cont1;
Container cont2 = new Container();
cont2.setLayout(new BorderLayout());
cont2.add(newtCanvasAWT2, BorderLayout.CENTER);
cont2.setVisible(true);
final Container f_cont2 = cont2;
Frame frame1 = new Frame("AWT Parent Frame");
frame1.setLayout(new BorderLayout());
frame1.add(cont1, BorderLayout.EAST);
frame1.add(new Label("center"), BorderLayout.CENTER);
frame1.setLocation(0, 0);
frame1.setSize((int)size.getWidth()*2, (int)size.getHeight()*2);
final Frame f_frame1 = frame1;
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
f_frame1.pack();
f_frame1.setVisible(true);
}});
Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent());
Assert.assertEquals(newtCanvasAWT2.getNativeWindow(),glWindow2.getParent());
Assert.assertEquals(true, animator1.isAnimating());
Assert.assertEquals(false, animator1.isPaused());
Assert.assertNotNull(animator1.getThread());
Assert.assertEquals(true, animator2.isAnimating());
Assert.assertEquals(false, animator2.isPaused());
Assert.assertNotNull(animator2.getThread());
Thread.sleep(waitAdd2nd);
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
f_frame1.add(f_cont2, BorderLayout.WEST);
f_frame1.pack();
}});
Thread.sleep(durationPerTest);
animator1.stop();
Assert.assertEquals(false, animator1.isAnimating());
Assert.assertEquals(false, animator1.isPaused());
Assert.assertEquals(null, animator1.getThread());
animator2.stop();
Assert.assertEquals(false, animator2.isAnimating());
Assert.assertEquals(false, animator2.isPaused());
Assert.assertEquals(null, animator2.getThread());
frame1.dispose();
glWindow1.invalidate();
glWindow2.invalidate();
}
public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
Assert.assertNotNull(demo);
Assert.assertNotNull(glWindow);
Window window = glWindow.getWindow();
if(debug) {
MiscUtils.setFieldIfExists(demo, "glDebug", true);
MiscUtils.setFieldIfExists(demo, "glTrace", true);
}
if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
}
}
static int atoi(String a) {
int i=0;
try {
i = Integer.parseInt(a);
} catch (Exception ex) { ex.printStackTrace(); }
return i;
}
public static void main(String args[]) throws IOException {
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
durationPerTest = atoi(args[++i]);
} else if(args[i].equals("-wait")) {
waitAdd2nd = atoi(args[++i]);
}
}
String tstname = TestParenting03bAWT.class.getName();
/*
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
tstname,
"filtertrace=true",
"haltOnError=false",
"haltOnFailure=false",
"showoutput=true",
"outputtoformatters=true",
"logfailedtests=true",
"logtestlistenerevents=true",
"formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
"formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); */
org.junit.runner.JUnitCore.main(tstname);
}
}
|