From 6e273ec07af21ad3c2a1b50fece9f46a3cc92658 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 24 Apr 2010 14:27:18 +0200 Subject: NEWT Cleanup - Moved all implementation details (awt/x11/windows/macosx/..) to com.jogamp.newt.impl - Moved awt event handling com.jogamp.newt.awt.event -> com.jogamp.newt.event.awt - NEWTEvent extends java.util.EventObject - NEWTEventListener extends java.util.EventListener - Added Trace*Adapter, logging the event, incl. the time lag --- src/newt/classes/com/jogamp/newt/Display.java | 18 +- src/newt/classes/com/jogamp/newt/Screen.java | 10 +- src/newt/classes/com/jogamp/newt/Window.java | 12 +- .../classes/com/jogamp/newt/awt/AWTCanvas.java | 264 ---------- .../classes/com/jogamp/newt/awt/AWTDisplay.java | 59 --- .../classes/com/jogamp/newt/awt/AWTScreen.java | 65 --- .../classes/com/jogamp/newt/awt/AWTWindow.java | 335 ------------ .../com/jogamp/newt/awt/event/AWTAdapter.java | 155 ------ .../com/jogamp/newt/awt/event/AWTKeyAdapter.java | 80 --- .../com/jogamp/newt/awt/event/AWTMouseAdapter.java | 117 ----- .../jogamp/newt/awt/event/AWTNewtEventFactory.java | 140 ----- .../jogamp/newt/awt/event/AWTWindowAdapter.java | 126 ----- src/newt/classes/com/jogamp/newt/event/Event.java | 139 ----- .../com/jogamp/newt/event/EventListener.java | 46 -- .../classes/com/jogamp/newt/event/InputEvent.java | 4 +- .../classes/com/jogamp/newt/event/KeyListener.java | 2 +- .../com/jogamp/newt/event/MouseListener.java | 2 +- .../classes/com/jogamp/newt/event/NEWTEvent.java | 133 +++++ .../com/jogamp/newt/event/NEWTEventListener.java | 46 ++ .../classes/com/jogamp/newt/event/PaintEvent.java | 2 +- .../com/jogamp/newt/event/TraceKeyAdapter.java | 60 +++ .../com/jogamp/newt/event/TraceMouseAdapter.java | 81 +++ .../com/jogamp/newt/event/TraceWindowAdapter.java | 68 +++ .../classes/com/jogamp/newt/event/WindowEvent.java | 2 +- .../com/jogamp/newt/event/WindowListener.java | 2 +- .../com/jogamp/newt/event/awt/AWTAdapter.java | 155 ++++++ .../com/jogamp/newt/event/awt/AWTKeyAdapter.java | 80 +++ .../com/jogamp/newt/event/awt/AWTMouseAdapter.java | 117 +++++ .../jogamp/newt/event/awt/AWTNewtEventFactory.java | 140 +++++ .../jogamp/newt/event/awt/AWTWindowAdapter.java | 126 +++++ .../com/jogamp/newt/impl/awt/AWTCanvas.java | 264 ++++++++++ .../com/jogamp/newt/impl/awt/AWTDisplay.java | 59 +++ .../com/jogamp/newt/impl/awt/AWTScreen.java | 65 +++ .../com/jogamp/newt/impl/awt/AWTWindow.java | 335 ++++++++++++ .../com/jogamp/newt/impl/intel/gdl/Display.java | 104 ++++ .../com/jogamp/newt/impl/intel/gdl/Screen.java | 68 +++ .../com/jogamp/newt/impl/intel/gdl/Window.java | 179 +++++++ .../com/jogamp/newt/impl/macosx/MacDisplay.java | 82 +++ .../com/jogamp/newt/impl/macosx/MacScreen.java | 56 ++ .../com/jogamp/newt/impl/macosx/MacWindow.java | 575 +++++++++++++++++++++ .../newt/impl/opengl/broadcom/egl/Display.java | 81 +++ .../newt/impl/opengl/broadcom/egl/Screen.java | 62 +++ .../newt/impl/opengl/broadcom/egl/Window.java | 154 ++++++ .../com/jogamp/newt/impl/opengl/kd/KDDisplay.java | 84 +++ .../com/jogamp/newt/impl/opengl/kd/KDScreen.java | 57 ++ .../com/jogamp/newt/impl/opengl/kd/KDWindow.java | 154 ++++++ .../jogamp/newt/impl/windows/WindowsDisplay.java | 105 ++++ .../jogamp/newt/impl/windows/WindowsScreen.java | 57 ++ .../jogamp/newt/impl/windows/WindowsWindow.java | 290 +++++++++++ .../com/jogamp/newt/impl/x11/X11Display.java | 118 +++++ .../com/jogamp/newt/impl/x11/X11Screen.java | 69 +++ .../com/jogamp/newt/impl/x11/X11Window.java | 203 ++++++++ .../classes/com/jogamp/newt/intel/gdl/Display.java | 104 ---- .../classes/com/jogamp/newt/intel/gdl/Screen.java | 68 --- .../classes/com/jogamp/newt/intel/gdl/Window.java | 179 ------- .../classes/com/jogamp/newt/macosx/MacDisplay.java | 82 --- .../classes/com/jogamp/newt/macosx/MacScreen.java | 56 -- .../classes/com/jogamp/newt/macosx/MacWindow.java | 575 --------------------- .../jogamp/newt/opengl/broadcom/egl/Display.java | 81 --- .../jogamp/newt/opengl/broadcom/egl/Screen.java | 62 --- .../jogamp/newt/opengl/broadcom/egl/Window.java | 154 ------ .../com/jogamp/newt/opengl/kd/KDDisplay.java | 84 --- .../com/jogamp/newt/opengl/kd/KDScreen.java | 57 -- .../com/jogamp/newt/opengl/kd/KDWindow.java | 154 ------ .../classes/com/jogamp/newt/util/MainThread.java | 2 +- .../com/jogamp/newt/windows/WindowsDisplay.java | 105 ---- .../com/jogamp/newt/windows/WindowsScreen.java | 57 -- .../com/jogamp/newt/windows/WindowsWindow.java | 290 ----------- .../classes/com/jogamp/newt/x11/X11Display.java | 118 ----- .../classes/com/jogamp/newt/x11/X11Screen.java | 69 --- .../classes/com/jogamp/newt/x11/X11Window.java | 203 -------- 71 files changed, 4255 insertions(+), 4052 deletions(-) delete mode 100644 src/newt/classes/com/jogamp/newt/awt/AWTCanvas.java delete mode 100644 src/newt/classes/com/jogamp/newt/awt/AWTDisplay.java delete mode 100644 src/newt/classes/com/jogamp/newt/awt/AWTScreen.java delete mode 100644 src/newt/classes/com/jogamp/newt/awt/AWTWindow.java delete mode 100644 src/newt/classes/com/jogamp/newt/awt/event/AWTAdapter.java delete mode 100644 src/newt/classes/com/jogamp/newt/awt/event/AWTKeyAdapter.java delete mode 100644 src/newt/classes/com/jogamp/newt/awt/event/AWTMouseAdapter.java delete mode 100644 src/newt/classes/com/jogamp/newt/awt/event/AWTNewtEventFactory.java delete mode 100644 src/newt/classes/com/jogamp/newt/awt/event/AWTWindowAdapter.java delete mode 100644 src/newt/classes/com/jogamp/newt/event/Event.java delete mode 100644 src/newt/classes/com/jogamp/newt/event/EventListener.java create mode 100644 src/newt/classes/com/jogamp/newt/event/NEWTEvent.java create mode 100644 src/newt/classes/com/jogamp/newt/event/NEWTEventListener.java create mode 100644 src/newt/classes/com/jogamp/newt/event/TraceKeyAdapter.java create mode 100644 src/newt/classes/com/jogamp/newt/event/TraceMouseAdapter.java create mode 100644 src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java create mode 100644 src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java create mode 100644 src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java create mode 100644 src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java create mode 100644 src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java create mode 100644 src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java create mode 100644 src/newt/classes/com/jogamp/newt/impl/awt/AWTCanvas.java create mode 100644 src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java create mode 100644 src/newt/classes/com/jogamp/newt/impl/awt/AWTScreen.java create mode 100644 src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java create mode 100644 src/newt/classes/com/jogamp/newt/impl/intel/gdl/Display.java create mode 100644 src/newt/classes/com/jogamp/newt/impl/intel/gdl/Screen.java create mode 100644 src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java create mode 100755 src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java create mode 100755 src/newt/classes/com/jogamp/newt/impl/macosx/MacScreen.java create mode 100755 src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java create mode 100644 src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Display.java create mode 100755 src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Screen.java create mode 100755 src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java create mode 100755 src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java create mode 100755 src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDScreen.java create mode 100755 src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java create mode 100755 src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java create mode 100755 src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java create mode 100755 src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java create mode 100755 src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java create mode 100755 src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java create mode 100755 src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java delete mode 100644 src/newt/classes/com/jogamp/newt/intel/gdl/Display.java delete mode 100644 src/newt/classes/com/jogamp/newt/intel/gdl/Screen.java delete mode 100644 src/newt/classes/com/jogamp/newt/intel/gdl/Window.java delete mode 100755 src/newt/classes/com/jogamp/newt/macosx/MacDisplay.java delete mode 100755 src/newt/classes/com/jogamp/newt/macosx/MacScreen.java delete mode 100755 src/newt/classes/com/jogamp/newt/macosx/MacWindow.java delete mode 100644 src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Display.java delete mode 100755 src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Screen.java delete mode 100755 src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Window.java delete mode 100755 src/newt/classes/com/jogamp/newt/opengl/kd/KDDisplay.java delete mode 100755 src/newt/classes/com/jogamp/newt/opengl/kd/KDScreen.java delete mode 100755 src/newt/classes/com/jogamp/newt/opengl/kd/KDWindow.java delete mode 100755 src/newt/classes/com/jogamp/newt/windows/WindowsDisplay.java delete mode 100755 src/newt/classes/com/jogamp/newt/windows/WindowsScreen.java delete mode 100755 src/newt/classes/com/jogamp/newt/windows/WindowsWindow.java delete mode 100755 src/newt/classes/com/jogamp/newt/x11/X11Display.java delete mode 100755 src/newt/classes/com/jogamp/newt/x11/X11Screen.java delete mode 100755 src/newt/classes/com/jogamp/newt/x11/X11Window.java (limited to 'src/newt/classes') diff --git a/src/newt/classes/com/jogamp/newt/Display.java b/src/newt/classes/com/jogamp/newt/Display.java index 931c16cd9..df4d5b4f8 100755 --- a/src/newt/classes/com/jogamp/newt/Display.java +++ b/src/newt/classes/com/jogamp/newt/Display.java @@ -48,15 +48,15 @@ public abstract class Display { Class displayClass = NewtFactory.getCustomClass(type, "Display"); if(null==displayClass) { if (NativeWindowFactory.TYPE_EGL.equals(type)) { - displayClass = Class.forName("com.jogamp.newt.opengl.kd.KDDisplay"); + displayClass = Class.forName("com.jogamp.newt.impl.opengl.kd.KDDisplay"); } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { - displayClass = Class.forName("com.jogamp.newt.windows.WindowsDisplay"); + displayClass = Class.forName("com.jogamp.newt.impl.windows.WindowsDisplay"); } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { - displayClass = Class.forName("com.jogamp.newt.macosx.MacDisplay"); + displayClass = Class.forName("com.jogamp.newt.impl.macosx.MacDisplay"); } else if (NativeWindowFactory.TYPE_X11.equals(type)) { - displayClass = Class.forName("com.jogamp.newt.x11.X11Display"); + displayClass = Class.forName("com.jogamp.newt.impl.x11.X11Display"); } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { - displayClass = Class.forName("com.jogamp.newt.awt.AWTDisplay"); + displayClass = Class.forName("com.jogamp.newt.impl.awt.AWTDisplay"); } else { throw new RuntimeException("Unknown display type \"" + type + "\""); } @@ -267,14 +267,14 @@ public abstract class Display { protected abstract void dispatchMessagesNative(); - private LinkedList/**/ events = new LinkedList(); + private LinkedList/**/ events = new LinkedList(); protected void dispatchMessages() { - Event e; + NEWTEvent e; do { synchronized(events) { if (!events.isEmpty()) { - e = (Event) events.removeFirst(); + e = (NEWTEvent) events.removeFirst(); } else { e = null; } @@ -292,7 +292,7 @@ public abstract class Display { dispatchMessagesNative(); } - public void enqueueEvent(com.jogamp.newt.event.Event e) { + public void enqueueEvent(NEWTEvent e) { synchronized(events) { events.add(e); } diff --git a/src/newt/classes/com/jogamp/newt/Screen.java b/src/newt/classes/com/jogamp/newt/Screen.java index b393d30de..7bf520332 100755 --- a/src/newt/classes/com/jogamp/newt/Screen.java +++ b/src/newt/classes/com/jogamp/newt/Screen.java @@ -46,15 +46,15 @@ public abstract class Screen { Class screenClass = NewtFactory.getCustomClass(type, "Screen"); if(null==screenClass) { if (NativeWindowFactory.TYPE_EGL.equals(type)) { - screenClass = Class.forName("com.jogamp.newt.opengl.kd.KDScreen"); + screenClass = Class.forName("com.jogamp.newt.impl.opengl.kd.KDScreen"); } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { - screenClass = Class.forName("com.jogamp.newt.windows.WindowsScreen"); + screenClass = Class.forName("com.jogamp.newt.impl.windows.WindowsScreen"); } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { - screenClass = Class.forName("com.jogamp.newt.macosx.MacScreen"); + screenClass = Class.forName("com.jogamp.newt.impl.macosx.MacScreen"); } else if (NativeWindowFactory.TYPE_X11.equals(type)) { - screenClass = Class.forName("com.jogamp.newt.x11.X11Screen"); + screenClass = Class.forName("com.jogamp.newt.impl.x11.X11Screen"); } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { - screenClass = Class.forName("com.jogamp.newt.awt.AWTScreen"); + screenClass = Class.forName("com.jogamp.newt.impl.awt.AWTScreen"); } else { throw new RuntimeException("Unknown window type \"" + type + "\""); } diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index 33b971578..6f585a20a 100755 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -71,15 +71,15 @@ public abstract class Window implements NativeWindow Class windowClass = NewtFactory.getCustomClass(type, "Window"); if(null==windowClass) { if (NativeWindowFactory.TYPE_EGL.equals(type)) { - windowClass = Class.forName("com.jogamp.newt.opengl.kd.KDWindow"); + windowClass = Class.forName("com.jogamp.newt.impl.opengl.kd.KDWindow"); } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { - windowClass = Class.forName("com.jogamp.newt.windows.WindowsWindow"); + windowClass = Class.forName("com.jogamp.newt.impl.windows.WindowsWindow"); } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { - windowClass = Class.forName("com.jogamp.newt.macosx.MacWindow"); + windowClass = Class.forName("com.jogamp.newt.impl.macosx.MacWindow"); } else if (NativeWindowFactory.TYPE_X11.equals(type)) { - windowClass = Class.forName("com.jogamp.newt.x11.X11Window"); + windowClass = Class.forName("com.jogamp.newt.impl.x11.X11Window"); } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { - windowClass = Class.forName("com.jogamp.newt.awt.AWTWindow"); + windowClass = Class.forName("com.jogamp.newt.impl.awt.AWTWindow"); } else { throw new NativeWindowException("Unknown window type \"" + type + "\""); } @@ -576,7 +576,7 @@ public abstract class Window implements NativeWindow // Generic Event Support // - protected void sendEvent(Event e) { + protected void sendEvent(NEWTEvent e) { if(e instanceof WindowEvent) { sendWindowEvent((WindowEvent)e); } else if(e instanceof KeyEvent) { diff --git a/src/newt/classes/com/jogamp/newt/awt/AWTCanvas.java b/src/newt/classes/com/jogamp/newt/awt/AWTCanvas.java deleted file mode 100644 index f6ea9acc3..000000000 --- a/src/newt/classes/com/jogamp/newt/awt/AWTCanvas.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.awt; - -import com.jogamp.newt.Window; - -import java.awt.Canvas; -import java.awt.GraphicsDevice; -import java.awt.GraphicsEnvironment; -import java.awt.GraphicsConfiguration; - -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; -import com.jogamp.newt.impl.Debug; -import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; - -public class AWTCanvas extends Canvas { - private GraphicsDevice device; - private GraphicsConfiguration chosen; - private AWTGraphicsConfiguration awtConfig; - - private Capabilities capabilities; - - private boolean displayConfigChanged=false; - - public AWTCanvas(Capabilities capabilities) { - super(); - - if(null==capabilities) { - throw new NativeWindowException("Capabilities null"); - } - this.capabilities=capabilities; - } - - public AWTGraphicsConfiguration getAWTGraphicsConfiguration() { - return awtConfig; - } - - public boolean hasDeviceChanged() { - boolean res = displayConfigChanged; - displayConfigChanged=false; - return res; - } - - public void addNotify() { - super.addNotify(); - - disableBackgroundErase(); - - GraphicsConfiguration gc = super.getGraphicsConfiguration(); - if(null!=gc) { - device = gc.getDevice(); - } - - /* - * Save the chosen capabilities for use in getGraphicsConfiguration(). - */ - awtConfig = chooseGraphicsConfiguration(capabilities, device); - if(Window.DEBUG_IMPLEMENTATION) { - Exception e = new Exception("Created Config: "+awtConfig); - e.printStackTrace(); - } - if(null!=awtConfig) { - // update .. - chosen = awtConfig.getGraphicsConfiguration(); - } - if(null==awtConfig) { - throw new NativeWindowException("Error: AWTGraphicsConfiguration is null"); - } - } - - /** - * Overridden to choose a GraphicsConfiguration on a parent container's - * GraphicsDevice because both devices - */ - public GraphicsConfiguration getGraphicsConfiguration() { - /* - * Workaround for problems with Xinerama and java.awt.Component.checkGD - * when adding to a container on a different graphics device than the - * one that this Canvas is associated with. - * - * GC will be null unless: - * - A native peer has assigned it. This means we have a native - * peer, and are already comitted to a graphics configuration. - * - This canvas has been added to a component hierarchy and has - * an ancestor with a non-null GC, but the native peer has not - * yet been created. This means we can still choose the GC on - * all platforms since the peer hasn't been created. - */ - final GraphicsConfiguration gc = super.getGraphicsConfiguration(); - /* - * chosen is only non-null on platforms where the GLDrawableFactory - * returns a non-null GraphicsConfiguration (in the GLCanvas - * constructor). - * - * if gc is from this Canvas' native peer then it should equal chosen, - * otherwise it is from an ancestor component that this Canvas is being - * added to, and we go into this block. - */ - if (gc != null && chosen != null && !chosen.equals(gc)) { - /* - * Check for compatibility with gc. If they differ by only the - * device then return a new GCconfig with the super-class' GDevice - * (and presumably the same visual ID in Xinerama). - * - */ - if (!chosen.getDevice().getIDstring().equals(gc.getDevice().getIDstring())) { - /* - * Here we select a GraphicsConfiguration on the alternate - * device that is presumably identical to the chosen - * configuration, but on the other device. - * - * Should really check to ensure that we select a configuration - * with the same X visual ID for Xinerama screens, otherwise the - * GLDrawable may have the wrong visual ID (I don't think this - * ever gets updated). May need to add a method to - * X11GLDrawableFactory to do this in a platform specific - * manner. - * - * However, on platforms where we can actually get into this - * block, both devices should have the same visual list, and the - * same configuration should be selected here. - */ - AWTGraphicsConfiguration config = chooseGraphicsConfiguration((Capabilities)awtConfig.getRequestedCapabilities(), gc.getDevice()); - final GraphicsConfiguration compatible = (null!=config)?config.getGraphicsConfiguration():null; - if(Window.DEBUG_IMPLEMENTATION) { - Exception e = new Exception("Call Stack: "+Thread.currentThread().getName()); - e.printStackTrace(); - System.err.println("!!! Created Config (n): HAVE GC "+chosen); - System.err.println("!!! Created Config (n): THIS GC "+gc); - System.err.println("!!! Created Config (n): Choosen GC "+compatible); - System.err.println("!!! Created Config (n): HAVE CF "+awtConfig); - System.err.println("!!! Created Config (n): Choosen CF "+config); - System.err.println("!!! Created Config (n): EQUALS CAPS "+config.getChosenCapabilities().equals(awtConfig.getChosenCapabilities())); - } - - if (compatible != null) { - /* - * Save the new GC for equals test above, and to return to - * any outside callers of this method. - */ - chosen = compatible; - if( !config.getChosenCapabilities().equals(awtConfig.getChosenCapabilities())) { - displayConfigChanged=true; - } - awtConfig = config; - } - } - - /* - * If a compatible GC was not found in the block above, this will - * return the GC that was selected in the constructor (and might - * cause an exception in Component.checkGD when adding to a - * container, but in this case that would be the desired behavior). - * - */ - return chosen; - } else if (gc == null) { - /* - * The GC is null, which means we have no native peer, and are not - * part of a (realized) component hierarchy. So we return the - * desired visual that was selected in the constructor (possibly - * null). - */ - return chosen; - } - - /* - * Otherwise we have not explicitly selected a GC in the constructor, so - * just return what Canvas would have. - */ - return gc; - } - - private static AWTGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities, - GraphicsDevice device) { - AbstractGraphicsScreen aScreen = AWTGraphicsScreen.createScreenDevice(device); - AWTGraphicsConfiguration config = (AWTGraphicsConfiguration) - GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class).chooseGraphicsConfiguration(capabilities, - null, - aScreen); - if (config == null) { - throw new NativeWindowException("Error: Couldn't fetch AWTGraphicsConfiguration"); - } - - return config; - } - - // Disables the AWT's erasing of this Canvas's background on Windows - // in Java SE 6. This internal API is not available in previous - // releases, but the system property - // -Dsun.awt.noerasebackground=true can be specified to get similar - // results globally in previous releases. - private static boolean disableBackgroundEraseInitialized; - private static Method disableBackgroundEraseMethod; - private void disableBackgroundErase() { - if (!disableBackgroundEraseInitialized) { - try { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - try { - Class clazz = getToolkit().getClass(); - while (clazz != null && disableBackgroundEraseMethod == null) { - try { - disableBackgroundEraseMethod = - clazz.getDeclaredMethod("disableBackgroundErase", - new Class[] { Canvas.class }); - disableBackgroundEraseMethod.setAccessible(true); - } catch (Exception e) { - clazz = clazz.getSuperclass(); - } - } - } catch (Exception e) { - } - return null; - } - }); - } catch (Exception e) { - } - disableBackgroundEraseInitialized = true; - } - if (disableBackgroundEraseMethod != null) { - try { - disableBackgroundEraseMethod.invoke(getToolkit(), new Object[] { this }); - } catch (Exception e) { - // FIXME: workaround for 6504460 (incorrect backport of 6333613 in 5.0u10) - // throw new GLException(e); - } - } - } -} diff --git a/src/newt/classes/com/jogamp/newt/awt/AWTDisplay.java b/src/newt/classes/com/jogamp/newt/awt/AWTDisplay.java deleted file mode 100644 index d1fc1bc85..000000000 --- a/src/newt/classes/com/jogamp/newt/awt/AWTDisplay.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.awt; - -import java.awt.event.*; -import com.jogamp.newt.Display; -import com.jogamp.newt.Window; -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; -import java.util.*; - -public class AWTDisplay extends Display { - public AWTDisplay() { - } - - protected void createNative() { - aDevice = (AWTGraphicsDevice) AWTGraphicsDevice.createDevice(null); // default - } - - protected void setAWTGraphicsDevice(AWTGraphicsDevice d) { - aDevice = d; - } - - protected void closeNative() { } - - protected void dispatchMessagesNative() { /* nop */ } -} - diff --git a/src/newt/classes/com/jogamp/newt/awt/AWTScreen.java b/src/newt/classes/com/jogamp/newt/awt/AWTScreen.java deleted file mode 100644 index c804bce06..000000000 --- a/src/newt/classes/com/jogamp/newt/awt/AWTScreen.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.awt; - -import com.jogamp.newt.*; -import java.awt.DisplayMode; -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; - -public class AWTScreen extends Screen { - public AWTScreen() { - } - - protected void createNative(int index) { - aScreen = new AWTGraphicsScreen((AWTGraphicsDevice)display.getGraphicsDevice()); - - DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode(); - int w = mode.getWidth(); - int h = mode.getHeight(); - setScreenSize(w, h); - } - - protected void setAWTGraphicsScreen(AWTGraphicsScreen s) { - aScreen = s; - } - - // done by AWTWindow .. - protected void setScreenSize(int w, int h) { - super.setScreenSize(w, h); - } - - protected void closeNative() { } - -} diff --git a/src/newt/classes/com/jogamp/newt/awt/AWTWindow.java b/src/newt/classes/com/jogamp/newt/awt/AWTWindow.java deleted file mode 100644 index daeaa3e4e..000000000 --- a/src/newt/classes/com/jogamp/newt/awt/AWTWindow.java +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.awt; - -import com.jogamp.newt.awt.event.*; - -import java.awt.BorderLayout; -import java.awt.Canvas; -import java.awt.Container; -import java.awt.DisplayMode; -import java.awt.EventQueue; -import java.awt.Frame; -import java.awt.GraphicsDevice; -import java.awt.GraphicsEnvironment; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.*; -import com.jogamp.newt.Window; -import java.awt.Insets; -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; - -/** An implementation of the Newt Window class built using the - AWT. This is provided for convenience of porting to platforms - supporting Java SE. */ - -public class AWTWindow extends Window { - - public AWTWindow() { - this(null); - } - - public static Class[] getCustomConstructorArgumentTypes() { - return new Class[] { Container.class } ; - } - - public AWTWindow(Container container) { - super(); - title = "AWT NewtWindow"; - this.container = container; - if(container instanceof Frame) { - frame = (Frame) container; - } - } - - private boolean owningFrame; - private Container container = null; - private Frame frame = null; // same instance as container, just for impl. convenience - private AWTCanvas canvas; - // non fullscreen dimensions .. - private int nfs_width, nfs_height, nfs_x, nfs_y; - - public void setTitle(final String title) { - super.setTitle(title); - runOnEDT(true, new Runnable() { - public void run() { - if (frame != null) { - frame.setTitle(title); - } - } - }); - } - - protected void createNative(long parentWindowHandle, final Capabilities caps) { - - if(0!=parentWindowHandle) { - throw new RuntimeException("Window parenting not supported in AWT, use AWTWindow(Frame) cstr for wrapping instead"); - } - - final AWTWindow awtWindow = this; - - runOnEDT(true, new Runnable() { - public void run() { - if(null==container) { - frame = new Frame(); - container = frame; - owningFrame=true; - } else { - owningFrame=false; - width = container.getWidth(); - height = container.getHeight(); - x = container.getX(); - y = container.getY(); - } - if(null!=frame) { - frame.setTitle(getTitle()); - } - container.setLayout(new BorderLayout()); - canvas = new AWTCanvas(caps); - - addWindowListener(new LocalWindowListener()); - - new AWTMouseAdapter(awtWindow).addTo(canvas); // fwd all AWT Mouse events to here - new AWTKeyAdapter(awtWindow).addTo(canvas); // fwd all AWT Key events to here - - // canvas.addComponentListener(listener); - container.add(canvas, BorderLayout.CENTER); - container.setSize(width, height); - container.setLocation(x, y); - new AWTWindowAdapter(awtWindow).addTo(container); // fwd all AWT Window events to here - - if(null!=frame) { - frame.setUndecorated(undecorated||fullscreen); - } - } - }); - this.windowHandle = 1; // just a marker .. - } - - protected void closeNative() { - this.windowHandle = 0; // just a marker .. - if(null!=container) { - runOnEDT(true, new Runnable() { - public void run() { - container.setVisible(false); - container.remove(canvas); - container.setEnabled(false); - canvas.setEnabled(false); - } - }); - } - if(owningFrame && null!=frame) { - runOnEDT(true, new Runnable() { - public void run() { - frame.dispose(); - owningFrame=false; - frame = null; - } - }); - } - } - - public boolean hasDeviceChanged() { - boolean res = canvas.hasDeviceChanged(); - if(res) { - config = canvas.getAWTGraphicsConfiguration(); - if (config == null) { - throw new NativeWindowException("Error Device change null GraphicsConfiguration: "+this); - } - updateDeviceData(); - } - return res; - } - - public void setVisible(final boolean visible) { - runOnEDT(true, new Runnable() { - public void run() { - container.setVisible(visible); - } - }); - - config = canvas.getAWTGraphicsConfiguration(); - - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - - updateDeviceData(); - } - - private void updateDeviceData() { - // propagate new info .. - ((AWTScreen)getScreen()).setAWTGraphicsScreen((AWTGraphicsScreen)config.getScreen()); - ((AWTDisplay)getScreen().getDisplay()).setAWTGraphicsDevice((AWTGraphicsDevice)config.getScreen().getDevice()); - - DisplayMode mode = ((AWTGraphicsDevice)config.getScreen().getDevice()).getGraphicsDevice().getDisplayMode(); - int w = mode.getWidth(); - int h = mode.getHeight(); - ((AWTScreen)screen).setScreenSize(w, h); - } - - public void setSize(final int width, final int height) { - this.width = width; - this.height = height; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - /** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */ - runOnEDT(false, new Runnable() { - public void run() { - Insets insets = container.getInsets(); - container.setSize(width + insets.left + insets.right, - height + insets.top + insets.bottom); - } - }); - } - - public com.jogamp.newt.Insets getInsets() { - final int insets[] = new int[] { 0, 0, 0, 0 }; - runOnEDT(true, new Runnable() { - public void run() { - Insets contInsets = container.getInsets(); - insets[0] = contInsets.top; - insets[1] = contInsets.left; - insets[2] = contInsets.bottom; - insets[3] = contInsets.right; - } - }); - return new com.jogamp.newt. - Insets(insets[0],insets[1],insets[2],insets[3]); - } - - public void setPosition(final int x, final int y) { - this.x = x; - this.y = y; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - runOnEDT(true, new Runnable() { - public void run() { - container.setLocation(x, y); - } - }); - } - - public boolean setFullscreen(final boolean fullscreen) { - if(this.fullscreen!=fullscreen) { - final int x,y,w,h; - this.fullscreen=fullscreen; - if(fullscreen) { - x = 0; y = 0; - w = screen.getWidth(); - h = screen.getHeight(); - } else { - x = nfs_x; - y = nfs_y; - w = nfs_width; - h = nfs_height; - } - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("AWTWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); - } - /** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */ - runOnEDT(false, new Runnable() { - public void run() { - if(null!=frame) { - if(!container.isDisplayable()) { - frame.setUndecorated(undecorated||fullscreen); - } else { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("AWTWindow can't undecorate already created frame"); - } - } - } - container.setLocation(x, y); - container.setSize(w, h); - } - }); - } - return true; - } - - public Object getWrappedWindow() { - return canvas; - } - - protected void sendWindowEvent(int eventType) { - super.sendWindowEvent(eventType); - } - - protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { - super.sendKeyEvent(eventType, modifiers, keyCode, keyChar); - } - - protected void sendMouseEvent(int eventType, int modifiers, - int x, int y, int button, int rotation) { - super.sendMouseEvent(eventType, modifiers, x, y, button, rotation); - } - - private static void runOnEDT(boolean wait, Runnable r) { - if (EventQueue.isDispatchThread()) { - r.run(); - } else { - try { - if(wait) { - EventQueue.invokeAndWait(r); - } else { - EventQueue.invokeLater(r); - } - } catch (Exception e) { - throw new NativeWindowException(e); - } - } - } - - class LocalWindowListener extends com.jogamp.newt.event.WindowAdapter { - public void windowMoved(com.jogamp.newt.event.WindowEvent e) { - if(null!=container) { - x = container.getX(); - y = container.getY(); - } - } - public void windowResized(com.jogamp.newt.event.WindowEvent e) { - if(null!=canvas) { - width = canvas.getWidth(); - height = canvas.getHeight(); - } - } - } -} diff --git a/src/newt/classes/com/jogamp/newt/awt/event/AWTAdapter.java b/src/newt/classes/com/jogamp/newt/awt/event/AWTAdapter.java deleted file mode 100644 index 345eb02b9..000000000 --- a/src/newt/classes/com/jogamp/newt/awt/event/AWTAdapter.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2010 Sven Gothel. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name Sven Gothel or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - */ -package com.jogamp.newt.awt.event; - -/** - * Convenient adapter forwarding AWT events to NEWT via the event listener model.
- * - * You may attach an instance of this adapter to an AWT Component. When an event happen, - * it is converted to a NEWT event and the given NEWT listener is being called.
- * - * This adapter fullfills three use cases. First as a plain utility to write code AWT agnostic, - * ie write an {@link javax.media.opengl.GLEvenListener} and some appropriate NEWT {@link com.jogamp.newt.event.EventListener}.
- * - * Attach the {@link javax.media.opengl.GLEvenListener} to a NEWT {@link javax.media.opengl.GLAutoDrawable}, e.g. {@link com.jogamp.newt.opengl.GLWindow}, - * or to an AWT {@link javax.media.opengl.GLAutoDrawable}, e.g. {@link javax.media.opengl.awt.GLCanvas}.
- * Attach the NEWT {@link com.jogamp.newt.event.EventListener} to a NEWT component, e.g. {@link com.jogamp.newt.Window}, - * or to an AWT component, e.g. {@link java.awt.Component}.

- * - javax.media.opengl.GLEvenListener demo1 = new javax.media.opengl.GLEvenListener() { ... } ; - com.jogamp.newt.event.MouseListener mouseListener = new com.jogamp.newt.event.MouseAdapter() { ... } ; - - // NEWT Usage - GLWindow glWindow = GLWindow.create(); - glWindow.addGLEventListener(demo1); - glWindow.addMouseListener(mouseListener); - .. - - // AWT Usage - GLCanvas glCanvas = new GLCanvas(); - glCanvas.addGLEventListener(demo1); - new AWTMouseAdapter(mouseListener).addTo(glCanvas); - - // This last line is nothing else but a simplified form of: - AWTMouseAdapter mouseAdapter = new AWTMouseAdapter(mouseListener); - glCanvas.addMouseListener(mouseAdapter); - glCanvas.addMouseMotionListener(mouseAdapter); - * - * - * Second is just a litte variation, where we pass a NEWT Window - * to impersonate as the source of the event.
- * - * - com.jogamp.newt.event.MouseListener mouseListener = new com.jogamp.newt.event.MouseAdapter() { ... } ; - Component comp = ... ; // the AWT component - GLWindow glWindow = GLWindow.create(); // the NEWT component - - new AWTMouseAdapter(mouseListener, glWindow).addTo(comp); - * - * - * Last but not least, the AWTAdapter maybe used as a general AWT event forwarder to NEWT.
- * - * - com.jogamp.newt.event.MouseListener mouseListener = new com.jogamp.newt.event.MouseAdapter() { ... } ; - Component comp = ... ; // the AWT component - GLWindow glWindow = GLWindow.create(); // the NEWT component - glWindow.addMouseListener(mouseListener); // add the custom EventListener to the NEWT component - - new AWTMouseAdapter(glWindow).addTo(comp); // forward all AWT events to glWindow, as NEWT events - * - * - * - * - * @see #attachTo - */ -public abstract class AWTAdapter implements java.util.EventListener -{ - com.jogamp.newt.event.EventListener newtListener; - com.jogamp.newt.Window newtWindow; - - /** - * Simply wrap aroung a NEWT EventListener, exposed as an AWT EventListener.
- * The NEWT EventListener will be called when an event happens.
- */ - public AWTAdapter(com.jogamp.newt.event.EventListener newtListener) { - if(null==newtListener) { - throw new RuntimeException("Argument newtListener is null"); - } - this.newtListener = newtListener; - this.newtWindow = null; - } - - /** - * Wrap aroung a NEWT EventListener, exposed as an AWT EventListener,
- * where the given NEWT Window impersonates as the event's source. - * The NEWT EventListener will be called when an event happens.
- */ - public AWTAdapter(com.jogamp.newt.event.EventListener newtListener, com.jogamp.newt.Window newtProxy) { - if(null==newtListener) { - throw new RuntimeException("Argument newtListener is null"); - } - if(null==newtProxy) { - throw new RuntimeException("Argument newtProxy is null"); - } - this.newtListener = newtListener; - this.newtWindow = newtProxy; - } - - /** - * Create a pipeline adapter, AWT EventListener.
- * Once attached to an AWT component, it sends the converted AWT events to the NEWT downstream window.
- */ - public AWTAdapter(com.jogamp.newt.Window downstream) { - if(null==downstream) { - throw new RuntimeException("Argument downstream is null"); - } - this.newtListener = null; - this.newtWindow = downstream; - } - - /** - * Due to the fact that some NEWT {@link com.jogamp.newt.event.EventListener} - * are mapped to more than one {@link java.util.EventListener}, - * this method is for your convenience to use this Adapter as a listener for all types.
- * E.g. {@link com.jogamp.newt.event.MouseListener} is mapped to {@link java.awt.event.MouseListener} and {@link java.awt.event.MouseMotionListener}. - */ - public abstract AWTAdapter addTo(java.awt.Component awtComponent); - - void enqueueEvent(com.jogamp.newt.event.Event event) { - try { - newtWindow.getScreen().getDisplay().enqueueEvent(event); - } catch (NullPointerException npe) { - /* that's ok .. window might be down already */ - } - } -} - diff --git a/src/newt/classes/com/jogamp/newt/awt/event/AWTKeyAdapter.java b/src/newt/classes/com/jogamp/newt/awt/event/AWTKeyAdapter.java deleted file mode 100644 index 866ec5476..000000000 --- a/src/newt/classes/com/jogamp/newt/awt/event/AWTKeyAdapter.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2010 Sven Gothel. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name Sven Gothel or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - */ -package com.jogamp.newt.awt.event; - -public class AWTKeyAdapter extends AWTAdapter implements java.awt.event.KeyListener -{ - public AWTKeyAdapter(com.jogamp.newt.event.KeyListener newtListener) { - super(newtListener); - } - - public AWTKeyAdapter(com.jogamp.newt.event.KeyListener newtListener, com.jogamp.newt.Window newtProxy) { - super(newtListener, newtProxy); - } - - public AWTKeyAdapter(com.jogamp.newt.Window downstream) { - super(downstream); - } - - public AWTAdapter addTo(java.awt.Component awtComponent) { - awtComponent.addKeyListener(this); - return this; - } - - public void keyPressed(java.awt.event.KeyEvent e) { - com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(e, newtWindow); - if(null!=newtListener) { - ((com.jogamp.newt.event.KeyListener)newtListener).keyPressed(event); - } else { - enqueueEvent(event); - } - } - - public void keyReleased(java.awt.event.KeyEvent e) { - com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(e, newtWindow); - if(null!=newtListener) { - ((com.jogamp.newt.event.KeyListener)newtListener).keyReleased(event); - } else { - enqueueEvent(event); - } - } - - public void keyTyped(java.awt.event.KeyEvent e) { - com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(e, newtWindow); - if(null!=newtListener) { - ((com.jogamp.newt.event.KeyListener)newtListener).keyTyped(event); - } else { - enqueueEvent(event); - } - } -} - diff --git a/src/newt/classes/com/jogamp/newt/awt/event/AWTMouseAdapter.java b/src/newt/classes/com/jogamp/newt/awt/event/AWTMouseAdapter.java deleted file mode 100644 index db28616b9..000000000 --- a/src/newt/classes/com/jogamp/newt/awt/event/AWTMouseAdapter.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2010 Sven Gothel. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name Sven Gothel or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - */ -package com.jogamp.newt.awt.event; - -public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener -{ - public AWTMouseAdapter(com.jogamp.newt.event.MouseListener newtListener) { - super(newtListener); - } - - public AWTMouseAdapter(com.jogamp.newt.event.MouseListener newtListener, com.jogamp.newt.Window newtProxy) { - super(newtListener, newtProxy); - } - - public AWTMouseAdapter(com.jogamp.newt.Window downstream) { - super(downstream); - } - - public AWTAdapter addTo(java.awt.Component awtComponent) { - awtComponent.addMouseListener(this); - awtComponent.addMouseMotionListener(this); - return this; - } - - public void mouseClicked(java.awt.event.MouseEvent e) { - com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); - if(null!=newtListener) { - ((com.jogamp.newt.event.MouseListener)newtListener).mouseClicked(event); - } else { - enqueueEvent(event); - } - } - - public void mouseEntered(java.awt.event.MouseEvent e) { - com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); - if(null!=newtListener) { - ((com.jogamp.newt.event.MouseListener)newtListener).mouseEntered(event); - } else { - enqueueEvent(event); - } - } - - public void mouseExited(java.awt.event.MouseEvent e) { - com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); - if(null!=newtListener) { - ((com.jogamp.newt.event.MouseListener)newtListener).mouseExited(event); - } else { - enqueueEvent(event); - } - } - - public void mousePressed(java.awt.event.MouseEvent e) { - com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); - if(null!=newtListener) { - ((com.jogamp.newt.event.MouseListener)newtListener).mousePressed(event); - } else { - enqueueEvent(event); - } - } - - public void mouseReleased(java.awt.event.MouseEvent e) { - com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); - if(null!=newtListener) { - ((com.jogamp.newt.event.MouseListener)newtListener).mouseReleased(event); - } else { - enqueueEvent(event); - } - } - - public void mouseDragged(java.awt.event.MouseEvent e) { - com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); - if(null!=newtListener) { - ((com.jogamp.newt.event.MouseListener)newtListener).mouseDragged(event); - } else { - enqueueEvent(event); - } - } - - public void mouseMoved(java.awt.event.MouseEvent e) { - com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); - if(null!=newtListener) { - ((com.jogamp.newt.event.MouseListener)newtListener).mouseMoved(event); - } else { - enqueueEvent(event); - } - } -} - diff --git a/src/newt/classes/com/jogamp/newt/awt/event/AWTNewtEventFactory.java b/src/newt/classes/com/jogamp/newt/awt/event/AWTNewtEventFactory.java deleted file mode 100644 index ea10c9de5..000000000 --- a/src/newt/classes/com/jogamp/newt/awt/event/AWTNewtEventFactory.java +++ /dev/null @@ -1,140 +0,0 @@ - -/* - * Copyright (c) 2010 Sven Gothel. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name Sven Gothel or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - */ -package com.jogamp.newt.awt.event; - -import com.jogamp.common.util.IntIntHashMap; - -class AWTNewtEventFactory { - - protected static final IntIntHashMap eventTypeAWT2NEWT; - - static { - IntIntHashMap map = new IntIntHashMap(); - 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); - // 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); - map.put(java.awt.event.WindowEvent.WINDOW_GAINED_FOCUS, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS); - map.put(java.awt.event.WindowEvent.WINDOW_DEACTIVATED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_LOST_FOCUS); - map.put(java.awt.event.WindowEvent.WINDOW_LOST_FOCUS, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_LOST_FOCUS); - // n/a map.put(java.awt.event.WindowEvent.WINDOW_STATE_CHANGED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_STATE_CHANGED); - - map.put(java.awt.event.ComponentEvent.COMPONENT_MOVED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_MOVED); - map.put(java.awt.event.ComponentEvent.COMPONENT_RESIZED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_RESIZED); - // n/a map.put(java.awt.event.ComponentEvent.COMPONENT_SHOWN, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_SHOWN); - // n/a map.put(java.awt.event.ComponentEvent.COMPONENT_HIDDEN, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_HIDDEN); - - map.put(java.awt.event.MouseEvent.MOUSE_CLICKED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_CLICKED); - map.put(java.awt.event.MouseEvent.MOUSE_PRESSED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED); - map.put(java.awt.event.MouseEvent.MOUSE_RELEASED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED); - map.put(java.awt.event.MouseEvent.MOUSE_MOVED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_MOVED); - map.put(java.awt.event.MouseEvent.MOUSE_ENTERED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_ENTERED); - map.put(java.awt.event.MouseEvent.MOUSE_EXITED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_EXITED); - map.put(java.awt.event.MouseEvent.MOUSE_DRAGGED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_DRAGGED); - map.put(java.awt.event.MouseEvent.MOUSE_WHEEL, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_WHEEL_MOVED); - - map.put(java.awt.event.KeyEvent.KEY_PRESSED, com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED); - map.put(java.awt.event.KeyEvent.KEY_RELEASED, com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED); - map.put(java.awt.event.KeyEvent.KEY_TYPED, com.jogamp.newt.event.KeyEvent.EVENT_KEY_TYPED); - - eventTypeAWT2NEWT = map; - } - - public static final int awtModifiers2Newt(int awtMods, boolean mouseHint) { - int newtMods = 0; - if ((awtMods & java.awt.event.InputEvent.SHIFT_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.SHIFT_MASK; - if ((awtMods & java.awt.event.InputEvent.CTRL_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.CTRL_MASK; - if ((awtMods & java.awt.event.InputEvent.META_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.META_MASK; - if ((awtMods & java.awt.event.InputEvent.ALT_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.ALT_MASK; - if ((awtMods & java.awt.event.InputEvent.ALT_GRAPH_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.ALT_GRAPH_MASK; - return newtMods; - } - - public static final int awtButton2Newt(int awtButton) { - switch (awtButton) { - case java.awt.event.MouseEvent.BUTTON1: return com.jogamp.newt.event.MouseEvent.BUTTON1; - case java.awt.event.MouseEvent.BUTTON2: return com.jogamp.newt.event.MouseEvent.BUTTON2; - case java.awt.event.MouseEvent.BUTTON3: return com.jogamp.newt.event.MouseEvent.BUTTON3; - } - return 0; - } - - static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.WindowEvent event, com.jogamp.newt.Window newtSource) { - int type = eventTypeAWT2NEWT.get(event.getID()); - if(-1 < type) { - return new com.jogamp.newt.event.WindowEvent(type, ((null==newtSource)?(Object)event.getComponent():(Object)newtSource), System.currentTimeMillis()); - } - return null; // no mapping .. - } - - static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.ComponentEvent event, com.jogamp.newt.Window newtSource) { - int type = eventTypeAWT2NEWT.get(event.getID()); - if(-1 < type) { - return new com.jogamp.newt.event.WindowEvent(type, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, System.currentTimeMillis()); - } - return null; // no mapping .. - } - - static final com.jogamp.newt.event.MouseEvent createMouseEvent(java.awt.event.MouseEvent event, com.jogamp.newt.Window newtSource) { - int type = eventTypeAWT2NEWT.get(event.getID()); - if(-1 < type) { - int rotation = 0; - if (event instanceof java.awt.event.MouseWheelEvent) { - rotation = ((java.awt.event.MouseWheelEvent)event).getWheelRotation(); - } - - return new com.jogamp.newt.event.MouseEvent( - type, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, event.getWhen(), - awtModifiers2Newt(event.getModifiers(), true), - event.getX(), event.getY(), event.getClickCount(), - awtButton2Newt(event.getButton()), rotation); - } - return null; // no mapping .. - } - - static final com.jogamp.newt.event.KeyEvent createKeyEvent(java.awt.event.KeyEvent event, com.jogamp.newt.Window newtSource) { - int type = eventTypeAWT2NEWT.get(event.getID()); - if(-1 < type) { - return new com.jogamp.newt.event.KeyEvent( - type, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, event.getWhen(), - awtModifiers2Newt(event.getModifiers(), false), - event.getKeyCode(), event.getKeyChar()); - } - return null; // no mapping .. - } - -} - diff --git a/src/newt/classes/com/jogamp/newt/awt/event/AWTWindowAdapter.java b/src/newt/classes/com/jogamp/newt/awt/event/AWTWindowAdapter.java deleted file mode 100644 index d17bac242..000000000 --- a/src/newt/classes/com/jogamp/newt/awt/event/AWTWindowAdapter.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2010 Sven Gothel. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name Sven Gothel or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - */ -package com.jogamp.newt.awt.event; - -public class AWTWindowAdapter extends AWTAdapter implements java.awt.event.ComponentListener, java.awt.event.WindowListener -{ - public AWTWindowAdapter(com.jogamp.newt.event.WindowListener newtListener) { - super(newtListener); - } - - public AWTWindowAdapter(com.jogamp.newt.event.WindowListener newtListener, com.jogamp.newt.Window newtProxy) { - super(newtListener, newtProxy); - } - - public AWTWindowAdapter(com.jogamp.newt.Window downstream) { - super(downstream); - } - - public AWTAdapter addTo(java.awt.Component awtComponent) { - awtComponent.addComponentListener(this); - if(awtComponent instanceof java.awt.Window) { - ((java.awt.Window)awtComponent).addWindowListener(this); - } - return this; - } - - public void componentResized(java.awt.event.ComponentEvent e) { - com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); - if(null!=newtListener) { - ((com.jogamp.newt.event.WindowListener)newtListener).windowResized(event); - } else { - enqueueEvent(event); - } - } - - public void componentMoved(java.awt.event.ComponentEvent e) { - com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); - if(null!=newtListener) { - ((com.jogamp.newt.event.WindowListener)newtListener).windowMoved(event); - } else { - enqueueEvent(event); - } - } - - public void componentShown(java.awt.event.ComponentEvent e) { - // n/a - } - - public void componentHidden(java.awt.event.ComponentEvent e) { - // n/a - } - - public void windowActivated(java.awt.event.WindowEvent e) { - com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); - if(null!=newtListener) { - ((com.jogamp.newt.event.WindowListener)newtListener).windowGainedFocus(event); - } else { - enqueueEvent(event); - } - } - - public void windowClosed(java.awt.event.WindowEvent e) { - // n/a - } - - public void windowClosing(java.awt.event.WindowEvent e) { - com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); - if(null!=newtListener) { - ((com.jogamp.newt.event.WindowListener)newtListener).windowDestroyNotify(event); - } else { - enqueueEvent(event); - } - } - - public void windowDeactivated(java.awt.event.WindowEvent e) { - com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); - if(null!=newtListener) { - ((com.jogamp.newt.event.WindowListener)newtListener).windowLostFocus(event); - } else { - enqueueEvent(event); - } - } - - public void windowDeiconified(java.awt.event.WindowEvent e) { - // n/a - } - - public void windowIconified(java.awt.event.WindowEvent e) { - // n/a - } - - public void windowOpened(java.awt.event.WindowEvent e) { - // n/a - } - -} - diff --git a/src/newt/classes/com/jogamp/newt/event/Event.java b/src/newt/classes/com/jogamp/newt/event/Event.java deleted file mode 100644 index d93995ead..000000000 --- a/src/newt/classes/com/jogamp/newt/event/Event.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.event; - -import com.jogamp.newt.*; -import java.util.*; - -public class Event { - private boolean isSystemEvent; - private int eventType; - private Object source; - private long when; - - static final boolean DEBUG = false; - - // 0: Event.java - // 1: InputEvent.java - // 2: KeyEvent.java - // 3: com.jogamp.newt.Window - // 3: com.jogamp.newt.awt.event.AWTNewtEventFactory - // 2: MouseEvent.java - // 3: com.jogamp.newt.Window - // 3: com.jogamp.newt.awt.event.AWTNewtEventFactory - // 1: PaintEvent.java - // 2: com.jogamp.newt.Window - // 2: com.jogamp.newt.awt.event.AWTNewtEventFactory - // 1: WindowEvent.java - // 2: com.jogamp.newt.Window - // 2: com.jogamp.newt.awt.event.AWTNewtEventFactory - // - static final String WindowClazzName = "com.jogamp.newt.Window" ; - static final String AWTNewtEventFactoryClazzName = "com.jogamp.newt.awt.event.AWTNewtEventFactory" ; - - static final boolean evaluateIsSystemEvent(Event event, Throwable t) { - StackTraceElement[] stack = t.getStackTrace(); - if(stack.length==0 || null==stack[0]) { - return false; - } - if(DEBUG) { - for (int i = 0; i < stack.length && i<5; i++) { - System.out.println(i+": " + stack[i].getClassName()+ "." + stack[i].getMethodName()); - } - } - - String clazzName = null; - - if( (event instanceof com.jogamp.newt.event.WindowEvent) || - (event instanceof com.jogamp.newt.event.PaintEvent) ) { - if ( stack.length > 2 ) { - clazzName = stack[2].getClassName(); - } - } else if( (event instanceof com.jogamp.newt.event.MouseEvent) || - (event instanceof com.jogamp.newt.event.KeyEvent) ) { - if ( stack.length > 3 ) { - clazzName = stack[3].getClassName(); - } - } - - boolean res = null!=clazzName && ( - clazzName.equals(WindowClazzName) || - clazzName.equals(AWTNewtEventFactoryClazzName) ) ; - if(DEBUG) { - System.out.println("system: "+res); - } - return res; - } - - protected Event(int eventType, Object source, long when) { - this.isSystemEvent = evaluateIsSystemEvent(this, new Throwable()); - this.eventType = eventType; - this.source = source; - this.when = when; - } - - /** Indicates whether this event was produced by the system or - generated by user code. */ - public final boolean isSystemEvent() { - return isSystemEvent; - } - - /** Returns the event type of this event. */ - public final int getEventType() { - return eventType; - } - - /** Returns the source Object which produced this Event. */ - public final Object getSource() { - return source; - } - - /** Returns the timestamp, in milliseconds, of this event. */ - public final long getWhen() { - return when; - } - - public String toString() { - return "Event[sys:"+isSystemEvent()+", source:"+getSource()+", when:"+getWhen()+"]"; - } - - public static String toHexString(int hex) { - return "0x" + Integer.toHexString(hex); - } - - public static String toHexString(long hex) { - return "0x" + Long.toHexString(hex); - } - -} diff --git a/src/newt/classes/com/jogamp/newt/event/EventListener.java b/src/newt/classes/com/jogamp/newt/event/EventListener.java deleted file mode 100644 index e47b9ccb3..000000000 --- a/src/newt/classes/com/jogamp/newt/event/EventListener.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.event; - -import com.jogamp.newt.*; - -public interface EventListener extends java.util.EventListener -{ - public static final int WINDOW = 1 << 0; - public static final int MOUSE = 1 << 1; - public static final int KEY = 1 << 2; - public static final int SURFACE = 1 << 3; - -} - diff --git a/src/newt/classes/com/jogamp/newt/event/InputEvent.java b/src/newt/classes/com/jogamp/newt/event/InputEvent.java index 01a4b307a..02fbe59ef 100644 --- a/src/newt/classes/com/jogamp/newt/event/InputEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/InputEvent.java @@ -35,7 +35,7 @@ package com.jogamp.newt.event; import com.jogamp.newt.*; -public abstract class InputEvent extends Event +public abstract class InputEvent extends NEWTEvent { public static final int SHIFT_MASK = 1 << 0; public static final int CTRL_MASK = 1 << 1; @@ -91,7 +91,7 @@ public abstract class InputEvent extends Event } public String toString() { - return "InputEvent[modifiers:"+modifiers+"]"; + return "InputEvent[modifiers:"+modifiers+", "+super.toString()+"]"; } private boolean consumed; diff --git a/src/newt/classes/com/jogamp/newt/event/KeyListener.java b/src/newt/classes/com/jogamp/newt/event/KeyListener.java index 925a902f7..5ce3868f5 100644 --- a/src/newt/classes/com/jogamp/newt/event/KeyListener.java +++ b/src/newt/classes/com/jogamp/newt/event/KeyListener.java @@ -35,7 +35,7 @@ package com.jogamp.newt.event; import com.jogamp.newt.*; -public interface KeyListener extends EventListener +public interface KeyListener extends NEWTEventListener { public void keyPressed(KeyEvent e); public void keyReleased(KeyEvent e); diff --git a/src/newt/classes/com/jogamp/newt/event/MouseListener.java b/src/newt/classes/com/jogamp/newt/event/MouseListener.java index 3d5b4d83f..b328aeac7 100644 --- a/src/newt/classes/com/jogamp/newt/event/MouseListener.java +++ b/src/newt/classes/com/jogamp/newt/event/MouseListener.java @@ -35,7 +35,7 @@ package com.jogamp.newt.event; import com.jogamp.newt.*; -public interface MouseListener extends EventListener +public interface MouseListener extends NEWTEventListener { public void mouseClicked(MouseEvent e); public void mouseEntered(MouseEvent e); diff --git a/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java b/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java new file mode 100644 index 000000000..6559c5953 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.event; + +import com.jogamp.newt.*; +import java.util.*; + +public class NEWTEvent extends java.util.EventObject { + private boolean isSystemEvent; + private int eventType; + private long when; + + static final boolean DEBUG = false; + + // 0: NEWTEvent.java + // 1: InputEvent.java + // 2: KeyEvent.java + // 3: com.jogamp.newt.Window + // 3: com.jogamp.newt.event.awt.AWTNewtEventFactory + // 2: MouseEvent.java + // 3: com.jogamp.newt.Window + // 3: com.jogamp.newt.event.awt.AWTNewtEventFactory + // 1: PaintEvent.java + // 2: com.jogamp.newt.Window + // 2: com.jogamp.newt.event.awt.AWTNewtEventFactory + // 1: WindowEvent.java + // 2: com.jogamp.newt.Window + // 2: com.jogamp.newt.event.awt.AWTNewtEventFactory + // + static final String WindowClazzName = "com.jogamp.newt.Window" ; + static final String AWTNewtEventFactoryClazzName = "com.jogamp.newt.event.awt.AWTNewtEventFactory" ; + + static final boolean evaluateIsSystemEvent(NEWTEvent event, Throwable t) { + StackTraceElement[] stack = t.getStackTrace(); + if(stack.length==0 || null==stack[0]) { + return false; + } + if(DEBUG) { + for (int i = 0; i < stack.length && i<5; i++) { + System.out.println(i+": " + stack[i].getClassName()+ "." + stack[i].getMethodName()); + } + } + + String clazzName = null; + + if( (event instanceof com.jogamp.newt.event.WindowEvent) || + (event instanceof com.jogamp.newt.event.PaintEvent) ) { + if ( stack.length > 2 ) { + clazzName = stack[2].getClassName(); + } + } else if( (event instanceof com.jogamp.newt.event.MouseEvent) || + (event instanceof com.jogamp.newt.event.KeyEvent) ) { + if ( stack.length > 3 ) { + clazzName = stack[3].getClassName(); + } + } + + boolean res = null!=clazzName && ( + clazzName.equals(WindowClazzName) || + clazzName.equals(AWTNewtEventFactoryClazzName) ) ; + if(DEBUG) { + System.out.println("system: "+res); + } + return res; + } + + protected NEWTEvent(int eventType, Object source, long when) { + super(source); + this.isSystemEvent = evaluateIsSystemEvent(this, new Throwable()); + this.eventType = eventType; + this.when = when; + } + + /** Indicates whether this event was produced by the system or + generated by user code. */ + public final boolean isSystemEvent() { + return isSystemEvent; + } + + /** Returns the event type of this event. */ + public final int getEventType() { + return eventType; + } + + /** Returns the timestamp, in milliseconds, of this event. */ + public final long getWhen() { + return when; + } + + public String toString() { + return "NEWTEvent[sys:"+isSystemEvent()+", source:"+getSource().getClass().getName()+", when:"+getWhen()+" d "+(System.currentTimeMillis()-getWhen())+"ms]"; + } + + public static String toHexString(int hex) { + return "0x" + Integer.toHexString(hex); + } + + public static String toHexString(long hex) { + return "0x" + Long.toHexString(hex); + } + +} diff --git a/src/newt/classes/com/jogamp/newt/event/NEWTEventListener.java b/src/newt/classes/com/jogamp/newt/event/NEWTEventListener.java new file mode 100644 index 000000000..2a187f8c4 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/NEWTEventListener.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.event; + +import com.jogamp.newt.*; + +public interface NEWTEventListener extends java.util.EventListener +{ + public static final int WINDOW = 1 << 0; + public static final int MOUSE = 1 << 1; + public static final int KEY = 1 << 2; + public static final int SURFACE = 1 << 3; + +} + diff --git a/src/newt/classes/com/jogamp/newt/event/PaintEvent.java b/src/newt/classes/com/jogamp/newt/event/PaintEvent.java index 469358625..e1c667b55 100755 --- a/src/newt/classes/com/jogamp/newt/event/PaintEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/PaintEvent.java @@ -39,7 +39,7 @@ import com.jogamp.newt.*; * * @author tdv */ -public class PaintEvent extends Event { +public class PaintEvent extends NEWTEvent { // bounds of the damage region private int x, y, width, height; diff --git a/src/newt/classes/com/jogamp/newt/event/TraceKeyAdapter.java b/src/newt/classes/com/jogamp/newt/event/TraceKeyAdapter.java new file mode 100644 index 000000000..8034bdb9f --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/TraceKeyAdapter.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2010 Sven Gothel. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name Sven Gothel or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.jogamp.newt.event; + +public class TraceKeyAdapter implements KeyListener { + + KeyListener downstream; + + public TraceKeyAdapter() { + this.downstream = null; + } + + public TraceKeyAdapter(KeyListener downstream) { + this.downstream = downstream; + } + + public void keyPressed(KeyEvent e) { + System.out.println(e); + if(null!=downstream) { downstream.keyPressed(e); } + } + public void keyReleased(KeyEvent e) { + System.out.println(e); + if(null!=downstream) { downstream.keyReleased(e); } + } + public void keyTyped(KeyEvent e) { + System.out.println(e); + if(null!=downstream) { downstream.keyTyped(e); } + } +} + diff --git a/src/newt/classes/com/jogamp/newt/event/TraceMouseAdapter.java b/src/newt/classes/com/jogamp/newt/event/TraceMouseAdapter.java new file mode 100644 index 000000000..b19b5eb21 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/TraceMouseAdapter.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2010 Sven Gothel. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name Sven Gothel or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ +package com.jogamp.newt.event; + +import com.jogamp.newt.*; + +public class TraceMouseAdapter implements MouseListener { + + MouseListener downstream; + + public TraceMouseAdapter() { + this.downstream = null; + } + + public TraceMouseAdapter(MouseListener downstream) { + this.downstream = downstream; + } + + public void mouseClicked(MouseEvent e) { + System.out.println(e); + if(null!=downstream) { downstream.mouseClicked(e); } + } + public void mouseEntered(MouseEvent e) { + System.out.println(e); + if(null!=downstream) { downstream.mouseEntered(e); } + } + public void mouseExited(MouseEvent e) { + System.out.println(e); + if(null!=downstream) { downstream.mouseExited(e); } + } + public void mousePressed(MouseEvent e) { + System.out.println(e); + if(null!=downstream) { downstream.mousePressed(e); } + } + public void mouseReleased(MouseEvent e) { + System.out.println(e); + if(null!=downstream) { downstream.mouseReleased(e); } + } + public void mouseMoved(MouseEvent e) { + System.out.println(e); + if(null!=downstream) { downstream.mouseMoved(e); } + } + public void mouseDragged(MouseEvent e) { + System.out.println(e); + if(null!=downstream) { downstream.mouseDragged(e); } + } + public void mouseWheelMoved(MouseEvent e) { + System.out.println(e); + if(null!=downstream) { downstream.mouseWheelMoved(e); } + } +} + diff --git a/src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java new file mode 100644 index 000000000..5a93bca36 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2010 Sven Gothel. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name Sven Gothel or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ +package com.jogamp.newt.event; + +import com.jogamp.newt.*; + +public class TraceWindowAdapter implements WindowListener { + + WindowListener downstream; + + public TraceWindowAdapter() { + this.downstream = null; + } + + public TraceWindowAdapter(WindowListener downstream) { + this.downstream = downstream; + } + + public void windowResized(WindowEvent e) { + System.out.println(e); + if(null!=downstream) { downstream.windowResized(e); } + } + public void windowMoved(WindowEvent e) { + System.out.println(e); + if(null!=downstream) { downstream.windowMoved(e); } + } + public void windowDestroyNotify(WindowEvent e) { + System.out.println(e); + if(null!=downstream) { downstream.windowDestroyNotify(e); } + } + public void windowGainedFocus(WindowEvent e) { + System.out.println(e); + if(null!=downstream) { downstream.windowGainedFocus(e); } + } + public void windowLostFocus(WindowEvent e) { + System.out.println(e); + if(null!=downstream) { downstream.windowLostFocus(e); } + } +} diff --git a/src/newt/classes/com/jogamp/newt/event/WindowEvent.java b/src/newt/classes/com/jogamp/newt/event/WindowEvent.java index 8204bfc79..6706ef778 100644 --- a/src/newt/classes/com/jogamp/newt/event/WindowEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/WindowEvent.java @@ -35,7 +35,7 @@ package com.jogamp.newt.event; import com.jogamp.newt.*; -public class WindowEvent extends Event { +public class WindowEvent extends NEWTEvent { public static final int EVENT_WINDOW_RESIZED = 100; public static final int EVENT_WINDOW_MOVED = 101; public static final int EVENT_WINDOW_DESTROY_NOTIFY = 102; diff --git a/src/newt/classes/com/jogamp/newt/event/WindowListener.java b/src/newt/classes/com/jogamp/newt/event/WindowListener.java index 8c7601a8d..871f0fe12 100644 --- a/src/newt/classes/com/jogamp/newt/event/WindowListener.java +++ b/src/newt/classes/com/jogamp/newt/event/WindowListener.java @@ -35,7 +35,7 @@ package com.jogamp.newt.event; import com.jogamp.newt.*; -public interface WindowListener extends EventListener { +public interface WindowListener extends NEWTEventListener { public void windowResized(WindowEvent e); public void windowMoved(WindowEvent e); public void windowDestroyNotify(WindowEvent e); diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java new file mode 100644 index 000000000..6fb02e8e7 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2010 Sven Gothel. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name Sven Gothel or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ +package com.jogamp.newt.event.awt; + +/** + * Convenient adapter forwarding AWT events to NEWT via the event listener model.
+ * + * You may attach an instance of this adapter to an AWT Component. When an event happen, + * it is converted to a NEWT event and the given NEWT listener is being called.
+ * + * This adapter fullfills three use cases. First as a plain utility to write code AWT agnostic, + * ie write an {@link javax.media.opengl.GLEvenListener} and some appropriate NEWT {@link com.jogamp.newt.event.NEWTEventListener}.
+ * + * Attach the {@link javax.media.opengl.GLEvenListener} to a NEWT {@link javax.media.opengl.GLAutoDrawable}, e.g. {@link com.jogamp.newt.opengl.GLWindow}, + * or to an AWT {@link javax.media.opengl.GLAutoDrawable}, e.g. {@link javax.media.opengl.awt.GLCanvas}.
+ * Attach the NEWT {@link com.jogamp.newt.event.NEWTEventListener} to a NEWT component, e.g. {@link com.jogamp.newt.Window}, + * or to an AWT component, e.g. {@link java.awt.Component}.

+ * + javax.media.opengl.GLEvenListener demo1 = new javax.media.opengl.GLEvenListener() { ... } ; + com.jogamp.newt.event.MouseListener mouseListener = new com.jogamp.newt.event.MouseAdapter() { ... } ; + + // NEWT Usage + GLWindow glWindow = GLWindow.create(); + glWindow.addGLEventListener(demo1); + glWindow.addMouseListener(mouseListener); + .. + + // AWT Usage + GLCanvas glCanvas = new GLCanvas(); + glCanvas.addGLEventListener(demo1); + new AWTMouseAdapter(mouseListener).addTo(glCanvas); + + // This last line is nothing else but a simplified form of: + AWTMouseAdapter mouseAdapter = new AWTMouseAdapter(mouseListener); + glCanvas.addMouseListener(mouseAdapter); + glCanvas.addMouseMotionListener(mouseAdapter); + * + * + * Second is just a litte variation, where we pass a NEWT Window + * to impersonate as the source of the event.
+ * + * + com.jogamp.newt.event.MouseListener mouseListener = new com.jogamp.newt.event.MouseAdapter() { ... } ; + Component comp = ... ; // the AWT component + GLWindow glWindow = GLWindow.create(); // the NEWT component + + new AWTMouseAdapter(mouseListener, glWindow).addTo(comp); + * + * + * Last but not least, the AWTAdapter maybe used as a general AWT event forwarder to NEWT.
+ * + * + com.jogamp.newt.event.MouseListener mouseListener = new com.jogamp.newt.event.MouseAdapter() { ... } ; + Component comp = ... ; // the AWT component + GLWindow glWindow = GLWindow.create(); // the NEWT component + glWindow.addMouseListener(mouseListener); // add the custom EventListener to the NEWT component + + new AWTMouseAdapter(glWindow).addTo(comp); // forward all AWT events to glWindow, as NEWT events + * + * + * + * + * @see #attachTo + */ +public abstract class AWTAdapter implements java.util.EventListener +{ + com.jogamp.newt.event.NEWTEventListener newtListener; + com.jogamp.newt.Window newtWindow; + + /** + * Simply wrap aroung a NEWT EventListener, exposed as an AWT EventListener.
+ * The NEWT EventListener will be called when an event happens.
+ */ + public AWTAdapter(com.jogamp.newt.event.NEWTEventListener newtListener) { + if(null==newtListener) { + throw new RuntimeException("Argument newtListener is null"); + } + this.newtListener = newtListener; + this.newtWindow = null; + } + + /** + * Wrap aroung a NEWT EventListener, exposed as an AWT EventListener,
+ * where the given NEWT Window impersonates as the event's source. + * The NEWT EventListener will be called when an event happens.
+ */ + public AWTAdapter(com.jogamp.newt.event.NEWTEventListener newtListener, com.jogamp.newt.Window newtProxy) { + if(null==newtListener) { + throw new RuntimeException("Argument newtListener is null"); + } + if(null==newtProxy) { + throw new RuntimeException("Argument newtProxy is null"); + } + this.newtListener = newtListener; + this.newtWindow = newtProxy; + } + + /** + * Create a pipeline adapter, AWT EventListener.
+ * Once attached to an AWT component, it sends the converted AWT events to the NEWT downstream window.
+ */ + public AWTAdapter(com.jogamp.newt.Window downstream) { + if(null==downstream) { + throw new RuntimeException("Argument downstream is null"); + } + this.newtListener = null; + this.newtWindow = downstream; + } + + /** + * Due to the fact that some NEWT {@link com.jogamp.newt.event.NEWTEventListener} + * are mapped to more than one {@link java.util.EventListener}, + * this method is for your convenience to use this Adapter as a listener for all types.
+ * E.g. {@link com.jogamp.newt.event.MouseListener} is mapped to {@link java.awt.event.MouseListener} and {@link java.awt.event.MouseMotionListener}. + */ + public abstract AWTAdapter addTo(java.awt.Component awtComponent); + + void enqueueEvent(com.jogamp.newt.event.NEWTEvent event) { + try { + newtWindow.getScreen().getDisplay().enqueueEvent(event); + } catch (NullPointerException npe) { + /* that's ok .. window might be down already */ + } + } +} + diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java new file mode 100644 index 000000000..64d4d8d86 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2010 Sven Gothel. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name Sven Gothel or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ +package com.jogamp.newt.event.awt; + +public class AWTKeyAdapter extends AWTAdapter implements java.awt.event.KeyListener +{ + public AWTKeyAdapter(com.jogamp.newt.event.KeyListener newtListener) { + super(newtListener); + } + + public AWTKeyAdapter(com.jogamp.newt.event.KeyListener newtListener, com.jogamp.newt.Window newtProxy) { + super(newtListener, newtProxy); + } + + public AWTKeyAdapter(com.jogamp.newt.Window downstream) { + super(downstream); + } + + public AWTAdapter addTo(java.awt.Component awtComponent) { + awtComponent.addKeyListener(this); + return this; + } + + public void keyPressed(java.awt.event.KeyEvent e) { + com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.KeyListener)newtListener).keyPressed(event); + } else { + enqueueEvent(event); + } + } + + public void keyReleased(java.awt.event.KeyEvent e) { + com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.KeyListener)newtListener).keyReleased(event); + } else { + enqueueEvent(event); + } + } + + public void keyTyped(java.awt.event.KeyEvent e) { + com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.KeyListener)newtListener).keyTyped(event); + } else { + enqueueEvent(event); + } + } +} + diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java new file mode 100644 index 000000000..7efcd123e --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2010 Sven Gothel. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name Sven Gothel or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ +package com.jogamp.newt.event.awt; + +public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener +{ + public AWTMouseAdapter(com.jogamp.newt.event.MouseListener newtListener) { + super(newtListener); + } + + public AWTMouseAdapter(com.jogamp.newt.event.MouseListener newtListener, com.jogamp.newt.Window newtProxy) { + super(newtListener, newtProxy); + } + + public AWTMouseAdapter(com.jogamp.newt.Window downstream) { + super(downstream); + } + + public AWTAdapter addTo(java.awt.Component awtComponent) { + awtComponent.addMouseListener(this); + awtComponent.addMouseMotionListener(this); + return this; + } + + public void mouseClicked(java.awt.event.MouseEvent e) { + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.MouseListener)newtListener).mouseClicked(event); + } else { + enqueueEvent(event); + } + } + + public void mouseEntered(java.awt.event.MouseEvent e) { + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.MouseListener)newtListener).mouseEntered(event); + } else { + enqueueEvent(event); + } + } + + public void mouseExited(java.awt.event.MouseEvent e) { + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.MouseListener)newtListener).mouseExited(event); + } else { + enqueueEvent(event); + } + } + + public void mousePressed(java.awt.event.MouseEvent e) { + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.MouseListener)newtListener).mousePressed(event); + } else { + enqueueEvent(event); + } + } + + public void mouseReleased(java.awt.event.MouseEvent e) { + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.MouseListener)newtListener).mouseReleased(event); + } else { + enqueueEvent(event); + } + } + + public void mouseDragged(java.awt.event.MouseEvent e) { + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.MouseListener)newtListener).mouseDragged(event); + } else { + enqueueEvent(event); + } + } + + public void mouseMoved(java.awt.event.MouseEvent e) { + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.MouseListener)newtListener).mouseMoved(event); + } else { + enqueueEvent(event); + } + } +} + diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java new file mode 100644 index 000000000..e4e97946a --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java @@ -0,0 +1,140 @@ + +/* + * Copyright (c) 2010 Sven Gothel. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name Sven Gothel or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ +package com.jogamp.newt.event.awt; + +import com.jogamp.common.util.IntIntHashMap; + +class AWTNewtEventFactory { + + protected static final IntIntHashMap eventTypeAWT2NEWT; + + static { + IntIntHashMap map = new IntIntHashMap(); + 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); + // 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); + map.put(java.awt.event.WindowEvent.WINDOW_GAINED_FOCUS, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + map.put(java.awt.event.WindowEvent.WINDOW_DEACTIVATED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_LOST_FOCUS); + map.put(java.awt.event.WindowEvent.WINDOW_LOST_FOCUS, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_LOST_FOCUS); + // n/a map.put(java.awt.event.WindowEvent.WINDOW_STATE_CHANGED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_STATE_CHANGED); + + map.put(java.awt.event.ComponentEvent.COMPONENT_MOVED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_MOVED); + map.put(java.awt.event.ComponentEvent.COMPONENT_RESIZED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_RESIZED); + // n/a map.put(java.awt.event.ComponentEvent.COMPONENT_SHOWN, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_SHOWN); + // n/a map.put(java.awt.event.ComponentEvent.COMPONENT_HIDDEN, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_HIDDEN); + + map.put(java.awt.event.MouseEvent.MOUSE_CLICKED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_CLICKED); + map.put(java.awt.event.MouseEvent.MOUSE_PRESSED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED); + map.put(java.awt.event.MouseEvent.MOUSE_RELEASED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED); + map.put(java.awt.event.MouseEvent.MOUSE_MOVED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_MOVED); + map.put(java.awt.event.MouseEvent.MOUSE_ENTERED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_ENTERED); + map.put(java.awt.event.MouseEvent.MOUSE_EXITED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_EXITED); + map.put(java.awt.event.MouseEvent.MOUSE_DRAGGED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_DRAGGED); + map.put(java.awt.event.MouseEvent.MOUSE_WHEEL, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_WHEEL_MOVED); + + map.put(java.awt.event.KeyEvent.KEY_PRESSED, com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED); + map.put(java.awt.event.KeyEvent.KEY_RELEASED, com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED); + map.put(java.awt.event.KeyEvent.KEY_TYPED, com.jogamp.newt.event.KeyEvent.EVENT_KEY_TYPED); + + eventTypeAWT2NEWT = map; + } + + public static final int awtModifiers2Newt(int awtMods, boolean mouseHint) { + int newtMods = 0; + if ((awtMods & java.awt.event.InputEvent.SHIFT_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.SHIFT_MASK; + if ((awtMods & java.awt.event.InputEvent.CTRL_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.CTRL_MASK; + if ((awtMods & java.awt.event.InputEvent.META_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.META_MASK; + if ((awtMods & java.awt.event.InputEvent.ALT_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.ALT_MASK; + if ((awtMods & java.awt.event.InputEvent.ALT_GRAPH_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.ALT_GRAPH_MASK; + return newtMods; + } + + public static final int awtButton2Newt(int awtButton) { + switch (awtButton) { + case java.awt.event.MouseEvent.BUTTON1: return com.jogamp.newt.event.MouseEvent.BUTTON1; + case java.awt.event.MouseEvent.BUTTON2: return com.jogamp.newt.event.MouseEvent.BUTTON2; + case java.awt.event.MouseEvent.BUTTON3: return com.jogamp.newt.event.MouseEvent.BUTTON3; + } + return 0; + } + + static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.WindowEvent event, com.jogamp.newt.Window newtSource) { + int type = eventTypeAWT2NEWT.get(event.getID()); + if(-1 < type) { + return new com.jogamp.newt.event.WindowEvent(type, ((null==newtSource)?(Object)event.getComponent():(Object)newtSource), System.currentTimeMillis()); + } + return null; // no mapping .. + } + + static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.ComponentEvent event, com.jogamp.newt.Window newtSource) { + int type = eventTypeAWT2NEWT.get(event.getID()); + if(-1 < type) { + return new com.jogamp.newt.event.WindowEvent(type, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, System.currentTimeMillis()); + } + return null; // no mapping .. + } + + static final com.jogamp.newt.event.MouseEvent createMouseEvent(java.awt.event.MouseEvent event, com.jogamp.newt.Window newtSource) { + int type = eventTypeAWT2NEWT.get(event.getID()); + if(-1 < type) { + int rotation = 0; + if (event instanceof java.awt.event.MouseWheelEvent) { + rotation = ((java.awt.event.MouseWheelEvent)event).getWheelRotation(); + } + + return new com.jogamp.newt.event.MouseEvent( + type, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, event.getWhen(), + awtModifiers2Newt(event.getModifiers(), true), + event.getX(), event.getY(), event.getClickCount(), + awtButton2Newt(event.getButton()), rotation); + } + return null; // no mapping .. + } + + static final com.jogamp.newt.event.KeyEvent createKeyEvent(java.awt.event.KeyEvent event, com.jogamp.newt.Window newtSource) { + int type = eventTypeAWT2NEWT.get(event.getID()); + if(-1 < type) { + return new com.jogamp.newt.event.KeyEvent( + type, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, event.getWhen(), + awtModifiers2Newt(event.getModifiers(), false), + event.getKeyCode(), event.getKeyChar()); + } + return null; // no mapping .. + } + +} + diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java new file mode 100644 index 000000000..2a5312d0b --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2010 Sven Gothel. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name Sven Gothel or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ +package com.jogamp.newt.event.awt; + +public class AWTWindowAdapter extends AWTAdapter implements java.awt.event.ComponentListener, java.awt.event.WindowListener +{ + public AWTWindowAdapter(com.jogamp.newt.event.WindowListener newtListener) { + super(newtListener); + } + + public AWTWindowAdapter(com.jogamp.newt.event.WindowListener newtListener, com.jogamp.newt.Window newtProxy) { + super(newtListener, newtProxy); + } + + public AWTWindowAdapter(com.jogamp.newt.Window downstream) { + super(downstream); + } + + public AWTAdapter addTo(java.awt.Component awtComponent) { + awtComponent.addComponentListener(this); + if(awtComponent instanceof java.awt.Window) { + ((java.awt.Window)awtComponent).addWindowListener(this); + } + return this; + } + + public void componentResized(java.awt.event.ComponentEvent e) { + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.WindowListener)newtListener).windowResized(event); + } else { + enqueueEvent(event); + } + } + + public void componentMoved(java.awt.event.ComponentEvent e) { + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.WindowListener)newtListener).windowMoved(event); + } else { + enqueueEvent(event); + } + } + + public void componentShown(java.awt.event.ComponentEvent e) { + // n/a + } + + public void componentHidden(java.awt.event.ComponentEvent e) { + // n/a + } + + public void windowActivated(java.awt.event.WindowEvent e) { + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.WindowListener)newtListener).windowGainedFocus(event); + } else { + enqueueEvent(event); + } + } + + public void windowClosed(java.awt.event.WindowEvent e) { + // n/a + } + + public void windowClosing(java.awt.event.WindowEvent e) { + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.WindowListener)newtListener).windowDestroyNotify(event); + } else { + enqueueEvent(event); + } + } + + public void windowDeactivated(java.awt.event.WindowEvent e) { + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.WindowListener)newtListener).windowLostFocus(event); + } else { + enqueueEvent(event); + } + } + + public void windowDeiconified(java.awt.event.WindowEvent e) { + // n/a + } + + public void windowIconified(java.awt.event.WindowEvent e) { + // n/a + } + + public void windowOpened(java.awt.event.WindowEvent e) { + // n/a + } + +} + diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/AWTCanvas.java b/src/newt/classes/com/jogamp/newt/impl/awt/AWTCanvas.java new file mode 100644 index 000000000..8750a8bc1 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTCanvas.java @@ -0,0 +1,264 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.awt; + +import com.jogamp.newt.Window; + +import java.awt.Canvas; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.awt.GraphicsConfiguration; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.awt.*; +import com.jogamp.newt.impl.Debug; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; + +public class AWTCanvas extends Canvas { + private GraphicsDevice device; + private GraphicsConfiguration chosen; + private AWTGraphicsConfiguration awtConfig; + + private Capabilities capabilities; + + private boolean displayConfigChanged=false; + + public AWTCanvas(Capabilities capabilities) { + super(); + + if(null==capabilities) { + throw new NativeWindowException("Capabilities null"); + } + this.capabilities=capabilities; + } + + public AWTGraphicsConfiguration getAWTGraphicsConfiguration() { + return awtConfig; + } + + public boolean hasDeviceChanged() { + boolean res = displayConfigChanged; + displayConfigChanged=false; + return res; + } + + public void addNotify() { + super.addNotify(); + + disableBackgroundErase(); + + GraphicsConfiguration gc = super.getGraphicsConfiguration(); + if(null!=gc) { + device = gc.getDevice(); + } + + /* + * Save the chosen capabilities for use in getGraphicsConfiguration(). + */ + awtConfig = chooseGraphicsConfiguration(capabilities, device); + if(Window.DEBUG_IMPLEMENTATION) { + Exception e = new Exception("Created Config: "+awtConfig); + e.printStackTrace(); + } + if(null!=awtConfig) { + // update .. + chosen = awtConfig.getGraphicsConfiguration(); + } + if(null==awtConfig) { + throw new NativeWindowException("Error: AWTGraphicsConfiguration is null"); + } + } + + /** + * Overridden to choose a GraphicsConfiguration on a parent container's + * GraphicsDevice because both devices + */ + public GraphicsConfiguration getGraphicsConfiguration() { + /* + * Workaround for problems with Xinerama and java.awt.Component.checkGD + * when adding to a container on a different graphics device than the + * one that this Canvas is associated with. + * + * GC will be null unless: + * - A native peer has assigned it. This means we have a native + * peer, and are already comitted to a graphics configuration. + * - This canvas has been added to a component hierarchy and has + * an ancestor with a non-null GC, but the native peer has not + * yet been created. This means we can still choose the GC on + * all platforms since the peer hasn't been created. + */ + final GraphicsConfiguration gc = super.getGraphicsConfiguration(); + /* + * chosen is only non-null on platforms where the GLDrawableFactory + * returns a non-null GraphicsConfiguration (in the GLCanvas + * constructor). + * + * if gc is from this Canvas' native peer then it should equal chosen, + * otherwise it is from an ancestor component that this Canvas is being + * added to, and we go into this block. + */ + if (gc != null && chosen != null && !chosen.equals(gc)) { + /* + * Check for compatibility with gc. If they differ by only the + * device then return a new GCconfig with the super-class' GDevice + * (and presumably the same visual ID in Xinerama). + * + */ + if (!chosen.getDevice().getIDstring().equals(gc.getDevice().getIDstring())) { + /* + * Here we select a GraphicsConfiguration on the alternate + * device that is presumably identical to the chosen + * configuration, but on the other device. + * + * Should really check to ensure that we select a configuration + * with the same X visual ID for Xinerama screens, otherwise the + * GLDrawable may have the wrong visual ID (I don't think this + * ever gets updated). May need to add a method to + * X11GLDrawableFactory to do this in a platform specific + * manner. + * + * However, on platforms where we can actually get into this + * block, both devices should have the same visual list, and the + * same configuration should be selected here. + */ + AWTGraphicsConfiguration config = chooseGraphicsConfiguration((Capabilities)awtConfig.getRequestedCapabilities(), gc.getDevice()); + final GraphicsConfiguration compatible = (null!=config)?config.getGraphicsConfiguration():null; + if(Window.DEBUG_IMPLEMENTATION) { + Exception e = new Exception("Call Stack: "+Thread.currentThread().getName()); + e.printStackTrace(); + System.err.println("!!! Created Config (n): HAVE GC "+chosen); + System.err.println("!!! Created Config (n): THIS GC "+gc); + System.err.println("!!! Created Config (n): Choosen GC "+compatible); + System.err.println("!!! Created Config (n): HAVE CF "+awtConfig); + System.err.println("!!! Created Config (n): Choosen CF "+config); + System.err.println("!!! Created Config (n): EQUALS CAPS "+config.getChosenCapabilities().equals(awtConfig.getChosenCapabilities())); + } + + if (compatible != null) { + /* + * Save the new GC for equals test above, and to return to + * any outside callers of this method. + */ + chosen = compatible; + if( !config.getChosenCapabilities().equals(awtConfig.getChosenCapabilities())) { + displayConfigChanged=true; + } + awtConfig = config; + } + } + + /* + * If a compatible GC was not found in the block above, this will + * return the GC that was selected in the constructor (and might + * cause an exception in Component.checkGD when adding to a + * container, but in this case that would be the desired behavior). + * + */ + return chosen; + } else if (gc == null) { + /* + * The GC is null, which means we have no native peer, and are not + * part of a (realized) component hierarchy. So we return the + * desired visual that was selected in the constructor (possibly + * null). + */ + return chosen; + } + + /* + * Otherwise we have not explicitly selected a GC in the constructor, so + * just return what Canvas would have. + */ + return gc; + } + + private static AWTGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities, + GraphicsDevice device) { + AbstractGraphicsScreen aScreen = AWTGraphicsScreen.createScreenDevice(device); + AWTGraphicsConfiguration config = (AWTGraphicsConfiguration) + GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class).chooseGraphicsConfiguration(capabilities, + null, + aScreen); + if (config == null) { + throw new NativeWindowException("Error: Couldn't fetch AWTGraphicsConfiguration"); + } + + return config; + } + + // Disables the AWT's erasing of this Canvas's background on Windows + // in Java SE 6. This internal API is not available in previous + // releases, but the system property + // -Dsun.awt.noerasebackground=true can be specified to get similar + // results globally in previous releases. + private static boolean disableBackgroundEraseInitialized; + private static Method disableBackgroundEraseMethod; + private void disableBackgroundErase() { + if (!disableBackgroundEraseInitialized) { + try { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + try { + Class clazz = getToolkit().getClass(); + while (clazz != null && disableBackgroundEraseMethod == null) { + try { + disableBackgroundEraseMethod = + clazz.getDeclaredMethod("disableBackgroundErase", + new Class[] { Canvas.class }); + disableBackgroundEraseMethod.setAccessible(true); + } catch (Exception e) { + clazz = clazz.getSuperclass(); + } + } + } catch (Exception e) { + } + return null; + } + }); + } catch (Exception e) { + } + disableBackgroundEraseInitialized = true; + } + if (disableBackgroundEraseMethod != null) { + try { + disableBackgroundEraseMethod.invoke(getToolkit(), new Object[] { this }); + } catch (Exception e) { + // FIXME: workaround for 6504460 (incorrect backport of 6333613 in 5.0u10) + // throw new GLException(e); + } + } + } +} diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java b/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java new file mode 100644 index 000000000..f54e66f07 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.awt; + +import java.awt.event.*; +import com.jogamp.newt.Display; +import com.jogamp.newt.Window; +import javax.media.nativewindow.*; +import javax.media.nativewindow.awt.*; +import java.util.*; + +public class AWTDisplay extends Display { + public AWTDisplay() { + } + + protected void createNative() { + aDevice = (AWTGraphicsDevice) AWTGraphicsDevice.createDevice(null); // default + } + + protected void setAWTGraphicsDevice(AWTGraphicsDevice d) { + aDevice = d; + } + + protected void closeNative() { } + + protected void dispatchMessagesNative() { /* nop */ } +} + diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/AWTScreen.java b/src/newt/classes/com/jogamp/newt/impl/awt/AWTScreen.java new file mode 100644 index 000000000..8702686c0 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTScreen.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.awt; + +import com.jogamp.newt.*; +import java.awt.DisplayMode; +import javax.media.nativewindow.*; +import javax.media.nativewindow.awt.*; + +public class AWTScreen extends Screen { + public AWTScreen() { + } + + protected void createNative(int index) { + aScreen = new AWTGraphicsScreen((AWTGraphicsDevice)display.getGraphicsDevice()); + + DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode(); + int w = mode.getWidth(); + int h = mode.getHeight(); + setScreenSize(w, h); + } + + protected void setAWTGraphicsScreen(AWTGraphicsScreen s) { + aScreen = s; + } + + // done by AWTWindow .. + protected void setScreenSize(int w, int h) { + super.setScreenSize(w, h); + } + + protected void closeNative() { } + +} diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java b/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java new file mode 100644 index 000000000..bc04f2523 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java @@ -0,0 +1,335 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.awt; + +import com.jogamp.newt.event.awt.*; + +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Container; +import java.awt.DisplayMode; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.*; +import com.jogamp.newt.Window; +import java.awt.Insets; +import javax.media.nativewindow.*; +import javax.media.nativewindow.awt.*; + +/** An implementation of the Newt Window class built using the + AWT. This is provided for convenience of porting to platforms + supporting Java SE. */ + +public class AWTWindow extends Window { + + public AWTWindow() { + this(null); + } + + public static Class[] getCustomConstructorArgumentTypes() { + return new Class[] { Container.class } ; + } + + public AWTWindow(Container container) { + super(); + title = "AWT NewtWindow"; + this.container = container; + if(container instanceof Frame) { + frame = (Frame) container; + } + } + + private boolean owningFrame; + private Container container = null; + private Frame frame = null; // same instance as container, just for impl. convenience + private AWTCanvas canvas; + // non fullscreen dimensions .. + private int nfs_width, nfs_height, nfs_x, nfs_y; + + public void setTitle(final String title) { + super.setTitle(title); + runOnEDT(true, new Runnable() { + public void run() { + if (frame != null) { + frame.setTitle(title); + } + } + }); + } + + protected void createNative(long parentWindowHandle, final Capabilities caps) { + + if(0!=parentWindowHandle) { + throw new RuntimeException("Window parenting not supported in AWT, use AWTWindow(Frame) cstr for wrapping instead"); + } + + final AWTWindow awtWindow = this; + + runOnEDT(true, new Runnable() { + public void run() { + if(null==container) { + frame = new Frame(); + container = frame; + owningFrame=true; + } else { + owningFrame=false; + width = container.getWidth(); + height = container.getHeight(); + x = container.getX(); + y = container.getY(); + } + if(null!=frame) { + frame.setTitle(getTitle()); + } + container.setLayout(new BorderLayout()); + canvas = new AWTCanvas(caps); + + addWindowListener(new LocalWindowListener()); + + new AWTMouseAdapter(awtWindow).addTo(canvas); // fwd all AWT Mouse events to here + new AWTKeyAdapter(awtWindow).addTo(canvas); // fwd all AWT Key events to here + + // canvas.addComponentListener(listener); + container.add(canvas, BorderLayout.CENTER); + container.setSize(width, height); + container.setLocation(x, y); + new AWTWindowAdapter(awtWindow).addTo(container); // fwd all AWT Window events to here + + if(null!=frame) { + frame.setUndecorated(undecorated||fullscreen); + } + } + }); + this.windowHandle = 1; // just a marker .. + } + + protected void closeNative() { + this.windowHandle = 0; // just a marker .. + if(null!=container) { + runOnEDT(true, new Runnable() { + public void run() { + container.setVisible(false); + container.remove(canvas); + container.setEnabled(false); + canvas.setEnabled(false); + } + }); + } + if(owningFrame && null!=frame) { + runOnEDT(true, new Runnable() { + public void run() { + frame.dispose(); + owningFrame=false; + frame = null; + } + }); + } + } + + public boolean hasDeviceChanged() { + boolean res = canvas.hasDeviceChanged(); + if(res) { + config = canvas.getAWTGraphicsConfiguration(); + if (config == null) { + throw new NativeWindowException("Error Device change null GraphicsConfiguration: "+this); + } + updateDeviceData(); + } + return res; + } + + public void setVisible(final boolean visible) { + runOnEDT(true, new Runnable() { + public void run() { + container.setVisible(visible); + } + }); + + config = canvas.getAWTGraphicsConfiguration(); + + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + + updateDeviceData(); + } + + private void updateDeviceData() { + // propagate new info .. + ((AWTScreen)getScreen()).setAWTGraphicsScreen((AWTGraphicsScreen)config.getScreen()); + ((AWTDisplay)getScreen().getDisplay()).setAWTGraphicsDevice((AWTGraphicsDevice)config.getScreen().getDevice()); + + DisplayMode mode = ((AWTGraphicsDevice)config.getScreen().getDevice()).getGraphicsDevice().getDisplayMode(); + int w = mode.getWidth(); + int h = mode.getHeight(); + ((AWTScreen)screen).setScreenSize(w, h); + } + + public void setSize(final int width, final int height) { + this.width = width; + this.height = height; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + /** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */ + runOnEDT(false, new Runnable() { + public void run() { + Insets insets = container.getInsets(); + container.setSize(width + insets.left + insets.right, + height + insets.top + insets.bottom); + } + }); + } + + public com.jogamp.newt.Insets getInsets() { + final int insets[] = new int[] { 0, 0, 0, 0 }; + runOnEDT(true, new Runnable() { + public void run() { + Insets contInsets = container.getInsets(); + insets[0] = contInsets.top; + insets[1] = contInsets.left; + insets[2] = contInsets.bottom; + insets[3] = contInsets.right; + } + }); + return new com.jogamp.newt. + Insets(insets[0],insets[1],insets[2],insets[3]); + } + + public void setPosition(final int x, final int y) { + this.x = x; + this.y = y; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + runOnEDT(true, new Runnable() { + public void run() { + container.setLocation(x, y); + } + }); + } + + public boolean setFullscreen(final boolean fullscreen) { + if(this.fullscreen!=fullscreen) { + final int x,y,w,h; + this.fullscreen=fullscreen; + if(fullscreen) { + x = 0; y = 0; + w = screen.getWidth(); + h = screen.getHeight(); + } else { + x = nfs_x; + y = nfs_y; + w = nfs_width; + h = nfs_height; + } + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("AWTWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); + } + /** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */ + runOnEDT(false, new Runnable() { + public void run() { + if(null!=frame) { + if(!container.isDisplayable()) { + frame.setUndecorated(undecorated||fullscreen); + } else { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("AWTWindow can't undecorate already created frame"); + } + } + } + container.setLocation(x, y); + container.setSize(w, h); + } + }); + } + return true; + } + + public Object getWrappedWindow() { + return canvas; + } + + protected void sendWindowEvent(int eventType) { + super.sendWindowEvent(eventType); + } + + protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { + super.sendKeyEvent(eventType, modifiers, keyCode, keyChar); + } + + protected void sendMouseEvent(int eventType, int modifiers, + int x, int y, int button, int rotation) { + super.sendMouseEvent(eventType, modifiers, x, y, button, rotation); + } + + private static void runOnEDT(boolean wait, Runnable r) { + if (EventQueue.isDispatchThread()) { + r.run(); + } else { + try { + if(wait) { + EventQueue.invokeAndWait(r); + } else { + EventQueue.invokeLater(r); + } + } catch (Exception e) { + throw new NativeWindowException(e); + } + } + } + + class LocalWindowListener extends com.jogamp.newt.event.WindowAdapter { + public void windowMoved(com.jogamp.newt.event.WindowEvent e) { + if(null!=container) { + x = container.getX(); + y = container.getY(); + } + } + public void windowResized(com.jogamp.newt.event.WindowEvent e) { + if(null!=canvas) { + width = canvas.getWidth(); + height = canvas.getHeight(); + } + } + } +} diff --git a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Display.java b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Display.java new file mode 100644 index 000000000..d19aaf796 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Display.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.intel.gdl; + +import com.jogamp.newt.impl.*; +import javax.media.nativewindow.*; + +public class Display extends com.jogamp.newt.Display { + static int initCounter = 0; + + static { + NEWTJNILibLoader.loadNEWT(); + + if (!Screen.initIDs()) { + throw new NativeWindowException("Failed to initialize GDL Screen jmethodIDs"); + } + if (!Window.initIDs()) { + throw new NativeWindowException("Failed to initialize GDL Window jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public Display() { + } + + protected void createNative() { + synchronized(Display.class) { + if(0==initCounter) { + displayHandle = CreateDisplay(); + if(0==displayHandle) { + throw new NativeWindowException("Couldn't initialize GDL Display"); + } + } + initCounter++; + } + aDevice = new DefaultGraphicsDevice(NativeWindowFactory.TYPE_DEFAULT, displayHandle); + } + + protected void closeNative() { + if(0==displayHandle) { + throw new NativeWindowException("displayHandle null; initCnt "+initCounter); + } + synchronized(Display.class) { + if(initCounter>0) { + initCounter--; + if(0==initCounter) { + DestroyDisplay(displayHandle); + } + } + } + } + + protected void dispatchMessagesNative() { + if(0!=displayHandle) { + DispatchMessages(displayHandle, focusedWindow); + } + } + + protected void setFocus(Window focus) { + focusedWindow = focus; + } + + private long displayHandle = 0; + private Window focusedWindow = null; + private native long CreateDisplay(); + private native void DestroyDisplay(long displayHandle); + private native void DispatchMessages(long displayHandle, Window focusedWindow); +} + diff --git a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Screen.java b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Screen.java new file mode 100644 index 000000000..3d9a5a309 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Screen.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.intel.gdl; + +import com.jogamp.newt.impl.*; +import javax.media.nativewindow.*; + +public class Screen extends com.jogamp.newt.Screen { + + static { + Display.initSingleton(); + } + + public Screen() { + } + + protected void createNative(int index) { + AbstractGraphicsDevice adevice = getDisplay().getGraphicsDevice(); + GetScreenInfo(adevice.getHandle(), index); + aScreen = new DefaultGraphicsScreen(adevice, index); + } + + protected void closeNative() { } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native void GetScreenInfo(long displayHandle, int screen_idx); + + // called by GetScreenInfo() .. + private void screenCreated(int width, int height) { + setScreenSize(width, height); + } +} + diff --git a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java new file mode 100644 index 000000000..cb52618b2 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.intel.gdl; + +import javax.media.nativewindow.*; + +public class Window extends com.jogamp.newt.Window { + static { + Display.initSingleton(); + } + + public Window() { + } + + static long nextWindowHandle = 1; + + protected void createNative(long parentWindowHandle, Capabilities caps) { + if(0!=parentWindowHandle) { + throw new NativeWindowException("GDL Window does not support window parenting"); + } + AbstractGraphicsScreen aScreen = screen.getGraphicsScreen(); + AbstractGraphicsDevice aDevice = screen.getDisplay().getGraphicsDevice(); + + config = GraphicsConfigurationFactory.getFactory(aDevice).chooseGraphicsConfiguration(caps, null, aScreen); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + + synchronized(Window.class) { + windowHandle = nextWindowHandle++; + } + } + + protected void closeNative() { + if(0!=surfaceHandle) { + synchronized(Window.class) { + CloseSurface(getDisplayHandle(), surfaceHandle); + } + surfaceHandle = 0; + ((Display)screen.getDisplay()).setFocus(null); + } + } + + public void setVisible(boolean visible) { + if(this.visible!=visible) { + this.visible=visible; + if(visible && 0==surfaceHandle) { + synchronized(Window.class) { + AbstractGraphicsDevice aDevice = screen.getDisplay().getGraphicsDevice(); + surfaceHandle = CreateSurface(aDevice.getHandle(), screen.getWidth(), screen.getHeight(), x, y, width, height); + } + if (surfaceHandle == 0) { + throw new NativeWindowException("Error creating window"); + } + ((Display)screen.getDisplay()).setFocus(this); + } + } + } + + public void setSize(int width, int height) { + Screen screen = (Screen) getScreen(); + if((x+width)>screen.getWidth()) { + width=screen.getWidth()-x; + } + if((y+height)>screen.getHeight()) { + height=screen.getHeight()-y; + } + this.width = width; + this.height = height; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + if(0!=surfaceHandle) { + SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, width, height); + } + } + + public void setPosition(int x, int y) { + Screen screen = (Screen) getScreen(); + if((x+width)>screen.getWidth()) { + x=screen.getWidth()-width; + } + if((y+height)>screen.getHeight()) { + y=screen.getHeight()-height; + } + this.x = x; + this.y = y; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + if(0!=surfaceHandle) { + SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, width, height); + } + } + + public boolean setFullscreen(boolean fullscreen) { + if(this.fullscreen!=fullscreen) { + int x,y,w,h; + this.fullscreen=fullscreen; + if(fullscreen) { + x = 0; y = 0; + w = screen.getWidth(); + h = screen.getHeight(); + } else { + x = nfs_x; + y = nfs_y; + w = nfs_width; + h = nfs_height; + } + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("IntelGDL Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); + } + if(0!=surfaceHandle) { + SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, w, h); + } + } + return fullscreen; + } + + public void requestFocus() { + ((Display)screen.getDisplay()).setFocus(this); + } + + public long getSurfaceHandle() { + return surfaceHandle; + } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native long CreateSurface(long displayHandle, int scrn_width, int scrn_height, int x, int y, int width, int height); + private native void CloseSurface(long displayHandle, long surfaceHandle); + private native void SetBounds0(long surfaceHandle, int scrn_width, int scrn_height, int x, int y, int width, int height); + + private void updateBounds(int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + private long surfaceHandle; + private int nfs_width, nfs_height, nfs_x, nfs_y; +} diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java new file mode 100755 index 000000000..68242bba7 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.macosx; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.macosx.*; +import com.jogamp.newt.*; +import com.jogamp.newt.impl.*; +import com.jogamp.newt.util.MainThread; + +public class MacDisplay extends Display { + static { + NEWTJNILibLoader.loadNEWT(); + + if(!initNSApplication()) { + throw new NativeWindowException("Failed to initialize native Application hook"); + } + if(!MacWindow.initIDs()) { + throw new NativeWindowException("Failed to initialize jmethodIDs"); + } + if(DEBUG) System.out.println("MacDisplay.init App and IDs OK "+Thread.currentThread().getName()); + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + public MacDisplay() { + } + + class DispatchAction implements Runnable { + public void run() { + dispatchMessages0(); + } + } + private DispatchAction dispatchAction = new DispatchAction(); + + protected void dispatchMessagesNative() { + MainThread.invoke(false, dispatchAction); + } + + protected void createNative() { + aDevice = new MacOSXGraphicsDevice(); + } + + protected void closeNative() { } + + private static native boolean initNSApplication(); + protected native void dispatchMessages0(); +} + diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacScreen.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacScreen.java new file mode 100755 index 000000000..ce9254857 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacScreen.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.macosx; + +import com.jogamp.newt.*; +import javax.media.nativewindow.*; + +public class MacScreen extends Screen { + static { + MacDisplay.initSingleton(); + } + + public MacScreen() { + } + + protected void createNative(int index) { + aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); + setScreenSize(getWidthImpl(getIndex()), getHeightImpl(getIndex())); + } + + protected void closeNative() { } + + private static native int getWidthImpl(int scrn_idx); + private static native int getHeightImpl(int scrn_idx); +} diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java new file mode 100755 index 000000000..8fb095661 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java @@ -0,0 +1,575 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.macosx; + +import javax.media.nativewindow.*; + +import com.jogamp.newt.util.MainThread; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.impl.*; + +public class MacWindow extends Window { + + // Window styles + private static final int NSBorderlessWindowMask = 0; + private static final int NSTitledWindowMask = 1 << 0; + private static final int NSClosableWindowMask = 1 << 1; + private static final int NSMiniaturizableWindowMask = 1 << 2; + private static final int NSResizableWindowMask = 1 << 3; + + // Window backing store types + private static final int NSBackingStoreRetained = 0; + private static final int NSBackingStoreNonretained = 1; + private static final int NSBackingStoreBuffered = 2; + + // Key constants handled differently on Mac OS X than other platforms + private static final int NSUpArrowFunctionKey = 0xF700; + private static final int NSDownArrowFunctionKey = 0xF701; + private static final int NSLeftArrowFunctionKey = 0xF702; + private static final int NSRightArrowFunctionKey = 0xF703; + private static final int NSF1FunctionKey = 0xF704; + private static final int NSF2FunctionKey = 0xF705; + private static final int NSF3FunctionKey = 0xF706; + private static final int NSF4FunctionKey = 0xF707; + private static final int NSF5FunctionKey = 0xF708; + private static final int NSF6FunctionKey = 0xF709; + private static final int NSF7FunctionKey = 0xF70A; + private static final int NSF8FunctionKey = 0xF70B; + private static final int NSF9FunctionKey = 0xF70C; + private static final int NSF10FunctionKey = 0xF70D; + private static final int NSF11FunctionKey = 0xF70E; + private static final int NSF12FunctionKey = 0xF70F; + private static final int NSF13FunctionKey = 0xF710; + private static final int NSF14FunctionKey = 0xF711; + private static final int NSF15FunctionKey = 0xF712; + private static final int NSF16FunctionKey = 0xF713; + private static final int NSF17FunctionKey = 0xF714; + private static final int NSF18FunctionKey = 0xF715; + private static final int NSF19FunctionKey = 0xF716; + private static final int NSF20FunctionKey = 0xF717; + private static final int NSF21FunctionKey = 0xF718; + private static final int NSF22FunctionKey = 0xF719; + private static final int NSF23FunctionKey = 0xF71A; + private static final int NSF24FunctionKey = 0xF71B; + private static final int NSF25FunctionKey = 0xF71C; + private static final int NSF26FunctionKey = 0xF71D; + private static final int NSF27FunctionKey = 0xF71E; + private static final int NSF28FunctionKey = 0xF71F; + private static final int NSF29FunctionKey = 0xF720; + private static final int NSF30FunctionKey = 0xF721; + private static final int NSF31FunctionKey = 0xF722; + private static final int NSF32FunctionKey = 0xF723; + private static final int NSF33FunctionKey = 0xF724; + private static final int NSF34FunctionKey = 0xF725; + private static final int NSF35FunctionKey = 0xF726; + private static final int NSInsertFunctionKey = 0xF727; + private static final int NSDeleteFunctionKey = 0xF728; + private static final int NSHomeFunctionKey = 0xF729; + private static final int NSBeginFunctionKey = 0xF72A; + private static final int NSEndFunctionKey = 0xF72B; + private static final int NSPageUpFunctionKey = 0xF72C; + private static final int NSPageDownFunctionKey = 0xF72D; + private static final int NSPrintScreenFunctionKey = 0xF72E; + private static final int NSScrollLockFunctionKey = 0xF72F; + private static final int NSPauseFunctionKey = 0xF730; + private static final int NSSysReqFunctionKey = 0xF731; + private static final int NSBreakFunctionKey = 0xF732; + private static final int NSResetFunctionKey = 0xF733; + private static final int NSStopFunctionKey = 0xF734; + private static final int NSMenuFunctionKey = 0xF735; + private static final int NSUserFunctionKey = 0xF736; + private static final int NSSystemFunctionKey = 0xF737; + private static final int NSPrintFunctionKey = 0xF738; + private static final int NSClearLineFunctionKey = 0xF739; + private static final int NSClearDisplayFunctionKey = 0xF73A; + private static final int NSInsertLineFunctionKey = 0xF73B; + private static final int NSDeleteLineFunctionKey = 0xF73C; + private static final int NSInsertCharFunctionKey = 0xF73D; + private static final int NSDeleteCharFunctionKey = 0xF73E; + private static final int NSPrevFunctionKey = 0xF73F; + private static final int NSNextFunctionKey = 0xF740; + private static final int NSSelectFunctionKey = 0xF741; + private static final int NSExecuteFunctionKey = 0xF742; + private static final int NSUndoFunctionKey = 0xF743; + private static final int NSRedoFunctionKey = 0xF744; + private static final int NSFindFunctionKey = 0xF745; + private static final int NSHelpFunctionKey = 0xF746; + private static final int NSModeSwitchFunctionKey = 0xF747; + + private volatile long surfaceHandle; + private long parentWindowHandle; + + // non fullscreen dimensions .. + private int nfs_width, nfs_height, nfs_x, nfs_y; + private final Insets insets = new Insets(0,0,0,0); + + static { + MacDisplay.initSingleton(); + } + + public MacWindow() { + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + this.parentWindowHandle=parentWindowHandle; + config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + } + + class CloseAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.CloseAction "+Thread.currentThread().getName()); + if (windowHandle != 0) { + close0(windowHandle); + windowHandle = 0; + } + } finally { + nsViewLock.unlock(); + } + } + } + private CloseAction closeAction = new CloseAction(); + + protected void closeNative() { + MainThread.invoke(true, closeAction); + } + + public long getWindowHandle() { + nsViewLock.lock(); + try { + return windowHandle; + } finally { + nsViewLock.unlock(); + } + } + + public long getSurfaceHandle() { + nsViewLock.lock(); + try { + return surfaceHandle; + } finally { + nsViewLock.unlock(); + } + } + + class EnsureWindowCreatedAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + createWindow(parentWindowHandle, false); + } finally { + nsViewLock.unlock(); + } + } + } + private EnsureWindowCreatedAction ensureWindowCreatedAction = + new EnsureWindowCreatedAction(); + + public Insets getInsets() { + // in order to properly calculate insets we need the window to be + // created + MainThread.invoke(true, ensureWindowCreatedAction); + nsViewLock.lock(); + try { + return (Insets) insets.clone(); + } finally { + nsViewLock.unlock(); + } + } + + private WindowToolkitLock nsViewLock = new WindowToolkitLock(); + + public synchronized int lockSurface() throws NativeWindowException { + nsViewLock.lock(); + try { + return super.lockSurface(); + } catch (RuntimeException re) { + nsViewLock.unlock(); + throw re; + } + } + + public void unlockSurface() { + super.unlockSurface(); + nsViewLock.unlock(); + } + + class VisibleAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.VisibleAction "+visible+" "+Thread.currentThread().getName()); + if (visible) { + createWindow(parentWindowHandle, false); + if (windowHandle != 0) { + makeKeyAndOrderFront(windowHandle); + } + } else { + if (windowHandle != 0) { + orderOut(windowHandle); + } + } + } finally { + nsViewLock.unlock(); + } + } + } + private VisibleAction visibleAction = new VisibleAction(); + + public void setVisible(boolean visible) { + this.visible = visible; + MainThread.invoke(true, visibleAction); + } + + class TitleAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if (windowHandle != 0) { + setTitle0(windowHandle, title); + } + } finally { + nsViewLock.unlock(); + } + } + } + private TitleAction titleAction = new TitleAction(); + + public void setTitle(String title) { + super.setTitle(title); + MainThread.invoke(true, titleAction); + } + + class FocusAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if (windowHandle != 0) { + makeKey(windowHandle); + } + } finally { + nsViewLock.unlock(); + } + } + } + private FocusAction focusAction = new FocusAction(); + + public void requestFocus() { + super.requestFocus(); + MainThread.invoke(true, focusAction); + } + + class SizeAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if (windowHandle != 0) { + setContentSize(windowHandle, width, height); + } + } finally { + nsViewLock.unlock(); + } + } + } + private SizeAction sizeAction = new SizeAction(); + + public void setSize(int width, int height) { + this.width=width; + this.height=height; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + MainThread.invoke(true, sizeAction); + } + + class PositionAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if (windowHandle != 0) { + setFrameTopLeftPoint(parentWindowHandle, windowHandle, x, y); + } + } finally { + nsViewLock.unlock(); + } + } + } + private PositionAction positionAction = new PositionAction(); + + public void setPosition(int x, int y) { + this.x=x; + this.y=y; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + MainThread.invoke(true, positionAction); + } + + class FullscreenAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("MacWindow fs: "+fullscreen+" "+x+"/"+y+" "+width+"x"+height); + } + createWindow(parentWindowHandle, true); + if (windowHandle != 0) { + makeKeyAndOrderFront(windowHandle); + } + } finally { + nsViewLock.unlock(); + } + } + } + private FullscreenAction fullscreenAction = new FullscreenAction(); + + public boolean setFullscreen(boolean fullscreen) { + if(this.fullscreen!=fullscreen) { + this.fullscreen=fullscreen; + if(fullscreen) { + x = 0; + y = 0; + width = screen.getWidth(); + height = screen.getHeight(); + } else { + x = nfs_x; + y = nfs_y; + width = nfs_width; + height = nfs_height; + } + MainThread.invoke(true, fullscreenAction); + } + return fullscreen; + } + + private void sizeChanged(int newWidth, int newHeight) { + if (DEBUG_IMPLEMENTATION) { + System.out.println(Thread.currentThread().getName()+" Size changed to " + newWidth + ", " + newHeight); + } + width = newWidth; + height = newHeight; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + if (DEBUG_IMPLEMENTATION) { + System.out.println(" Posted WINDOW_RESIZED event"); + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } + + private void insetsChanged(int left, int top, int right, int bottom) { + if (DEBUG_IMPLEMENTATION) { + System.out.println(Thread.currentThread().getName()+ + " Insets changed to " + left + ", " + top + ", " + right + ", " + bottom); + } + if (left != -1 && top != -1 && right != -1 && bottom != -1) { + insets.left = left; + insets.top = top; + insets.right = right; + insets.bottom = bottom; + } + } + + private void positionChanged(int newX, int newY) { + if (DEBUG_IMPLEMENTATION) { + System.out.println(Thread.currentThread().getName()+" Position changed to " + newX + ", " + newY); + } + x = newX; + y = newY; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + if (DEBUG_IMPLEMENTATION) { + System.out.println(" Posted WINDOW_MOVED event"); + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + } + + private void focusChanged(boolean focusGained) { + if (focusGained) { + sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + } else { + sendWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS); + } + } + + private char convertKeyChar(char keyChar) { + if (keyChar == '\r') { + // Turn these into \n + return '\n'; + } + + if (keyChar >= NSUpArrowFunctionKey && keyChar <= NSModeSwitchFunctionKey) { + switch (keyChar) { + case NSUpArrowFunctionKey: return KeyEvent.VK_UP; + case NSDownArrowFunctionKey: return KeyEvent.VK_DOWN; + case NSLeftArrowFunctionKey: return KeyEvent.VK_LEFT; + case NSRightArrowFunctionKey: return KeyEvent.VK_RIGHT; + case NSF1FunctionKey: return KeyEvent.VK_F1; + case NSF2FunctionKey: return KeyEvent.VK_F2; + case NSF3FunctionKey: return KeyEvent.VK_F3; + case NSF4FunctionKey: return KeyEvent.VK_F4; + case NSF5FunctionKey: return KeyEvent.VK_F5; + case NSF6FunctionKey: return KeyEvent.VK_F6; + case NSF7FunctionKey: return KeyEvent.VK_F7; + case NSF8FunctionKey: return KeyEvent.VK_F8; + case NSF9FunctionKey: return KeyEvent.VK_F9; + case NSF10FunctionKey: return KeyEvent.VK_F10; + case NSF11FunctionKey: return KeyEvent.VK_F11; + case NSF12FunctionKey: return KeyEvent.VK_F12; + case NSF13FunctionKey: return KeyEvent.VK_F13; + case NSF14FunctionKey: return KeyEvent.VK_F14; + case NSF15FunctionKey: return KeyEvent.VK_F15; + case NSF16FunctionKey: return KeyEvent.VK_F16; + case NSF17FunctionKey: return KeyEvent.VK_F17; + case NSF18FunctionKey: return KeyEvent.VK_F18; + case NSF19FunctionKey: return KeyEvent.VK_F19; + case NSF20FunctionKey: return KeyEvent.VK_F20; + case NSF21FunctionKey: return KeyEvent.VK_F21; + case NSF22FunctionKey: return KeyEvent.VK_F22; + case NSF23FunctionKey: return KeyEvent.VK_F23; + case NSF24FunctionKey: return KeyEvent.VK_F24; + case NSInsertFunctionKey: return KeyEvent.VK_INSERT; + case NSDeleteFunctionKey: return KeyEvent.VK_DELETE; + case NSHomeFunctionKey: return KeyEvent.VK_HOME; + case NSBeginFunctionKey: return KeyEvent.VK_BEGIN; + case NSEndFunctionKey: return KeyEvent.VK_END; + case NSPageUpFunctionKey: return KeyEvent.VK_PAGE_UP; + case NSPageDownFunctionKey: return KeyEvent.VK_PAGE_DOWN; + case NSPrintScreenFunctionKey: return KeyEvent.VK_PRINTSCREEN; + case NSScrollLockFunctionKey: return KeyEvent.VK_SCROLL_LOCK; + case NSPauseFunctionKey: return KeyEvent.VK_PAUSE; + // Not handled: + // NSSysReqFunctionKey + // NSBreakFunctionKey + // NSResetFunctionKey + case NSStopFunctionKey: return KeyEvent.VK_STOP; + // Not handled: + // NSMenuFunctionKey + // NSUserFunctionKey + // NSSystemFunctionKey + // NSPrintFunctionKey + // NSClearLineFunctionKey + // NSClearDisplayFunctionKey + // NSInsertLineFunctionKey + // NSDeleteLineFunctionKey + // NSInsertCharFunctionKey + // NSDeleteCharFunctionKey + // NSPrevFunctionKey + // NSNextFunctionKey + // NSSelectFunctionKey + // NSExecuteFunctionKey + // NSUndoFunctionKey + // NSRedoFunctionKey + // NSFindFunctionKey + // NSHelpFunctionKey + // NSModeSwitchFunctionKey + default: break; + } + } + + // NSEvent's charactersIgnoringModifiers doesn't ignore the shift key + if (keyChar >= 'a' && keyChar <= 'z') { + return Character.toUpperCase(keyChar); + } + + return keyChar; + } + + protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { + int key = convertKeyChar(keyChar); + if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.sendKeyEvent "+Thread.currentThread().getName()); + // Note that we send the key char for the key code on this + // platform -- we do not get any useful key codes out of the system + super.sendKeyEvent(eventType, modifiers, key, keyChar); + } + + private void createWindow(long parentWindowHandle, boolean recreate) { + if(0!=windowHandle && !recreate) { + return; + } + if(0!=windowHandle) { + // save the view .. close the window + surfaceHandle = changeContentView(parentWindowHandle, windowHandle, 0); + if(recreate && 0==surfaceHandle) { + throw new NativeWindowException("Internal Error - recreate, window but no view"); + } + close0(windowHandle); + windowHandle=0; + } else { + surfaceHandle = 0; + } + windowHandle = createWindow0(parentWindowHandle, + getX(), getY(), getWidth(), getHeight(), fullscreen, + (isUndecorated() ? + NSBorderlessWindowMask : + NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask), + NSBackingStoreBuffered, + getScreen().getIndex(), surfaceHandle); + if (windowHandle == 0) { + throw new NativeWindowException("Could create native window "+Thread.currentThread().getName()+" "+this); + } + surfaceHandle = contentView(windowHandle); + setTitle0(windowHandle, getTitle()); + // don't make the window visible on window creation +// makeKeyAndOrderFront(windowHandle); + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + } + + protected static native boolean initIDs(); + private native long createWindow0(long parentWindowHandle, int x, int y, int w, int h, + boolean fullscreen, int windowStyle, + int backingStoreType, + int screen_idx, long view); + private native void makeKeyAndOrderFront(long window); + private native void makeKey(long window); + private native void orderOut(long window); + private native void close0(long window); + private native void setTitle0(long window, String title); + private native long contentView(long window); + private native long changeContentView(long parentWindowHandle, long window, long view); + private native void setContentSize(long window, int w, int h); + private native void setFrameTopLeftPoint(long parentWindowHandle, long window, int x, int y); +} diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Display.java b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Display.java new file mode 100644 index 000000000..c2d323e56 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Display.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.opengl.broadcom.egl; + +import com.jogamp.newt.impl.*; +import com.jogamp.opengl.impl.egl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.egl.*; + +public class Display extends com.jogamp.newt.Display { + + static { + NEWTJNILibLoader.loadNEWT(); + + if (!Window.initIDs()) { + throw new NativeWindowException("Failed to initialize BCEGL Window jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public Display() { + } + + protected void createNative() { + long handle = CreateDisplay(Screen.fixedWidth, Screen.fixedHeight); + if (handle == EGL.EGL_NO_DISPLAY) { + throw new NativeWindowException("BC EGL CreateDisplay failed"); + } + aDevice = new EGLGraphicsDevice(handle); + } + + protected void closeNative() { + if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) { + DestroyDisplay(aDevice.getHandle()); + } + } + + protected void dispatchMessagesNative() { + // n/a .. DispatchMessages(); + } + + private native long CreateDisplay(int width, int height); + private native void DestroyDisplay(long dpy); + private native void DispatchMessages(); +} + diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Screen.java b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Screen.java new file mode 100755 index 000000000..e30896468 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Screen.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.opengl.broadcom.egl; + +import javax.media.nativewindow.*; + +public class Screen extends com.jogamp.newt.Screen { + + static { + Display.initSingleton(); + } + + + public Screen() { + } + + protected void createNative(int index) { + aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); + setScreenSize(fixedWidth, fixedHeight); + } + + protected void closeNative() { } + + //---------------------------------------------------------------------- + // Internals only + // + + static final int fixedWidth = 1920; + static final int fixedHeight = 1080; +} + diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java new file mode 100755 index 000000000..9e1ead40e --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.opengl.broadcom.egl; + +import com.jogamp.opengl.impl.egl.*; +import javax.media.nativewindow.*; +import javax.media.opengl.GLCapabilities; +import javax.media.nativewindow.NativeWindowException; + +public class Window extends com.jogamp.newt.Window { + static { + Display.initSingleton(); + } + + public Window() { + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + if(0!=parentWindowHandle) { + throw new RuntimeException("Window parenting not supported (yet)"); + } + // query a good configuration .. even thought we drop this one + // and reuse the EGLUtil choosen one later. + config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + setSizeImpl(getScreen().getWidth(), getScreen().getHeight()); + } + + protected void closeNative() { + if(0!=windowHandleClose) { + CloseWindow(getDisplayHandle(), windowHandleClose); + } + } + + public void setVisible(boolean visible) { + if(this.visible!=visible) { + this.visible=visible; + if ( 0==windowHandle ) { + windowHandle = realizeWindow(true, width, height); + if (0 == windowHandle) { + throw new NativeWindowException("Error native Window Handle is null"); + } + } + clearEventMask(); + } + } + + public void setSize(int width, int height) { + System.err.println("setSize "+width+"x"+height+" n/a in BroadcomEGL"); + } + + void setSizeImpl(int width, int height) { + if(0!=windowHandle) { + // n/a in BroadcomEGL + System.err.println("BCEGL Window.setSizeImpl n/a in BroadcomEGL with realized window"); + } else { + if(DEBUG_IMPLEMENTATION) { + Exception e = new Exception("BCEGL Window.setSizeImpl() "+this.width+"x"+this.height+" -> "+width+"x"+height); + e.printStackTrace(); + } + this.width = width; + this.height = height; + } + } + + public void setPosition(int x, int y) { + // n/a in BroadcomEGL + System.err.println("setPosition n/a in BroadcomEGL"); + } + + public boolean setFullscreen(boolean fullscreen) { + // n/a in BroadcomEGL + System.err.println("setFullscreen n/a in BroadcomEGL"); + return false; + } + + public boolean surfaceSwap() { + if ( 0!=windowHandle ) { + SwapWindow(getDisplayHandle(), windowHandle); + return true; + } + return false; + } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native long CreateWindow(long eglDisplayHandle, boolean chromaKey, int width, int height); + private native void CloseWindow(long eglDisplayHandle, long eglWindowHandle); + private native void SwapWindow(long eglDisplayHandle, long eglWindowHandle); + + + private long realizeWindow(boolean chromaKey, int width, int height) { + if(DEBUG_IMPLEMENTATION) { + System.out.println("BCEGL Window.realizeWindow() with: chroma "+chromaKey+", "+width+"x"+height+", "+config); + } + long handle = CreateWindow(getDisplayHandle(), chromaKey, width, height); + if (0 == handle) { + throw new NativeWindowException("Error native Window Handle is null"); + } + windowHandleClose = handle; + return handle; + } + + private void windowCreated(int cfgID, int width, int height) { + this.width = width; + this.height = height; + GLCapabilities capsReq = (GLCapabilities) config.getRequestedCapabilities(); + config = EGLGraphicsConfiguration.create(capsReq, screen.getGraphicsScreen(), cfgID); + if (config == null) { + throw new NativeWindowException("Error creating EGLGraphicsConfiguration from id: "+cfgID+", "+this); + } + if(DEBUG_IMPLEMENTATION) { + System.out.println("BCEGL Window.windowCreated(): "+toHexString(cfgID)+", "+width+"x"+height+", "+config); + } + } + + private long windowHandleClose; +} diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java new file mode 100755 index 000000000..2ab30773f --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.opengl.kd; + +import com.jogamp.newt.*; +import com.jogamp.newt.impl.*; +import com.jogamp.opengl.impl.egl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.egl.*; + +public class KDDisplay extends Display { + + static { + NEWTJNILibLoader.loadNEWT(); + + if (!KDWindow.initIDs()) { + throw new NativeWindowException("Failed to initialize KDWindow jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public KDDisplay() { + } + + protected void createNative() { + // FIXME: map name to EGL_*_DISPLAY + long handle = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY); + if (handle == EGL.EGL_NO_DISPLAY) { + throw new NativeWindowException("eglGetDisplay failed"); + } + if (!EGL.eglInitialize(handle, null, null)) { + throw new NativeWindowException("eglInitialize failed"); + } + aDevice = new EGLGraphicsDevice(handle); + } + + protected void closeNative() { + if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) { + EGL.eglTerminate(aDevice.getHandle()); + } + } + + protected void dispatchMessagesNative() { + DispatchMessages(); + } + + private native void DispatchMessages(); +} + diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDScreen.java b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDScreen.java new file mode 100755 index 000000000..d570d9f5b --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDScreen.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.opengl.kd; + +import com.jogamp.newt.*; +import javax.media.nativewindow.*; + +public class KDScreen extends Screen { + static { + KDDisplay.initSingleton(); + } + + public KDScreen() { + } + + protected void createNative(int index) { + aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); + } + + protected void closeNative() { } + + // elevate access to this package .. + protected void setScreenSize(int w, int h) { + super.setScreenSize(w, h); + } +} diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java new file mode 100755 index 000000000..5f1068cad --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.opengl.kd; + +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.impl.*; +import com.jogamp.opengl.impl.egl.*; +import javax.media.nativewindow.*; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import javax.media.nativewindow.NativeWindowException; + +public class KDWindow extends Window { + private static final String WINDOW_CLASS_NAME = "NewtWindow"; + // non fullscreen dimensions .. + private int nfs_width, nfs_height, nfs_x, nfs_y; + + static { + KDDisplay.initSingleton(); + } + + public KDWindow() { + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + if(0!=parentWindowHandle) { + throw new RuntimeException("Window parenting not supported (yet)"); + } + config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + + GLCapabilities eglCaps = (GLCapabilities)config.getChosenCapabilities(); + int[] eglAttribs = EGLGraphicsConfiguration.GLCapabilities2AttribList(eglCaps); + + windowHandle = 0; + eglWindowHandle = CreateWindow(getDisplayHandle(), eglAttribs); + if (eglWindowHandle == 0) { + throw new NativeWindowException("Error creating egl window: "+config); + } + setVisible0(eglWindowHandle, false); + windowHandleClose = eglWindowHandle; + } + + protected void closeNative() { + if(0!=windowHandleClose) { + CloseWindow(windowHandleClose, windowUserData); + windowUserData=0; + } + } + + public void setVisible(boolean visible) { + if(0!=eglWindowHandle && this.visible!=visible) { + this.visible=visible; + setVisible0(eglWindowHandle, visible); + if ( 0==windowHandle ) { + windowHandle = RealizeWindow(eglWindowHandle); + if (0 == windowHandle) { + throw new NativeWindowException("Error native Window Handle is null"); + } + } + clearEventMask(); + } + } + + public void setSize(int width, int height) { + if(0!=eglWindowHandle) { + setSize0(eglWindowHandle, width, height); + } + } + + public void setPosition(int x, int y) { + // n/a in KD + System.err.println("setPosition n/a in KD"); + } + + public boolean setFullscreen(boolean fullscreen) { + if(0!=eglWindowHandle && this.fullscreen!=fullscreen) { + this.fullscreen=fullscreen; + if(this.fullscreen) { + setFullScreen0(eglWindowHandle, true); + } else { + setFullScreen0(eglWindowHandle, false); + setSize0(eglWindowHandle, nfs_width, nfs_height); + } + } + return true; + } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native long CreateWindow(long displayHandle, int[] attributes); + private native long RealizeWindow(long eglWindowHandle); + private native int CloseWindow(long eglWindowHandle, long userData); + private native void setVisible0(long eglWindowHandle, boolean visible); + private native void setSize0(long eglWindowHandle, int width, int height); + private native void setFullScreen0(long eglWindowHandle, boolean fullscreen); + + private void windowCreated(long userData) { + windowUserData=userData; + } + + private void sizeChanged(int newWidth, int newHeight) { + width = newWidth; + height = newHeight; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } else { + ((KDScreen)screen).setScreenSize(width, height); + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } + + private long eglWindowHandle; + private long windowHandleClose; + private long windowUserData; +} diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java new file mode 100755 index 000000000..000e64b6d --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.windows; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.windows.*; +import com.jogamp.newt.*; +import com.jogamp.newt.impl.*; + +public class WindowsDisplay extends Display { + + protected static final String WINDOW_CLASS_NAME = "NewtWindowClass"; + private static int windowClassAtom; + private static long hInstance; + + static { + NEWTJNILibLoader.loadNEWT(); + + if (!WindowsWindow.initIDs()) { + throw new NativeWindowException("Failed to initialize WindowsWindow jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public WindowsDisplay() { + } + + protected void createNative() { + aDevice = new WindowsGraphicsDevice(); + } + + protected void closeNative() { + // Can't do .. only at application shutdown + // UnregisterWindowClass(getWindowClassAtom(), getHInstance()); + } + + protected void dispatchMessagesNative() { + DispatchMessages(); + } + + protected static synchronized int getWindowClassAtom() { + if(0 == windowClassAtom) { + windowClassAtom = RegisterWindowClass(WINDOW_CLASS_NAME, getHInstance()); + if (0 == windowClassAtom) { + throw new NativeWindowException("Error while registering window class"); + } + } + return windowClassAtom; + } + + protected static synchronized long getHInstance() { + if(0 == hInstance) { + hInstance = LoadLibraryW("newt"); + if (0 == hInstance) { + throw new NativeWindowException("Error finding HINSTANCE for \"newt\""); + } + } + return hInstance; + } + + //---------------------------------------------------------------------- + // Internals only + // + private static native long LoadLibraryW(String libraryName); + private static native int RegisterWindowClass(String windowClassName, long hInstance); + private static native void UnregisterWindowClass(int wndClassAtom, long hInstance); + + private static native void DispatchMessages(); +} + diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java new file mode 100755 index 000000000..b0161cfc2 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.windows; + +import com.jogamp.newt.*; +import javax.media.nativewindow.*; + +public class WindowsScreen extends Screen { + static { + WindowsDisplay.initSingleton(); + } + + + public WindowsScreen() { + } + + protected void createNative(int index) { + aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); + setScreenSize(getWidthImpl(getIndex()), getHeightImpl(getIndex())); + } + + protected void closeNative() { } + + private native int getWidthImpl(int scrn_idx); + private native int getHeightImpl(int scrn_idx); +} diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java new file mode 100755 index 000000000..dc870f43d --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java @@ -0,0 +1,290 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.windows; + +import javax.media.nativewindow.*; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; + +public class WindowsWindow extends Window { + + private long hmon; + private long hdc; + private long windowHandleClose; + private long parentWindowHandle; + // non fullscreen dimensions .. + private int nfs_width, nfs_height, nfs_x, nfs_y; + private final Insets insets = new Insets(0, 0, 0, 0); + + static { + WindowsDisplay.initSingleton(); + } + + public WindowsWindow() { + } + + Thread hdcOwner = null; + + public synchronized int lockSurface() throws NativeWindowException { + int res = super.lockSurface(); + if(LOCK_SUCCESS==res && 0!=windowHandle) { + if(hdc!=0) { + throw new NativeWindowException("NEWT Surface handle set HDC "+toHexString(hdc)+" - "+Thread.currentThread().getName()+" ; "+this); + } + hdc = GetDC(windowHandle); + hmon = MonitorFromWindow(windowHandle); + hdcOwner = Thread.currentThread(); + } + return res; + } + + public synchronized void unlockSurface() { + // prevalidate, before we change data .. + Thread cur = Thread.currentThread(); + if ( getSurfaceLockOwner() != cur ) { + getLockedStack().printStackTrace(); + throw new NativeWindowException(cur+": Not owner, owner is "+getSurfaceLockOwner()); + } + if (0!=hdc && 0!=windowHandle) { + if(hdcOwner != cur) { + throw new NativeWindowException("NEWT Surface handle set HDC "+toHexString(hdc)+" by other thread "+hdcOwner+", this "+cur+" ; "+this); + } + ReleaseDC(windowHandle, hdc); + hdc=0; + hdcOwner=null; + } + super.unlockSurface(); + } + + public long getSurfaceHandle() { + return hdc; + } + + public boolean hasDeviceChanged() { + if(0!=windowHandle) { + long _hmon = MonitorFromWindow(windowHandle); + if (hmon != _hmon) { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + Exception e = new Exception("!!! Window Device Changed "+Thread.currentThread().getName()+ + ", HMON "+toHexString(hmon)+" -> "+toHexString(_hmon)); + e.printStackTrace(); + } + hmon = _hmon; + return true; + } + } + return false; + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + WindowsScreen screen = (WindowsScreen) getScreen(); + WindowsDisplay display = (WindowsDisplay) screen.getDisplay(); + config = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, screen.getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + windowHandle = CreateWindow(parentWindowHandle, + display.getWindowClassAtom(), display.WINDOW_CLASS_NAME, display.getHInstance(), + 0, undecorated, x, y, width, height); + if (windowHandle == 0) { + throw new NativeWindowException("Error creating window"); + } + this.parentWindowHandle = parentWindowHandle; + windowHandleClose = windowHandle; + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + Exception e = new Exception("!!! Window new window handle "+Thread.currentThread().getName()+ + " (Parent HWND "+toHexString(parentWindowHandle)+ + ") : HWND "+toHexString(windowHandle)+", "+Thread.currentThread()); + e.printStackTrace(); + } + } + + protected void closeNative() { + if (hdc != 0) { + if(windowHandleClose != 0) { + ReleaseDC(windowHandleClose, hdc); + } + hdc = 0; + } + if(windowHandleClose != 0) { + DestroyWindow(windowHandleClose); + windowHandleClose = 0; + } + } + + protected void windowDestroyed() { + windowHandleClose = 0; + super.windowDestroyed(); + } + + public void setVisible(boolean visible) { + if(this.visible!=visible && 0!=windowHandle) { + this.visible=visible; + setVisible0(windowHandle, visible); + } + } + + // @Override + public void setSize(int width, int height) { + if (0!=windowHandle && (width != this.width || this.height != height)) { + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + this.width = width; + this.height = height; + setSize0(parentWindowHandle, windowHandle, x, y, width, height); + } + } + + //@Override + public void setPosition(int x, int y) { + if (0!=windowHandle && (this.x != x || this.y != y)) { + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + this.x = x; + this.y = y; + setPosition(parentWindowHandle, windowHandle, x , y); + } + } + + public boolean setFullscreen(boolean fullscreen) { + if(0!=windowHandle && (this.fullscreen!=fullscreen)) { + int x,y,w,h; + this.fullscreen=fullscreen; + if(fullscreen) { + x = 0; y = 0; + w = screen.getWidth(); + h = screen.getHeight(); + } else { + x = nfs_x; + y = nfs_y; + w = nfs_width; + h = nfs_height; + } + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("WindowsWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); + } + setFullscreen0(parentWindowHandle, windowHandle, x, y, w, h, undecorated, fullscreen); + } + return fullscreen; + } + + // @Override + public void requestFocus() { + super.requestFocus(); + if (windowHandle != 0L) { + requestFocus(windowHandle); + } + } + + // @Override + public void setTitle(String title) { + if (title == null) { + title = ""; + } + if (0!=windowHandle && !title.equals(getTitle())) { + super.setTitle(title); + setTitle(windowHandle, title); + } + } + + public Insets getInsets() { + return (Insets)insets.clone(); + } + + //---------------------------------------------------------------------- + // Internals only + // + protected static native boolean initIDs(); + private native long CreateWindow(long parentWindowHandle, + int wndClassAtom, String wndName, + long hInstance, long visualID, + boolean isUndecorated, + int x, int y, int width, int height); + private native void DestroyWindow(long windowHandle); + private native long GetDC(long windowHandle); + private native void ReleaseDC(long windowHandle, long hdc); + private native long MonitorFromWindow(long windowHandle); + private static native void setVisible0(long windowHandle, boolean visible); + private native void setSize0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height); + private native void setPosition(long parentWindowHandle, long windowHandle, int x, int y); + private native void setFullscreen0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height, boolean isUndecorated, boolean on); + private static native void setTitle(long windowHandle, String title); + private static native void requestFocus(long windowHandle); + + private void insetsChanged(int left, int top, int right, int bottom) { + if (left != -1 && top != -1 && right != -1 && bottom != -1) { + insets.left = left; + insets.top = top; + insets.right = right; + insets.bottom = bottom; + } + } + private void sizeChanged(int newWidth, int newHeight) { + width = newWidth; + height = newHeight; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } + + private void positionChanged(int newX, int newY) { + x = newX; + y = newY; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + } + + /** + * + * @param focusOwner if focusGained is true, focusOwner is the previous + * focus owner, if focusGained is false, focusOwner is the new focus owner + * @param focusGained + */ + private void focusChanged(long focusOwner, boolean focusGained) { + if (focusGained) { + sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + } else { + sendWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS); + } + } +} diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java new file mode 100755 index 000000000..94d568f55 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.x11; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; +import com.jogamp.newt.*; +import com.jogamp.newt.impl.*; +import com.jogamp.nativewindow.impl.x11.X11Util; + +public class X11Display extends Display { + static { + NEWTJNILibLoader.loadNEWT(); + + if (!initIDs()) { + throw new NativeWindowException("Failed to initialize X11Display jmethodIDs"); + } + + if (!X11Window.initIDs()) { + throw new NativeWindowException("Failed to initialize X11Window jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public X11Display() { + } + + protected void createNative() { + long handle= X11Util.createThreadLocalDisplay(name); + if (handle == 0 ) { + throw new RuntimeException("Error creating display: "+name); + } + try { + CompleteDisplay(handle); + } catch(RuntimeException e) { + X11Util.closeThreadLocalDisplay(name); + throw e; + } + aDevice = new X11GraphicsDevice(handle); + } + + protected void closeNative() { + X11Util.closeThreadLocalDisplay(name); + } + + protected void dispatchMessagesNative() { + DispatchMessages(getHandle(), javaObjectAtom, windowDeleteAtom); + } + + protected void lockDisplay() { + super.lockDisplay(); + LockDisplay(getHandle()); + } + + protected void unlockDisplay() { + UnlockDisplay(getHandle()); + super.unlockDisplay(); + } + + protected long getJavaObjectAtom() { return javaObjectAtom; } + protected long getWindowDeleteAtom() { return windowDeleteAtom; } + + //---------------------------------------------------------------------- + // Internals only + // + private static native boolean initIDs(); + + private native void LockDisplay(long handle); + private native void UnlockDisplay(long handle); + + private native void CompleteDisplay(long handle); + + private native void DispatchMessages(long display, long javaObjectAtom, long windowDeleteAtom); + + private void displayCompleted(long javaObjectAtom, long windowDeleteAtom) { + this.javaObjectAtom=javaObjectAtom; + this.windowDeleteAtom=windowDeleteAtom; + } + + private long windowDeleteAtom; + private long javaObjectAtom; +} + diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java new file mode 100755 index 000000000..3561bec2a --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.x11; + +import com.jogamp.newt.*; +import javax.media.nativewindow.x11.*; + +public class X11Screen extends Screen { + + static { + X11Display.initSingleton(); + } + + + public X11Screen() { + } + + protected void createNative(int index) { + long handle = GetScreen(display.getHandle(), index); + if (handle == 0 ) { + throw new RuntimeException("Error creating screen: "+index); + } + aScreen = new X11GraphicsScreen((X11GraphicsDevice)getDisplay().getGraphicsDevice(), index); + setScreenSize(getWidth0(display.getHandle(), index), + getHeight0(display.getHandle(), index)); + } + + protected void closeNative() { } + + //---------------------------------------------------------------------- + // Internals only + // + + private native long GetScreen(long dpy, int scrn_idx); + private native int getWidth0(long display, int scrn_idx); + private native int getHeight0(long display, int scrn_idx); +} + diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java new file mode 100755 index 000000000..c7401ef23 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.impl.x11; + +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; + +public class X11Window extends Window { + private static final String WINDOW_CLASS_NAME = "NewtWindow"; + // non fullscreen dimensions .. + private int nfs_width, nfs_height, nfs_x, nfs_y; + + static { + X11Display.initSingleton(); + } + + public X11Window() { + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + X11Screen screen = (X11Screen) getScreen(); + X11Display display = (X11Display) screen.getDisplay(); + config = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, screen.getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + X11GraphicsConfiguration x11config = (X11GraphicsConfiguration) config; + long visualID = x11config.getVisualID(); + long w = CreateWindow(parentWindowHandle, + display.getHandle(), screen.getIndex(), visualID, + display.getJavaObjectAtom(), display.getWindowDeleteAtom(), x, y, width, height); + if (w == 0 || w!=windowHandle) { + throw new NativeWindowException("Error creating window: "+w); + } + this.parentWindowHandle = parentWindowHandle; + windowHandleClose = windowHandle; + displayHandleClose = display.getHandle(); + } + + protected void closeNative() { + if(0!=displayHandleClose && 0!=windowHandleClose && null!=getScreen() ) { + X11Display display = (X11Display) getScreen().getDisplay(); + CloseWindow(displayHandleClose, windowHandleClose, display.getJavaObjectAtom()); + windowHandleClose = 0; + displayHandleClose = 0; + } + } + + protected void windowDestroyed() { + windowHandleClose = 0; + displayHandleClose = 0; + super.windowDestroyed(); + } + + public void setVisible(boolean visible) { + if(0!=windowHandle && this.visible!=visible) { + this.visible=visible; + setVisible0(getDisplayHandle(), windowHandle, visible); + clearEventMask(); + } + } + + public void requestFocus() { + super.requestFocus(); + } + + public void setSize(int width, int height) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("X11Window setSize: "+this.x+"/"+this.y+" "+this.width+"x"+this.height+" -> "+width+"x"+height); + // Exception e = new Exception("XXXXXXXXXX"); + // e.printStackTrace(); + } + this.width = width; + this.height = height; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + if(0!=windowHandle) { + setSize0(parentWindowHandle, getDisplayHandle(), getScreenIndex(), windowHandle, x, y, width, height, (undecorated||fullscreen)?-1:1, false); + } + } + + public void setPosition(int x, int y) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("X11Window setPosition: "+this.x+"/"+this.y+" -> "+x+"/"+y); + // Exception e = new Exception("XXXXXXXXXX"); + // e.printStackTrace(); + } + this.x = x; + this.y = y; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + if(0!=windowHandle) { + setPosition0(getDisplayHandle(), windowHandle, x, y); + } + } + + public boolean setFullscreen(boolean fullscreen) { + if(0!=windowHandle && this.fullscreen!=fullscreen) { + int x,y,w,h; + this.fullscreen=fullscreen; + if(fullscreen) { + x = 0; y = 0; + w = screen.getWidth(); + h = screen.getHeight(); + } else { + x = nfs_x; + y = nfs_y; + w = nfs_width; + h = nfs_height; + } + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("X11Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); + } + setSize0(parentWindowHandle, getDisplayHandle(), getScreenIndex(), windowHandle, x, y, w, h, (undecorated||fullscreen)?-1:1, false); + } + return fullscreen; + } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native long CreateWindow(long parentWindowHandle, long display, int screen_index, + long visualID, long javaObjectAtom, long windowDeleteAtom, int x, int y, int width, int height); + private native void CloseWindow(long display, long windowHandle, long javaObjectAtom); + private native void setVisible0(long display, long windowHandle, boolean visible); + private native void setSize0(long parentWindowHandle, long display, int screen_index, long windowHandle, + int x, int y, int width, int height, int decorationToggle, boolean setVisible); + private native void setPosition0(long display, long windowHandle, int x, int y); + + private void windowChanged(int newX, int newY, int newWidth, int newHeight) { + if(width != newWidth || height != newHeight) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("X11Window windowChanged size: "+this.width+"x"+this.height+" -> "+newWidth+"x"+newHeight); + } + width = newWidth; + height = newHeight; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } + if( 0==parentWindowHandle && ( x != newX || y != newY ) ) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("X11Window windowChanged position: "+this.x+"/"+this.y+" -> "+newX+"x"+newY); + } + x = newX; + y = newY; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + } + } + + private void windowCreated(long windowHandle) { + this.windowHandle = windowHandle; + } + + private long windowHandleClose; + private long displayHandleClose; + private long parentWindowHandle; +} diff --git a/src/newt/classes/com/jogamp/newt/intel/gdl/Display.java b/src/newt/classes/com/jogamp/newt/intel/gdl/Display.java deleted file mode 100644 index f79573644..000000000 --- a/src/newt/classes/com/jogamp/newt/intel/gdl/Display.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.intel.gdl; - -import com.jogamp.newt.impl.*; -import javax.media.nativewindow.*; - -public class Display extends com.jogamp.newt.Display { - static int initCounter = 0; - - static { - NEWTJNILibLoader.loadNEWT(); - - if (!Screen.initIDs()) { - throw new NativeWindowException("Failed to initialize GDL Screen jmethodIDs"); - } - if (!Window.initIDs()) { - throw new NativeWindowException("Failed to initialize GDL Window jmethodIDs"); - } - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - - public Display() { - } - - protected void createNative() { - synchronized(Display.class) { - if(0==initCounter) { - displayHandle = CreateDisplay(); - if(0==displayHandle) { - throw new NativeWindowException("Couldn't initialize GDL Display"); - } - } - initCounter++; - } - aDevice = new DefaultGraphicsDevice(NativeWindowFactory.TYPE_DEFAULT, displayHandle); - } - - protected void closeNative() { - if(0==displayHandle) { - throw new NativeWindowException("displayHandle null; initCnt "+initCounter); - } - synchronized(Display.class) { - if(initCounter>0) { - initCounter--; - if(0==initCounter) { - DestroyDisplay(displayHandle); - } - } - } - } - - protected void dispatchMessagesNative() { - if(0!=displayHandle) { - DispatchMessages(displayHandle, focusedWindow); - } - } - - protected void setFocus(Window focus) { - focusedWindow = focus; - } - - private long displayHandle = 0; - private Window focusedWindow = null; - private native long CreateDisplay(); - private native void DestroyDisplay(long displayHandle); - private native void DispatchMessages(long displayHandle, Window focusedWindow); -} - diff --git a/src/newt/classes/com/jogamp/newt/intel/gdl/Screen.java b/src/newt/classes/com/jogamp/newt/intel/gdl/Screen.java deleted file mode 100644 index 873d1d009..000000000 --- a/src/newt/classes/com/jogamp/newt/intel/gdl/Screen.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.intel.gdl; - -import com.jogamp.newt.impl.*; -import javax.media.nativewindow.*; - -public class Screen extends com.jogamp.newt.Screen { - - static { - Display.initSingleton(); - } - - public Screen() { - } - - protected void createNative(int index) { - AbstractGraphicsDevice adevice = getDisplay().getGraphicsDevice(); - GetScreenInfo(adevice.getHandle(), index); - aScreen = new DefaultGraphicsScreen(adevice, index); - } - - protected void closeNative() { } - - //---------------------------------------------------------------------- - // Internals only - // - - protected static native boolean initIDs(); - private native void GetScreenInfo(long displayHandle, int screen_idx); - - // called by GetScreenInfo() .. - private void screenCreated(int width, int height) { - setScreenSize(width, height); - } -} - diff --git a/src/newt/classes/com/jogamp/newt/intel/gdl/Window.java b/src/newt/classes/com/jogamp/newt/intel/gdl/Window.java deleted file mode 100644 index 879fc6134..000000000 --- a/src/newt/classes/com/jogamp/newt/intel/gdl/Window.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.intel.gdl; - -import javax.media.nativewindow.*; - -public class Window extends com.jogamp.newt.Window { - static { - Display.initSingleton(); - } - - public Window() { - } - - static long nextWindowHandle = 1; - - protected void createNative(long parentWindowHandle, Capabilities caps) { - if(0!=parentWindowHandle) { - throw new NativeWindowException("GDL Window does not support window parenting"); - } - AbstractGraphicsScreen aScreen = screen.getGraphicsScreen(); - AbstractGraphicsDevice aDevice = screen.getDisplay().getGraphicsDevice(); - - config = GraphicsConfigurationFactory.getFactory(aDevice).chooseGraphicsConfiguration(caps, null, aScreen); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - - synchronized(Window.class) { - windowHandle = nextWindowHandle++; - } - } - - protected void closeNative() { - if(0!=surfaceHandle) { - synchronized(Window.class) { - CloseSurface(getDisplayHandle(), surfaceHandle); - } - surfaceHandle = 0; - ((Display)screen.getDisplay()).setFocus(null); - } - } - - public void setVisible(boolean visible) { - if(this.visible!=visible) { - this.visible=visible; - if(visible && 0==surfaceHandle) { - synchronized(Window.class) { - AbstractGraphicsDevice aDevice = screen.getDisplay().getGraphicsDevice(); - surfaceHandle = CreateSurface(aDevice.getHandle(), screen.getWidth(), screen.getHeight(), x, y, width, height); - } - if (surfaceHandle == 0) { - throw new NativeWindowException("Error creating window"); - } - ((Display)screen.getDisplay()).setFocus(this); - } - } - } - - public void setSize(int width, int height) { - Screen screen = (Screen) getScreen(); - if((x+width)>screen.getWidth()) { - width=screen.getWidth()-x; - } - if((y+height)>screen.getHeight()) { - height=screen.getHeight()-y; - } - this.width = width; - this.height = height; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - if(0!=surfaceHandle) { - SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, width, height); - } - } - - public void setPosition(int x, int y) { - Screen screen = (Screen) getScreen(); - if((x+width)>screen.getWidth()) { - x=screen.getWidth()-width; - } - if((y+height)>screen.getHeight()) { - y=screen.getHeight()-height; - } - this.x = x; - this.y = y; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - if(0!=surfaceHandle) { - SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, width, height); - } - } - - public boolean setFullscreen(boolean fullscreen) { - if(this.fullscreen!=fullscreen) { - int x,y,w,h; - this.fullscreen=fullscreen; - if(fullscreen) { - x = 0; y = 0; - w = screen.getWidth(); - h = screen.getHeight(); - } else { - x = nfs_x; - y = nfs_y; - w = nfs_width; - h = nfs_height; - } - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("IntelGDL Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); - } - if(0!=surfaceHandle) { - SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, w, h); - } - } - return fullscreen; - } - - public void requestFocus() { - ((Display)screen.getDisplay()).setFocus(this); - } - - public long getSurfaceHandle() { - return surfaceHandle; - } - - //---------------------------------------------------------------------- - // Internals only - // - - protected static native boolean initIDs(); - private native long CreateSurface(long displayHandle, int scrn_width, int scrn_height, int x, int y, int width, int height); - private native void CloseSurface(long displayHandle, long surfaceHandle); - private native void SetBounds0(long surfaceHandle, int scrn_width, int scrn_height, int x, int y, int width, int height); - - private void updateBounds(int x, int y, int width, int height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - private long surfaceHandle; - private int nfs_width, nfs_height, nfs_x, nfs_y; -} diff --git a/src/newt/classes/com/jogamp/newt/macosx/MacDisplay.java b/src/newt/classes/com/jogamp/newt/macosx/MacDisplay.java deleted file mode 100755 index cf67537ae..000000000 --- a/src/newt/classes/com/jogamp/newt/macosx/MacDisplay.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.macosx; - -import javax.media.nativewindow.*; -import javax.media.nativewindow.macosx.*; -import com.jogamp.newt.*; -import com.jogamp.newt.impl.*; -import com.jogamp.newt.util.MainThread; - -public class MacDisplay extends Display { - static { - NEWTJNILibLoader.loadNEWT(); - - if(!initNSApplication()) { - throw new NativeWindowException("Failed to initialize native Application hook"); - } - if(!MacWindow.initIDs()) { - throw new NativeWindowException("Failed to initialize jmethodIDs"); - } - if(DEBUG) System.out.println("MacDisplay.init App and IDs OK "+Thread.currentThread().getName()); - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - public MacDisplay() { - } - - class DispatchAction implements Runnable { - public void run() { - dispatchMessages0(); - } - } - private DispatchAction dispatchAction = new DispatchAction(); - - protected void dispatchMessagesNative() { - MainThread.invoke(false, dispatchAction); - } - - protected void createNative() { - aDevice = new MacOSXGraphicsDevice(); - } - - protected void closeNative() { } - - private static native boolean initNSApplication(); - protected native void dispatchMessages0(); -} - diff --git a/src/newt/classes/com/jogamp/newt/macosx/MacScreen.java b/src/newt/classes/com/jogamp/newt/macosx/MacScreen.java deleted file mode 100755 index 92f8e908c..000000000 --- a/src/newt/classes/com/jogamp/newt/macosx/MacScreen.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.macosx; - -import com.jogamp.newt.*; -import javax.media.nativewindow.*; - -public class MacScreen extends Screen { - static { - MacDisplay.initSingleton(); - } - - public MacScreen() { - } - - protected void createNative(int index) { - aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); - setScreenSize(getWidthImpl(getIndex()), getHeightImpl(getIndex())); - } - - protected void closeNative() { } - - private static native int getWidthImpl(int scrn_idx); - private static native int getHeightImpl(int scrn_idx); -} diff --git a/src/newt/classes/com/jogamp/newt/macosx/MacWindow.java b/src/newt/classes/com/jogamp/newt/macosx/MacWindow.java deleted file mode 100755 index 8762d106c..000000000 --- a/src/newt/classes/com/jogamp/newt/macosx/MacWindow.java +++ /dev/null @@ -1,575 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.macosx; - -import javax.media.nativewindow.*; - -import com.jogamp.newt.util.MainThread; -import com.jogamp.newt.*; -import com.jogamp.newt.event.*; -import com.jogamp.newt.impl.*; - -public class MacWindow extends Window { - - // Window styles - private static final int NSBorderlessWindowMask = 0; - private static final int NSTitledWindowMask = 1 << 0; - private static final int NSClosableWindowMask = 1 << 1; - private static final int NSMiniaturizableWindowMask = 1 << 2; - private static final int NSResizableWindowMask = 1 << 3; - - // Window backing store types - private static final int NSBackingStoreRetained = 0; - private static final int NSBackingStoreNonretained = 1; - private static final int NSBackingStoreBuffered = 2; - - // Key constants handled differently on Mac OS X than other platforms - private static final int NSUpArrowFunctionKey = 0xF700; - private static final int NSDownArrowFunctionKey = 0xF701; - private static final int NSLeftArrowFunctionKey = 0xF702; - private static final int NSRightArrowFunctionKey = 0xF703; - private static final int NSF1FunctionKey = 0xF704; - private static final int NSF2FunctionKey = 0xF705; - private static final int NSF3FunctionKey = 0xF706; - private static final int NSF4FunctionKey = 0xF707; - private static final int NSF5FunctionKey = 0xF708; - private static final int NSF6FunctionKey = 0xF709; - private static final int NSF7FunctionKey = 0xF70A; - private static final int NSF8FunctionKey = 0xF70B; - private static final int NSF9FunctionKey = 0xF70C; - private static final int NSF10FunctionKey = 0xF70D; - private static final int NSF11FunctionKey = 0xF70E; - private static final int NSF12FunctionKey = 0xF70F; - private static final int NSF13FunctionKey = 0xF710; - private static final int NSF14FunctionKey = 0xF711; - private static final int NSF15FunctionKey = 0xF712; - private static final int NSF16FunctionKey = 0xF713; - private static final int NSF17FunctionKey = 0xF714; - private static final int NSF18FunctionKey = 0xF715; - private static final int NSF19FunctionKey = 0xF716; - private static final int NSF20FunctionKey = 0xF717; - private static final int NSF21FunctionKey = 0xF718; - private static final int NSF22FunctionKey = 0xF719; - private static final int NSF23FunctionKey = 0xF71A; - private static final int NSF24FunctionKey = 0xF71B; - private static final int NSF25FunctionKey = 0xF71C; - private static final int NSF26FunctionKey = 0xF71D; - private static final int NSF27FunctionKey = 0xF71E; - private static final int NSF28FunctionKey = 0xF71F; - private static final int NSF29FunctionKey = 0xF720; - private static final int NSF30FunctionKey = 0xF721; - private static final int NSF31FunctionKey = 0xF722; - private static final int NSF32FunctionKey = 0xF723; - private static final int NSF33FunctionKey = 0xF724; - private static final int NSF34FunctionKey = 0xF725; - private static final int NSF35FunctionKey = 0xF726; - private static final int NSInsertFunctionKey = 0xF727; - private static final int NSDeleteFunctionKey = 0xF728; - private static final int NSHomeFunctionKey = 0xF729; - private static final int NSBeginFunctionKey = 0xF72A; - private static final int NSEndFunctionKey = 0xF72B; - private static final int NSPageUpFunctionKey = 0xF72C; - private static final int NSPageDownFunctionKey = 0xF72D; - private static final int NSPrintScreenFunctionKey = 0xF72E; - private static final int NSScrollLockFunctionKey = 0xF72F; - private static final int NSPauseFunctionKey = 0xF730; - private static final int NSSysReqFunctionKey = 0xF731; - private static final int NSBreakFunctionKey = 0xF732; - private static final int NSResetFunctionKey = 0xF733; - private static final int NSStopFunctionKey = 0xF734; - private static final int NSMenuFunctionKey = 0xF735; - private static final int NSUserFunctionKey = 0xF736; - private static final int NSSystemFunctionKey = 0xF737; - private static final int NSPrintFunctionKey = 0xF738; - private static final int NSClearLineFunctionKey = 0xF739; - private static final int NSClearDisplayFunctionKey = 0xF73A; - private static final int NSInsertLineFunctionKey = 0xF73B; - private static final int NSDeleteLineFunctionKey = 0xF73C; - private static final int NSInsertCharFunctionKey = 0xF73D; - private static final int NSDeleteCharFunctionKey = 0xF73E; - private static final int NSPrevFunctionKey = 0xF73F; - private static final int NSNextFunctionKey = 0xF740; - private static final int NSSelectFunctionKey = 0xF741; - private static final int NSExecuteFunctionKey = 0xF742; - private static final int NSUndoFunctionKey = 0xF743; - private static final int NSRedoFunctionKey = 0xF744; - private static final int NSFindFunctionKey = 0xF745; - private static final int NSHelpFunctionKey = 0xF746; - private static final int NSModeSwitchFunctionKey = 0xF747; - - private volatile long surfaceHandle; - private long parentWindowHandle; - - // non fullscreen dimensions .. - private int nfs_width, nfs_height, nfs_x, nfs_y; - private final Insets insets = new Insets(0,0,0,0); - - static { - MacDisplay.initSingleton(); - } - - public MacWindow() { - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - this.parentWindowHandle=parentWindowHandle; - config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - } - - class CloseAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.CloseAction "+Thread.currentThread().getName()); - if (windowHandle != 0) { - close0(windowHandle); - windowHandle = 0; - } - } finally { - nsViewLock.unlock(); - } - } - } - private CloseAction closeAction = new CloseAction(); - - protected void closeNative() { - MainThread.invoke(true, closeAction); - } - - public long getWindowHandle() { - nsViewLock.lock(); - try { - return windowHandle; - } finally { - nsViewLock.unlock(); - } - } - - public long getSurfaceHandle() { - nsViewLock.lock(); - try { - return surfaceHandle; - } finally { - nsViewLock.unlock(); - } - } - - class EnsureWindowCreatedAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - createWindow(parentWindowHandle, false); - } finally { - nsViewLock.unlock(); - } - } - } - private EnsureWindowCreatedAction ensureWindowCreatedAction = - new EnsureWindowCreatedAction(); - - public Insets getInsets() { - // in order to properly calculate insets we need the window to be - // created - MainThread.invoke(true, ensureWindowCreatedAction); - nsViewLock.lock(); - try { - return (Insets) insets.clone(); - } finally { - nsViewLock.unlock(); - } - } - - private WindowToolkitLock nsViewLock = new WindowToolkitLock(); - - public synchronized int lockSurface() throws NativeWindowException { - nsViewLock.lock(); - try { - return super.lockSurface(); - } catch (RuntimeException re) { - nsViewLock.unlock(); - throw re; - } - } - - public void unlockSurface() { - super.unlockSurface(); - nsViewLock.unlock(); - } - - class VisibleAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.VisibleAction "+visible+" "+Thread.currentThread().getName()); - if (visible) { - createWindow(parentWindowHandle, false); - if (windowHandle != 0) { - makeKeyAndOrderFront(windowHandle); - } - } else { - if (windowHandle != 0) { - orderOut(windowHandle); - } - } - } finally { - nsViewLock.unlock(); - } - } - } - private VisibleAction visibleAction = new VisibleAction(); - - public void setVisible(boolean visible) { - this.visible = visible; - MainThread.invoke(true, visibleAction); - } - - class TitleAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - setTitle0(windowHandle, title); - } - } finally { - nsViewLock.unlock(); - } - } - } - private TitleAction titleAction = new TitleAction(); - - public void setTitle(String title) { - super.setTitle(title); - MainThread.invoke(true, titleAction); - } - - class FocusAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - makeKey(windowHandle); - } - } finally { - nsViewLock.unlock(); - } - } - } - private FocusAction focusAction = new FocusAction(); - - public void requestFocus() { - super.requestFocus(); - MainThread.invoke(true, focusAction); - } - - class SizeAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - setContentSize(windowHandle, width, height); - } - } finally { - nsViewLock.unlock(); - } - } - } - private SizeAction sizeAction = new SizeAction(); - - public void setSize(int width, int height) { - this.width=width; - this.height=height; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - MainThread.invoke(true, sizeAction); - } - - class PositionAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - setFrameTopLeftPoint(parentWindowHandle, windowHandle, x, y); - } - } finally { - nsViewLock.unlock(); - } - } - } - private PositionAction positionAction = new PositionAction(); - - public void setPosition(int x, int y) { - this.x=x; - this.y=y; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - MainThread.invoke(true, positionAction); - } - - class FullscreenAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("MacWindow fs: "+fullscreen+" "+x+"/"+y+" "+width+"x"+height); - } - createWindow(parentWindowHandle, true); - if (windowHandle != 0) { - makeKeyAndOrderFront(windowHandle); - } - } finally { - nsViewLock.unlock(); - } - } - } - private FullscreenAction fullscreenAction = new FullscreenAction(); - - public boolean setFullscreen(boolean fullscreen) { - if(this.fullscreen!=fullscreen) { - this.fullscreen=fullscreen; - if(fullscreen) { - x = 0; - y = 0; - width = screen.getWidth(); - height = screen.getHeight(); - } else { - x = nfs_x; - y = nfs_y; - width = nfs_width; - height = nfs_height; - } - MainThread.invoke(true, fullscreenAction); - } - return fullscreen; - } - - private void sizeChanged(int newWidth, int newHeight) { - if (DEBUG_IMPLEMENTATION) { - System.out.println(Thread.currentThread().getName()+" Size changed to " + newWidth + ", " + newHeight); - } - width = newWidth; - height = newHeight; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - if (DEBUG_IMPLEMENTATION) { - System.out.println(" Posted WINDOW_RESIZED event"); - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - } - - private void insetsChanged(int left, int top, int right, int bottom) { - if (DEBUG_IMPLEMENTATION) { - System.out.println(Thread.currentThread().getName()+ - " Insets changed to " + left + ", " + top + ", " + right + ", " + bottom); - } - if (left != -1 && top != -1 && right != -1 && bottom != -1) { - insets.left = left; - insets.top = top; - insets.right = right; - insets.bottom = bottom; - } - } - - private void positionChanged(int newX, int newY) { - if (DEBUG_IMPLEMENTATION) { - System.out.println(Thread.currentThread().getName()+" Position changed to " + newX + ", " + newY); - } - x = newX; - y = newY; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - if (DEBUG_IMPLEMENTATION) { - System.out.println(" Posted WINDOW_MOVED event"); - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); - } - - private void focusChanged(boolean focusGained) { - if (focusGained) { - sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); - } else { - sendWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS); - } - } - - private char convertKeyChar(char keyChar) { - if (keyChar == '\r') { - // Turn these into \n - return '\n'; - } - - if (keyChar >= NSUpArrowFunctionKey && keyChar <= NSModeSwitchFunctionKey) { - switch (keyChar) { - case NSUpArrowFunctionKey: return KeyEvent.VK_UP; - case NSDownArrowFunctionKey: return KeyEvent.VK_DOWN; - case NSLeftArrowFunctionKey: return KeyEvent.VK_LEFT; - case NSRightArrowFunctionKey: return KeyEvent.VK_RIGHT; - case NSF1FunctionKey: return KeyEvent.VK_F1; - case NSF2FunctionKey: return KeyEvent.VK_F2; - case NSF3FunctionKey: return KeyEvent.VK_F3; - case NSF4FunctionKey: return KeyEvent.VK_F4; - case NSF5FunctionKey: return KeyEvent.VK_F5; - case NSF6FunctionKey: return KeyEvent.VK_F6; - case NSF7FunctionKey: return KeyEvent.VK_F7; - case NSF8FunctionKey: return KeyEvent.VK_F8; - case NSF9FunctionKey: return KeyEvent.VK_F9; - case NSF10FunctionKey: return KeyEvent.VK_F10; - case NSF11FunctionKey: return KeyEvent.VK_F11; - case NSF12FunctionKey: return KeyEvent.VK_F12; - case NSF13FunctionKey: return KeyEvent.VK_F13; - case NSF14FunctionKey: return KeyEvent.VK_F14; - case NSF15FunctionKey: return KeyEvent.VK_F15; - case NSF16FunctionKey: return KeyEvent.VK_F16; - case NSF17FunctionKey: return KeyEvent.VK_F17; - case NSF18FunctionKey: return KeyEvent.VK_F18; - case NSF19FunctionKey: return KeyEvent.VK_F19; - case NSF20FunctionKey: return KeyEvent.VK_F20; - case NSF21FunctionKey: return KeyEvent.VK_F21; - case NSF22FunctionKey: return KeyEvent.VK_F22; - case NSF23FunctionKey: return KeyEvent.VK_F23; - case NSF24FunctionKey: return KeyEvent.VK_F24; - case NSInsertFunctionKey: return KeyEvent.VK_INSERT; - case NSDeleteFunctionKey: return KeyEvent.VK_DELETE; - case NSHomeFunctionKey: return KeyEvent.VK_HOME; - case NSBeginFunctionKey: return KeyEvent.VK_BEGIN; - case NSEndFunctionKey: return KeyEvent.VK_END; - case NSPageUpFunctionKey: return KeyEvent.VK_PAGE_UP; - case NSPageDownFunctionKey: return KeyEvent.VK_PAGE_DOWN; - case NSPrintScreenFunctionKey: return KeyEvent.VK_PRINTSCREEN; - case NSScrollLockFunctionKey: return KeyEvent.VK_SCROLL_LOCK; - case NSPauseFunctionKey: return KeyEvent.VK_PAUSE; - // Not handled: - // NSSysReqFunctionKey - // NSBreakFunctionKey - // NSResetFunctionKey - case NSStopFunctionKey: return KeyEvent.VK_STOP; - // Not handled: - // NSMenuFunctionKey - // NSUserFunctionKey - // NSSystemFunctionKey - // NSPrintFunctionKey - // NSClearLineFunctionKey - // NSClearDisplayFunctionKey - // NSInsertLineFunctionKey - // NSDeleteLineFunctionKey - // NSInsertCharFunctionKey - // NSDeleteCharFunctionKey - // NSPrevFunctionKey - // NSNextFunctionKey - // NSSelectFunctionKey - // NSExecuteFunctionKey - // NSUndoFunctionKey - // NSRedoFunctionKey - // NSFindFunctionKey - // NSHelpFunctionKey - // NSModeSwitchFunctionKey - default: break; - } - } - - // NSEvent's charactersIgnoringModifiers doesn't ignore the shift key - if (keyChar >= 'a' && keyChar <= 'z') { - return Character.toUpperCase(keyChar); - } - - return keyChar; - } - - protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { - int key = convertKeyChar(keyChar); - if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.sendKeyEvent "+Thread.currentThread().getName()); - // Note that we send the key char for the key code on this - // platform -- we do not get any useful key codes out of the system - super.sendKeyEvent(eventType, modifiers, key, keyChar); - } - - private void createWindow(long parentWindowHandle, boolean recreate) { - if(0!=windowHandle && !recreate) { - return; - } - if(0!=windowHandle) { - // save the view .. close the window - surfaceHandle = changeContentView(parentWindowHandle, windowHandle, 0); - if(recreate && 0==surfaceHandle) { - throw new NativeWindowException("Internal Error - recreate, window but no view"); - } - close0(windowHandle); - windowHandle=0; - } else { - surfaceHandle = 0; - } - windowHandle = createWindow0(parentWindowHandle, - getX(), getY(), getWidth(), getHeight(), fullscreen, - (isUndecorated() ? - NSBorderlessWindowMask : - NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask), - NSBackingStoreBuffered, - getScreen().getIndex(), surfaceHandle); - if (windowHandle == 0) { - throw new NativeWindowException("Could create native window "+Thread.currentThread().getName()+" "+this); - } - surfaceHandle = contentView(windowHandle); - setTitle0(windowHandle, getTitle()); - // don't make the window visible on window creation -// makeKeyAndOrderFront(windowHandle); - sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); - } - - protected static native boolean initIDs(); - private native long createWindow0(long parentWindowHandle, int x, int y, int w, int h, - boolean fullscreen, int windowStyle, - int backingStoreType, - int screen_idx, long view); - private native void makeKeyAndOrderFront(long window); - private native void makeKey(long window); - private native void orderOut(long window); - private native void close0(long window); - private native void setTitle0(long window, String title); - private native long contentView(long window); - private native long changeContentView(long parentWindowHandle, long window, long view); - private native void setContentSize(long window, int w, int h); - private native void setFrameTopLeftPoint(long parentWindowHandle, long window, int x, int y); -} diff --git a/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Display.java b/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Display.java deleted file mode 100644 index 7db5b18dd..000000000 --- a/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Display.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.opengl.broadcom.egl; - -import com.jogamp.newt.impl.*; -import com.jogamp.opengl.impl.egl.*; -import javax.media.nativewindow.*; -import javax.media.nativewindow.egl.*; - -public class Display extends com.jogamp.newt.Display { - - static { - NEWTJNILibLoader.loadNEWT(); - - if (!Window.initIDs()) { - throw new NativeWindowException("Failed to initialize BCEGL Window jmethodIDs"); - } - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - - public Display() { - } - - protected void createNative() { - long handle = CreateDisplay(Screen.fixedWidth, Screen.fixedHeight); - if (handle == EGL.EGL_NO_DISPLAY) { - throw new NativeWindowException("BC EGL CreateDisplay failed"); - } - aDevice = new EGLGraphicsDevice(handle); - } - - protected void closeNative() { - if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) { - DestroyDisplay(aDevice.getHandle()); - } - } - - protected void dispatchMessagesNative() { - // n/a .. DispatchMessages(); - } - - private native long CreateDisplay(int width, int height); - private native void DestroyDisplay(long dpy); - private native void DispatchMessages(); -} - diff --git a/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Screen.java b/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Screen.java deleted file mode 100755 index b4f07599b..000000000 --- a/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Screen.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.opengl.broadcom.egl; - -import javax.media.nativewindow.*; - -public class Screen extends com.jogamp.newt.Screen { - - static { - Display.initSingleton(); - } - - - public Screen() { - } - - protected void createNative(int index) { - aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); - setScreenSize(fixedWidth, fixedHeight); - } - - protected void closeNative() { } - - //---------------------------------------------------------------------- - // Internals only - // - - static final int fixedWidth = 1920; - static final int fixedHeight = 1080; -} - diff --git a/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Window.java b/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Window.java deleted file mode 100755 index 185dc97b9..000000000 --- a/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Window.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.opengl.broadcom.egl; - -import com.jogamp.opengl.impl.egl.*; -import javax.media.nativewindow.*; -import javax.media.opengl.GLCapabilities; -import javax.media.nativewindow.NativeWindowException; - -public class Window extends com.jogamp.newt.Window { - static { - Display.initSingleton(); - } - - public Window() { - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - if(0!=parentWindowHandle) { - throw new RuntimeException("Window parenting not supported (yet)"); - } - // query a good configuration .. even thought we drop this one - // and reuse the EGLUtil choosen one later. - config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - setSizeImpl(getScreen().getWidth(), getScreen().getHeight()); - } - - protected void closeNative() { - if(0!=windowHandleClose) { - CloseWindow(getDisplayHandle(), windowHandleClose); - } - } - - public void setVisible(boolean visible) { - if(this.visible!=visible) { - this.visible=visible; - if ( 0==windowHandle ) { - windowHandle = realizeWindow(true, width, height); - if (0 == windowHandle) { - throw new NativeWindowException("Error native Window Handle is null"); - } - } - clearEventMask(); - } - } - - public void setSize(int width, int height) { - System.err.println("setSize "+width+"x"+height+" n/a in BroadcomEGL"); - } - - void setSizeImpl(int width, int height) { - if(0!=windowHandle) { - // n/a in BroadcomEGL - System.err.println("BCEGL Window.setSizeImpl n/a in BroadcomEGL with realized window"); - } else { - if(DEBUG_IMPLEMENTATION) { - Exception e = new Exception("BCEGL Window.setSizeImpl() "+this.width+"x"+this.height+" -> "+width+"x"+height); - e.printStackTrace(); - } - this.width = width; - this.height = height; - } - } - - public void setPosition(int x, int y) { - // n/a in BroadcomEGL - System.err.println("setPosition n/a in BroadcomEGL"); - } - - public boolean setFullscreen(boolean fullscreen) { - // n/a in BroadcomEGL - System.err.println("setFullscreen n/a in BroadcomEGL"); - return false; - } - - public boolean surfaceSwap() { - if ( 0!=windowHandle ) { - SwapWindow(getDisplayHandle(), windowHandle); - return true; - } - return false; - } - - //---------------------------------------------------------------------- - // Internals only - // - - protected static native boolean initIDs(); - private native long CreateWindow(long eglDisplayHandle, boolean chromaKey, int width, int height); - private native void CloseWindow(long eglDisplayHandle, long eglWindowHandle); - private native void SwapWindow(long eglDisplayHandle, long eglWindowHandle); - - - private long realizeWindow(boolean chromaKey, int width, int height) { - if(DEBUG_IMPLEMENTATION) { - System.out.println("BCEGL Window.realizeWindow() with: chroma "+chromaKey+", "+width+"x"+height+", "+config); - } - long handle = CreateWindow(getDisplayHandle(), chromaKey, width, height); - if (0 == handle) { - throw new NativeWindowException("Error native Window Handle is null"); - } - windowHandleClose = handle; - return handle; - } - - private void windowCreated(int cfgID, int width, int height) { - this.width = width; - this.height = height; - GLCapabilities capsReq = (GLCapabilities) config.getRequestedCapabilities(); - config = EGLGraphicsConfiguration.create(capsReq, screen.getGraphicsScreen(), cfgID); - if (config == null) { - throw new NativeWindowException("Error creating EGLGraphicsConfiguration from id: "+cfgID+", "+this); - } - if(DEBUG_IMPLEMENTATION) { - System.out.println("BCEGL Window.windowCreated(): "+toHexString(cfgID)+", "+width+"x"+height+", "+config); - } - } - - private long windowHandleClose; -} diff --git a/src/newt/classes/com/jogamp/newt/opengl/kd/KDDisplay.java b/src/newt/classes/com/jogamp/newt/opengl/kd/KDDisplay.java deleted file mode 100755 index 8a8e2a7c3..000000000 --- a/src/newt/classes/com/jogamp/newt/opengl/kd/KDDisplay.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.opengl.kd; - -import com.jogamp.newt.*; -import com.jogamp.newt.impl.*; -import com.jogamp.opengl.impl.egl.*; -import javax.media.nativewindow.*; -import javax.media.nativewindow.egl.*; - -public class KDDisplay extends Display { - - static { - NEWTJNILibLoader.loadNEWT(); - - if (!KDWindow.initIDs()) { - throw new NativeWindowException("Failed to initialize KDWindow jmethodIDs"); - } - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - - public KDDisplay() { - } - - protected void createNative() { - // FIXME: map name to EGL_*_DISPLAY - long handle = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY); - if (handle == EGL.EGL_NO_DISPLAY) { - throw new NativeWindowException("eglGetDisplay failed"); - } - if (!EGL.eglInitialize(handle, null, null)) { - throw new NativeWindowException("eglInitialize failed"); - } - aDevice = new EGLGraphicsDevice(handle); - } - - protected void closeNative() { - if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) { - EGL.eglTerminate(aDevice.getHandle()); - } - } - - protected void dispatchMessagesNative() { - DispatchMessages(); - } - - private native void DispatchMessages(); -} - diff --git a/src/newt/classes/com/jogamp/newt/opengl/kd/KDScreen.java b/src/newt/classes/com/jogamp/newt/opengl/kd/KDScreen.java deleted file mode 100755 index cd53c8152..000000000 --- a/src/newt/classes/com/jogamp/newt/opengl/kd/KDScreen.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.opengl.kd; - -import com.jogamp.newt.*; -import javax.media.nativewindow.*; - -public class KDScreen extends Screen { - static { - KDDisplay.initSingleton(); - } - - public KDScreen() { - } - - protected void createNative(int index) { - aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); - } - - protected void closeNative() { } - - // elevate access to this package .. - protected void setScreenSize(int w, int h) { - super.setScreenSize(w, h); - } -} diff --git a/src/newt/classes/com/jogamp/newt/opengl/kd/KDWindow.java b/src/newt/classes/com/jogamp/newt/opengl/kd/KDWindow.java deleted file mode 100755 index c8bed8a68..000000000 --- a/src/newt/classes/com/jogamp/newt/opengl/kd/KDWindow.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.opengl.kd; - -import com.jogamp.newt.*; -import com.jogamp.newt.event.*; -import com.jogamp.newt.impl.*; -import com.jogamp.opengl.impl.egl.*; -import javax.media.nativewindow.*; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLProfile; -import javax.media.nativewindow.NativeWindowException; - -public class KDWindow extends Window { - private static final String WINDOW_CLASS_NAME = "NewtWindow"; - // non fullscreen dimensions .. - private int nfs_width, nfs_height, nfs_x, nfs_y; - - static { - KDDisplay.initSingleton(); - } - - public KDWindow() { - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - if(0!=parentWindowHandle) { - throw new RuntimeException("Window parenting not supported (yet)"); - } - config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - - GLCapabilities eglCaps = (GLCapabilities)config.getChosenCapabilities(); - int[] eglAttribs = EGLGraphicsConfiguration.GLCapabilities2AttribList(eglCaps); - - windowHandle = 0; - eglWindowHandle = CreateWindow(getDisplayHandle(), eglAttribs); - if (eglWindowHandle == 0) { - throw new NativeWindowException("Error creating egl window: "+config); - } - setVisible0(eglWindowHandle, false); - windowHandleClose = eglWindowHandle; - } - - protected void closeNative() { - if(0!=windowHandleClose) { - CloseWindow(windowHandleClose, windowUserData); - windowUserData=0; - } - } - - public void setVisible(boolean visible) { - if(0!=eglWindowHandle && this.visible!=visible) { - this.visible=visible; - setVisible0(eglWindowHandle, visible); - if ( 0==windowHandle ) { - windowHandle = RealizeWindow(eglWindowHandle); - if (0 == windowHandle) { - throw new NativeWindowException("Error native Window Handle is null"); - } - } - clearEventMask(); - } - } - - public void setSize(int width, int height) { - if(0!=eglWindowHandle) { - setSize0(eglWindowHandle, width, height); - } - } - - public void setPosition(int x, int y) { - // n/a in KD - System.err.println("setPosition n/a in KD"); - } - - public boolean setFullscreen(boolean fullscreen) { - if(0!=eglWindowHandle && this.fullscreen!=fullscreen) { - this.fullscreen=fullscreen; - if(this.fullscreen) { - setFullScreen0(eglWindowHandle, true); - } else { - setFullScreen0(eglWindowHandle, false); - setSize0(eglWindowHandle, nfs_width, nfs_height); - } - } - return true; - } - - //---------------------------------------------------------------------- - // Internals only - // - - protected static native boolean initIDs(); - private native long CreateWindow(long displayHandle, int[] attributes); - private native long RealizeWindow(long eglWindowHandle); - private native int CloseWindow(long eglWindowHandle, long userData); - private native void setVisible0(long eglWindowHandle, boolean visible); - private native void setSize0(long eglWindowHandle, int width, int height); - private native void setFullScreen0(long eglWindowHandle, boolean fullscreen); - - private void windowCreated(long userData) { - windowUserData=userData; - } - - private void sizeChanged(int newWidth, int newHeight) { - width = newWidth; - height = newHeight; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } else { - ((KDScreen)screen).setScreenSize(width, height); - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - } - - private long eglWindowHandle; - private long windowHandleClose; - private long windowUserData; -} diff --git a/src/newt/classes/com/jogamp/newt/util/MainThread.java b/src/newt/classes/com/jogamp/newt/util/MainThread.java index daa09edce..cfe1876b5 100644 --- a/src/newt/classes/com/jogamp/newt/util/MainThread.java +++ b/src/newt/classes/com/jogamp/newt/util/MainThread.java @@ -46,7 +46,7 @@ import javax.media.nativewindow.*; import com.jogamp.common.util.*; import com.jogamp.newt.*; import com.jogamp.newt.impl.*; -import com.jogamp.newt.macosx.MacDisplay; +import com.jogamp.newt.impl.macosx.MacDisplay; /** * NEWT Utility class MainThread

diff --git a/src/newt/classes/com/jogamp/newt/windows/WindowsDisplay.java b/src/newt/classes/com/jogamp/newt/windows/WindowsDisplay.java deleted file mode 100755 index 678777e81..000000000 --- a/src/newt/classes/com/jogamp/newt/windows/WindowsDisplay.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.windows; - -import javax.media.nativewindow.*; -import javax.media.nativewindow.windows.*; -import com.jogamp.newt.*; -import com.jogamp.newt.impl.*; - -public class WindowsDisplay extends Display { - - protected static final String WINDOW_CLASS_NAME = "NewtWindowClass"; - private static int windowClassAtom; - private static long hInstance; - - static { - NEWTJNILibLoader.loadNEWT(); - - if (!WindowsWindow.initIDs()) { - throw new NativeWindowException("Failed to initialize WindowsWindow jmethodIDs"); - } - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - - public WindowsDisplay() { - } - - protected void createNative() { - aDevice = new WindowsGraphicsDevice(); - } - - protected void closeNative() { - // Can't do .. only at application shutdown - // UnregisterWindowClass(getWindowClassAtom(), getHInstance()); - } - - protected void dispatchMessagesNative() { - DispatchMessages(); - } - - protected static synchronized int getWindowClassAtom() { - if(0 == windowClassAtom) { - windowClassAtom = RegisterWindowClass(WINDOW_CLASS_NAME, getHInstance()); - if (0 == windowClassAtom) { - throw new NativeWindowException("Error while registering window class"); - } - } - return windowClassAtom; - } - - protected static synchronized long getHInstance() { - if(0 == hInstance) { - hInstance = LoadLibraryW("newt"); - if (0 == hInstance) { - throw new NativeWindowException("Error finding HINSTANCE for \"newt\""); - } - } - return hInstance; - } - - //---------------------------------------------------------------------- - // Internals only - // - private static native long LoadLibraryW(String libraryName); - private static native int RegisterWindowClass(String windowClassName, long hInstance); - private static native void UnregisterWindowClass(int wndClassAtom, long hInstance); - - private static native void DispatchMessages(); -} - diff --git a/src/newt/classes/com/jogamp/newt/windows/WindowsScreen.java b/src/newt/classes/com/jogamp/newt/windows/WindowsScreen.java deleted file mode 100755 index aea3cd439..000000000 --- a/src/newt/classes/com/jogamp/newt/windows/WindowsScreen.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.windows; - -import com.jogamp.newt.*; -import javax.media.nativewindow.*; - -public class WindowsScreen extends Screen { - static { - WindowsDisplay.initSingleton(); - } - - - public WindowsScreen() { - } - - protected void createNative(int index) { - aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); - setScreenSize(getWidthImpl(getIndex()), getHeightImpl(getIndex())); - } - - protected void closeNative() { } - - private native int getWidthImpl(int scrn_idx); - private native int getHeightImpl(int scrn_idx); -} diff --git a/src/newt/classes/com/jogamp/newt/windows/WindowsWindow.java b/src/newt/classes/com/jogamp/newt/windows/WindowsWindow.java deleted file mode 100755 index db1ae4718..000000000 --- a/src/newt/classes/com/jogamp/newt/windows/WindowsWindow.java +++ /dev/null @@ -1,290 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.windows; - -import javax.media.nativewindow.*; -import com.jogamp.newt.*; -import com.jogamp.newt.event.*; - -public class WindowsWindow extends Window { - - private long hmon; - private long hdc; - private long windowHandleClose; - private long parentWindowHandle; - // non fullscreen dimensions .. - private int nfs_width, nfs_height, nfs_x, nfs_y; - private final Insets insets = new Insets(0, 0, 0, 0); - - static { - WindowsDisplay.initSingleton(); - } - - public WindowsWindow() { - } - - Thread hdcOwner = null; - - public synchronized int lockSurface() throws NativeWindowException { - int res = super.lockSurface(); - if(LOCK_SUCCESS==res && 0!=windowHandle) { - if(hdc!=0) { - throw new NativeWindowException("NEWT Surface handle set HDC "+toHexString(hdc)+" - "+Thread.currentThread().getName()+" ; "+this); - } - hdc = GetDC(windowHandle); - hmon = MonitorFromWindow(windowHandle); - hdcOwner = Thread.currentThread(); - } - return res; - } - - public synchronized void unlockSurface() { - // prevalidate, before we change data .. - Thread cur = Thread.currentThread(); - if ( getSurfaceLockOwner() != cur ) { - getLockedStack().printStackTrace(); - throw new NativeWindowException(cur+": Not owner, owner is "+getSurfaceLockOwner()); - } - if (0!=hdc && 0!=windowHandle) { - if(hdcOwner != cur) { - throw new NativeWindowException("NEWT Surface handle set HDC "+toHexString(hdc)+" by other thread "+hdcOwner+", this "+cur+" ; "+this); - } - ReleaseDC(windowHandle, hdc); - hdc=0; - hdcOwner=null; - } - super.unlockSurface(); - } - - public long getSurfaceHandle() { - return hdc; - } - - public boolean hasDeviceChanged() { - if(0!=windowHandle) { - long _hmon = MonitorFromWindow(windowHandle); - if (hmon != _hmon) { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - Exception e = new Exception("!!! Window Device Changed "+Thread.currentThread().getName()+ - ", HMON "+toHexString(hmon)+" -> "+toHexString(_hmon)); - e.printStackTrace(); - } - hmon = _hmon; - return true; - } - } - return false; - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - WindowsScreen screen = (WindowsScreen) getScreen(); - WindowsDisplay display = (WindowsDisplay) screen.getDisplay(); - config = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, screen.getGraphicsScreen()); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - windowHandle = CreateWindow(parentWindowHandle, - display.getWindowClassAtom(), display.WINDOW_CLASS_NAME, display.getHInstance(), - 0, undecorated, x, y, width, height); - if (windowHandle == 0) { - throw new NativeWindowException("Error creating window"); - } - this.parentWindowHandle = parentWindowHandle; - windowHandleClose = windowHandle; - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - Exception e = new Exception("!!! Window new window handle "+Thread.currentThread().getName()+ - " (Parent HWND "+toHexString(parentWindowHandle)+ - ") : HWND "+toHexString(windowHandle)+", "+Thread.currentThread()); - e.printStackTrace(); - } - } - - protected void closeNative() { - if (hdc != 0) { - if(windowHandleClose != 0) { - ReleaseDC(windowHandleClose, hdc); - } - hdc = 0; - } - if(windowHandleClose != 0) { - DestroyWindow(windowHandleClose); - windowHandleClose = 0; - } - } - - protected void windowDestroyed() { - windowHandleClose = 0; - super.windowDestroyed(); - } - - public void setVisible(boolean visible) { - if(this.visible!=visible && 0!=windowHandle) { - this.visible=visible; - setVisible0(windowHandle, visible); - } - } - - // @Override - public void setSize(int width, int height) { - if (0!=windowHandle && (width != this.width || this.height != height)) { - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - this.width = width; - this.height = height; - setSize0(parentWindowHandle, windowHandle, x, y, width, height); - } - } - - //@Override - public void setPosition(int x, int y) { - if (0!=windowHandle && (this.x != x || this.y != y)) { - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - this.x = x; - this.y = y; - setPosition(parentWindowHandle, windowHandle, x , y); - } - } - - public boolean setFullscreen(boolean fullscreen) { - if(0!=windowHandle && (this.fullscreen!=fullscreen)) { - int x,y,w,h; - this.fullscreen=fullscreen; - if(fullscreen) { - x = 0; y = 0; - w = screen.getWidth(); - h = screen.getHeight(); - } else { - x = nfs_x; - y = nfs_y; - w = nfs_width; - h = nfs_height; - } - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("WindowsWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); - } - setFullscreen0(parentWindowHandle, windowHandle, x, y, w, h, undecorated, fullscreen); - } - return fullscreen; - } - - // @Override - public void requestFocus() { - super.requestFocus(); - if (windowHandle != 0L) { - requestFocus(windowHandle); - } - } - - // @Override - public void setTitle(String title) { - if (title == null) { - title = ""; - } - if (0!=windowHandle && !title.equals(getTitle())) { - super.setTitle(title); - setTitle(windowHandle, title); - } - } - - public Insets getInsets() { - return (Insets)insets.clone(); - } - - //---------------------------------------------------------------------- - // Internals only - // - protected static native boolean initIDs(); - private native long CreateWindow(long parentWindowHandle, - int wndClassAtom, String wndName, - long hInstance, long visualID, - boolean isUndecorated, - int x, int y, int width, int height); - private native void DestroyWindow(long windowHandle); - private native long GetDC(long windowHandle); - private native void ReleaseDC(long windowHandle, long hdc); - private native long MonitorFromWindow(long windowHandle); - private static native void setVisible0(long windowHandle, boolean visible); - private native void setSize0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height); - private native void setPosition(long parentWindowHandle, long windowHandle, int x, int y); - private native void setFullscreen0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height, boolean isUndecorated, boolean on); - private static native void setTitle(long windowHandle, String title); - private static native void requestFocus(long windowHandle); - - private void insetsChanged(int left, int top, int right, int bottom) { - if (left != -1 && top != -1 && right != -1 && bottom != -1) { - insets.left = left; - insets.top = top; - insets.right = right; - insets.bottom = bottom; - } - } - private void sizeChanged(int newWidth, int newHeight) { - width = newWidth; - height = newHeight; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - } - - private void positionChanged(int newX, int newY) { - x = newX; - y = newY; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); - } - - /** - * - * @param focusOwner if focusGained is true, focusOwner is the previous - * focus owner, if focusGained is false, focusOwner is the new focus owner - * @param focusGained - */ - private void focusChanged(long focusOwner, boolean focusGained) { - if (focusGained) { - sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); - } else { - sendWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS); - } - } -} diff --git a/src/newt/classes/com/jogamp/newt/x11/X11Display.java b/src/newt/classes/com/jogamp/newt/x11/X11Display.java deleted file mode 100755 index 70e002e9e..000000000 --- a/src/newt/classes/com/jogamp/newt/x11/X11Display.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.x11; - -import javax.media.nativewindow.*; -import javax.media.nativewindow.x11.*; -import com.jogamp.newt.*; -import com.jogamp.newt.impl.*; -import com.jogamp.nativewindow.impl.x11.X11Util; - -public class X11Display extends Display { - static { - NEWTJNILibLoader.loadNEWT(); - - if (!initIDs()) { - throw new NativeWindowException("Failed to initialize X11Display jmethodIDs"); - } - - if (!X11Window.initIDs()) { - throw new NativeWindowException("Failed to initialize X11Window jmethodIDs"); - } - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - - public X11Display() { - } - - protected void createNative() { - long handle= X11Util.createThreadLocalDisplay(name); - if (handle == 0 ) { - throw new RuntimeException("Error creating display: "+name); - } - try { - CompleteDisplay(handle); - } catch(RuntimeException e) { - X11Util.closeThreadLocalDisplay(name); - throw e; - } - aDevice = new X11GraphicsDevice(handle); - } - - protected void closeNative() { - X11Util.closeThreadLocalDisplay(name); - } - - protected void dispatchMessagesNative() { - DispatchMessages(getHandle(), javaObjectAtom, windowDeleteAtom); - } - - protected void lockDisplay() { - super.lockDisplay(); - LockDisplay(getHandle()); - } - - protected void unlockDisplay() { - UnlockDisplay(getHandle()); - super.unlockDisplay(); - } - - protected long getJavaObjectAtom() { return javaObjectAtom; } - protected long getWindowDeleteAtom() { return windowDeleteAtom; } - - //---------------------------------------------------------------------- - // Internals only - // - private static native boolean initIDs(); - - private native void LockDisplay(long handle); - private native void UnlockDisplay(long handle); - - private native void CompleteDisplay(long handle); - - private native void DispatchMessages(long display, long javaObjectAtom, long windowDeleteAtom); - - private void displayCompleted(long javaObjectAtom, long windowDeleteAtom) { - this.javaObjectAtom=javaObjectAtom; - this.windowDeleteAtom=windowDeleteAtom; - } - - private long windowDeleteAtom; - private long javaObjectAtom; -} - diff --git a/src/newt/classes/com/jogamp/newt/x11/X11Screen.java b/src/newt/classes/com/jogamp/newt/x11/X11Screen.java deleted file mode 100755 index e053d99c0..000000000 --- a/src/newt/classes/com/jogamp/newt/x11/X11Screen.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.x11; - -import com.jogamp.newt.*; -import javax.media.nativewindow.x11.*; - -public class X11Screen extends Screen { - - static { - X11Display.initSingleton(); - } - - - public X11Screen() { - } - - protected void createNative(int index) { - long handle = GetScreen(display.getHandle(), index); - if (handle == 0 ) { - throw new RuntimeException("Error creating screen: "+index); - } - aScreen = new X11GraphicsScreen((X11GraphicsDevice)getDisplay().getGraphicsDevice(), index); - setScreenSize(getWidth0(display.getHandle(), index), - getHeight0(display.getHandle(), index)); - } - - protected void closeNative() { } - - //---------------------------------------------------------------------- - // Internals only - // - - private native long GetScreen(long dpy, int scrn_idx); - private native int getWidth0(long display, int scrn_idx); - private native int getHeight0(long display, int scrn_idx); -} - diff --git a/src/newt/classes/com/jogamp/newt/x11/X11Window.java b/src/newt/classes/com/jogamp/newt/x11/X11Window.java deleted file mode 100755 index 59ecc3bab..000000000 --- a/src/newt/classes/com/jogamp/newt/x11/X11Window.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.newt.x11; - -import com.jogamp.newt.*; -import com.jogamp.newt.event.*; -import javax.media.nativewindow.*; -import javax.media.nativewindow.x11.*; - -public class X11Window extends Window { - private static final String WINDOW_CLASS_NAME = "NewtWindow"; - // non fullscreen dimensions .. - private int nfs_width, nfs_height, nfs_x, nfs_y; - - static { - X11Display.initSingleton(); - } - - public X11Window() { - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - X11Screen screen = (X11Screen) getScreen(); - X11Display display = (X11Display) screen.getDisplay(); - config = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, screen.getGraphicsScreen()); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - X11GraphicsConfiguration x11config = (X11GraphicsConfiguration) config; - long visualID = x11config.getVisualID(); - long w = CreateWindow(parentWindowHandle, - display.getHandle(), screen.getIndex(), visualID, - display.getJavaObjectAtom(), display.getWindowDeleteAtom(), x, y, width, height); - if (w == 0 || w!=windowHandle) { - throw new NativeWindowException("Error creating window: "+w); - } - this.parentWindowHandle = parentWindowHandle; - windowHandleClose = windowHandle; - displayHandleClose = display.getHandle(); - } - - protected void closeNative() { - if(0!=displayHandleClose && 0!=windowHandleClose && null!=getScreen() ) { - X11Display display = (X11Display) getScreen().getDisplay(); - CloseWindow(displayHandleClose, windowHandleClose, display.getJavaObjectAtom()); - windowHandleClose = 0; - displayHandleClose = 0; - } - } - - protected void windowDestroyed() { - windowHandleClose = 0; - displayHandleClose = 0; - super.windowDestroyed(); - } - - public void setVisible(boolean visible) { - if(0!=windowHandle && this.visible!=visible) { - this.visible=visible; - setVisible0(getDisplayHandle(), windowHandle, visible); - clearEventMask(); - } - } - - public void requestFocus() { - super.requestFocus(); - } - - public void setSize(int width, int height) { - if(DEBUG_IMPLEMENTATION) { - System.err.println("X11Window setSize: "+this.x+"/"+this.y+" "+this.width+"x"+this.height+" -> "+width+"x"+height); - // Exception e = new Exception("XXXXXXXXXX"); - // e.printStackTrace(); - } - this.width = width; - this.height = height; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - if(0!=windowHandle) { - setSize0(parentWindowHandle, getDisplayHandle(), getScreenIndex(), windowHandle, x, y, width, height, (undecorated||fullscreen)?-1:1, false); - } - } - - public void setPosition(int x, int y) { - if(DEBUG_IMPLEMENTATION) { - System.err.println("X11Window setPosition: "+this.x+"/"+this.y+" -> "+x+"/"+y); - // Exception e = new Exception("XXXXXXXXXX"); - // e.printStackTrace(); - } - this.x = x; - this.y = y; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - if(0!=windowHandle) { - setPosition0(getDisplayHandle(), windowHandle, x, y); - } - } - - public boolean setFullscreen(boolean fullscreen) { - if(0!=windowHandle && this.fullscreen!=fullscreen) { - int x,y,w,h; - this.fullscreen=fullscreen; - if(fullscreen) { - x = 0; y = 0; - w = screen.getWidth(); - h = screen.getHeight(); - } else { - x = nfs_x; - y = nfs_y; - w = nfs_width; - h = nfs_height; - } - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("X11Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); - } - setSize0(parentWindowHandle, getDisplayHandle(), getScreenIndex(), windowHandle, x, y, w, h, (undecorated||fullscreen)?-1:1, false); - } - return fullscreen; - } - - //---------------------------------------------------------------------- - // Internals only - // - - protected static native boolean initIDs(); - private native long CreateWindow(long parentWindowHandle, long display, int screen_index, - long visualID, long javaObjectAtom, long windowDeleteAtom, int x, int y, int width, int height); - private native void CloseWindow(long display, long windowHandle, long javaObjectAtom); - private native void setVisible0(long display, long windowHandle, boolean visible); - private native void setSize0(long parentWindowHandle, long display, int screen_index, long windowHandle, - int x, int y, int width, int height, int decorationToggle, boolean setVisible); - private native void setPosition0(long display, long windowHandle, int x, int y); - - private void windowChanged(int newX, int newY, int newWidth, int newHeight) { - if(width != newWidth || height != newHeight) { - if(DEBUG_IMPLEMENTATION) { - System.err.println("X11Window windowChanged size: "+this.width+"x"+this.height+" -> "+newWidth+"x"+newHeight); - } - width = newWidth; - height = newHeight; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - } - if( 0==parentWindowHandle && ( x != newX || y != newY ) ) { - if(DEBUG_IMPLEMENTATION) { - System.err.println("X11Window windowChanged position: "+this.x+"/"+this.y+" -> "+newX+"x"+newY); - } - x = newX; - y = newY; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); - } - } - - private void windowCreated(long windowHandle) { - this.windowHandle = windowHandle; - } - - private long windowHandleClose; - private long displayHandleClose; - private long parentWindowHandle; -} -- cgit v1.2.3