From 9c23064a6df1e3ef66a715759ee801a80ef516bd Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 15 Sep 2015 07:54:07 +0200 Subject: Bug 1211: Adopt changes to unit test from commit 68c8e39fa8d6e700f0a99241c1a01a435b7f6284 --- .../opengl/test/android/NEWTGearsES2Activity.java | 3 +- .../opengl/test/bugs/Bug735Inv0AppletAWT.java | 4 +- .../opengl/test/bugs/Bug735Inv1AppletAWT.java | 4 +- .../opengl/test/bugs/Bug735Inv2AppletAWT.java | 7 +- .../com/jogamp/opengl/test/bugs/Issue344Base.java | 3 +- .../junit/graph/demos/GPUUISceneGLListener0A.java | 3 +- .../junit/graph/demos/ui/MediaPlayerButton.java | 4 +- .../junit/jogl/acore/InitConcurrentBaseNEWT.java | 8 +- .../TestBug1146GLContextDialogToolTipAWT.java | 5 +- .../jogl/acore/TestFBOAutoDrawableDeadlockAWT.java | 3 +- .../junit/jogl/acore/TestFBOMix2DemosES2NEWT.java | 9 +- ...tFBOOffThreadSharedContextMix2DemosES2NEWT.java | 4 +- .../TestFBOOnThreadSharedContext1DemoES2NEWT.java | 4 +- .../jogl/acore/TestGLContextSurfaceLockNEWT.java | 9 +- .../acore/TestOffscreenLayer02NewtCanvasAWT.java | 7 +- .../junit/jogl/acore/TestPBufferDeadlockAWT.java | 3 +- .../jogl/acore/TestSharedExternalContextAWT.java | 3 +- .../jogl/acore/anim/Bug898AnimatorFromEDTAWT.java | 9 +- .../test/junit/jogl/caps/TestTranslucencyNEWT.java | 8 +- .../jogl/demos/es1/newt/TestGearsES1NEWT.java | 5 +- .../jogl/demos/es1/newt/TestRedSquareES1NEWT.java | 5 +- .../junit/jogl/demos/es2/av/CrossFadePlayer.java | 7 +- .../test/junit/jogl/demos/es2/av/MovieCube.java | 5 +- .../junit/jogl/demos/es2/av/MovieSBSStereo.java | 5 +- .../test/junit/jogl/demos/es2/av/MovieSimple.java | 9 +- .../es2/newt/TestElektronenMultipliziererNEWT.java | 5 +- .../jogl/demos/es2/newt/TestGearsES2NEWT.java | 16 +- .../demos/es2/newt/TestGearsES2NewtCanvasAWT.java | 13 +- .../demos/es2/newt/TestGearsES2NewtCanvasSWT.java | 7 +- .../demos/es2/newt/TestGearsES2SimpleNEWT.java | 2 +- .../jogl/demos/es2/newt/TestLandscapeES2NEWT.java | 8 +- .../es2/newt/TestLandscapeES2NewtCanvasAWT.java | 14 +- .../jogl/demos/es2/newt/TestRedSquareES2NEWT.java | 8 +- .../junit/jogl/demos/gl2/newt/TestGearsNEWT.java | 2 +- .../jogl/swt/TestBug672NewtCanvasSWTSashForm.java | 4 +- .../TestBug672NewtCanvasSWTSashFormComposite.java | 4 +- .../TestNewtCanvasSWTBug628ResizeDeadlockAWT.java | 17 +- .../junit/jogl/swt/TestSWTBug643AsyncExec.java | 8 +- .../TestGLReadBufferUtilTextureIOWrite02NEWT.java | 3 +- .../test/junit/newt/TestBug1211IRQ00NEWT.java | 57 +-- .../junit/newt/event/BaseNewtEventModifiers.java | 10 +- .../event/TestParentingFocus03KeyTraversalAWT.java | 2 +- .../parenting/NewtAWTReparentingKeyAdapter.java | 12 +- .../newt/parenting/TestParenting01cSwingAWT.java | 5 +- .../junit/newt/parenting/TestParenting03AWT.java | 4 +- .../jogamp/opengl/test/junit/util/MiscUtils.java | 3 +- .../opengl/test/junit/util/NEWTDemoListener.java | 501 --------------------- 47 files changed, 165 insertions(+), 676 deletions(-) delete mode 100644 src/test/com/jogamp/opengl/test/junit/util/NEWTDemoListener.java (limited to 'src/test/com') diff --git a/src/test/com/jogamp/opengl/test/android/NEWTGearsES2Activity.java b/src/test/com/jogamp/opengl/test/android/NEWTGearsES2Activity.java index e4fabbbcc..eff2aae49 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTGearsES2Activity.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTGearsES2Activity.java @@ -36,6 +36,7 @@ import com.jogamp.opengl.GLProfile; import jogamp.newt.driver.android.NewtBaseActivity; +import com.jogamp.common.util.InterruptSource; import com.jogamp.newt.event.MonitorEvent; import com.jogamp.newt.event.MouseAdapter; import com.jogamp.newt.event.MouseEvent; @@ -90,7 +91,7 @@ public class NEWTGearsES2Activity extends NewtBaseActivity { public void mousePressed(final MouseEvent e) { if( e.getPointerCount() == 3 ) { Log.d(TAG, "MemoryHog"); - new Thread(new Runnable() { + new InterruptSource.Thread(null, new Runnable() { public void run() { final ArrayList buffers = new ArrayList(); while(true) { diff --git a/src/test/com/jogamp/opengl/test/bugs/Bug735Inv0AppletAWT.java b/src/test/com/jogamp/opengl/test/bugs/Bug735Inv0AppletAWT.java index 89d28c08d..7430dcd38 100644 --- a/src/test/com/jogamp/opengl/test/bugs/Bug735Inv0AppletAWT.java +++ b/src/test/com/jogamp/opengl/test/bugs/Bug735Inv0AppletAWT.java @@ -27,7 +27,7 @@ import com.jogamp.opengl.GLRunnable; import com.jogamp.opengl.GLUniformData; import com.jogamp.opengl.awt.GLCanvas; import com.jogamp.opengl.glu.GLU; - +import com.jogamp.common.util.InterruptSource; import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.test.junit.jogl.demos.es2.LandscapeES2; @@ -98,7 +98,7 @@ public class Bug735Inv0AppletAWT extends Applet implements Runnable { } public void start() { - thread = new Thread(this, "Animation Thread"); + thread = new InterruptSource.Thread(null, this, "Animation Thread"); thread.start(); } diff --git a/src/test/com/jogamp/opengl/test/bugs/Bug735Inv1AppletAWT.java b/src/test/com/jogamp/opengl/test/bugs/Bug735Inv1AppletAWT.java index 5019391ad..b31a5f410 100644 --- a/src/test/com/jogamp/opengl/test/bugs/Bug735Inv1AppletAWT.java +++ b/src/test/com/jogamp/opengl/test/bugs/Bug735Inv1AppletAWT.java @@ -27,7 +27,7 @@ import com.jogamp.opengl.GLRunnable; import com.jogamp.opengl.GLUniformData; import com.jogamp.opengl.awt.GLCanvas; import com.jogamp.opengl.glu.GLU; - +import com.jogamp.common.util.InterruptSource; import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.test.junit.jogl.demos.es2.LandscapeES2; @@ -100,7 +100,7 @@ public class Bug735Inv1AppletAWT extends Applet implements Runnable { } public void start() { - thread = new Thread(this, "Animation Thread"); + thread = new InterruptSource.Thread(null, this, "Animation Thread"); thread.start(); } diff --git a/src/test/com/jogamp/opengl/test/bugs/Bug735Inv2AppletAWT.java b/src/test/com/jogamp/opengl/test/bugs/Bug735Inv2AppletAWT.java index 1228f1453..d0e4448cc 100644 --- a/src/test/com/jogamp/opengl/test/bugs/Bug735Inv2AppletAWT.java +++ b/src/test/com/jogamp/opengl/test/bugs/Bug735Inv2AppletAWT.java @@ -20,7 +20,8 @@ import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLEventListener; import com.jogamp.opengl.GLProfile; import com.jogamp.opengl.awt.GLCanvas; - +import com.jogamp.common.util.InterruptSource; +import com.jogamp.junit.util.JunitTracer; import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.test.junit.jogl.demos.es2.LandscapeES2; @@ -82,7 +83,7 @@ public class Bug735Inv2AppletAWT extends Applet implements Runnable { public void start() { initDraw(); - thread = new Thread(this, "Animation Thread"); + thread = new InterruptSource.Thread(null, this, "Animation Thread"); thread.start(); } @@ -219,7 +220,7 @@ public class Bug735Inv2AppletAWT extends Applet implements Runnable { System.err.println("swapInterval "+SWAP_INTERVAL); System.err.println("exclusiveContext "+USE_ECT); if(waitForKey) { - UITestCase.waitForKey("Start"); + JunitTracer.waitForKey("Start"); } final GraphicsEnvironment environment = diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue344Base.java b/src/test/com/jogamp/opengl/test/bugs/Issue344Base.java index 184a2ef0f..7532ca6db 100644 --- a/src/test/com/jogamp/opengl/test/bugs/Issue344Base.java +++ b/src/test/com/jogamp/opengl/test/bugs/Issue344Base.java @@ -6,6 +6,7 @@ import java.awt.Frame; import java.awt.event.*; import java.awt.geom.*; +import com.jogamp.common.util.InterruptSource; import com.jogamp.opengl.GL; import com.jogamp.opengl.GL2; import com.jogamp.opengl.GLAutoDrawable; @@ -49,7 +50,7 @@ public abstract class Issue344Base implements GLEventListener frame.setSize(512, 512); frame.addWindowListener(new WindowAdapter() { public void windowClosing(final WindowEvent e) { - new Thread(new Runnable() { + new InterruptSource.Thread(null, new Runnable() { public void run() { System.exit(0); } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java index 4bb72bbd2..3f5c5229e 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java @@ -16,6 +16,7 @@ import com.jogamp.opengl.GLPipelineFactory; import com.jogamp.opengl.GLRunnable; import com.jogamp.common.net.Uri; +import com.jogamp.common.util.InterruptSource; import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.curve.opengl.RenderState; @@ -354,7 +355,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { button.addMouseListener(new UIShape.MouseGestureAdapter() { @Override public void mouseClicked(final MouseEvent e) { - new Thread() { + new InterruptSource.Thread() { public void run() { if( null != cDrawable ) { final GLAnimatorControl actrl = cDrawable.getAnimator(); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/MediaPlayerButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/MediaPlayerButton.java index bdde61ad9..83fc6ca95 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/MediaPlayerButton.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/MediaPlayerButton.java @@ -28,7 +28,7 @@ package com.jogamp.opengl.test.junit.graph.demos.ui; import com.jogamp.opengl.GL2ES2; - +import com.jogamp.common.util.InterruptSource; import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.Vertex.Factory; @@ -91,7 +91,7 @@ public class MediaPlayerButton extends TextureSeqButton { // FIXME: mPlayer.resetGLState(); } if( 0 != ( GLMediaEventListener.EVENT_CHANGE_EOS & event_mask ) ) { - new Thread() { + new InterruptSource.Thread() { public void run() { // loop for-ever .. mPlayer.seek(0); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/InitConcurrentBaseNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/InitConcurrentBaseNEWT.java index 3379129dd..7a5b49168 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/InitConcurrentBaseNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/InitConcurrentBaseNEWT.java @@ -28,6 +28,8 @@ package com.jogamp.opengl.test.junit.jogl.acore; +import com.jogamp.common.util.InterruptSource; +import com.jogamp.common.util.InterruptedRuntimeException; import com.jogamp.nativewindow.Capabilities; import com.jogamp.nativewindow.util.InsetsImmutable; import com.jogamp.opengl.GLCapabilities; @@ -194,11 +196,11 @@ public abstract class InitConcurrentBaseNEWT extends UITestCase { final String currentThreadName = Thread.currentThread().getName(); final Object syncDone = new Object(); final JOGLTask[] tasks = new JOGLTask[num]; - final Thread[] threads = new Thread[num]; + final InterruptSource.Thread[] threads = new InterruptSource.Thread[num]; int i; for(i=0; i tool tip if( null != approveButtonPos ) { AWTRobotUtil.mouseMove(robot, approveButtonPos, MOVE_ITER, MOVE_DELAY); - Thread.sleep(TOOLTIP_WAIT); + java.lang.Thread.sleep(TOOLTIP_WAIT); try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOAutoDrawableDeadlockAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOAutoDrawableDeadlockAWT.java index fd012e86f..a034f9c8a 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOAutoDrawableDeadlockAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOAutoDrawableDeadlockAWT.java @@ -44,6 +44,7 @@ import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; +import com.jogamp.common.util.InterruptSource; import com.jogamp.common.util.RunnableTask; import com.jogamp.opengl.test.junit.util.UITestCase; @@ -83,7 +84,7 @@ public class TestFBOAutoDrawableDeadlockAWT extends UITestCase { System.err.println("BB.0: "+rTask.getSyncObject()); synchronized (rTask.getSyncObject()) { System.err.println("BB.1: "+rTask.getSyncObject()); - new Thread(rTask, Thread.currentThread().getName()+"-Pbuffer_Creation").start(); + new InterruptSource.Thread(null, rTask, Thread.currentThread().getName()+"-Pbuffer_Creation").start(); try { System.err.println("BB.2"); rTask.getSyncObject().wait(); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOMix2DemosES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOMix2DemosES2NEWT.java index f2e8b86af..d8900b44e 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOMix2DemosES2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOMix2DemosES2NEWT.java @@ -32,6 +32,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import com.jogamp.common.util.InterruptSource; import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.WindowEvent; @@ -114,7 +115,7 @@ public class TestFBOMix2DemosES2NEWT extends UITestCase { if( 3 == c ) { demo.setMSAA(4); } else if( 6 == c ) { - new Thread() { + new InterruptSource.Thread() { @Override public void run() { glWindow.setSize(dw+64, dh+64); @@ -124,14 +125,14 @@ public class TestFBOMix2DemosES2NEWT extends UITestCase { } else if( 12 == c ) { demo.setMSAA(0); } else if( 15 == c ) { - new Thread() { + new InterruptSource.Thread() { @Override public void run() { glWindow.setSize(dw+128, dh+128); } }.start(); } else if( 18 == c ) { c=0; - new Thread() { + new InterruptSource.Thread() { @Override public void run() { glWindow.setSize(dw+256, dh+256); @@ -167,7 +168,7 @@ public class TestFBOMix2DemosES2NEWT extends UITestCase { } System.err.println("*** "+e); if(e.getKeyChar()=='f') { - new Thread() { + new InterruptSource.Thread() { public void run() { System.err.println("[set fullscreen pre]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets()); glWindow.setFullscreen(!glWindow.isFullscreen()); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOOffThreadSharedContextMix2DemosES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOOffThreadSharedContextMix2DemosES2NEWT.java index 26d510a45..6c1e4b812 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOOffThreadSharedContextMix2DemosES2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOOffThreadSharedContextMix2DemosES2NEWT.java @@ -48,7 +48,7 @@ import com.jogamp.opengl.test.junit.jogl.demos.GLFinishOnDisplay; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; import com.jogamp.opengl.test.junit.jogl.demos.es2.Mix2TexturesES2; import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2; - +import com.jogamp.common.util.InterruptSource; import com.jogamp.nativewindow.NativeSurface; import com.jogamp.nativewindow.SurfaceUpdatedListener; import com.jogamp.opengl.GL; @@ -192,7 +192,7 @@ public class TestFBOOffThreadSharedContextMix2DemosES2NEWT extends UITestCase { } if(9 == c) { c=0; - new Thread() { + new InterruptSource.Thread() { @Override public void run() { glWindow.setSize(dw+256, dh+256); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOOnThreadSharedContext1DemoES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOOnThreadSharedContext1DemoES2NEWT.java index 0586eef8e..1886d3d2a 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOOnThreadSharedContext1DemoES2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOOnThreadSharedContext1DemoES2NEWT.java @@ -46,7 +46,7 @@ import com.jogamp.opengl.util.texture.TextureIO; import com.jogamp.opengl.test.junit.jogl.demos.GLFinishOnDisplay; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; import com.jogamp.opengl.test.junit.jogl.demos.es2.Mix2TexturesES2; - +import com.jogamp.common.util.InterruptSource; import com.jogamp.nativewindow.NativeSurface; import com.jogamp.nativewindow.SurfaceUpdatedListener; import com.jogamp.opengl.GL; @@ -178,7 +178,7 @@ public class TestFBOOnThreadSharedContext1DemoES2NEWT extends UITestCase { } if(9 == c) { c=0; - new Thread() { + new InterruptSource.Thread() { @Override public void run() { glWindow.setSize(dw+256, dh+256); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextSurfaceLockNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextSurfaceLockNEWT.java index 1e78691c4..8d26ebb82 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextSurfaceLockNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextSurfaceLockNEWT.java @@ -31,6 +31,7 @@ package com.jogamp.opengl.test.junit.jogl.acore; import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; +import com.jogamp.common.util.InterruptSource; import com.jogamp.nativewindow.NativeSurface; import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.GLCapabilities; @@ -194,8 +195,8 @@ public class TestGLContextSurfaceLockNEWT extends UITestCase { final Object sync = new Object(); final MyRunnable[] animTasks = new MyRunnable[animThreadCount]; final MyRunnable[] resizeTasks = new MyRunnable[animThreadCount]; - final Thread[] animThreads = new Thread[reszThreadCount]; - final Thread[] resizeThreads = new Thread[reszThreadCount]; + final InterruptSource.Thread[] animThreads = new InterruptSource.Thread[reszThreadCount]; + final InterruptSource.Thread[] resizeThreads = new InterruptSource.Thread[reszThreadCount]; System.err.println("animThreadCount "+animThreadCount+", frameCount "+frameCount); System.err.println("reszThreadCount "+reszThreadCount+", resizeCount "+resizeCount); @@ -204,12 +205,12 @@ public class TestGLContextSurfaceLockNEWT extends UITestCase { for(int i=0; i TRUE (silent interruption)"); + if( java.lang.Thread.interrupted() ) { + throw SourcedInterruptedException.wrap( + new InterruptedException(java.lang.Thread.currentThread().getName()+".testInterrupted -> TRUE (silent interruption)")); } } public synchronized void testInterrupted(final boolean ignore) throws InterruptedException { if( isInterrupted() ) { final boolean current; - if( this == Thread.currentThread() ) { - Thread.interrupted(); // clear! + if( this == java.lang.Thread.currentThread() ) { + java.lang.Thread.interrupted(); // clear! current = true; } else { current = false; } - final InterruptedException e = new MyInterruptedException(getName()+".testInterrupted -> TRUE (current "+current+", counter "+interruptCounter+")", - interruptCause); - interruptCause = null; - interruptCounter = 0; + final int counter = getInterruptCounter(false); + final Throwable source = getInterruptSource(true); + final InterruptedException e = new SourcedInterruptedException( + getName()+".testInterrupted -> TRUE (current "+current+", counter "+counter+")", + null, source); if( !ignore ) { throw e; } else { @@ -145,16 +133,9 @@ public class TestBug1211IRQ00NEWT extends SingletonJunitCase { myThreadStopped = true; } } - @Override - public synchronized void interrupt() { - interruptCounter++; - interruptCause = new Throwable(getName()+".interrupt() ************************************************* - count "+interruptCounter); - ExceptionUtils.dumpThrowable("causing", interruptCause); - super.interrupt(); - } @Override - public void uncaughtException(final Thread t, final Throwable e) { + public void uncaughtException(final java.lang.Thread t, final Throwable e) { System.err.println("UncaughtException on Thread "+t.getName()+": "+e.getMessage()); ExceptionUtils.dumpThrowable("UncaughtException", e); } @@ -200,7 +181,7 @@ public class TestBug1211IRQ00NEWT extends SingletonJunitCase { } System.err.println("test00.resize["+i+"]: "+ow+"x"+oh+" -> "+nw+"x"+nh); window1.setSize(nw, nh); - ok = !t.interruptCalled() && !t.isInterrupted() && edt.isRunning() && anim.isAnimating(); + ok = 0==t.getInterruptCounter(false) && !t.isInterrupted() && edt.isRunning() && anim.isAnimating(); t.testInterrupted(false); } } catch (final InterruptedException e) { @@ -215,7 +196,7 @@ public class TestBug1211IRQ00NEWT extends SingletonJunitCase { ExceptionUtils.dumpThrowable("InterruptedException-2", e); interrupt2 = true; } - Assert.assertFalse("interruptCalled()", t.interruptCalled()); + Assert.assertEquals("interruptCounter not zero", 0, t.getInterruptCounter(false)); Assert.assertFalse("interrupt() occured!", t.isInterrupted()); Assert.assertFalse("Interrupt-1 occured!", interrupt1); Assert.assertFalse("Interrupt-2 occured!", interrupt2); @@ -256,7 +237,7 @@ public class TestBug1211IRQ00NEWT extends SingletonJunitCase { ExceptionUtils.dumpThrowable("InterruptedException-2", e); interrupt2 = true; } - Assert.assertFalse("interruptCalled()", t.interruptCalled()); + Assert.assertEquals("interruptCounter not zero", 0, t.getInterruptCounter(false)); Assert.assertFalse("interrupt() occured!", t.isInterrupted()); Assert.assertFalse("Interrupt-1 occured!", interrupt1); Assert.assertFalse("Interrupt-2 occured!", interrupt2); @@ -279,7 +260,7 @@ public class TestBug1211IRQ00NEWT extends SingletonJunitCase { interruptInit0 = true; test = null; } - t.clearInterruptCounter(); + t.clearInterruptSource(); if( null != test ) { test.initTest(); test.subTest00(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java b/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java index 39c6c9f4d..5f88d1c6f 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java @@ -40,6 +40,7 @@ import org.junit.FixMethodOrder; import org.junit.Test ; import org.junit.runners.MethodSorters; +import com.jogamp.common.util.InterruptSource; import com.jogamp.common.util.RunnableTask; import com.jogamp.newt.event.MouseEvent; import com.jogamp.opengl.test.junit.util.AWTRobotUtil; @@ -344,20 +345,17 @@ public abstract class BaseNewtEventModifiers extends UITestCase { } _testMouseListener.setModifierCheckEnabled( true ) ; - Throwable throwable = null; // final Object sync = new Object(); final RunnableTask rt = new RunnableTask( testAction, null, true, System.err ); try { // synchronized(sync) { - new Thread(rt, "Test-Thread").start(); + new InterruptSource.Thread(null, rt, "Test-Thread").start(); int i=0; - while( !rt.isExecuted() && null == throwable ) { + while( rt.isInQueue() ) { System.err.println("WAIT-till-done: eventDispatch() #"+i++); eventDispatch(); } - if(null==throwable) { - throwable = rt.getThrowable(); - } + final Throwable throwable = rt.getThrowable(); if(null!=throwable) { throw new RuntimeException(throwable); } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/TestParentingFocus03KeyTraversalAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/event/TestParentingFocus03KeyTraversalAWT.java index cade05478..b9be0ad9a 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/TestParentingFocus03KeyTraversalAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/TestParentingFocus03KeyTraversalAWT.java @@ -154,7 +154,7 @@ public class TestParentingFocus03KeyTraversalAWT extends UITestCase { final GLEventListener demo1 = new GearsES2(1); setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); - glWindow1.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1, null)); + glWindow1.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1)); glWindow1.addKeyListener(new KeyAdapter() { public void keyReleased(final KeyEvent e) { if( !e.isPrintableKey() || e.isAutoRepeat() ) { diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java index ae873eaf0..3bf13f063 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java @@ -29,21 +29,21 @@ package com.jogamp.opengl.test.junit.newt.parenting; import java.awt.Frame; +import com.jogamp.common.util.InterruptSource; import com.jogamp.nativewindow.CapabilitiesImmutable; import com.jogamp.nativewindow.util.InsetsImmutable; import com.jogamp.newt.Window; import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.test.junit.util.NEWTDemoListener; -import com.jogamp.opengl.test.junit.util.QuitAdapter; +import com.jogamp.newt.opengl.util.NEWTDemoListener; public class NewtAWTReparentingKeyAdapter extends NEWTDemoListener { final Frame frame; final NewtCanvasAWT newtCanvasAWT; - public NewtAWTReparentingKeyAdapter(final Frame frame, final NewtCanvasAWT newtCanvasAWT, final GLWindow glWindow, final QuitAdapter quitAdapter) { - super(glWindow, quitAdapter, null); + public NewtAWTReparentingKeyAdapter(final Frame frame, final NewtCanvasAWT newtCanvasAWT, final GLWindow glWindow) { + super(glWindow, null); this.frame = frame; this.newtCanvasAWT = newtCanvasAWT; } @@ -64,9 +64,9 @@ public class NewtAWTReparentingKeyAdapter extends NEWTDemoListener { case KeyEvent.VK_R: e.setConsumed(true); quitAdapterOff(); - new Thread() { + new InterruptSource.Thread() { public void run() { - final Thread t = glWindow.setExclusiveContextThread(null); + final java.lang.Thread t = glWindow.setExclusiveContextThread(null); if(glWindow.getParent()==null) { printlnState("[reparent pre - glWin to HOME]"); glWindow.reparentWindow(newtCanvasAWT.getNativeWindow(), -1, -1, 0 /* hints */); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java index b53da38d7..4af752eb4 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java @@ -47,6 +47,7 @@ import javax.swing.WindowConstants; import com.jogamp.opengl.*; import com.jogamp.opengl.util.Animator; +import com.jogamp.common.util.InterruptSource; import com.jogamp.newt.*; import com.jogamp.newt.opengl.*; import com.jogamp.newt.awt.NewtCanvasAWT; @@ -140,7 +141,7 @@ public class TestParenting01cSwingAWT extends UITestCase { animator1.start(); final GLDisturbanceAction disturbanceAction = new GLDisturbanceAction(glWindow1); - new Thread(disturbanceAction).start(); + new InterruptSource.Thread(null, disturbanceAction).start(); disturbanceAction.waitUntilRunning(); final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); @@ -274,7 +275,7 @@ public class TestParenting01cSwingAWT extends UITestCase { animator1.start(); final GLDisturbanceAction disturbanceAction = new GLDisturbanceAction(glWindow1); - new Thread(disturbanceAction).start(); + new InterruptSource.Thread(null, disturbanceAction).start(); disturbanceAction.waitUntilRunning(); final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java index 723b84081..73d41aefd 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java @@ -88,7 +88,7 @@ public class TestParenting03AWT extends UITestCase { final GLEventListener demo1 = new GearsES2(1); setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); - glWindow1.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1, null)); + glWindow1.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1)); final GLAnimatorControl animator1 = new Animator(glWindow1); animator1.start(); @@ -104,7 +104,7 @@ public class TestParenting03AWT extends UITestCase { final GLEventListener demo2 = new GearsES2(1); setDemoFields(demo2, glWindow2, false); glWindow2.addGLEventListener(demo2); - glWindow2.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT2, glWindow2, null)); + glWindow2.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT2, glWindow2)); animator2 = new Animator(glWindow2); animator2.start(); } diff --git a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java index 60f2f962c..bf656bb4d 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java +++ b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java @@ -42,6 +42,7 @@ import java.util.List; import com.jogamp.opengl.GLContext; import com.jogamp.common.os.Platform; +import com.jogamp.common.util.InterruptSource; public class MiscUtils { public static boolean atob(final String str, final boolean def) { @@ -160,7 +161,7 @@ public class MiscUtils { return false; } - public static class StreamDump extends Thread { + public static class StreamDump extends InterruptSource.Thread { final InputStream is; final StringBuilder outString; final OutputStream outStream; diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTDemoListener.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTDemoListener.java deleted file mode 100644 index 3e0b7c780..000000000 --- a/src/test/com/jogamp/opengl/test/junit/util/NEWTDemoListener.java +++ /dev/null @@ -1,501 +0,0 @@ -/** - * Copyright 2015 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.opengl.test.junit.util; - -import java.net.URLConnection; - -import com.jogamp.common.util.IOUtil; -import com.jogamp.nativewindow.CapabilitiesImmutable; -import com.jogamp.nativewindow.ScalableSurface; -import com.jogamp.newt.Display; -import com.jogamp.newt.Display.PointerIcon; -import com.jogamp.newt.event.KeyEvent; -import com.jogamp.newt.event.KeyListener; -import com.jogamp.newt.event.MouseAdapter; -import com.jogamp.newt.event.MouseEvent; -import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.FPSCounter; -import com.jogamp.opengl.GL; -import com.jogamp.opengl.GLAnimatorControl; -import com.jogamp.opengl.GLAutoDrawable; -import com.jogamp.opengl.GLRunnable; -import com.jogamp.opengl.util.Gamma; -import com.jogamp.opengl.util.PNGPixelRect; - -import jogamp.newt.driver.PNGIcon; - -public class NEWTDemoListener extends MouseAdapter implements KeyListener { - protected final GLWindow glWindow; - protected final QuitAdapter quitAdapter; - final PointerIcon[] pointerIcons; - int pointerIconIdx = 0; - float gamma = 1f; - float brightness = 0f; - float contrast = 1f; - boolean confinedFixedCenter = false; - - public NEWTDemoListener(final GLWindow glWin, final QuitAdapter quitAdapter, final PointerIcon[] pointerIcons) { - this.glWindow = glWin; - this.quitAdapter = quitAdapter; - if( null != pointerIcons ) { - this.pointerIcons = pointerIcons; - } else { - this.pointerIcons = createPointerIcons(glWindow); - } - } - public NEWTDemoListener(final GLWindow glWin, final PointerIcon[] pointerIcons) { - this(glWin, null, pointerIcons); - } - public NEWTDemoListener(final GLWindow glWin) { - this(glWin, null, null); - } - - protected void printlnState(final String prelude) { - System.err.println(prelude+": "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets()+", state "+glWindow.getStateMaskString()); - } - protected void printlnState(final String prelude, final String post) { - System.err.println(prelude+": "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets()+", state "+glWindow.getStateMaskString()+", "+post); - } - protected void quitAdapterOff() { - if( null != quitAdapter ) { - quitAdapter.enable(false); - } - } - protected void quitAdapterOn() { - if( null != quitAdapter ) { - quitAdapter.clear(); - quitAdapter.enable(true); - } - } - - @Override - public void keyPressed(final KeyEvent e) { - if( e.isAutoRepeat() || e.isConsumed() ) { - return; - } - final int keySymbol = e.getKeySymbol(); - switch(keySymbol) { - case KeyEvent.VK_SPACE: - e.setConsumed(true); - new Thread() { - public void run() { - if(glWindow.getAnimator().isPaused()) { - glWindow.getAnimator().resume(); - } else { - glWindow.getAnimator().pause(); - } - } - }.run(); - break; - case KeyEvent.VK_A: - e.setConsumed(true); - new Thread() { - public void run() { - final Thread t = glWindow.setExclusiveContextThread(null); - printlnState("[set alwaysontop pre]"); - glWindow.setAlwaysOnTop(!glWindow.isAlwaysOnTop()); - printlnState("[set alwaysontop post]"); - glWindow.setExclusiveContextThread(t); - } }.start(); - break; - case KeyEvent.VK_B: - e.setConsumed(true); - new Thread() { - public void run() { - final Thread t = glWindow.setExclusiveContextThread(null); - printlnState("[set alwaysonbottom pre]"); - glWindow.setAlwaysOnBottom(!glWindow.isAlwaysOnBottom()); - printlnState("[set alwaysonbottom post]"); - glWindow.setExclusiveContextThread(t); - } }.start(); - break; - case KeyEvent.VK_C: - e.setConsumed(true); - new Thread() { - public void run() { - if( null != pointerIcons ) { - final Thread t = glWindow.setExclusiveContextThread(null); - printlnState("[set pointer-icon pre]"); - final PointerIcon currentPI = glWindow.getPointerIcon(); - final PointerIcon newPI; - if( pointerIconIdx >= pointerIcons.length ) { - newPI=null; - pointerIconIdx=0; - } else { - newPI=pointerIcons[pointerIconIdx++]; - } - glWindow.setPointerIcon( newPI ); - printlnState("[set pointer-icon post]", currentPI+" -> "+glWindow.getPointerIcon()); - glWindow.setExclusiveContextThread(t); - } - } }.start(); - break; - case KeyEvent.VK_D: - e.setConsumed(true); - new Thread() { - public void run() { - final Thread t = glWindow.setExclusiveContextThread(null); - // while( null != glWindow.getExclusiveContextThread() ) ; - printlnState("[set undecorated pre]"); - glWindow.setUndecorated(!glWindow.isUndecorated()); - printlnState("[set undecorated post]"); - glWindow.setExclusiveContextThread(t); - } }.start(); - break; - case KeyEvent.VK_F: - e.setConsumed(true); - quitAdapterOff(); - new Thread() { - public void run() { - final Thread t = glWindow.setExclusiveContextThread(null); - printlnState("[set fullscreen pre]"); - if( glWindow.isFullscreen() ) { - glWindow.setFullscreen( false ); - } else { - if( e.isAltDown() ) { - glWindow.setFullscreen( null ); - } else { - glWindow.setFullscreen( true ); - } - } - printlnState("[set fullscreen post]"); - glWindow.setExclusiveContextThread(t); - quitAdapterOn(); - } }.start(); - break; - case KeyEvent.VK_G: - e.setConsumed(true); - new Thread() { - public void run() { - final float newGamma = gamma + ( e.isShiftDown() ? -0.1f : 0.1f ); - System.err.println("[set gamma]: "+gamma+" -> "+newGamma); - if( Gamma.setDisplayGamma(glWindow, newGamma, brightness, contrast) ) { - gamma = newGamma; - } - } }.start(); - break; - case KeyEvent.VK_I: - e.setConsumed(true); - new Thread() { - public void run() { - final Thread t = glWindow.setExclusiveContextThread(null); - printlnState("[set pointer-visible pre]"); - glWindow.setPointerVisible(!glWindow.isPointerVisible()); - printlnState("[set pointer-visible post]"); - glWindow.setExclusiveContextThread(t); - } }.start(); - break; - case KeyEvent.VK_J: - e.setConsumed(true); - new Thread() { - public void run() { - final Thread t = glWindow.setExclusiveContextThread(null); - printlnState("[set pointer-confined pre]", "warp-center: "+e.isShiftDown()); - final boolean confine = !glWindow.isPointerConfined(); - glWindow.confinePointer(confine); - printlnState("[set pointer-confined post]", "warp-center: "+e.isShiftDown()); - if( e.isShiftDown() ) { - setConfinedFixedCenter(confine); - } else if( !confine ) { - setConfinedFixedCenter(false); - } - glWindow.setExclusiveContextThread(t); - } }.start(); - break; - case KeyEvent.VK_M: - e.setConsumed(true); - new Thread() { - public void run() { - // none: max-v - // alt: max-h - // shift: max-hv - // ctrl: max-off - final boolean horz, vert; - if( e.isControlDown() ) { - horz = false; - vert = false; - } else if( e.isShiftDown() ) { - final boolean bothMax = glWindow.isMaximizedHorz() && glWindow.isMaximizedVert(); - horz = !bothMax; - vert = !bothMax; - } else if( !e.isAltDown() ) { - horz = glWindow.isMaximizedHorz(); - vert = !glWindow.isMaximizedVert(); - } else if( e.isAltDown() ) { - horz = !glWindow.isMaximizedHorz(); - vert = glWindow.isMaximizedVert(); - } else { - vert = glWindow.isMaximizedVert(); - horz = glWindow.isMaximizedHorz(); - } - final Thread t = glWindow.setExclusiveContextThread(null); - printlnState("[set maximize pre]", "max[vert "+vert+", horz "+horz+"]"); - glWindow.setMaximized(horz, vert); - printlnState("[set maximize post]", "max[vert "+vert+", horz "+horz+"]"); - glWindow.setExclusiveContextThread(t); - } }.start(); - break; - case KeyEvent.VK_P: - e.setConsumed(true); - new Thread() { - public void run() { - final Thread t = glWindow.setExclusiveContextThread(null); - printlnState("[set position pre]"); - glWindow.setPosition(100, 100); - printlnState("[set position post]"); - glWindow.setExclusiveContextThread(t); - } }.start(); - break; - case KeyEvent.VK_R: - e.setConsumed(true); - new Thread() { - public void run() { - final Thread t = glWindow.setExclusiveContextThread(null); - printlnState("[set resizable pre]"); - glWindow.setResizable(!glWindow.isResizable()); - printlnState("[set resizable post]"); - glWindow.setExclusiveContextThread(t); - } }.start(); - break; - case KeyEvent.VK_S: - e.setConsumed(true); - new Thread() { - public void run() { - final Thread t = glWindow.setExclusiveContextThread(null); - printlnState("[set sticky pre]"); - glWindow.setSticky(!glWindow.isSticky()); - printlnState("[set sticky post]"); - glWindow.setExclusiveContextThread(t); - } }.start(); - break; - case KeyEvent.VK_V: - e.setConsumed(true); - if( e.isControlDown() ) { - glWindow.invoke(false, new GLRunnable() { - @Override - public boolean run(final GLAutoDrawable drawable) { - final GL gl = drawable.getGL(); - final int _i = gl.getSwapInterval(); - final int i; - switch(_i) { - case 0: i = -1; break; - case -1: i = 1; break; - case 1: i = 0; break; - default: i = 1; break; - } - gl.setSwapInterval(i); - - final GLAnimatorControl a = drawable.getAnimator(); - if( null != a ) { - a.resetFPSCounter(); - } - if(drawable instanceof FPSCounter) { - ((FPSCounter)drawable).resetFPSCounter(); - } - System.err.println("Swap Interval: "+_i+" -> "+i+" -> "+gl.getSwapInterval()); - return true; - } - }); - } else { - new Thread() { - public void run() { - final boolean wasVisible = glWindow.isVisible(); - { - final Thread t = glWindow.setExclusiveContextThread(null); - printlnState("[set visible pre]"); - glWindow.setVisible(!wasVisible); - printlnState("[set visible post]"); - glWindow.setExclusiveContextThread(t); - } - if( wasVisible && !e.isControlDown() ) { - try { - Thread.sleep(5000); - } catch (final InterruptedException e) { - e.printStackTrace(); - } - final Thread t = glWindow.setExclusiveContextThread(null); - printlnState("[reset visible pre]"); - glWindow.setVisible(true); - printlnState("[reset visible post]"); - glWindow.setExclusiveContextThread(t); - } - } }.start(); - } - break; - case KeyEvent.VK_W: - e.setConsumed(true); - new Thread() { - public void run() { - final Thread t = glWindow.setExclusiveContextThread(null); - printlnState("[set pointer-pos pre]"); - glWindow.warpPointer(glWindow.getSurfaceWidth()/2, glWindow.getSurfaceHeight()/2); - printlnState("[set pointer-pos post]"); - glWindow.setExclusiveContextThread(t); - } }.start(); - break; - case KeyEvent.VK_X: - e.setConsumed(true); - final float[] hadSurfacePixelScale = glWindow.getCurrentSurfaceScale(new float[2]); - final float[] reqSurfacePixelScale; - if( hadSurfacePixelScale[0] == ScalableSurface.IDENTITY_PIXELSCALE ) { - reqSurfacePixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE }; - } else { - reqSurfacePixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; - } - System.err.println("[set PixelScale pre]: had "+hadSurfacePixelScale[0]+"x"+hadSurfacePixelScale[1]+" -> req "+reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]); - glWindow.setSurfaceScale(reqSurfacePixelScale); - final float[] valReqSurfacePixelScale = glWindow.getRequestedSurfaceScale(new float[2]); - final float[] hasSurfacePixelScale1 = glWindow.getCurrentSurfaceScale(new float[2]); - System.err.println("[set PixelScale post]: "+hadSurfacePixelScale[0]+"x"+hadSurfacePixelScale[1]+" (had) -> "+ - reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]+" (req) -> "+ - valReqSurfacePixelScale[0]+"x"+valReqSurfacePixelScale[1]+" (val) -> "+ - hasSurfacePixelScale1[0]+"x"+hasSurfacePixelScale1[1]+" (has)"); - setTitle(); - } - } - @Override - public void keyReleased(final KeyEvent e) { } - - public void setConfinedFixedCenter(final boolean v) { - confinedFixedCenter = v; - } - @Override - public void mouseMoved(final MouseEvent e) { - if( e.isConfined() ) { - mouseCenterWarp(e); - } - } - @Override - public void mouseDragged(final MouseEvent e) { - if( e.isConfined() ) { - mouseCenterWarp(e); - } - } - @Override - public void mouseClicked(final MouseEvent e) { - if(e.getClickCount() == 2 && e.getPointerCount() == 1) { - glWindow.setFullscreen(!glWindow.isFullscreen()); - System.err.println("setFullscreen: "+glWindow.isFullscreen()); - } - } - private void mouseCenterWarp(final MouseEvent e) { - if(e.isConfined() && confinedFixedCenter ) { - final int x=glWindow.getSurfaceWidth()/2; - final int y=glWindow.getSurfaceHeight()/2; - glWindow.warpPointer(x, y); - } - } - - public void setTitle() { - setTitle(glWindow); - } - public static void setTitle(final GLWindow win) { - final CapabilitiesImmutable chosenCaps = win.getChosenCapabilities(); - final CapabilitiesImmutable reqCaps = win.getRequestedCapabilities(); - final CapabilitiesImmutable caps = null != chosenCaps ? chosenCaps : reqCaps; - final String capsA = caps.isBackgroundOpaque() ? "opaque" : "transl"; - final float[] sDPI = win.getPixelsPerMM(new float[2]); - sDPI[0] *= 25.4f; - sDPI[1] *= 25.4f; - win.setTitle("GLWindow["+capsA+"], win: "+win.getBounds()+", pix: "+win.getSurfaceWidth()+"x"+win.getSurfaceHeight()+", sDPI "+sDPI[0]+" x "+sDPI[1]); - } - - public static PointerIcon[] createPointerIcons(final GLWindow glWindow) { - final PointerIcon[] pointerIcons = { null, null, null, null, null }; - { - final Display disp = glWindow.getScreen().getDisplay(); - disp.createNative(); - int idx = 0; - { - PointerIcon _pointerIcon = null; - final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/cross-grey-alpha-16x16.png" } ); - try { - _pointerIcon = disp.createPointerIcon(res, 8, 8); - System.err.printf("Create PointerIcon #%02d: %s%n", idx, _pointerIcon.toString()); - } catch (final Exception e) { - e.printStackTrace(); - } - pointerIcons[idx] = _pointerIcon; - } - idx++; - { - PointerIcon _pointerIcon = null; - final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/pointer-grey-alpha-16x24.png" } ); - try { - _pointerIcon = disp.createPointerIcon(res, 0, 0); - System.err.printf("Create PointerIcon #%02d: %s%n", idx, _pointerIcon.toString()); - } catch (final Exception e) { - e.printStackTrace(); - } - pointerIcons[idx] = _pointerIcon; - } - idx++; - { - PointerIcon _pointerIcon = null; - final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "arrow-red-alpha-64x64.png" } ); - try { - _pointerIcon = disp.createPointerIcon(res, 0, 0); - System.err.printf("Create PointerIcon #%02d: %s%n", idx, _pointerIcon.toString()); - } catch (final Exception e) { - e.printStackTrace(); - } - pointerIcons[idx] = _pointerIcon; - } - idx++; - { - PointerIcon _pointerIcon = null; - final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "arrow-blue-alpha-64x64.png" } ); - try { - _pointerIcon = disp.createPointerIcon(res, 0, 0); - System.err.printf("Create PointerIcon #%02d: %s%n", idx, _pointerIcon.toString()); - } catch (final Exception e) { - e.printStackTrace(); - } - pointerIcons[idx] = _pointerIcon; - } - idx++; - if( PNGIcon.isAvailable() ) { - PointerIcon _pointerIcon = null; - final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "jogamp-pointer-64x64.png" } ); - try { - final URLConnection urlConn = res.resolve(0); - final PNGPixelRect image = PNGPixelRect.read(urlConn.getInputStream(), null, false /* directBuffer */, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); - System.err.printf("Create PointerIcon #%02d: %s%n", idx, image.toString()); - _pointerIcon = disp.createPointerIcon(image, 32, 0); - System.err.printf("Create PointerIcon #%02d: %s%n", idx, _pointerIcon.toString()); - } catch (final Exception e) { - e.printStackTrace(); - } - pointerIcons[idx] = _pointerIcon; - } - idx++; - } - return pointerIcons; - } - -} \ No newline at end of file -- cgit v1.2.3