28package com.jogamp.newt.util.applet;
30import java.lang.reflect.Field;
31import java.security.PrivilegedAction;
33import com.jogamp.nativewindow.NativeWindow;
34import com.jogamp.nativewindow.WindowClosingProtocol.WindowClosingMode;
35import com.jogamp.nativewindow.util.InsetsImmutable;
36import com.jogamp.opengl.FPSCounter;
37import com.jogamp.opengl.GL;
38import com.jogamp.opengl.GLAutoDrawable;
39import com.jogamp.opengl.GLEventListener;
40import com.jogamp.opengl.GLPipelineFactory;
42import jogamp.newt.Debug;
44import com.jogamp.common.util.InterruptSource;
45import com.jogamp.common.util.SecurityUtil;
46import com.jogamp.newt.Window;
47import com.jogamp.newt.event.KeyEvent;
48import com.jogamp.newt.event.KeyListener;
49import com.jogamp.newt.event.MouseListener;
50import com.jogamp.newt.event.WindowAdapter;
51import com.jogamp.newt.event.WindowEvent;
52import com.jogamp.newt.event.WindowListener;
53import com.jogamp.newt.opengl.GLWindow;
54import com.jogamp.newt.opengl.util.NEWTDemoListener;
55import com.jogamp.opengl.util.Animator;
56import com.jogamp.opengl.util.AnimatorBase;
67 public static final boolean DEBUG = Debug.debug(
"Applet");
69 String glEventListenerClazzName;
71 boolean noDefaultKeyListener;
79 boolean isValid =
false;
83 final int glSwapInterval,
84 final boolean noDefaultKeyListener,
85 final boolean glClosable,
86 final boolean glDebug,
87 final boolean glTrace) {
89 this.glEventListenerClazzName=glEventListenerClazzName;
90 this.glSwapInterval=glSwapInterval;
91 this.noDefaultKeyListener = noDefaultKeyListener;
92 this.glClosable = glClosable;
93 this.glDebug = glDebug;
94 this.glTrace = glTrace;
102 public static boolean str2Bool(
final String str,
final boolean def) {
103 if(
null==str)
return def;
105 return Boolean.valueOf(str).booleanValue();
106 }
catch (
final Exception ex) { ex.printStackTrace(); }
110 public static int str2Int(
final String str,
final int def) {
111 if(
null==str)
return def;
113 return Integer.parseInt(str);
114 }
catch (
final Exception ex) { ex.printStackTrace(); }
119 Object instance =
null;
122 final Class<?> clazz = SecurityUtil.doPrivileged(
new PrivilegedAction<Class<?>>() {
124 public Class<?> run() {
125 final ClassLoader cl = Thread.currentThread().getContextClassLoader();
126 Class<?> clazz =
null;
128 clazz = Class.forName(clazzName,
false, cl);
129 }
catch (
final Throwable t) {
135 instance = clazz.newInstance();
136 }
catch (
final Throwable t) {
138 throw new RuntimeException(
"Error while instantiating demo: "+clazzName);
140 if(
null == instance ) {
141 throw new RuntimeException(
"Null GLEventListener: "+clazzName);
144 throw new RuntimeException(
"Not a GLEventListener: "+clazzName);
149 public static boolean setField(
final Object instance,
final String fieldName,
final Object value) {
151 final Field f = instance.getClass().getField(fieldName);
152 if(f.getType().isInstance(value)) {
153 f.set(instance, value);
156 System.out.println(instance.getClass()+
" '"+fieldName+
"' field not assignable with "+value.getClass()+
", it's a: "+f.getType());
158 }
catch (
final NoSuchFieldException nsfe) {
159 System.out.println(instance.getClass()+
" has no '"+fieldName+
"' field");
160 }
catch (
final Throwable t) {
167 init(Thread.currentThread().getThreadGroup(), glWindow);
172 this.glWindow = glWindow;
174 if(
null == glEventListener) {
179 if(!
setField(glEventListener,
"window", glWindow)) {
180 setField(glEventListener,
"glWindow", glWindow);
200 if(!noDefaultKeyListener) {
212 glAnimator.
add(glWindow);
215 }
catch (
final Throwable t) {
216 throw new RuntimeException(t);
224 public void windowDestroyNotify(
final WindowEvent e) {
229 new InterruptSource.Thread(
null,
new Runnable() {
250 if(
null!=glAnimator) {
258 if(
null!=glAnimator) {
260 glAnimator.
remove(glWindow);
280 }
catch (
final Exception e) {e.printStackTrace();}
287 }
catch (
final Exception e) {e.printStackTrace();}
313 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
final char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
static boolean isPrintableKey(final short uniChar, final boolean isKeyChar)
Returns true if given uniChar represents a printable character, i.e.
final void setConsumed(final boolean consumed)
If consumed is true, this event is marked as consumed, ie.
NEWT Window events are provided for notification purposes ONLY.
static final short EVENT_WINDOW_RESIZED
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final NativeWindow getParent()
WindowClosingMode setDefaultCloseOperation(final WindowClosingMode op)
final boolean isNativeValid()
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
final ReparentOperation reparentWindow(final NativeWindow newParent, final int x, final int y, final int hints)
Change this window's parent window.
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
WindowClosingMode getDefaultCloseOperation()
void sendWindowEvent(final int eventType)
Send a WindowEvent to all WindowListener.
final InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
NEWT GLWindow Demo functionality.
Shows how to deploy an applet using JOGL.
void init(final ThreadGroup tg, final GLWindow glWindow)
static int str2Int(final String str, final int def)
void keyPressed(final KeyEvent e)
A key has been pressed, excluding auto-repeat modifier keys.
JOGLNewtAppletBase(final String glEventListenerClazzName, final int glSwapInterval, final boolean noDefaultKeyListener, final boolean glClosable, final boolean glDebug, final boolean glTrace)
void init(final GLWindow glWindow)
void keyReleased(final KeyEvent e)
A key has been released, excluding auto-repeat modifier keys.
static boolean setField(final Object instance, final String fieldName, final Object value)
static final boolean DEBUG
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height)
Called by the drawable during the first repaint after the component has been resized.
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
static GLEventListener createInstance(final String clazzName)
static boolean str2Bool(final String str, final boolean def)
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
GLEventListener getGLEventListener()
abstract GL setGL(GL gl)
Sets the GL pipeline object for this GLContext.
Factory for pipelining GL instances.
static final GL create(final String pipelineClazzBaseName, final Class<?> reqInterface, final GL downstream, final Object[] additionalArgs)
Creates a pipelined GL instance using the given downstream downstream and optional arguments addition...
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final synchronized void remove(final GLAutoDrawable drawable)
Removes a drawable from the animator's list of rendering drawables.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized void setThreadGroup(final ThreadGroup tg)
Set a ThreadGroup for the animation thread.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
Window closing mode if triggered by toolkit close operation.
DO_NOTHING_ON_CLOSE
Do nothing on native window close operation.
DISPOSE_ON_CLOSE
Dispose resources on native window close operation.
Extend the NativeSurface interface with windowing information such as window-handle,...
long getWindowHandle()
Returns the window handle for this NativeWindow.
Immutable insets representing rectangular window decoration insets on all four edges in window units.
Specifying NEWT's Window functionality:
static final int REPARENT_HINT_BECOMES_VISIBLE
Reparenting hint (bitfield value): Claim window becomes visible after reparenting,...
Listener for MouseEvents.
NEWT WindowEvent listener.
void setUpdateFPSFrames(int frames, PrintStream out)
static final int DEFAULT_FRAMES_PER_INTERVAL
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
void setSwapInterval(int interval)
Set the swap interval of the current context and attached onscreen GLDrawable.
GLContext getContext()
Returns the GLContext associated which this GL object.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.