diff options
author | Sven Gothel <[email protected]> | 2023-08-23 05:40:52 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-08-23 05:40:52 +0200 |
commit | fd93c0692ea3ed32bcbd1f08cca2290b6da3d451 (patch) | |
tree | f84e508ef416364d762b08b5c1e8c2a4366989a8 /src/demos/com/jogamp/opengl | |
parent | f8434687e144967164b770e4d323b77fd9d295da (diff) |
Demos: Use Runnable lambda for window.destroy() off-thread and use key-symbols F4, ESC and Q to trigger off-thread window.destroy()
Diffstat (limited to 'src/demos/com/jogamp/opengl')
10 files changed, 37 insertions, 57 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/av/MovieCube.java b/src/demos/com/jogamp/opengl/demos/av/MovieCube.java index a08423b62..c2cae3e2b 100644 --- a/src/demos/com/jogamp/opengl/demos/av/MovieCube.java +++ b/src/demos/com/jogamp/opengl/demos/av/MovieCube.java @@ -632,11 +632,7 @@ public class MovieCube implements GLEventListener { if( null != se ) { se.printStackTrace(); } - new InterruptSource.Thread() { - @Override - public void run() { - window.destroy(); - } }.start(); + new InterruptSource.Thread( () -> { window.destroy(); } ).start(); } } }); diff --git a/src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java b/src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java index 0700ca5bc..37bf5489e 100644 --- a/src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java +++ b/src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java @@ -817,11 +817,7 @@ public class MovieSBSStereo implements StereoGLEventListener { static class StereoGLMediaEventListener implements GLMediaEventListener { void destroyWindow(final Window window) { - new InterruptSource.Thread() { - @Override - public void run() { - window.destroy(); - } }.start(); + new InterruptSource.Thread( () -> { window.destroy(); } ).start(); } @Override diff --git a/src/demos/com/jogamp/opengl/demos/av/MovieSimple.java b/src/demos/com/jogamp/opengl/demos/av/MovieSimple.java index d170d204f..84e99ad15 100644 --- a/src/demos/com/jogamp/opengl/demos/av/MovieSimple.java +++ b/src/demos/com/jogamp/opengl/demos/av/MovieSimple.java @@ -564,11 +564,7 @@ public class MovieSimple implements GLEventListener { static class MyGLMediaEventListener implements GLMediaEventListener { void destroyWindow(final Window window) { - new InterruptSource.Thread() { - @Override - public void run() { - window.destroy(); - } }.start(); + new InterruptSource.Thread( () -> { window.destroy(); } ).start(); } @Override diff --git a/src/demos/com/jogamp/opengl/demos/graph/GPURegionNewtDemo.java b/src/demos/com/jogamp/opengl/demos/graph/GPURegionNewtDemo.java index 070371713..33a7be35a 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/GPURegionNewtDemo.java +++ b/src/demos/com/jogamp/opengl/demos/graph/GPURegionNewtDemo.java @@ -31,6 +31,7 @@ package com.jogamp.opengl.demos.graph; import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLProfile; import com.jogamp.opengl.demos.util.MiscUtils; +import com.jogamp.common.util.InterruptSource; import com.jogamp.graph.curve.Region; import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; @@ -142,8 +143,9 @@ public class GPURegionNewtDemo { window.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent arg0) { - if(arg0.getKeyCode() == KeyEvent.VK_F4) { - window.destroy(); + final short keySym = arg0.getKeySymbol(); + if( keySym == KeyEvent.VK_F4 || keySym == KeyEvent.VK_ESCAPE || keySym == KeyEvent.VK_Q ) { + new InterruptSource.Thread( () -> { window.destroy(); } ).start(); } } }); diff --git a/src/demos/com/jogamp/opengl/demos/graph/GPUTextNewtDemo.java b/src/demos/com/jogamp/opengl/demos/graph/GPUTextNewtDemo.java index 06f39d8ba..0c85ca1a0 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/GPUTextNewtDemo.java +++ b/src/demos/com/jogamp/opengl/demos/graph/GPUTextNewtDemo.java @@ -169,12 +169,9 @@ public class GPUTextNewtDemo { window.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent arg0) { - if(arg0.getKeyCode() == KeyEvent.VK_F4) { - new InterruptSource.Thread() { - @Override - public void run() { - window.destroy(); - } }.start(); + final short keySym = arg0.getKeySymbol(); + if( keySym == KeyEvent.VK_F4 || keySym == KeyEvent.VK_ESCAPE || keySym == KeyEvent.VK_Q ) { + new InterruptSource.Thread( () -> { window.destroy(); } ).start(); } } }); diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java index d10f10764..e1febc560 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java @@ -34,6 +34,7 @@ import java.util.Random; import com.jogamp.common.os.Clock; import com.jogamp.common.util.IOUtil; +import com.jogamp.common.util.InterruptSource; import com.jogamp.graph.curve.Region; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; @@ -166,22 +167,25 @@ public class UISceneDemo03 { window.addKeyListener(new KeyAdapter() { @Override public void keyReleased(final KeyEvent e) { - if (e.getKeySymbol() == KeyEvent.VK_PLUS || - e.getKeySymbol() == KeyEvent.VK_ADD) + final short keySym = e.getKeySymbol(); + if (keySym == KeyEvent.VK_PLUS || + keySym == KeyEvent.VK_ADD) { if (e.isShiftDown()) { setVelocity(velocity + 10 / 1000f); } else { setVelocity(velocity + 1 / 1000f); } - } else if (e.getKeySymbol() == KeyEvent.VK_MINUS || - e.getKeySymbol() == KeyEvent.VK_SUBTRACT) + } else if (keySym == KeyEvent.VK_MINUS || + keySym == KeyEvent.VK_SUBTRACT) { if (e.isShiftDown()) { setVelocity(velocity - 10 / 1000f); } else { setVelocity(velocity - 1 / 1000f); } + } else if( keySym == KeyEvent.VK_F4 || keySym == KeyEvent.VK_ESCAPE || keySym == KeyEvent.VK_Q ) { + new InterruptSource.Thread( () -> { window.destroy(); } ).start(); } } }); @@ -305,7 +309,7 @@ public class UISceneDemo03 { final float start_pos_z = 0f + random.nextFloat() * sceneBox.getHeight() * 1f; gs.moveTo(start_pos_x, start_pos_y, start_pos_z); } - // just add destText to scene to be cleaned up, invisible + // just add testGlyph to scene to be cleaned up, invisible testGlyph.setEnabled(false); glyphGroup.addShape(testGlyph); } @@ -316,7 +320,7 @@ public class UISceneDemo03 { final long t0_us = Clock.currentNanos() / 1000; // [us] final long[] t2_us = { t0_us }; - while (!glyphShapes.isEmpty()) { + while ( !glyphShapes.isEmpty() && window.isNativeValid() ) { window.invoke(true, (drawable) -> { final long t3_us = Clock.currentNanos() / 1000; final float dt_s = (t3_us - t2_us[0]) / 1e6f; diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo10.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo10.java index e65c9ce5f..58e382c43 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo10.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo10.java @@ -165,12 +165,9 @@ public class UISceneDemo10 { window.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent arg0) { - if(arg0.getKeyCode() == KeyEvent.VK_F4) { - new InterruptSource.Thread() { - @Override - public void run() { - window.destroy(); - } }.start(); + final short keySym = arg0.getKeySymbol(); + if( keySym == KeyEvent.VK_F4 || keySym == KeyEvent.VK_ESCAPE || keySym == KeyEvent.VK_Q ) { + new InterruptSource.Thread( () -> { window.destroy(); } ).start(); } } }); diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java index 6586f650c..64904bdb4 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java @@ -65,6 +65,7 @@ import com.jogamp.newt.MonitorDevice; import com.jogamp.newt.NewtFactory; import com.jogamp.newt.Screen; import com.jogamp.newt.Window; +import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.event.WindowAdapter; import com.jogamp.newt.event.WindowEvent; @@ -605,17 +606,14 @@ public class UISceneDemo20 implements GLEventListener { button.addMouseListener(new Shape.MouseGestureAdapter() { @Override public void mouseClicked(final MouseEvent e) { - new InterruptSource.Thread() { - @Override - public void run() { - if( null != cDrawable ) { - final GLAnimatorControl actrl = cDrawable.getAnimator(); - if( null != actrl ) { - actrl.stop(); - } - cDrawable.destroy(); + new InterruptSource.Thread( () -> { + if( null != cDrawable ) { + final GLAnimatorControl actrl = cDrawable.getAnimator(); + if( null != actrl ) { + actrl.stop(); } - } }.start(); + cDrawable.destroy(); + } } ).start(); } } ); button.addMouseListener(dragZoomRotateListener); buttonsLeft.addShape(button); diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java index 7d39003dd..c1dbaf700 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java @@ -126,12 +126,9 @@ public class UIShapeDemo01 implements GLEventListener { window.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent arg0) { - if(arg0.getKeyCode() == KeyEvent.VK_F4) { - new InterruptSource.Thread() { - @Override - public void run() { - window.destroy(); - } }.start(); + final short keySym = arg0.getKeySymbol(); + if( keySym == KeyEvent.VK_F4 || keySym == KeyEvent.VK_ESCAPE || keySym == KeyEvent.VK_Q ) { + new InterruptSource.Thread( () -> { window.destroy(); } ).start(); } } }); diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java index b1b3825f8..eb69bfb58 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java @@ -139,12 +139,9 @@ public class UITypeDemo01 implements GLEventListener { window.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent arg0) { - if(arg0.getKeyCode() == KeyEvent.VK_F4) { - new InterruptSource.Thread() { - @Override - public void run() { - window.destroy(); - } }.start(); + final short keySym = arg0.getKeySymbol(); + if( keySym == KeyEvent.VK_F4 || keySym == KeyEvent.VK_ESCAPE || keySym == KeyEvent.VK_Q ) { + new InterruptSource.Thread( () -> { window.destroy(); } ).start(); } } }); |