summaryrefslogtreecommitdiffstats
path: root/src/jogl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-12-19 14:54:08 +0100
committerSven Gothel <[email protected]>2010-12-19 14:54:08 +0100
commit2cbab63bd6c230d31b8ae6f1d794ad49bf23bb53 (patch)
tree9da105f466b81424ae089e59e4bd67fce7c32d54 /src/jogl
parent2323c30c23b6f9eb7d7ccf94e6cdcbcb3d2f34a6 (diff)
JOGL/NEWT: Introduce WindowClosingProtocol (solves Bug/Request 444)
Similar to JFrame's closing behavior, the following components window closing follow the new WindowClosingProtocol: - GLCanvas - GLJPanel - NEWT Window, GLWindow - NEWT NewtCanvasAWT The implementation obeys either 1) the user value set by this interface, 2) an underlying toolkit set user value (JFrame, ..) 3) or it's default, eg. {@link #DO_NOTHING_ON_CLOSE DO_NOTHING_ON_CLOSE} within an AWT environment. If none of the above determines the operation, this protocol default behavior {@link #DISPOSE_ON_CLOSE DISPOSE_ON_CLOSE} shall be used.
Diffstat (limited to 'src/jogl')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/awt/AWTUtil.java3
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/GLCanvas.java123
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/GLJPanel.java99
3 files changed, 138 insertions, 87 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/awt/AWTUtil.java b/src/jogl/classes/com/jogamp/opengl/impl/awt/AWTUtil.java
index 36c0a3250..081d1f9b3 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/awt/AWTUtil.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/awt/AWTUtil.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -38,8 +39,6 @@ package com.jogamp.opengl.impl.awt;
import com.jogamp.nativewindow.impl.jawt.*;
-import com.jogamp.opengl.impl.*;
-
import javax.media.opengl.*;
import java.lang.reflect.*;
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
index 1329977b2..9578ce291 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
@@ -40,32 +40,56 @@
package javax.media.opengl.awt;
-import com.jogamp.common.GlueGenVersion;
-import com.jogamp.common.util.VersionUtil;
-import com.jogamp.common.util.locks.RecursiveLock;
-import com.jogamp.nativewindow.NativeWindowVersion;
-import javax.media.opengl.*;
-import javax.media.nativewindow.*;
-import javax.media.nativewindow.awt.*;
-
-import com.jogamp.opengl.impl.*;
-import com.jogamp.opengl.JoglVersion;
+import java.beans.Beans;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.awt.Canvas;
import java.awt.Color;
-import java.awt.Component;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
-import java.awt.Window;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowAdapter;
-import java.awt.geom.*;
-import java.beans.*;
-import java.lang.reflect.*;
-import java.security.*;
+import java.awt.geom.Rectangle2D;
+
+import com.jogamp.common.GlueGenVersion;
+import com.jogamp.common.util.VersionUtil;
+import com.jogamp.common.util.locks.RecursiveLock;
+
+import javax.media.nativewindow.WindowClosingProtocol;
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.AbstractGraphicsScreen;
+import javax.media.nativewindow.GraphicsConfigurationFactory;
+import javax.media.nativewindow.NativeSurface;
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.nativewindow.awt.AWTGraphicsConfiguration;
+import javax.media.nativewindow.awt.AWTGraphicsDevice;
+import javax.media.nativewindow.awt.AWTGraphicsScreen;
+import javax.media.nativewindow.awt.AWTWindowClosingProtocol;
+import com.jogamp.nativewindow.NativeWindowVersion;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GLAnimatorControl;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLCapabilitiesChooser;
+import javax.media.opengl.GLCapabilitiesImmutable;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLDrawable;
+import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLException;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.GLRunnable;
+import javax.media.opengl.Threading;
+import com.jogamp.opengl.JoglVersion;
+import com.jogamp.opengl.impl.Debug;
+import com.jogamp.opengl.impl.GLContextImpl;
+import com.jogamp.opengl.impl.GLDrawableHelper;
+import com.jogamp.opengl.impl.ThreadingImpl;
// FIXME: Subclasses need to call resetGLFunctionAvailability() on their
// context whenever the displayChanged() function is called on our
@@ -105,7 +129,7 @@ import java.security.*;
* </ul>
*/
-public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
+public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosingProtocol {
private static final boolean DEBUG;
private static final GLProfile defaultGLProfile;
@@ -127,6 +151,13 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
private GLContext shareWith;
private GraphicsDevice device;
+ private AWTWindowClosingProtocol awtWindowClosingProtocol =
+ new AWTWindowClosingProtocol(this, new Runnable() {
+ public void run() {
+ GLCanvas.this.destroy();
+ }
+ });
+
/** Creates a new GLCanvas component with a default set of OpenGL
capabilities, using the default OpenGL capabilities selection
mechanism, on the default screen device. */
@@ -203,33 +234,6 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
this.device = device;
}
- protected interface DestroyMethod {
- public void destroyMethod();
- }
-
- /* package private */ final static Object addClosingListener(Component c, final DestroyMethod d) {
- WindowAdapter cl = null;
- Window w = getWindow(c);
- if(null!=w) {
- cl = new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- // we have to issue this call rigth away,
- // otherwise the window gets destroyed
- d.destroyMethod();
- }
- };
- w.addWindowListener(cl);
- }
- return cl;
- }
-
- private final static Window getWindow(Component c) {
- while ( c!=null && ! ( c instanceof Window ) ) {
- c = c.getParent();
- }
- return (Window)c;
- }
-
/**
* Overridden to choose a GraphicsConfiguration on a parent container's
* GraphicsDevice because both devices
@@ -351,8 +355,13 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
return ( null != drawable ) ? drawable.isRealized() : false;
}
- private Object closingListener = null;
- private Object closingListenerLock = new Object();
+ public int getDefaultCloseOperation() {
+ return awtWindowClosingProtocol.getDefaultCloseOperation();
+ }
+
+ public int setDefaultCloseOperation(int op) {
+ return awtWindowClosingProtocol.setDefaultCloseOperation(op);
+ }
public void display() {
if( !validateGLDrawable() ) {
@@ -360,14 +369,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
}
maybeDoSingleThreadedWorkaround(displayOnEventDispatchThreadAction,
displayAction);
- if(null==closingListener) {
- synchronized(closingListenerLock) {
- if(null==closingListener) {
- closingListener=addClosingListener(this, new DestroyMethod() {
- public void destroyMethod() { destroy(); } });
- }
- }
- }
+
+ awtWindowClosingProtocol.addClosingListenerOneShot();
}
private void dispose(boolean regenerate) {
@@ -564,6 +567,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
ex1.printStackTrace();
}
+ awtWindowClosingProtocol.removeClosingListener();
+
if (Beans.isDesignTime()) {
super.removeNotify();
} else {
@@ -685,15 +690,15 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
}
public NativeSurface getNativeSurface() {
- return drawable.getNativeSurface();
+ return (null != drawable) ? drawable.getNativeSurface() : null;
}
public long getHandle() {
- return drawable.getHandle();
+ return (null != drawable) ? drawable.getHandle() : 0;
}
public GLDrawableFactory getFactory() {
- return drawable.getFactory();
+ return (null != drawable) ? drawable.getFactory() : null;
}
public String toString() {
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
index 18ebcd129..46c799d71 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
@@ -40,19 +40,57 @@
package javax.media.opengl.awt;
-import javax.media.opengl.*;
-import javax.media.nativewindow.*;
-
-import java.awt.*;
-import java.awt.geom.*;
-import java.awt.image.*;
-import java.beans.*;
-import java.nio.*;
-import java.security.*;
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+import java.beans.Beans;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+
+import java.awt.Color;
+import java.awt.EventQueue;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsEnvironment;
+import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBufferByte;
+import java.awt.image.DataBufferInt;
import javax.swing.JPanel;
+
+import javax.media.nativewindow.WindowClosingProtocol;
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.NativeSurface;
+import javax.media.nativewindow.awt.AWTWindowClosingProtocol;
+
+import javax.media.opengl.DefaultGLCapabilitiesChooser;
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2;
+import javax.media.opengl.GL2GL3;
+import javax.media.opengl.GLAnimatorControl;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLCapabilitiesChooser;
+import javax.media.opengl.GLCapabilitiesImmutable;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLDrawable;
+import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLException;
+import javax.media.opengl.GLPbuffer;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.GLRunnable;
+import javax.media.opengl.Threading;
import com.jogamp.opengl.util.FBObject;
-import com.jogamp.opengl.impl.*;
-import com.jogamp.opengl.impl.awt.*;
+import com.jogamp.opengl.impl.Debug;
+import com.jogamp.opengl.impl.GLContextImpl;
+import com.jogamp.opengl.impl.GLDrawableFactoryImpl;
+import com.jogamp.opengl.impl.GLDrawableHelper;
+import com.jogamp.opengl.impl.GLDrawableImpl;
+import com.jogamp.opengl.impl.ThreadingImpl;
+import com.jogamp.opengl.impl.awt.Java2D;
+import com.jogamp.opengl.impl.awt.Java2DGLContext;
// FIXME: Subclasses need to call resetGLFunctionAvailability() on their
// context whenever the displayChanged() function is called on their
@@ -85,7 +123,7 @@ import com.jogamp.opengl.impl.awt.*;
* </P>
*/
-public class GLJPanel extends JPanel implements AWTGLAutoDrawable {
+public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosingProtocol {
private static final boolean DEBUG = Debug.debug("GLJPanel");
private static final boolean VERBOSE = Debug.verbose();
@@ -129,8 +167,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable {
!Debug.isPropertyDefined("jogl.gljpanel.noogl", true, localACC);
// For handling reshape events lazily
- private int reshapeX;
- private int reshapeY;
+ // private int reshapeX;
+ // private int reshapeY;
private int reshapeWidth;
private int reshapeHeight;
@@ -139,6 +177,13 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable {
private int viewportX;
private int viewportY;
+ private AWTWindowClosingProtocol awtWindowClosingProtocol =
+ new AWTWindowClosingProtocol(this, new Runnable() {
+ public void run() {
+ GLJPanel.this.destroy();
+ }
+ });
+
static {
// Force eager initialization of part of the Java2D class since
// otherwise it's likely it will try to be initialized while on
@@ -365,6 +410,9 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable {
Exception ex1 = new Exception("Info: removeNotify - start");
ex1.printStackTrace();
}
+
+ awtWindowClosingProtocol.removeClosingListener();
+
dispose(false);
if (backend != null) {
backend.destroy();
@@ -387,8 +435,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable {
public void reshape(int x, int y, int width, int height) {
super.reshape(x, y, width, height);
- reshapeX = x;
- reshapeY = y;
+ // reshapeX = x;
+ // reshapeY = y;
reshapeWidth = width;
reshapeHeight = height;
handleReshape = true;
@@ -573,17 +621,16 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable {
// a different implementation -- try again
} while (backend == null);
- if(null==closingListener) {
- synchronized(closingListenerLock) {
- if(null==closingListener) {
- closingListener=GLCanvas.addClosingListener(this, new GLCanvas.DestroyMethod() {
- public void destroyMethod() { destroy(); } });
- }
- }
- }
+ awtWindowClosingProtocol.addClosingListenerOneShot();
+ }
+
+ public int getDefaultCloseOperation() {
+ return awtWindowClosingProtocol.getDefaultCloseOperation();
+ }
+
+ public int setDefaultCloseOperation(int op) {
+ return awtWindowClosingProtocol.setDefaultCloseOperation(op);
}
- private Object closingListener = null;
- private Object closingListenerLock = new Object();
private void handleReshape() {
panelWidth = reshapeWidth;