diff options
Diffstat (limited to 'src/newt/classes/com/jogamp')
-rw-r--r-- | src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java | 86 |
1 files changed, 54 insertions, 32 deletions
diff --git a/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java b/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java index 409f78307..0bdc70586 100644 --- a/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java +++ b/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java @@ -32,6 +32,7 @@ import java.awt.BorderLayout; import java.awt.Button; import java.awt.Component; import java.awt.Container; +import java.awt.EventQueue; import java.awt.event.KeyListener; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; @@ -44,6 +45,7 @@ import javax.media.opengl.GLProfile; import jogamp.nativewindow.jawt.JAWTUtil; +import com.jogamp.common.util.awt.AWTEDTExecutor; import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.opengl.GLWindow; @@ -105,12 +107,12 @@ public class JOGLNewtApplet1Run extends Applet { @Override public void init() { if(DEBUG) { - System.err.println("JOGLNewtApplet1Run.init() START"); + System.err.println("JOGLNewtApplet1Run.init() START - "+currentThreadName()); } if(!(this instanceof Container)) { throw new RuntimeException("This Applet is not a AWT Container"); } - final Container container = (Container) this; + final Container container = this; String glEventListenerClazzName=null; String glProfileName=null; @@ -192,10 +194,13 @@ public class JOGLNewtApplet1Run extends Applet { glWindow.setDefaultCloseOperation(glCloseable ? WindowClosingMode.DISPOSE_ON_CLOSE : WindowClosingMode.DO_NOTHING_ON_CLOSE); container.setLayout(new BorderLayout()); if(appletDebugTestBorder) { - container.add(new Button("North"), BorderLayout.NORTH); - container.add(new Button("South"), BorderLayout.SOUTH); - container.add(new Button("East"), BorderLayout.EAST); - container.add(new Button("West"), BorderLayout.WEST); + AWTEDTExecutor.singleton.invoke(true, new Runnable() { + public void run() { + container.add(new Button("North"), BorderLayout.NORTH); + container.add(new Button("South"), BorderLayout.SOUTH); + container.add(new Button("East"), BorderLayout.EAST); + container.add(new Button("West"), BorderLayout.WEST); + } } ); } base.init(glWindow); if(base.isValid()) { @@ -212,32 +217,43 @@ public class JOGLNewtApplet1Run extends Applet { } } if( !glStandalone ) { - newtCanvasAWT = new NewtCanvasAWT(glWindow); - container.add(newtCanvasAWT, BorderLayout.CENTER); - container.validate(); + AWTEDTExecutor.singleton.invoke(true, new Runnable() { + public void run() { + newtCanvasAWT = new NewtCanvasAWT(glWindow); + container.add(newtCanvasAWT, BorderLayout.CENTER); + container.validate(); + } } ); } } catch (Throwable t) { throw new RuntimeException(t); } if(DEBUG) { - System.err.println("JOGLNewtApplet1Run.init() END"); + System.err.println("JOGLNewtApplet1Run.init() END - "+currentThreadName()); } } + private static String currentThreadName() { return "["+Thread.currentThread().getName()+", isAWT-EDT "+EventQueue.isDispatchThread()+"]"; } + @Override public void start() { if(DEBUG) { - System.err.println("JOGLNewtApplet1Run.start() START (isVisible "+isVisible()+", isDisplayable "+isDisplayable()+")"); + System.err.println("JOGLNewtApplet1Run.start() START (isVisible "+isVisible()+", isDisplayable "+isDisplayable()+") - "+currentThreadName()); } - this.setVisible(true); - final java.awt.Point p0 = this.getLocationOnScreen(); - if( null != newtCanvasAWT ) { - newtCanvasAWT.setFocusable(true); - newtCanvasAWT.requestFocus(); - } else { + final java.awt.Point[] p0 = { null }; + AWTEDTExecutor.singleton.invoke(true, new Runnable() { + public void run() { + setVisible(true); + p0[0] = getLocationOnScreen(); + if( null != newtCanvasAWT ) { + newtCanvasAWT.setFocusable(true); + newtCanvasAWT.requestFocus(); + } + } + }); + if( null == newtCanvasAWT ) { glWindow.requestFocus(); glWindow.setSize(glWidth, glHeight); - glWindow.setPosition(p0.x+glXd, p0.y+glYd); + glWindow.setPosition(p0[0].x+glXd, p0[0].y+glYd); } if(DEBUG) { Component topC = this; @@ -258,43 +274,49 @@ public class JOGLNewtApplet1Run extends Applet { newtCanvasAWT.isOffscreenLayerSurfaceEnabled() && 0 != ( JAWTUtil.JAWT_OSX_CALAYER_QUIRK_POSITION & JAWTUtil.getOSXCALayerQuirks() ) ) { // force relayout - final int cW = newtCanvasAWT.getWidth(); - final int cH = newtCanvasAWT.getHeight(); - newtCanvasAWT.setSize(cW+1, cH+1); - newtCanvasAWT.setSize(cW, cH); + AWTEDTExecutor.singleton.invoke(true, new Runnable() { + public void run() { + final int cW = newtCanvasAWT.getWidth(); + final int cH = newtCanvasAWT.getHeight(); + newtCanvasAWT.setSize(cW+1, cH+1); + newtCanvasAWT.setSize(cW, cH); + } } ); } if(DEBUG) { - System.err.println("JOGLNewtApplet1Run.start() END"); + System.err.println("JOGLNewtApplet1Run.start() END - "+currentThreadName()); } } @Override public void stop() { if(DEBUG) { - System.err.println("JOGLNewtApplet1Run.stop() START"); + System.err.println("JOGLNewtApplet1Run.stop() START - "+currentThreadName()); } base.stop(); if(DEBUG) { - System.err.println("JOGLNewtApplet1Run.stop() END"); + System.err.println("JOGLNewtApplet1Run.stop() END - "+currentThreadName()); } } @Override public void destroy() { if(DEBUG) { - System.err.println("JOGLNewtApplet1Run.destroy() START"); - } - glWindow.setVisible(false); // hide 1st - if( null != newtCanvasAWT ) { - glWindow.reparentWindow(null); // get out of newtCanvasAWT - this.remove(newtCanvasAWT); // remove newtCanvasAWT + System.err.println("JOGLNewtApplet1Run.destroy() START - "+currentThreadName()); } + AWTEDTExecutor.singleton.invoke(true, new Runnable() { + public void run() { + glWindow.setVisible(false); // hide 1st + if( null != newtCanvasAWT ) { + remove(newtCanvasAWT); // remove newtCanvasAWT incl. glWindow.reparentWindow(null) if not done yet! + newtCanvasAWT.destroy(); + } + } } ); base.destroy(); // destroy glWindow unrecoverable base=null; glWindow=null; newtCanvasAWT=null; if(DEBUG) { - System.err.println("JOGLNewtApplet1Run.destroy() END"); + System.err.println("JOGLNewtApplet1Run.destroy() END - "+currentThreadName()); } } } |