29package com.jogamp.opengl.test.junit.newt.parenting;
31import java.awt.BorderLayout;
33import java.awt.Container;
34import java.awt.Dimension;
36import java.awt.GraphicsConfiguration;
37import java.awt.GraphicsDevice;
38import java.awt.GraphicsEnvironment;
40import java.awt.Transparency;
41import java.awt.image.ColorModel;
42import java.io.IOException;
43import java.lang.reflect.InvocationTargetException;
45import com.jogamp.opengl.GLAnimatorControl;
46import com.jogamp.opengl.GLCapabilities;
47import com.jogamp.opengl.GLEventListener;
49import org.junit.Assert;
50import org.junit.BeforeClass;
52import org.junit.FixMethodOrder;
53import org.junit.runners.MethodSorters;
55import com.jogamp.common.util.ReflectionUtil;
56import com.jogamp.newt.Window;
57import com.jogamp.newt.awt.NewtCanvasAWT;
58import com.jogamp.newt.opengl.GLWindow;
59import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
60import com.jogamp.opengl.test.junit.util.MiscUtils;
61import com.jogamp.opengl.test.junit.util.UITestCase;
62import com.jogamp.opengl.util.Animator;
64@FixMethodOrder(MethodSorters.NAME_ASCENDING)
66 static Dimension size;
67 static long durationPerTest = 400;
68 static long waitAdd2nd = 200;
73 size =
new Dimension(400,200);
80 testWindowParenting1AWTOneNewtChild();
83 static Frame getTranslucentFrame() {
84 GraphicsConfiguration gc=
null;
85 final GraphicsDevice[] devices= GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
86 for (
int i = 0; i < devices.length ; i++)
88 final GraphicsConfiguration[] configs = devices[i].getConfigurations();
89 for (
int j = 0; j < configs.length ; j++) {
90 final GraphicsConfiguration config = configs[j];
91 final ColorModel tcm = config.getColorModel(Transparency.TRANSLUCENT);
92 final boolean capable1 = (
null != tcm ) ? tcm.getTransparency() == Transparency.TRANSLUCENT :
false;
93 boolean capable2 =
false;
95 capable2 = ((Boolean)ReflectionUtil.callStaticMethod(
96 "com.sun.awt.AWTUtilities",
"isTranslucencyCapable",
97 new Class<?>[] { GraphicsConfiguration.class },
98 new Object[] { config } ,
99 GraphicsConfiguration.class.getClassLoader())).booleanValue();
100 System.err.println(
"com.sun.awt.AWTUtilities.isTranslucencyCapable(config) passed: "+capable2);
101 }
catch (
final RuntimeException re) {
102 System.err.println(
"com.sun.awt.AWTUtilities.isTranslucencyCapable(config) failed: "+re.getMessage());
104 System.err.println(i+
":"+j+
" "+config+
", "+tcm+
", capable "+capable1+
"/"+capable2);
105 if(capable1&&capable2) {
107 System.err.println(
"Chosen "+i+
":"+j+
" "+config+
", "+tcm+
", capable "+capable1+
"/"+capable2);
112 final Frame frame =
new Frame(gc);
114 frame.setUndecorated(
true);
115 frame.setBackground(
new Color(0, 0, 0, 0));
117 frame.setTitle(
"AWT Parent Frame (opaque: "+(
null==gc)+
")");
122 final Frame frame1 = getTranslucentFrame();
127 newtCanvasAWT1.setPreferredSize(size);
130 setDemoFields(demo1, glWindow1,
false);
135 final Container cont1 =
new Container();
136 cont1.setLayout(
new BorderLayout());
137 cont1.add(newtCanvasAWT1, BorderLayout.CENTER);
138 cont1.setVisible(
true);
140 frame1.setLayout(
new BorderLayout());
141 frame1.add(cont1, BorderLayout.EAST);
142 frame1.add(
new Label(
"center"), BorderLayout.CENTER);
143 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
145 frame1.setLocation(0, 0);
146 frame1.setSize((
int)size.getWidth(), (
int)size.getHeight());
148 frame1.setVisible(
true);
152 Assert.assertEquals(
true, animator1.
isAnimating());
153 Assert.assertEquals(
false, animator1.
isPaused());
154 Assert.assertNotNull(animator1.
getThread());
156 Thread.sleep(durationPerTest);
159 Assert.assertEquals(
false, animator1.
isAnimating());
160 Assert.assertEquals(
false, animator1.
isPaused());
161 Assert.assertEquals(
null, animator1.
getThread());
163 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
171 Assert.assertNotNull(demo);
172 Assert.assertNotNull(glWindow);
183 public static void main(
final String args[])
throws IOException {
184 for(
int i=0; i<args.length; i++) {
185 if(args[i].equals(
"-time")) {
186 durationPerTest =
MiscUtils.
atol(args[++i], durationPerTest);
187 }
else if(args[i].equals(
"-wait")) {
204 org.junit.runner.JUnitCore.
main(tstname);
void setBackgroundOpaque(final boolean opaque)
Sets whether the surface shall be opaque or translucent.
AWT Canvas containing a NEWT Window using native parenting.
NativeWindow getNativeWindow()
Returns the associated NativeWindow of this NativeWindowHolder, which is identical to getNativeSurfac...
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final NativeWindow getParent()
final void setUndecorated(final boolean value)
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
final Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
void testWindowParenting1AWTOneNewtChild()
void testWindowParenting1AWTOneNewtChild01()
static void setDemoFields(final GLEventListener demo, final GLWindow glWindow, final boolean debug)
static void main(final String args[])
static boolean setFieldIfExists(final Object instance, final String fieldName, final Object value)
static long atol(final String str, final long def)
Specifying NEWT's Window functionality:
void setUpdateFPSFrames(int frames, PrintStream out)
An animator control interface, which implementation may drive a com.jogamp.opengl....
boolean start()
Starts this animator, if not running.
boolean isPaused()
Indicates whether this animator is started and either manually paused or paused automatically due to ...
boolean isAnimating()
Indicates whether this animator is started and is not paused.
boolean stop()
Stops this animator.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.