summaryrefslogtreecommitdiffstats
path: root/src/demos/applets
diff options
context:
space:
mode:
Diffstat (limited to 'src/demos/applets')
-rwxr-xr-xsrc/demos/applets/JOGLNewtApplet1Run.java93
-rwxr-xr-xsrc/demos/applets/JOGLNewtAppletBase.java243
2 files changed, 0 insertions, 336 deletions
diff --git a/src/demos/applets/JOGLNewtApplet1Run.java b/src/demos/applets/JOGLNewtApplet1Run.java
deleted file mode 100755
index 0a5311b..0000000
--- a/src/demos/applets/JOGLNewtApplet1Run.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package demos.applets;
-
-import java.applet.*;
-import java.awt.Container;
-import java.awt.event.MouseListener;
-import java.awt.event.MouseMotionListener;
-import java.awt.event.KeyListener;
-
-import javax.media.opengl.*;
-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. */
-
-public class JOGLNewtApplet1Run extends Applet {
- GLWindow glWindow;
- NewtCanvasAWT newtCanvasAWT;
- JOGLNewtAppletBase base;
-
- public void init() {
- if(!(this instanceof Container)) {
- throw new RuntimeException("This Applet is not a AWT Container");
- }
- Container container = (Container) this; // have to think about that, we may use a Container
-
- String glEventListenerClazzName=null;
- String glProfileName=null;
- int glSwapInterval=0;
- boolean glDebug=false;
- boolean glTrace=false;
- String tmp;
- 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);
- } catch (Exception e) {
- e.printStackTrace();
- }
- if(null==glEventListenerClazzName) {
- throw new RuntimeException("No applet parameter 'gl_event_listener_class'");
- }
- base = new JOGLNewtAppletBase(glEventListenerClazzName,
- glSwapInterval,
- glDebug,
- glTrace);
-
- try {
- GLProfile.initSingleton(false);
- GLCapabilities caps = new GLCapabilities(GLProfile.get(glProfileName));
- glWindow = GLWindow.create(caps);
- newtCanvasAWT = new NewtCanvasAWT(glWindow);
- container.setLayout(new BorderLayout());
- container.add(newtCanvasAWT, BorderLayout.CENTER);
- base.init(glWindow);
- if(base.isValid()) {
- GLEventListener glEventListener = base.getGLEventListener();
-
- if(glEventListener instanceof MouseListener) {
- addMouseListener((MouseListener)glEventListener);
- }
- if(glEventListener instanceof MouseMotionListener) {
- addMouseMotionListener((MouseMotionListener)glEventListener);
- }
- if(glEventListener instanceof KeyListener) {
- addKeyListener((KeyListener)glEventListener);
- }
- }
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
-
- public void start() {
- base.start();
- }
-
- public void stop() {
- base.stop();
- }
-
- public void destroy() {
- glWindow.setVisible(false); // hide 1st
- 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
deleted file mode 100755
index 9fa1bdc..0000000
--- a/src/demos/applets/JOGLNewtAppletBase.java
+++ /dev/null
@@ -1,243 +0,0 @@
-package demos.applets;
-
-import java.lang.reflect.*;
-
-import javax.media.nativewindow.NativeWindow;
-import javax.media.opengl.*;
-import com.jogamp.opengl.util.*;
-
-import com.jogamp.newt.event.*;
-import com.jogamp.newt.opengl.GLWindow;
-
-/** Shows how to deploy an applet using JOGL. This demo must be
- referenced from a web page via an <applet> tag. */
-
-public class JOGLNewtAppletBase extends WindowAdapter implements KeyListener, MouseListener, GLEventListener {
- String glEventListenerClazzName;
- int glSwapInterval;
- boolean glDebug;
- boolean glTrace;
-
- GLEventListener glEventListener = null;
- GLWindow glWindow = null;
- Animator glAnimator=null;
- boolean isValid = false;
- NativeWindow awtParent;
-
- public JOGLNewtAppletBase(String glEventListenerClazzName,
- int glSwapInterval,
- boolean glDebug,
- boolean glTrace) {
-
- this.glEventListenerClazzName=glEventListenerClazzName;
- this.glSwapInterval=glSwapInterval;
- this.glDebug = glDebug;
- this.glTrace = glTrace;
- }
-
- public GLEventListener getGLEventListener() { return glEventListener; }
- public GLWindow getGLWindow() { return glWindow; }
- public Animator getGLAnimator() { return glAnimator; }
- public boolean isValid() { return isValid; }
-
- public static boolean str2Bool(String str, boolean def) {
- if(null==str) return def;
- try {
- return Boolean.valueOf(str).booleanValue();
- } catch (Exception ex) { ex.printStackTrace(); }
- return def;
- }
-
- public static int str2Int(String str, int def) {
- if(null==str) return def;
- try {
- return Integer.parseInt(str);
- } catch (Exception ex) { ex.printStackTrace(); }
- return def;
- }
-
- public static GLEventListener createInstance(String clazzName) {
- Object instance = null;
-
- try {
- Class clazz = Class.forName(clazzName);
- instance = clazz.newInstance();
- } catch (Throwable t) {
- t.printStackTrace();
- throw new RuntimeException("Error while instantiating demo: "+clazzName);
- }
- if( null == instance ) {
- throw new RuntimeException("Null GLEventListener: "+clazzName);
- }
- if( !(instance instanceof GLEventListener) ) {
- throw new RuntimeException("Not a GLEventListener: "+clazzName);
- }
- return (GLEventListener) instance;
- }
-
- public static boolean setField(Object instance, String fieldName, Object value) {
- try {
- Field f = instance.getClass().getField(fieldName);
- if(f.getType().isInstance(value)) {
- f.set(instance, value);
- return true;
- } else {
- System.out.println(instance.getClass()+" '"+fieldName+"' field not assignable with "+value.getClass()+", it's a: "+f.getType());
- }
- } catch (NoSuchFieldException nsfe) {
- System.out.println(instance.getClass()+" has no '"+fieldName+"' field");
- } catch (Throwable t) {
- t.printStackTrace();
- }
- return false;
- }
-
- public void init(GLWindow glWindow) {
- init(Thread.currentThread().getThreadGroup(), glWindow);
- }
-
- public void init(ThreadGroup tg, GLWindow glWindow) {
- this.glWindow = glWindow;
-
- glEventListener = createInstance(glEventListenerClazzName);
-
- try {
- if(!setField(glEventListener, "window", glWindow)) {
- setField(glEventListener, "glWindow", glWindow);
- }
-
- glWindow.addGLEventListener(this);
- glWindow.addGLEventListener(glEventListener);
-
- if(glEventListener instanceof WindowListener) {
- glWindow.addWindowListener((WindowListener)glEventListener);
- }
- glWindow.addWindowListener(this);
-
- if(glEventListener instanceof MouseListener) {
- glWindow.addMouseListener((MouseListener)glEventListener);
- }
- glWindow.addMouseListener(this);
-
- if(glEventListener instanceof KeyListener) {
- glWindow.addKeyListener((KeyListener)glEventListener);
- }
- glWindow.addKeyListener(this);
-
- glWindow.enablePerfLog(true);
-
- // glAnimator = new FPSAnimator(canvas, 60);
- glAnimator = new Animator(tg, glWindow);
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- isValid = true;
- }
-
- public void start() {
- if(isValid) {
- glWindow.setVisible(true);
- glAnimator.start();
- awtParent = glWindow.getParent();
- if(null==awtParent) {
- throw new RuntimeException("Parent of GLWindow is null: "+glWindow);
- }
- }
- }
-
- public void stop() {
- if(null!=glAnimator) {
- glAnimator.stop();
- glWindow.setVisible(false);
- }
- }
-
- public void destroy() {
- isValid = false;
- if(null!=glAnimator) {
- glAnimator.stop();
- glAnimator.remove(glWindow);
- glAnimator=null;
- }
- if(null!=glWindow) {
- glWindow.destroy();
- glWindow=null;
- }
- }
-
- // ***********************************************************************************
- // ***********************************************************************************
- // ***********************************************************************************
-
- public void init(GLAutoDrawable drawable) {
- GL _gl = drawable.getGL();
-
- if(glDebug) {
- try {
- _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", null, _gl, null) );
- } catch (Exception e) {e.printStackTrace();}
- }
-
- if(glTrace) {
- try {
- // Trace ..
- _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, _gl, new Object[] { System.err } ) );
- } catch (Exception e) {e.printStackTrace();}
- }
-
- if(glSwapInterval>=0) {
- _gl.setSwapInterval(glSwapInterval);
- }
- }
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
- }
- public void display(GLAutoDrawable drawable) {
- }
- public void dispose(GLAutoDrawable drawable) {
- }
-
- // ***********************************************************************************
- // ***********************************************************************************
- // ***********************************************************************************
-
- public void keyPressed(KeyEvent e) {
- }
- public void keyReleased(KeyEvent e) {
- }
- public void keyTyped(KeyEvent e) {
- if(e.getKeyChar()=='d') {
- glWindow.setUndecorated(!glWindow.isUndecorated());
- } if(e.getKeyChar()=='f') {
- glWindow.setFullscreen(!glWindow.isFullscreen());
- } else if(e.getKeyChar()=='r') {
- if(null == glWindow.getParent()) {
- glWindow.reparentWindow(awtParent);
- } else {
- glWindow.reparentWindow(null);
- }
- }
- }
-
- // ***********************************************************************************
- // ***********************************************************************************
- // ***********************************************************************************
-
- public void mouseClicked(MouseEvent e) {
- }
- public void mouseEntered(MouseEvent e) {
- }
- public void mouseExited(MouseEvent e) {
- }
- public void mousePressed(MouseEvent e) {
- }
- public void mouseReleased(MouseEvent e) {
- }
- public void mouseMoved(MouseEvent e) {
- }
- public void mouseDragged(MouseEvent e) {
- }
- public void mouseWheelMoved(MouseEvent e) {
- }
-
-}
-