summaryrefslogtreecommitdiffstats
path: root/src/newt/classes
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt/classes')
-rw-r--r--src/newt/classes/com/jogamp/newt/Window.java3
-rw-r--r--src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java78
-rw-r--r--src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java4
-rw-r--r--src/newt/classes/com/jogamp/newt/event/WindowAdapter.java2
-rw-r--r--src/newt/classes/com/jogamp/newt/event/WindowEvent.java12
-rw-r--r--src/newt/classes/com/jogamp/newt/event/WindowListener.java3
-rw-r--r--src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java2
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/WindowImpl.java58
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/awt/opengl/VersionApplet.java174
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java1
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java49
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java34
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java5
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java5
-rw-r--r--src/newt/classes/com/jogamp/newt/opengl/GLWindow.java62
15 files changed, 368 insertions, 124 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java
index 99db47168..9fe5089be 100644
--- a/src/newt/classes/com/jogamp/newt/Window.java
+++ b/src/newt/classes/com/jogamp/newt/Window.java
@@ -36,13 +36,14 @@ import javax.media.nativewindow.CapabilitiesChooser;
import javax.media.nativewindow.CapabilitiesImmutable;
import javax.media.nativewindow.NativeWindow;
import javax.media.nativewindow.SurfaceUpdatedListener;
+import javax.media.nativewindow.WindowClosingProtocol;
import javax.media.nativewindow.util.Insets;
/**
* Specifying the public Window functionality for the
* using a Window and for shadowing one like {@link com.jogamp.newt.opengl.GLWindow}.
*/
-public interface Window extends NativeWindow {
+public interface Window extends NativeWindow, WindowClosingProtocol {
public static final boolean DEBUG_MOUSE_EVENT = Debug.debug("Window.MouseEvent");
public static final boolean DEBUG_KEY_EVENT = Debug.debug("Window.KeyEvent");
public static final boolean DEBUG_WINDOW_EVENT = Debug.debug("Window.WindowEvent");
diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
index bee81624a..18213f94f 100644
--- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
+++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
@@ -38,21 +38,36 @@ import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.KeyboardFocusManager;
-import javax.media.nativewindow.*;
+import javax.media.nativewindow.NativeWindow;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.WindowClosingProtocol;
+import javax.media.nativewindow.awt.AWTWindowClosingProtocol;
+import com.jogamp.nativewindow.impl.awt.AWTMisc;
import com.jogamp.newt.event.awt.AWTAdapter;
import com.jogamp.newt.event.awt.AWTParentWindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.Window;
+import com.jogamp.newt.event.WindowAdapter;
+import com.jogamp.newt.event.WindowListener;
import com.jogamp.newt.impl.Debug;
+import javax.swing.MenuSelectionManager;
-public class NewtCanvasAWT extends java.awt.Canvas {
+public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProtocol {
public static final boolean DEBUG = Debug.debug("Window");
NativeWindow nativeWindow = null;
Window newtChild = null;
+ int newtChildCloseOp;
AWTAdapter awtAdapter = null;
+ private AWTWindowClosingProtocol awtWindowClosingProtocol =
+ new AWTWindowClosingProtocol(this, new Runnable() {
+ public void run() {
+ NewtCanvasAWT.this.destroy();
+ }
+ });
+
/**
* Instantiates a NewtCanvas without a NEWT child.<br>
*/
@@ -97,12 +112,18 @@ public class NewtCanvasAWT extends java.awt.Canvas {
}
FocusAction focusAction = new FocusAction();
+ WindowListener clearAWTMenusOnNewtFocus = new WindowAdapter() {
+ public void windowGainedFocus(WindowEvent arg0) {
+ MenuSelectionManager.defaultManager().clearSelectedPath();
+ }
+ };
+
/** sets a new NEWT child, provoking reparenting on the NEWT level. */
public NewtCanvasAWT setNEWTChild(Window child) {
if(newtChild!=child) {
newtChild = child;
if(null!=nativeWindow) {
- java.awt.Container cont = getContainer(this);
+ java.awt.Container cont = AWTMisc.getContainer(this);
// reparent right away, addNotify has been called already
reparentWindow( (null!=newtChild) ? true : false, cont );
}
@@ -119,24 +140,37 @@ public class NewtCanvasAWT extends java.awt.Canvas {
* or {@link #addNotify()} hasn't been called yet.*/
public NativeWindow getNativeWindow() { return nativeWindow; }
- void setWindowAdapter(boolean attach) {
+ public int getDefaultCloseOperation() {
+ return awtWindowClosingProtocol.getDefaultCloseOperation();
+ }
+
+ public int setDefaultCloseOperation(int op) {
+ return awtWindowClosingProtocol.setDefaultCloseOperation(op);
+ }
+
+ void configureNewtChild(boolean attach) {
if(null!=awtAdapter) {
awtAdapter.removeFrom(this);
awtAdapter=null;
}
- if(attach && null!=newtChild) {
- awtAdapter = new AWTParentWindowAdapter(newtChild).addTo(this);
- }
- }
-
- static java.awt.Container getContainer(java.awt.Component comp) {
- while( null != comp ) {
- if( comp instanceof java.awt.Container ) {
- return (java.awt.Container) comp;
+ if( null != newtChild ) {
+ if(attach) {
+ awtAdapter = new AWTParentWindowAdapter(newtChild).addTo(this);
+ if(newtChild.isValid()) {
+ newtChild.addWindowListener(clearAWTMenusOnNewtFocus);
+ }
+ newtChild.setFocusAction(focusAction); // enable AWT focus traversal
+ newtChildCloseOp = newtChild.setDefaultCloseOperation(WindowClosingProtocol.DO_NOTHING_ON_CLOSE);
+ awtWindowClosingProtocol.addClosingListenerOneShot();
+ } else {
+ if(newtChild.isValid()) {
+ newtChild.removeWindowListener(clearAWTMenusOnNewtFocus);
+ }
+ newtChild.setFocusAction(null);
+ newtChild.setDefaultCloseOperation(newtChildCloseOp);
+ awtWindowClosingProtocol.removeClosingListener();
}
- comp = comp.getParent();
}
- return null;
}
public void addNotify() {
@@ -150,7 +184,7 @@ public class NewtCanvasAWT extends java.awt.Canvas {
// after native peer is valid: Windows
disableBackgroundErase();
- java.awt.Container cont = getContainer(this);
+ java.awt.Container cont = AWTMisc.getContainer(this);
if(DEBUG) {
// if ( isShowing() == false ) -> Container was not visible yet.
// if ( isShowing() == true ) -> Container is already visible.
@@ -161,7 +195,7 @@ public class NewtCanvasAWT extends java.awt.Canvas {
}
public void removeNotify() {
- java.awt.Container cont = getContainer(this);
+ java.awt.Container cont = AWTMisc.getContainer(this);
if(DEBUG) {
System.err.println("NewtCanvasAWT.removeNotify: "+newtChild+", from "+cont);
}
@@ -187,13 +221,12 @@ public class NewtCanvasAWT extends java.awt.Canvas {
newtChild.setSize(w, h);
newtChild.reparentWindow(nativeWindow);
newtChild.setVisible(true);
- setWindowAdapter(true);
+ configureNewtChild(true);
newtChild.sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout to listener
newtChild.windowRepaint(0, 0, w, h);
- newtChild.setFocusAction(focusAction); // enable AWT focus traversal
}
} else {
- setWindowAdapter(false);
+ configureNewtChild(false);
nativeWindow = null;
newtChild.setVisible(false);
newtChild.reparentWindow(null);
@@ -213,10 +246,11 @@ public class NewtCanvasAWT extends java.awt.Canvas {
*/
public final void destroy() {
if(null!=newtChild) {
- java.awt.Container cont = getContainer(this);
+ java.awt.Container cont = AWTMisc.getContainer(this);
if(DEBUG) {
System.err.println("NewtCanvasAWT.destroy(): "+newtChild+", from "+cont);
}
+ configureNewtChild(false);
nativeWindow = null;
newtChild.setVisible(false);
newtChild.reparentWindow(null);
@@ -229,11 +263,13 @@ public class NewtCanvasAWT extends java.awt.Canvas {
}
public void paint(Graphics g) {
+ awtWindowClosingProtocol.addClosingListenerOneShot();
if(null!=newtChild) {
newtChild.windowRepaint(0, 0, getWidth(), getHeight());
}
}
public void update(Graphics g) {
+ awtWindowClosingProtocol.addClosingListenerOneShot();
if(null!=newtChild) {
newtChild.windowRepaint(0, 0, getWidth(), getHeight());
}
diff --git a/src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java
index 88b165a8d..8542820c4 100644
--- a/src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java
@@ -52,6 +52,10 @@ public class TraceWindowAdapter implements WindowListener {
System.err.println(e);
if(null!=downstream) { downstream.windowDestroyNotify(e); }
}
+ public void windowDestroyed(WindowEvent e) {
+ System.err.println(e);
+ if(null!=downstream) { downstream.windowDestroyed(e); }
+ }
public void windowGainedFocus(WindowEvent e) {
System.err.println(e);
if(null!=downstream) { downstream.windowGainedFocus(e); }
diff --git a/src/newt/classes/com/jogamp/newt/event/WindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/WindowAdapter.java
index a1ad43a13..b9e487e9b 100644
--- a/src/newt/classes/com/jogamp/newt/event/WindowAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/WindowAdapter.java
@@ -36,6 +36,8 @@ public abstract class WindowAdapter implements WindowListener
}
public void windowDestroyNotify(WindowEvent e) {
}
+ public void windowDestroyed(WindowEvent e) {
+ }
public void windowGainedFocus(WindowEvent e) {
}
public void windowLostFocus(WindowEvent e) {
diff --git a/src/newt/classes/com/jogamp/newt/event/WindowEvent.java b/src/newt/classes/com/jogamp/newt/event/WindowEvent.java
index 2742e0d95..f3d62d8c6 100644
--- a/src/newt/classes/com/jogamp/newt/event/WindowEvent.java
+++ b/src/newt/classes/com/jogamp/newt/event/WindowEvent.java
@@ -46,6 +46,7 @@ public class WindowEvent extends NEWTEvent {
public static final int EVENT_WINDOW_GAINED_FOCUS = 103;
public static final int EVENT_WINDOW_LOST_FOCUS = 104;
public static final int EVENT_WINDOW_REPAINT = 105;
+ public static final int EVENT_WINDOW_DESTROYED = 106;
public WindowEvent(int eventType, Object source, long when) {
super(eventType, source, when);
@@ -54,11 +55,12 @@ public class WindowEvent extends NEWTEvent {
public static String getEventTypeString(int type) {
switch(type) {
case EVENT_WINDOW_RESIZED: return "WINDOW_RESIZED";
- case EVENT_WINDOW_MOVED: return "WINDOW_MOVED";
- case EVENT_WINDOW_DESTROY_NOTIFY: return "EVENT_WINDOW_DESTROY_NOTIFY";
- case EVENT_WINDOW_GAINED_FOCUS: return "EVENT_WINDOW_GAINED_FOCUS";
- case EVENT_WINDOW_LOST_FOCUS: return "EVENT_WINDOW_LOST_FOCUS";
- case EVENT_WINDOW_REPAINT: return "EVENT_WINDOW_REPAINT";
+ case EVENT_WINDOW_MOVED: return "WINDOW_MOVED";
+ case EVENT_WINDOW_DESTROY_NOTIFY: return "EVENT_WINDOW_DESTROY_NOTIFY";
+ case EVENT_WINDOW_GAINED_FOCUS: return "EVENT_WINDOW_GAINED_FOCUS";
+ case EVENT_WINDOW_LOST_FOCUS: return "EVENT_WINDOW_LOST_FOCUS";
+ case EVENT_WINDOW_REPAINT: return "EVENT_WINDOW_REPAINT";
+ case EVENT_WINDOW_DESTROYED: return "EVENT_WINDOW_DESTROYED";
default: return "unknown (" + type + ")";
}
}
diff --git a/src/newt/classes/com/jogamp/newt/event/WindowListener.java b/src/newt/classes/com/jogamp/newt/event/WindowListener.java
index 0d201a2a4..e841a06cf 100644
--- a/src/newt/classes/com/jogamp/newt/event/WindowListener.java
+++ b/src/newt/classes/com/jogamp/newt/event/WindowListener.java
@@ -44,6 +44,9 @@ public interface WindowListener extends NEWTEventListener {
/** Window will be destroyed. Release of resources is recommended. */
public void windowDestroyNotify(WindowEvent e);
+ /** Window has been destroyed.*/
+ public void windowDestroyed(WindowEvent e);
+
/** Window gained focus. */
public void windowGainedFocus(WindowEvent e);
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java
index 8e33285bf..20c0d15d1 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java
@@ -39,7 +39,7 @@ class AWTNewtEventFactory {
map.setKeyNotFoundValue(-1);
// n/a map.put(java.awt.event.WindowEvent.WINDOW_OPENED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_OPENED);
map.put(java.awt.event.WindowEvent.WINDOW_CLOSING, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
- // n/a map.put(java.awt.event.WindowEvent.WINDOW_CLOSED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_CLOSED);
+ map.put(java.awt.event.WindowEvent.WINDOW_CLOSED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_DESTROYED);
// n/a map.put(java.awt.event.WindowEvent.WINDOW_ICONIFIED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_ICONIFIED);
// n/a map.put(java.awt.event.WindowEvent.WINDOW_DEICONIFIED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_DEICONIFIED);
map.put(java.awt.event.WindowEvent.WINDOW_ACTIVATED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS);
diff --git a/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java b/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java
index eb46ef99e..74186f70f 100644
--- a/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java
+++ b/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java
@@ -34,6 +34,9 @@
package com.jogamp.newt.impl;
+import java.util.ArrayList;
+import java.lang.reflect.Method;
+
import com.jogamp.common.util.ReflectionUtil;
import com.jogamp.newt.NewtFactory;
import com.jogamp.newt.Display;
@@ -52,8 +55,6 @@ import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.event.WindowListener;
import com.jogamp.newt.event.WindowUpdateEvent;
-import java.util.ArrayList;
-import java.lang.reflect.Method;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.CapabilitiesChooser;
@@ -372,6 +373,26 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
protected void unlockSurfaceImpl() { }
//----------------------------------------------------------------------
+ // WindowClosingProtocol implementation
+ //
+ private Object closingListenerLock = new Object();
+ private int defaultCloseOperation = DISPOSE_ON_CLOSE;
+
+ public int getDefaultCloseOperation() {
+ synchronized (closingListenerLock) {
+ return defaultCloseOperation;
+ }
+ }
+
+ public int setDefaultCloseOperation(int op) {
+ synchronized (closingListenerLock) {
+ int _op = defaultCloseOperation;
+ defaultCloseOperation = op;
+ return _op;
+ }
+ }
+
+ //----------------------------------------------------------------------
// Window: Native implementation
//
@@ -466,11 +487,12 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
public final void unlockSurface() {
// may throw RuntimeException if not locked
windowLock.validateLocked();
+ AbstractGraphicsDevice adevice = screen.getDisplay().getGraphicsDevice();
try {
unlockSurfaceImpl();
} finally {
- screen.getDisplay().getGraphicsDevice().unlock();
+ adevice.unlock();
}
windowLock.unlock();
}
@@ -586,11 +608,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
public void run() {
windowLock.lock();
try {
- if(DEBUG_IMPLEMENTATION) {
- String msg = new String("Window setVisible: START ("+getThreadName()+") "+x+"/"+y+" "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible: "+WindowImpl.this.visible+" -> "+visible+", parentWindowHandle "+toHexString(WindowImpl.this.parentWindowHandle)+", parentWindow "+(null!=WindowImpl.this.parentWindow)/*+", "+this*/);
- System.err.println(msg);
- }
-
if(null!=lifecycleHook) {
lifecycleHook.resetCounter();
}
@@ -651,6 +668,12 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
// fast-path: not realized yet, make visible, but zero size
return;
}
+
+ if(DEBUG_IMPLEMENTATION) {
+ String msg = new String("Window setVisible: START ("+getThreadName()+") "+x+"/"+y+" "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible: "+this.visible+" -> "+visible+", parentWindowHandle "+toHexString(parentWindowHandle)+", parentWindow "+(null!=parentWindow)/*+", "+this*/);
+ System.err.println(msg);
+ Thread.dumpStack();
+ }
VisibleAction visibleAction = new VisibleAction(visible);
runOnEDTIfAvail(true, visibleAction);
}
@@ -737,11 +760,15 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
if(null!=lifecycleHook) {
+ // send synced destroy notification for proper cleanup, eg GLWindow/OpenGL
lifecycleHook.destroyActionInLock();
}
closeAndInvalidate();
+ // send synced destroyed notification
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROYED);
+
if(DEBUG_IMPLEMENTATION) {
System.err.println("Window.destroy() END "+getThreadName()/*+", "+WindowImpl.this*/);
}
@@ -2006,6 +2033,9 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
case WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY:
l.windowDestroyNotify(e);
break;
+ case WindowEvent.EVENT_WINDOW_DESTROYED:
+ l.windowDestroyed(e);
+ break;
case WindowEvent.EVENT_WINDOW_GAINED_FOCUS:
l.windowGainedFocus(e);
break;
@@ -2097,9 +2127,10 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
System.err.println("Window.windowDestroyNotify START "+getThreadName());
}
- enqueueWindowEvent(false, WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
+ // send synced destroy notifications
+ enqueueWindowEvent(true, WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
- if(handleDestroyNotify && isValid()) {
+ if(handleDestroyNotify && DISPOSE_ON_CLOSE == defaultCloseOperation && isValid()) {
destroy();
}
@@ -2108,13 +2139,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
- protected void windowDestroyed() {
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.windowDestroyed "+getThreadName());
- }
- closeAndInvalidate();
- }
-
public void windowRepaint(int x, int y, int width, int height) {
if(DEBUG_IMPLEMENTATION) {
System.err.println("Window.windowRepaint "+getThreadName()+" - "+x+"/"+y+" "+width+"x"+height);
diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/opengl/VersionApplet.java b/src/newt/classes/com/jogamp/newt/impl/awt/opengl/VersionApplet.java
new file mode 100644
index 000000000..f31d1bc0f
--- /dev/null
+++ b/src/newt/classes/com/jogamp/newt/impl/awt/opengl/VersionApplet.java
@@ -0,0 +1,174 @@
+package com.jogamp.newt.impl.awt.opengl;
+
+import java.applet.Applet;
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.Frame;
+import java.awt.GridLayout;
+import java.awt.TextArea;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import java.util.List;
+
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLCanvas;
+import javax.media.opengl.GL;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLCapabilitiesImmutable;
+import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLEventListener;
+
+import com.jogamp.common.GlueGenVersion;
+import com.jogamp.common.os.Platform;
+import com.jogamp.common.util.VersionUtil;
+import com.jogamp.nativewindow.NativeWindowVersion;
+import com.jogamp.newt.NewtVersion;
+import com.jogamp.opengl.JoglVersion;
+
+public class VersionApplet extends Applet {
+ static {
+ GLProfile.initSingleton(false);
+ }
+ TextArea tareaVersion;
+ TextArea tareaCaps;
+ GLCanvas canvas;
+
+ public static void main(String[] args) {
+ Frame frame = new Frame("JOGL Version Applet");
+ frame.setSize(800, 600);
+ frame.setLayout(new BorderLayout());
+
+ VersionApplet va = new VersionApplet();
+ frame.addWindowListener(new ClosingWindowAdapter(frame, va));
+
+ va.init();
+ frame.add(va, BorderLayout.CENTER);
+ frame.validate();
+
+ frame.setVisible(true);
+ va.start();
+ }
+
+ static class ClosingWindowAdapter extends WindowAdapter {
+ Frame f;
+ VersionApplet va;
+ public ClosingWindowAdapter(Frame f, VersionApplet va) {
+ this.f = f;
+ this.va = va;
+ }
+ public void windowClosing(WindowEvent ev) {
+ f.setVisible(false);
+ va.stop();
+ va.destroy();
+ f.remove(va);
+ f.dispose();
+ System.exit(0);
+ }
+ }
+
+ private synchronized void my_init() {
+ if(null != canvas) { return; }
+
+ GLProfile glp = GLProfile.getDefault();
+ GLCapabilities glcaps = new GLCapabilities(glp);
+
+ setLayout(new BorderLayout());
+ String s;
+
+ tareaVersion = new TextArea(120, 60);
+ s = VersionUtil.getPlatformInfo().toString();
+ System.err.println(s);
+ tareaVersion.append(s);
+
+ s = GlueGenVersion.getInstance().toString();
+ System.err.println(s);
+ tareaVersion.append(s);
+
+ s = NativeWindowVersion.getInstance().toString();
+ System.err.println(s);
+ tareaVersion.append(NativeWindowVersion.getInstance().toString());
+
+ s = JoglVersion.getInstance().toString();
+ System.err.println(s);
+ tareaVersion.append(s);
+
+ s = NewtVersion.getInstance().toString();
+ System.err.println(s);
+ tareaVersion.append(s);
+
+ tareaCaps = new TextArea(120, 20);
+ GLDrawableFactory factory = GLDrawableFactory.getFactory(glp);
+ List/*<GLCapabilitiesImmutable>*/ availCaps = factory.getAvailableCapabilities(null);
+ for(int i=0; i<availCaps.size(); i++) {
+ s = ((GLCapabilitiesImmutable) availCaps.get(i)).toString();
+ System.err.println(s);
+ tareaCaps.append(s);
+ tareaCaps.append(Platform.getNewline());
+ }
+
+ Container grid = new Container();
+ grid.setLayout(new GridLayout(2, 1));
+ grid.add(tareaVersion);
+ grid.add(tareaCaps);
+ add(grid, BorderLayout.CENTER);
+
+ canvas = new GLCanvas(glcaps);
+ canvas.addGLEventListener(new GLInfo());
+ canvas.setSize(10, 10);
+ add(canvas, BorderLayout.SOUTH);
+ validate();
+ }
+
+ private synchronized void my_release() {
+ if(null!=canvas) {
+ remove(canvas);
+ canvas.destroy();
+ canvas = null;
+ remove(tareaVersion);
+ tareaVersion=null;
+ }
+ }
+
+ public void init() {
+ System.err.println("VersionApplet: init() - begin");
+ my_init();
+ System.err.println("VersionApplet: init() - end");
+ }
+
+ public void start() {
+ System.err.println("VersionApplet: start() - begin");
+ System.err.println("VersionApplet: start() - end");
+ }
+
+ public void stop() {
+ System.err.println("VersionApplet: stop() - begin");
+ System.err.println("VersionApplet: stop() - end");
+ }
+
+ public void destroy() {
+ System.err.println("VersionApplet: destroy() - start");
+ my_release();
+ System.err.println("VersionApplet: destroy() - end");
+ }
+
+ class GLInfo implements GLEventListener {
+ public void init(GLAutoDrawable drawable) {
+ GL gl = drawable.getGL();
+ String s = JoglVersion.getInstance().getGLInfo(gl, null).toString();
+ System.err.println(s);
+ tareaVersion.append(s);
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ }
+ }
+
+}
diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java
index c01139b78..e789a0dc9 100644
--- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java
+++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java
@@ -166,7 +166,6 @@ public class MacWindow extends WindowImpl {
setWindowHandle(0);
nsViewLock.unlock();
}
- windowDestroyed(); // No OSX hook for DidClose, so do it here
}
public final long getSurfaceHandle() {
diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java
index 372859208..af32d1693 100644
--- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java
+++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008 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
@@ -33,73 +34,61 @@
package com.jogamp.newt.impl.windows;
-import javax.media.nativewindow.*;
-import javax.media.nativewindow.windows.*;
-import com.jogamp.newt.*;
-import com.jogamp.newt.impl.*;
+import com.jogamp.nativewindow.impl.windows.RegisteredClass;
+import com.jogamp.nativewindow.impl.windows.RegisteredClassFactory;
+import com.jogamp.newt.impl.DisplayImpl;
+import com.jogamp.newt.impl.NEWTJNILibLoader;
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.windows.WindowsGraphicsDevice;
public class WindowsDisplay extends DisplayImpl {
- protected static final String WINDOW_CLASS_NAME = "NewtWindowClass";
- private static int windowClassAtom;
- private static long hInstance;
+ private static final String newtClassBaseName = "_newt_clazz" ;
+ private static RegisteredClassFactory sharedClassFactory;
static {
NEWTJNILibLoader.loadNEWT();
if (!WindowsWindow.initIDs0()) {
throw new NativeWindowException("Failed to initialize WindowsWindow jmethodIDs");
- }
+ }
+ sharedClassFactory = new RegisteredClassFactory(newtClassBaseName, WindowsWindow.getNewtWndProc0());
}
public static void initSingleton() {
// just exist to ensure static init has been run
}
+ private RegisteredClass sharedClass;
public WindowsDisplay() {
}
protected void createNativeImpl() {
+ sharedClass = sharedClassFactory.getSharedClass();
aDevice = new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT);
}
protected void closeNativeImpl() {
- // Can't do .. only at application shutdown
- // UnregisterWindowClass0(getWindowClassAtom(), getHInstance());
+ sharedClassFactory.releaseSharedClass();
}
protected void dispatchMessagesNative() {
DispatchMessages0();
}
- protected static synchronized int getWindowClassAtom() {
- if(0 == windowClassAtom) {
- windowClassAtom = RegisterWindowClass0(WINDOW_CLASS_NAME, getHInstance());
- if (0 == windowClassAtom) {
- throw new NativeWindowException("Error while registering window class");
- }
- }
- return windowClassAtom;
+ protected long getHInstance() {
+ return sharedClass.getHandle();
}
- protected static synchronized long getHInstance() {
- if(0 == hInstance) {
- hInstance = LoadLibraryW0("newt");
- if (0 == hInstance) {
- throw new NativeWindowException("Error finding HINSTANCE for \"newt\"");
- }
- }
- return hInstance;
+ protected String getWindowClassName() {
+ return sharedClass.getName();
}
//----------------------------------------------------------------------
// Internals only
//
- private static native long LoadLibraryW0(String libraryName);
- private static native int RegisterWindowClass0(String windowClassName, long hInstance);
- private static native void UnregisterWindowClass0(int wndClassAtom, long hInstance);
-
private static native void DispatchMessages0();
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java
index d4f4f77ea..5ab0a5b79 100644
--- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java
+++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java
@@ -35,8 +35,9 @@
package com.jogamp.newt.impl.windows;
import com.jogamp.nativewindow.impl.windows.GDI;
-import javax.media.nativewindow.*;
import com.jogamp.newt.impl.WindowImpl;
+import javax.media.nativewindow.GraphicsConfigurationFactory;
+import javax.media.nativewindow.NativeWindowException;
import javax.media.nativewindow.util.Insets;
import javax.media.nativewindow.util.Point;
@@ -56,7 +57,7 @@ public class WindowsWindow extends WindowImpl {
protected int lockSurfaceImpl() {
if( 0 != getWindowHandle() && 0 == hdc ) {
- hdc = GetDC0(getWindowHandle());
+ hdc = GDI.GetDC(getWindowHandle());
hmon = MonitorFromWindow0(getWindowHandle());
}
return ( 0 != hdc ) ? LOCK_SUCCESS : LOCK_SURFACE_NOT_READY;
@@ -64,7 +65,7 @@ public class WindowsWindow extends WindowImpl {
protected void unlockSurfaceImpl() {
if ( 0 != hdc && 0 != getWindowHandle() && getWindowLockRecursionCount() == 0) {
- ReleaseDC0(getWindowHandle(), hdc);
+ GDI.ReleaseDC(getWindowHandle(), hdc);
hdc=0;
}
}
@@ -97,9 +98,8 @@ public class WindowsWindow extends WindowImpl {
if (config == null) {
throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
}
- setWindowHandle(CreateWindow0(getParentWindowHandle(),
- display.getWindowClassAtom(), display.WINDOW_CLASS_NAME, display.getHInstance(),
- 0, undecorated, x, y, width, height));
+ setWindowHandle(CreateWindow0(display.getHInstance(), display.getWindowClassName(), display.getWindowClassName(),
+ getParentWindowHandle(), 0, undecorated, x, y, width, height));
if (getWindowHandle() == 0) {
throw new NativeWindowException("Error creating window");
}
@@ -116,7 +116,7 @@ public class WindowsWindow extends WindowImpl {
if (hdc != 0) {
if(windowHandleClose != 0) {
try {
- ReleaseDC0(windowHandleClose, hdc);
+ GDI.ReleaseDC(windowHandleClose, hdc);
} catch (Throwable t) {
if(DEBUG_IMPLEMENTATION) {
Exception e = new Exception("Warning: closeNativeImpl failed - "+Thread.currentThread().getName(), t);
@@ -128,7 +128,7 @@ public class WindowsWindow extends WindowImpl {
}
if(windowHandleClose != 0) {
try {
- DestroyWindow0(windowHandleClose);
+ GDI.DestroyWindow(windowHandleClose);
} catch (Throwable t) {
if(DEBUG_IMPLEMENTATION) {
Exception e = new Exception("Warning: closeNativeImpl failed - "+Thread.currentThread().getName(), t);
@@ -140,11 +140,6 @@ public class WindowsWindow extends WindowImpl {
}
}
- protected void windowDestroyed() {
- windowHandleClose = 0;
- super.windowDestroyed();
- }
-
protected void setVisibleImpl(boolean visible, int x, int y, int width, int height) {
setVisible0(getWindowHandle(), visible, (getParentWindowHandle()==0)?true:false, x, y, width, height);
visibleChanged(visible);
@@ -177,14 +172,11 @@ public class WindowsWindow extends WindowImpl {
// Internals only
//
protected static native boolean initIDs0();
- private native long CreateWindow0(long parentWindowHandle,
- int wndClassAtom, String wndName,
- long hInstance, long visualID,
- boolean isUndecorated,
- int x, int y, int width, int height);
- private native void DestroyWindow0(long windowHandle);
- private native long GetDC0(long windowHandle);
- private native void ReleaseDC0(long windowHandle, long hdc);
+ protected static native long getNewtWndProc0();
+
+ private native long CreateWindow0(long hInstance, String wndClassName, String wndName,
+ long parentWindowHandle, long visualID, boolean isUndecorated,
+ int x, int y, int width, int height);
private native long MonitorFromWindow0(long windowHandle);
private native void setVisible0(long windowHandle, boolean visible, boolean top, int x, int y, int width, int height);
private native void reconfigureWindow0(long parentWindowHandle, long windowHandle,
diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java
index 1aaffacb5..af05c0356 100644
--- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java
+++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java
@@ -76,9 +76,8 @@ public class X11Display extends DisplayImpl {
throw e;
}
aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, NativeWindowFactory.getNullToolkitLock());
- // aDevice = new X11GraphicsDevice(handle, NativeWindowFactory.createDefaultToolkitLockNoAWT(NativeWindowFactory.TYPE_X11, handle));
- // aDevice = new X11GraphicsDevice(handle);
-
+ // aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, NativeWindowFactory.createDefaultToolkitLockNoAWT(NativeWindowFactory.TYPE_X11, handle));
+ // aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT);
}
protected void closeNativeImpl() {
diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java
index 73c6eb351..b8f1a0c95 100644
--- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java
+++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java
@@ -87,11 +87,6 @@ public class X11Window extends WindowImpl {
}
}
- protected void windowDestroyed() {
- windowHandleClose = 0;
- super.windowDestroyed();
- }
-
protected void setVisibleImpl(boolean visible, int x, int y, int width, int height) {
setVisible0(getDisplayHandle(), getWindowHandle(), visible, x, y, width, height);
}
diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
index 358a3d4ce..6886fc71b 100644
--- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
+++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
@@ -34,18 +34,22 @@
package com.jogamp.newt.opengl;
+import java.util.List;
+
import com.jogamp.common.GlueGenVersion;
import com.jogamp.common.util.VersionUtil;
import com.jogamp.nativewindow.NativeWindowVersion;
import com.jogamp.newt.*;
import com.jogamp.newt.event.*;
import com.jogamp.newt.impl.WindowImpl;
+
import javax.media.nativewindow.*;
import javax.media.nativewindow.util.Point;
+import javax.media.nativewindow.util.Insets;
import javax.media.opengl.*;
+
import com.jogamp.opengl.impl.GLDrawableHelper;
import com.jogamp.opengl.JoglVersion;
-import javax.media.nativewindow.util.Insets;
/**
* An implementation of {@link javax.media.opengl.GLAutoDrawable} interface,
@@ -85,24 +89,26 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer {
}
public void windowDestroyNotify(WindowEvent e) {
- // Is an animator thread perform rendering?
- if (GLWindow.this.helper.isExternalAnimatorRunning()) {
- // Pause animations before initiating safe destroy.
- GLAnimatorControl ctrl = GLWindow.this.helper.getAnimator();
- boolean isPaused = ctrl.pause();
- destroy();
- if(isPaused) {
- ctrl.resume();
+ if( DISPOSE_ON_CLOSE == GLWindow.this.getDefaultCloseOperation() ) {
+ // Is an animator thread perform rendering?
+ if (GLWindow.this.helper.isExternalAnimatorRunning()) {
+ // Pause animations before initiating safe destroy.
+ GLAnimatorControl ctrl = GLWindow.this.helper.getAnimator();
+ boolean isPaused = ctrl.pause();
+ destroy();
+ if(isPaused) {
+ ctrl.resume();
+ }
+ } else if (GLWindow.this.window.isSurfaceLockedByOtherThread()) {
+ // Surface is locked by another thread
+ // Flag that destroy should be performed on the next
+ // attempt to display.
+ sendDestroy = true;
+ } else {
+ // Without an external thread animating or locking the
+ // surface, we are safe.
+ destroy ();
}
- } else if (GLWindow.this.window.isSurfaceLockedByOtherThread()) {
- // Surface is locked by another thread
- // Flag that destroy should be performed on the next
- // attempt to display.
- sendDestroy = true;
- } else {
- // Without an external thread animating or locking the
- // surface, we are safe.
- destroy ();
}
}
});
@@ -152,6 +158,17 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer {
}
//----------------------------------------------------------------------
+ // WindowClosingProtocol implementation
+ //
+ public int getDefaultCloseOperation() {
+ return window.getDefaultCloseOperation();
+ }
+
+ public int setDefaultCloseOperation(int op) {
+ return window.setDefaultCloseOperation(op);
+ }
+
+ //----------------------------------------------------------------------
// Window Access
//
@@ -882,7 +899,14 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer {
System.err.println(NativeWindowVersion.getInstance());
System.err.println(JoglVersion.getInstance());
System.err.println(NewtVersion.getInstance());
- GLCapabilitiesImmutable caps = new GLCapabilities( GLProfile.getDefault() );
+
+ GLProfile glp = GLProfile.getDefault();
+ GLDrawableFactory factory = GLDrawableFactory.getFactory(glp);
+ List/*<GLCapabilitiesImmutable>*/ availCaps = factory.getAvailableCapabilities(null);
+ for(int i=0; i<availCaps.size(); i++) {
+ System.err.println(availCaps.get(i));
+ }
+ GLCapabilitiesImmutable caps = new GLCapabilities( glp );
GLWindow glWindow = GLWindow.create(caps);
glWindow.setSize(128, 128);