diff options
author | Sven Gothel <[email protected]> | 2011-09-15 07:53:49 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-09-15 07:53:49 +0200 |
commit | facc1023a83466305782796a61f87b61d17ad8d6 (patch) | |
tree | 00011a8a4dc8d0835a27c057531c085f7effe450 | |
parent | 926bf101da90eb450d1700d2ddc1242c9e18a2cb (diff) |
Add pos/size/translucency/above to JOGL Applet Runner
-rwxr-xr-x | src/demos/applets/JOGLNewtApplet1Run.java | 85 | ||||
-rwxr-xr-x | src/demos/applets/JOGLNewtAppletBase.java | 9 |
2 files changed, 80 insertions, 14 deletions
diff --git a/src/demos/applets/JOGLNewtApplet1Run.java b/src/demos/applets/JOGLNewtApplet1Run.java index 0a5311b..b321c14 100755 --- a/src/demos/applets/JOGLNewtApplet1Run.java +++ b/src/demos/applets/JOGLNewtApplet1Run.java @@ -11,13 +11,55 @@ import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.opengl.GLWindow; import java.awt.BorderLayout; -/** Shows how to deploy an applet using JOGL. This demo must be - referenced from a web page via an <applet> tag. */ - +/** + * Simple GLEventListener deployment as an applet using JOGL. This demo must be + * referenced from a web page via an <applet> tag. + * + * <p> + * Example of an applet tag using GearsES2 within the applet area (normal case): + * <pre> + <applet width=100 height=100> + <param name="java_arguments" value="-Dsun.java2d.noddraw=true"> + <param name="gl_event_listener_class" value="com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2"> + <param name="gl_profile" value="GL2"> + <param name="gl_swap_interval" value="1"> + <param name="gl_debug" value="false"> + <param name="gl_trace" value="false"> + <param name="jnlp_href" value="jogl-newt-applet-runner.jnlp"> + </applet>Hello Gears ! + * </pre> + * </p> + * + * <p> + * Example of an applet tag using GearsES2 in an undecorated, translucent and always-on-top window: + * <pre> + <applet width=1 height=1> + <param name="java_arguments" value="-Dsun.java2d.noddraw=true"> + <param name="gl_event_listener_class" value="com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2"> + <param name="gl_profile" value="GL2"> + <param name="gl_swap_interval" value="1"> + <param name="gl_undecorated" value="true"> + <param name="gl_alwaysontop" value="true"> + <param name="gl_opaque" value="false"> + <param name="gl_dx" value="10"> + <param name="gl_dy" value="0"> + <param name="gl_width" value="100"> + <param name="gl_height" value="100"> + <param name="gl_debug" value="false"> + <param name="gl_trace" value="false"> + <param name="jnlp_href" value="jogl-newt-applet-runner.jnlp"> + </applet>Hello Gears ! + * </pre> + * </p> + */ +@SuppressWarnings("serial") public class JOGLNewtApplet1Run extends Applet { GLWindow glWindow; NewtCanvasAWT newtCanvasAWT; JOGLNewtAppletBase base; + /** if valid glStandalone:=true (own window) ! */ + int glXd=Integer.MAX_VALUE, glYd=Integer.MAX_VALUE, glWidth=Integer.MAX_VALUE, glHeight=Integer.MAX_VALUE; + boolean glStandalone = false; public void init() { if(!(this instanceof Container)) { @@ -30,19 +72,30 @@ public class JOGLNewtApplet1Run extends Applet { int glSwapInterval=0; boolean glDebug=false; boolean glTrace=false; - String tmp; + boolean glUndecorated=false; + boolean glAlwaysOnTop=false; + boolean glOpaque=true; try { glEventListenerClazzName = getParameter("gl_event_listener_class"); glProfileName = getParameter("gl_profile"); glSwapInterval = JOGLNewtAppletBase.str2Int(getParameter("gl_swap_interval"), glSwapInterval); glDebug = JOGLNewtAppletBase.str2Bool(getParameter("gl_debug"), glDebug); glTrace = JOGLNewtAppletBase.str2Bool(getParameter("gl_trace"), glTrace); + glUndecorated = JOGLNewtAppletBase.str2Bool(getParameter("gl_undecorated"), glUndecorated); + glAlwaysOnTop = JOGLNewtAppletBase.str2Bool(getParameter("gl_alwaysontop"), glAlwaysOnTop); + glOpaque = JOGLNewtAppletBase.str2Bool(getParameter("gl_opaque"), glOpaque); + glXd = JOGLNewtAppletBase.str2Int(getParameter("gl_dx"), glXd); + glYd = JOGLNewtAppletBase.str2Int(getParameter("gl_dy"), glYd); + glWidth = JOGLNewtAppletBase.str2Int(getParameter("gl_width"), glWidth); + glHeight = JOGLNewtAppletBase.str2Int(getParameter("gl_height"), glHeight); } catch (Exception e) { e.printStackTrace(); } if(null==glEventListenerClazzName) { throw new RuntimeException("No applet parameter 'gl_event_listener_class'"); } + glStandalone = Integer.MAX_VALUE>glXd && Integer.MAX_VALUE>glYd && Integer.MAX_VALUE>glWidth && Integer.MAX_VALUE>glHeight; + base = new JOGLNewtAppletBase(glEventListenerClazzName, glSwapInterval, glDebug, @@ -51,10 +104,17 @@ public class JOGLNewtApplet1Run extends Applet { try { GLProfile.initSingleton(false); GLCapabilities caps = new GLCapabilities(GLProfile.get(glProfileName)); + caps.setBackgroundOpaque(glOpaque); glWindow = GLWindow.create(caps); - newtCanvasAWT = new NewtCanvasAWT(glWindow); - container.setLayout(new BorderLayout()); - container.add(newtCanvasAWT, BorderLayout.CENTER); + glWindow.setUndecorated(glUndecorated); + glWindow.setAlwaysOnTop(glAlwaysOnTop); + if(glStandalone) { + newtCanvasAWT = null; + } else { + newtCanvasAWT = new NewtCanvasAWT(glWindow); + container.setLayout(new BorderLayout()); + container.add(newtCanvasAWT, BorderLayout.CENTER); + } base.init(glWindow); if(base.isValid()) { GLEventListener glEventListener = base.getGLEventListener(); @@ -75,6 +135,11 @@ public class JOGLNewtApplet1Run extends Applet { } public void start() { + if(glStandalone) { + glWindow.setSize(glWidth, glHeight); + final java.awt.Point p0 = this.getLocationOnScreen(); + glWindow.setPosition(p0.x+glXd, p0.y+glYd); + } base.start(); } @@ -84,8 +149,10 @@ public class JOGLNewtApplet1Run extends Applet { public void destroy() { glWindow.setVisible(false); // hide 1st - glWindow.reparentWindow(null); // get out of newtCanvasAWT - this.remove(newtCanvasAWT); // remove newtCanvasAWT + if(!glStandalone) { + glWindow.reparentWindow(null); // get out of newtCanvasAWT + this.remove(newtCanvasAWT); // remove newtCanvasAWT + } base.destroy(); // destroy glWindow unrecoverable base=null; } diff --git a/src/demos/applets/JOGLNewtAppletBase.java b/src/demos/applets/JOGLNewtAppletBase.java index 5f85715..c8c6ac6 100755 --- a/src/demos/applets/JOGLNewtAppletBase.java +++ b/src/demos/applets/JOGLNewtAppletBase.java @@ -60,7 +60,7 @@ public class JOGLNewtAppletBase extends WindowAdapter implements KeyListener, Mo Object instance = null; try { - Class clazz = Class.forName(clazzName); + Class<?> clazz = Class.forName(clazzName); instance = clazz.newInstance(); } catch (Throwable t) { t.printStackTrace(); @@ -139,9 +139,6 @@ public class JOGLNewtAppletBase extends WindowAdapter implements KeyListener, Mo glWindow.setVisible(true); glAnimator.start(); awtParent = glWindow.getParent(); - if(null==awtParent) { - throw new RuntimeException("Parent of GLWindow is null: "+glWindow); - } } } @@ -209,7 +206,9 @@ public class JOGLNewtAppletBase extends WindowAdapter implements KeyListener, Mo glWindow.setUndecorated(!glWindow.isUndecorated()); } if(e.getKeyChar()=='f') { glWindow.setFullscreen(!glWindow.isFullscreen()); - } else if(e.getKeyChar()=='r') { + } else if(e.getKeyChar()=='a') { + glWindow.setAlwaysOnTop(!glWindow.isAlwaysOnTop()); + } else if(e.getKeyChar()=='r' && null!=awtParent) { if(null == glWindow.getParent()) { glWindow.reparentWindow(awtParent); } else { |