28package com.jogamp.newt.awt.applet;
30import java.applet.Applet;
31import java.awt.BorderLayout;
32import java.awt.Button;
33import java.awt.Component;
34import java.awt.Container;
35import java.awt.EventQueue;
36import java.awt.event.KeyListener;
37import java.awt.event.MouseListener;
38import java.awt.event.MouseMotionListener;
39import java.util.Arrays;
41import com.jogamp.nativewindow.WindowClosingProtocol.WindowClosingMode;
42import com.jogamp.opengl.FPSCounter;
43import com.jogamp.opengl.GLCapabilities;
44import com.jogamp.opengl.GLEventListener;
45import com.jogamp.opengl.GLProfile;
47import jogamp.nativewindow.jawt.JAWTUtil;
49import com.jogamp.common.util.awt.AWTEDTExecutor;
50import com.jogamp.newt.awt.NewtCanvasAWT;
51import com.jogamp.newt.opengl.GLWindow;
52import com.jogamp.newt.util.applet.JOGLNewtAppletBase;
99@SuppressWarnings(
"serial")
107 int glXd=Integer.MAX_VALUE, glYd=Integer.MAX_VALUE, glWidth=Integer.MAX_VALUE, glHeight=Integer.MAX_VALUE;
112 System.err.println(
"JOGLNewtApplet1Run.init() START - "+currentThreadName());
114 final Container container =
this;
116 String glEventListenerClazzName=
null;
117 String glProfileName=
null;
118 int glSwapInterval=1;
119 boolean glDebug=
false;
120 boolean glTrace=
false;
121 boolean glUndecorated=
false;
122 boolean glAlwaysOnTop=
false;
123 boolean glCloseable=
false;
124 boolean glOpaque=
true;
126 int glNumMultisampleBuffer=0;
127 boolean glNoDefaultKeyListener =
false;
128 boolean appletDebugTestBorder =
false;
130 glEventListenerClazzName = getParameter(
"gl_event_listener_class");
131 glProfileName = getParameter(
"gl_profile");
147 }
catch (
final Exception e) {
150 if(
null==glEventListenerClazzName) {
151 throw new RuntimeException(
"No applet parameter 'gl_event_listener_class'");
153 final boolean glStandalone = Integer.MAX_VALUE>glXd && Integer.MAX_VALUE>glYd && Integer.MAX_VALUE>glWidth && Integer.MAX_VALUE>glHeight;
155 System.err.println(
"JOGLNewtApplet1Run Configuration:");
156 System.err.println(
"glStandalone: "+glStandalone);
158 System.err.println(
"pos-size: "+glXd+
"/"+glYd+
" "+glWidth+
"x"+glHeight);
160 System.err.println(
"glEventListenerClazzName: "+glEventListenerClazzName);
161 System.err.println(
"glProfileName: "+glProfileName);
162 System.err.println(
"glSwapInterval: "+glSwapInterval);
163 System.err.println(
"glDebug: "+glDebug);
164 System.err.println(
"glTrace: "+glTrace);
165 System.err.println(
"glUndecorated: "+glUndecorated);
166 System.err.println(
"glAlwaysOnTop: "+glAlwaysOnTop);
167 System.err.println(
"glCloseable: "+glCloseable);
168 System.err.println(
"glOpaque: "+glOpaque);
169 System.err.println(
"glAlphaBits: "+glAlphaBits);
170 System.err.println(
"glNumMultisampleBuffer: "+glNumMultisampleBuffer);
171 System.err.println(
"glNoDefaultKeyListener: "+glNoDefaultKeyListener);
176 glNoDefaultKeyListener,
184 if(0<glNumMultisampleBuffer) {
194 container.setLayout(
new BorderLayout());
195 if(appletDebugTestBorder) {
196 AWTEDTExecutor.singleton.invoke(
true,
new Runnable() {
198 container.add(
new Button(
"North"), BorderLayout.NORTH);
199 container.add(
new Button(
"South"), BorderLayout.SOUTH);
200 container.add(
new Button(
"East"), BorderLayout.EAST);
201 container.add(
new Button(
"West"), BorderLayout.WEST);
208 if(glEventListener instanceof MouseListener) {
209 addMouseListener((MouseListener)glEventListener);
211 if(glEventListener instanceof MouseMotionListener) {
212 addMouseMotionListener((MouseMotionListener)glEventListener);
214 if(glEventListener instanceof KeyListener) {
215 addKeyListener((KeyListener)glEventListener);
218 if( !glStandalone ) {
219 AWTEDTExecutor.singleton.invoke(
true,
new Runnable() {
223 container.add(newtCanvasAWT, BorderLayout.CENTER);
224 container.validate();
227 }
catch (
final Throwable t) {
228 throw new RuntimeException(t);
231 System.err.println(
"JOGLNewtApplet1Run.init() END - "+currentThreadName());
235 private static String currentThreadName() {
return "["+Thread.currentThread().getName()+
", isAWT-EDT "+EventQueue.isDispatchThread()+
"]"; }
240 System.err.println(
"JOGLNewtApplet1Run.start() START (isVisible "+isVisible()+
", isDisplayable "+isDisplayable()+
") - "+currentThreadName());
242 final java.awt.Point[] p0 = {
null };
243 AWTEDTExecutor.singleton.invoke(
true,
new Runnable() {
246 p0[0] = getLocationOnScreen();
247 if(
null != newtCanvasAWT ) {
248 newtCanvasAWT.setFocusable(
true);
249 newtCanvasAWT.requestFocus();
253 if(
null == newtCanvasAWT ) {
255 glWindow.
setSize(glWidth, glHeight);
259 Component topC =
this;
260 while (
null != topC.getParent()) {
261 topC = topC.getParent();
263 System.err.println(
"JOGLNewtApplet1Run start:");
264 System.err.println(
"TopComponent: "+topC.getLocation()+
" rel, "+topC.getLocationOnScreen()+
" screen, visible "+topC.isVisible()+
", "+topC);
265 System.err.println(
"Applet Pos: "+this.getLocation()+
" rel, "+Arrays.toString(p0)+
" screen, visible "+this.isVisible()+
", "+
this);
266 if(
null != newtCanvasAWT) {
267 System.err.println(
"NewtCanvasAWT Pos: "+newtCanvasAWT.getLocation()+
" rel, "+newtCanvasAWT.getLocationOnScreen()+
" screen, visible "+newtCanvasAWT.isVisible()+
", "+newtCanvasAWT);
270 System.err.println(
"GLWindow: "+glWindow);
273 if(
null != newtCanvasAWT &&
275 0 != ( JAWTUtil.JAWT_OSX_CALAYER_QUIRK_POSITION & JAWTUtil.getOSXCALayerQuirks() ) ) {
277 AWTEDTExecutor.singleton.invoke(
true,
new Runnable() {
279 final int cW = newtCanvasAWT.getWidth();
280 final int cH = newtCanvasAWT.getHeight();
281 newtCanvasAWT.setSize(cW+1, cH+1);
282 newtCanvasAWT.setSize(cW, cH);
286 System.err.println(
"JOGLNewtApplet1Run.start() END - "+currentThreadName());
293 System.err.println(
"JOGLNewtApplet1Run.stop() START - "+currentThreadName());
297 System.err.println(
"JOGLNewtApplet1Run.stop() END - "+currentThreadName());
304 System.err.println(
"JOGLNewtApplet1Run.destroy() START - "+currentThreadName());
306 AWTEDTExecutor.singleton.invoke(
true,
new Runnable() {
309 if(
null != newtCanvasAWT ) {
311 remove(newtCanvasAWT);
320 System.err.println(
"JOGLNewtApplet1Run.destroy() END - "+currentThreadName());
void setBackgroundOpaque(final boolean opaque)
Sets whether the surface shall be opaque or translucent.
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
AWT Canvas containing a NEWT Window using native parenting.
final boolean isOffscreenLayerSurfaceEnabled()
Returns true if this instance uses an offscreen layer, otherwise false.
final void destroy()
Destroys this resource:
final void setSkipJAWTDestroy(final boolean v)
Mitigates Bug 910 (IcedTea-Web), i.e.
Simple GLEventListener deployment as an applet using JOGL.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Point getLocationOnScreen(final Point storage)
Returns the window's top-left client-area position in the screen.
WindowClosingMode setDefaultCloseOperation(final WindowClosingMode op)
final void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
final void setAlwaysOnTop(final boolean value)
final int getX()
Returns the current x position of this window, relative to it's parent.
final int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final void setUndecorated(final boolean value)
final void requestFocus()
Request focus for this native window.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Shows how to deploy an applet using JOGL.
static int str2Int(final String str, final int def)
void init(final GLWindow glWindow)
static final boolean DEBUG
static boolean str2Bool(final String str, final boolean def)
GLEventListener getGLEventListener()
Specifies a set of OpenGL capabilities.
void setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
void setSampleBuffers(final boolean enable)
Defaults to false.
Specifies the the OpenGL profile.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
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.
void setUpdateFPSFrames(int frames, PrintStream out)
static final int DEFAULT_FRAMES_PER_INTERVAL
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.