From 3fa1a00fc7a3215e9098028ce2c384bc252b7db1 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 16 Mar 2009 14:51:43 +0000 Subject: repair svn git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1869 232f8b59-042b-4e1e-8c03-345bb8c30851 --- src/newt/classes/com/sun/javafx/newt/Display.java | 96 +++ src/newt/classes/com/sun/javafx/newt/Event.java | 77 +++ .../classes/com/sun/javafx/newt/EventListener.java | 43 ++ .../classes/com/sun/javafx/newt/InputEvent.java | 82 +++ src/newt/classes/com/sun/javafx/newt/KeyEvent.java | 738 +++++++++++++++++++++ .../classes/com/sun/javafx/newt/KeyListener.java | 42 ++ .../classes/com/sun/javafx/newt/MouseEvent.java | 98 +++ .../classes/com/sun/javafx/newt/MouseListener.java | 46 ++ .../classes/com/sun/javafx/newt/NewtFactory.java | 178 +++++ src/newt/classes/com/sun/javafx/newt/Screen.java | 137 ++++ src/newt/classes/com/sun/javafx/newt/Window.java | 634 ++++++++++++++++++ .../classes/com/sun/javafx/newt/WindowEvent.java | 61 ++ .../com/sun/javafx/newt/WindowListener.java | 40 ++ .../com/sun/javafx/newt/awt/AWTDisplay.java | 45 ++ .../classes/com/sun/javafx/newt/awt/AWTScreen.java | 45 ++ .../classes/com/sun/javafx/newt/awt/AWTWindow.java | 355 ++++++++++ .../classes/com/sun/javafx/newt/impl/Debug.java | 93 +++ .../com/sun/javafx/newt/impl/NativeLibLoader.java | 130 ++++ .../com/sun/javafx/newt/macosx/MacDisplay.java | 45 ++ .../com/sun/javafx/newt/macosx/MacScreen.java | 45 ++ .../com/sun/javafx/newt/macosx/MacWindow.java | 350 ++++++++++ .../com/sun/javafx/newt/opengl/GLWindow.java | 532 +++++++++++++++ .../com/sun/javafx/newt/opengl/kd/KDDisplay.java | 60 ++ .../com/sun/javafx/newt/opengl/kd/KDScreen.java | 45 ++ .../com/sun/javafx/newt/opengl/kd/KDWindow.java | 163 +++++ .../sun/javafx/newt/windows/WindowsDisplay.java | 45 ++ .../com/sun/javafx/newt/windows/WindowsScreen.java | 45 ++ .../com/sun/javafx/newt/windows/WindowsWindow.java | 175 +++++ .../com/sun/javafx/newt/x11/X11Display.java | 59 ++ .../classes/com/sun/javafx/newt/x11/X11Screen.java | 64 ++ .../classes/com/sun/javafx/newt/x11/X11Window.java | 164 +++++ 31 files changed, 4732 insertions(+) create mode 100755 src/newt/classes/com/sun/javafx/newt/Display.java create mode 100644 src/newt/classes/com/sun/javafx/newt/Event.java create mode 100644 src/newt/classes/com/sun/javafx/newt/EventListener.java create mode 100644 src/newt/classes/com/sun/javafx/newt/InputEvent.java create mode 100644 src/newt/classes/com/sun/javafx/newt/KeyEvent.java create mode 100644 src/newt/classes/com/sun/javafx/newt/KeyListener.java create mode 100644 src/newt/classes/com/sun/javafx/newt/MouseEvent.java create mode 100644 src/newt/classes/com/sun/javafx/newt/MouseListener.java create mode 100755 src/newt/classes/com/sun/javafx/newt/NewtFactory.java create mode 100755 src/newt/classes/com/sun/javafx/newt/Screen.java create mode 100755 src/newt/classes/com/sun/javafx/newt/Window.java create mode 100644 src/newt/classes/com/sun/javafx/newt/WindowEvent.java create mode 100644 src/newt/classes/com/sun/javafx/newt/WindowListener.java create mode 100644 src/newt/classes/com/sun/javafx/newt/awt/AWTDisplay.java create mode 100644 src/newt/classes/com/sun/javafx/newt/awt/AWTScreen.java create mode 100644 src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java create mode 100644 src/newt/classes/com/sun/javafx/newt/impl/Debug.java create mode 100644 src/newt/classes/com/sun/javafx/newt/impl/NativeLibLoader.java create mode 100755 src/newt/classes/com/sun/javafx/newt/macosx/MacDisplay.java create mode 100755 src/newt/classes/com/sun/javafx/newt/macosx/MacScreen.java create mode 100755 src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java create mode 100644 src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java create mode 100755 src/newt/classes/com/sun/javafx/newt/opengl/kd/KDDisplay.java create mode 100755 src/newt/classes/com/sun/javafx/newt/opengl/kd/KDScreen.java create mode 100755 src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java create mode 100755 src/newt/classes/com/sun/javafx/newt/windows/WindowsDisplay.java create mode 100755 src/newt/classes/com/sun/javafx/newt/windows/WindowsScreen.java create mode 100755 src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java create mode 100755 src/newt/classes/com/sun/javafx/newt/x11/X11Display.java create mode 100755 src/newt/classes/com/sun/javafx/newt/x11/X11Screen.java create mode 100755 src/newt/classes/com/sun/javafx/newt/x11/X11Window.java (limited to 'src/newt/classes/com/sun') diff --git a/src/newt/classes/com/sun/javafx/newt/Display.java b/src/newt/classes/com/sun/javafx/newt/Display.java new file mode 100755 index 000000000..a0a4217ca --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/Display.java @@ -0,0 +1,96 @@ +/* + * 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.sun.javafx.newt; + +public abstract class Display { + + private static Class getDisplayClass(String type) + throws ClassNotFoundException + { + Class displayClass = null; + if (NewtFactory.KD.equals(type)) { + displayClass = Class.forName("com.sun.javafx.newt.opengl.kd.KDDisplay"); + } else if (NewtFactory.WINDOWS.equals(type)) { + displayClass = Class.forName("com.sun.javafx.newt.windows.WindowsDisplay"); + } else if (NewtFactory.MACOSX.equals(type)) { + displayClass = Class.forName("com.sun.javafx.newt.macosx.MacDisplay"); + } else if (NewtFactory.X11.equals(type)) { + displayClass = Class.forName("com.sun.javafx.newt.x11.X11Display"); + } else if (NewtFactory.AWT.equals(type)) { + displayClass = Class.forName("com.sun.javafx.newt.awt.AWTDisplay"); + } else { + throw new RuntimeException("Unknown display type \"" + type + "\""); + } + return displayClass; + } + + protected static Display create(String type, String name) { + try { + Class displayClass = getDisplayClass(type); + Display display = (Display) displayClass.newInstance(); + display.name=name; + display.handle=0; + display.createNative(); + return display; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected static Display wrapHandle(String type, String name, long handle) { + try { + Class displayClass = getDisplayClass(type); + Display display = (Display) displayClass.newInstance(); + display.name=name; + display.handle=handle; + return display; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected abstract void createNative(); + + public String getName() { + return name; + } + + public long getHandle() { + return handle; + } + + protected String name; + protected long handle; +} + diff --git a/src/newt/classes/com/sun/javafx/newt/Event.java b/src/newt/classes/com/sun/javafx/newt/Event.java new file mode 100644 index 000000000..7d2b24ba5 --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/Event.java @@ -0,0 +1,77 @@ +/* + * 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.sun.javafx.newt; + +public class Event { + private boolean isSystemEvent; + private int eventType; + private Window source; + private long when; + + Event(boolean isSystemEvent, int eventType, Window source, long when) { + this.isSystemEvent = isSystemEvent; + this.eventType = eventType; + this.source = source; + this.when = when; + } + + protected Event(int eventType, Window source, long when) { + this(false, eventType, source, 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 Window which produced this Event. */ + public final Window 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()+"]"; + } +} diff --git a/src/newt/classes/com/sun/javafx/newt/EventListener.java b/src/newt/classes/com/sun/javafx/newt/EventListener.java new file mode 100644 index 000000000..2af63bd7c --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/EventListener.java @@ -0,0 +1,43 @@ +/* + * 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.sun.javafx.newt; + +public interface EventListener +{ + public static final int WINDOW = 1 << 0; + public static final int MOUSE = 1 << 1; + public static final int KEY = 1 << 2; + +} + diff --git a/src/newt/classes/com/sun/javafx/newt/InputEvent.java b/src/newt/classes/com/sun/javafx/newt/InputEvent.java new file mode 100644 index 000000000..dc36be34d --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/InputEvent.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.sun.javafx.newt; + +public abstract class InputEvent extends Event +{ + public static int SHIFT_MASK = 1 << 0; + public static int CTRL_MASK = 1 << 1; + public static int META_MASK = 1 << 2; + public static int ALT_MASK = 1 << 3; + public static int ALT_GRAPH_MASK = 1 << 5; + + protected InputEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers) { + super(sysEvent, eventType, source, when); + this.consumed=false; + this.modifiers=modifiers; + } + + public void consume() { + consumed=true; + } + + public boolean isConsumed() { + return consumed; + } + public int getModifiers() { + return modifiers; + } + public boolean isAltDown() { + return (modifiers&ALT_MASK)!=0; + } + public boolean isAltGraphDown() { + return (modifiers&ALT_GRAPH_MASK)!=0; + } + public boolean isControlDown() { + return (modifiers&CTRL_MASK)!=0; + } + public boolean isMetaDown() { + return (modifiers&META_MASK)!=0; + } + public boolean isShiftDown() { + return (modifiers&SHIFT_MASK)!=0; + } + + public String toString() { + return "InputEvent[modifiers:"+modifiers+"]"; + } + + private boolean consumed; + private int modifiers; +} diff --git a/src/newt/classes/com/sun/javafx/newt/KeyEvent.java b/src/newt/classes/com/sun/javafx/newt/KeyEvent.java new file mode 100644 index 000000000..7e224dbad --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/KeyEvent.java @@ -0,0 +1,738 @@ +/* + * 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.sun.javafx.newt; + +public class KeyEvent extends InputEvent +{ + KeyEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) { + super(sysEvent, eventType, source, when, modifiers); + this.keyCode=keyCode; + this.keyChar=keyChar; + } + public KeyEvent(int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) { + this(false, eventType, source, when, modifiers, keyCode, keyChar); + } + + public char getKeyChar() { + return keyChar; + } + public int getKeyCode() { + return keyCode; + } + + public String toString() { + return "KeyEvent["+getEventTypeString(getEventType())+ + ", code "+keyCode+"(0x"+Integer.toHexString(keyCode)+"), char <"+keyChar+"> (0x"+Integer.toHexString((int)keyChar)+"), isActionKey "+isActionKey()+", "+super.toString()+"]"; + } + + public static String getEventTypeString(int type) { + switch(type) { + case EVENT_KEY_PRESSED: return "EVENT_KEY_PRESSED"; + case EVENT_KEY_RELEASED: return "EVENT_KEY_RELEASED"; + case EVENT_KEY_TYPED: return "EVENT_KEY_TYPED"; + default: return "unknown (" + type + ")"; + } + } + + public boolean isActionKey() { + switch (keyCode) { + case VK_HOME: + case VK_END: + case VK_PAGE_UP: + case VK_PAGE_DOWN: + case VK_UP: + case VK_DOWN: + case VK_LEFT: + case VK_RIGHT: + + case VK_F1: + case VK_F2: + case VK_F3: + case VK_F4: + case VK_F5: + case VK_F6: + case VK_F7: + case VK_F8: + case VK_F9: + case VK_F10: + case VK_F11: + case VK_F12: + case VK_F13: + case VK_F14: + case VK_F15: + case VK_F16: + case VK_F17: + case VK_F18: + case VK_F19: + case VK_F20: + case VK_F21: + case VK_F22: + case VK_F23: + case VK_F24: + case VK_PRINTSCREEN: + case VK_CAPS_LOCK: + case VK_PAUSE: + case VK_INSERT: + + case VK_HELP: + case VK_WINDOWS: + return true; + } + return false; + } + + private int keyCode; + private char keyChar; + + public static final int EVENT_KEY_PRESSED = 300; + public static final int EVENT_KEY_RELEASED= 301; + public static final int EVENT_KEY_TYPED = 302; + + /* Virtual key codes. */ + + public static final int VK_ENTER = '\n'; + public static final int VK_BACK_SPACE = '\b'; + public static final int VK_TAB = '\t'; + public static final int VK_CANCEL = 0x03; + public static final int VK_CLEAR = 0x0C; + public static final int VK_SHIFT = 0x10; + public static final int VK_CONTROL = 0x11; + public static final int VK_ALT = 0x12; + public static final int VK_PAUSE = 0x13; + public static final int VK_CAPS_LOCK = 0x14; + public static final int VK_ESCAPE = 0x1B; + public static final int VK_SPACE = 0x20; + public static final int VK_PAGE_UP = 0x21; + public static final int VK_PAGE_DOWN = 0x22; + public static final int VK_END = 0x23; + public static final int VK_HOME = 0x24; + + /** + * Constant for the non-numpad left arrow key. + * @see #VK_KP_LEFT + */ + public static final int VK_LEFT = 0x25; + + /** + * Constant for the non-numpad up arrow key. + * @see #VK_KP_UP + */ + public static final int VK_UP = 0x26; + + /** + * Constant for the non-numpad right arrow key. + * @see #VK_KP_RIGHT + */ + public static final int VK_RIGHT = 0x27; + + /** + * Constant for the non-numpad down arrow key. + * @see #VK_KP_DOWN + */ + public static final int VK_DOWN = 0x28; + + /** + * Constant for the comma key, "," + */ + public static final int VK_COMMA = 0x2C; + + /** + * Constant for the minus key, "-" + * @since 1.2 + */ + public static final int VK_MINUS = 0x2D; + + /** + * Constant for the period key, "." + */ + public static final int VK_PERIOD = 0x2E; + + /** + * Constant for the forward slash key, "/" + */ + public static final int VK_SLASH = 0x2F; + + /** VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */ + public static final int VK_0 = 0x30; + public static final int VK_1 = 0x31; + public static final int VK_2 = 0x32; + public static final int VK_3 = 0x33; + public static final int VK_4 = 0x34; + public static final int VK_5 = 0x35; + public static final int VK_6 = 0x36; + public static final int VK_7 = 0x37; + public static final int VK_8 = 0x38; + public static final int VK_9 = 0x39; + + /** + * Constant for the semicolon key, ";" + */ + public static final int VK_SEMICOLON = 0x3B; + + /** + * Constant for the equals key, "=" + */ + public static final int VK_EQUALS = 0x3D; + + /** VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */ + public static final int VK_A = 0x41; + public static final int VK_B = 0x42; + public static final int VK_C = 0x43; + public static final int VK_D = 0x44; + public static final int VK_E = 0x45; + public static final int VK_F = 0x46; + public static final int VK_G = 0x47; + public static final int VK_H = 0x48; + public static final int VK_I = 0x49; + public static final int VK_J = 0x4A; + public static final int VK_K = 0x4B; + public static final int VK_L = 0x4C; + public static final int VK_M = 0x4D; + public static final int VK_N = 0x4E; + public static final int VK_O = 0x4F; + public static final int VK_P = 0x50; + public static final int VK_Q = 0x51; + public static final int VK_R = 0x52; + public static final int VK_S = 0x53; + public static final int VK_T = 0x54; + public static final int VK_U = 0x55; + public static final int VK_V = 0x56; + public static final int VK_W = 0x57; + public static final int VK_X = 0x58; + public static final int VK_Y = 0x59; + public static final int VK_Z = 0x5A; + + /** + * Constant for the open bracket key, "[" + */ + public static final int VK_OPEN_BRACKET = 0x5B; + + /** + * Constant for the back slash key, "\" + */ + public static final int VK_BACK_SLASH = 0x5C; + + /** + * Constant for the close bracket key, "]" + */ + public static final int VK_CLOSE_BRACKET = 0x5D; + + public static final int VK_NUMPAD0 = 0x60; + public static final int VK_NUMPAD1 = 0x61; + public static final int VK_NUMPAD2 = 0x62; + public static final int VK_NUMPAD3 = 0x63; + public static final int VK_NUMPAD4 = 0x64; + public static final int VK_NUMPAD5 = 0x65; + public static final int VK_NUMPAD6 = 0x66; + public static final int VK_NUMPAD7 = 0x67; + public static final int VK_NUMPAD8 = 0x68; + public static final int VK_NUMPAD9 = 0x69; + public static final int VK_MULTIPLY = 0x6A; + public static final int VK_ADD = 0x6B; + + /** + * This constant is obsolete, and is included only for backwards + * compatibility. + * @see #VK_SEPARATOR + */ + public static final int VK_SEPARATER = 0x6C; + + /** + * Constant for the Numpad Separator key. + * @since 1.4 + */ + public static final int VK_SEPARATOR = VK_SEPARATER; + + public static final int VK_SUBTRACT = 0x6D; + public static final int VK_DECIMAL = 0x6E; + public static final int VK_DIVIDE = 0x6F; + public static final int VK_DELETE = 0x7F; /* ASCII DEL */ + public static final int VK_NUM_LOCK = 0x90; + public static final int VK_SCROLL_LOCK = 0x91; + + /** Constant for the F1 function key. */ + public static final int VK_F1 = 0x70; + + /** Constant for the F2 function key. */ + public static final int VK_F2 = 0x71; + + /** Constant for the F3 function key. */ + public static final int VK_F3 = 0x72; + + /** Constant for the F4 function key. */ + public static final int VK_F4 = 0x73; + + /** Constant for the F5 function key. */ + public static final int VK_F5 = 0x74; + + /** Constant for the F6 function key. */ + public static final int VK_F6 = 0x75; + + /** Constant for the F7 function key. */ + public static final int VK_F7 = 0x76; + + /** Constant for the F8 function key. */ + public static final int VK_F8 = 0x77; + + /** Constant for the F9 function key. */ + public static final int VK_F9 = 0x78; + + /** Constant for the F10 function key. */ + public static final int VK_F10 = 0x79; + + /** Constant for the F11 function key. */ + public static final int VK_F11 = 0x7A; + + /** Constant for the F12 function key. */ + public static final int VK_F12 = 0x7B; + + /** + * Constant for the F13 function key. + * @since 1.2 + */ + /* F13 - F24 are used on IBM 3270 keyboard; use random range for constants. */ + public static final int VK_F13 = 0xF000; + + /** + * Constant for the F14 function key. + * @since 1.2 + */ + public static final int VK_F14 = 0xF001; + + /** + * Constant for the F15 function key. + * @since 1.2 + */ + public static final int VK_F15 = 0xF002; + + /** + * Constant for the F16 function key. + * @since 1.2 + */ + public static final int VK_F16 = 0xF003; + + /** + * Constant for the F17 function key. + * @since 1.2 + */ + public static final int VK_F17 = 0xF004; + + /** + * Constant for the F18 function key. + * @since 1.2 + */ + public static final int VK_F18 = 0xF005; + + /** + * Constant for the F19 function key. + * @since 1.2 + */ + public static final int VK_F19 = 0xF006; + + /** + * Constant for the F20 function key. + * @since 1.2 + */ + public static final int VK_F20 = 0xF007; + + /** + * Constant for the F21 function key. + * @since 1.2 + */ + public static final int VK_F21 = 0xF008; + + /** + * Constant for the F22 function key. + * @since 1.2 + */ + public static final int VK_F22 = 0xF009; + + /** + * Constant for the F23 function key. + * @since 1.2 + */ + public static final int VK_F23 = 0xF00A; + + /** + * Constant for the F24 function key. + * @since 1.2 + */ + public static final int VK_F24 = 0xF00B; + + public static final int VK_PRINTSCREEN = 0x9A; + public static final int VK_INSERT = 0x9B; + public static final int VK_HELP = 0x9C; + public static final int VK_META = 0x9D; + + public static final int VK_BACK_QUOTE = 0xC0; + public static final int VK_QUOTE = 0xDE; + + /** + * Constant for the numeric keypad up arrow key. + * @see #VK_UP + * @since 1.2 + */ + public static final int VK_KP_UP = 0xE0; + + /** + * Constant for the numeric keypad down arrow key. + * @see #VK_DOWN + * @since 1.2 + */ + public static final int VK_KP_DOWN = 0xE1; + + /** + * Constant for the numeric keypad left arrow key. + * @see #VK_LEFT + * @since 1.2 + */ + public static final int VK_KP_LEFT = 0xE2; + + /** + * Constant for the numeric keypad right arrow key. + * @see #VK_RIGHT + * @since 1.2 + */ + public static final int VK_KP_RIGHT = 0xE3; + + /* For European keyboards */ + /** @since 1.2 */ + public static final int VK_DEAD_GRAVE = 0x80; + /** @since 1.2 */ + public static final int VK_DEAD_ACUTE = 0x81; + /** @since 1.2 */ + public static final int VK_DEAD_CIRCUMFLEX = 0x82; + /** @since 1.2 */ + public static final int VK_DEAD_TILDE = 0x83; + /** @since 1.2 */ + public static final int VK_DEAD_MACRON = 0x84; + /** @since 1.2 */ + public static final int VK_DEAD_BREVE = 0x85; + /** @since 1.2 */ + public static final int VK_DEAD_ABOVEDOT = 0x86; + /** @since 1.2 */ + public static final int VK_DEAD_DIAERESIS = 0x87; + /** @since 1.2 */ + public static final int VK_DEAD_ABOVERING = 0x88; + /** @since 1.2 */ + public static final int VK_DEAD_DOUBLEACUTE = 0x89; + /** @since 1.2 */ + public static final int VK_DEAD_CARON = 0x8a; + /** @since 1.2 */ + public static final int VK_DEAD_CEDILLA = 0x8b; + /** @since 1.2 */ + public static final int VK_DEAD_OGONEK = 0x8c; + /** @since 1.2 */ + public static final int VK_DEAD_IOTA = 0x8d; + /** @since 1.2 */ + public static final int VK_DEAD_VOICED_SOUND = 0x8e; + /** @since 1.2 */ + public static final int VK_DEAD_SEMIVOICED_SOUND = 0x8f; + + /** @since 1.2 */ + public static final int VK_AMPERSAND = 0x96; + /** @since 1.2 */ + public static final int VK_ASTERISK = 0x97; + /** @since 1.2 */ + public static final int VK_QUOTEDBL = 0x98; + /** @since 1.2 */ + public static final int VK_LESS = 0x99; + + /** @since 1.2 */ + public static final int VK_GREATER = 0xa0; + /** @since 1.2 */ + public static final int VK_BRACELEFT = 0xa1; + /** @since 1.2 */ + public static final int VK_BRACERIGHT = 0xa2; + + /** + * Constant for the "@" key. + * @since 1.2 + */ + public static final int VK_AT = 0x0200; + + /** + * Constant for the ":" key. + * @since 1.2 + */ + public static final int VK_COLON = 0x0201; + + /** + * Constant for the "^" key. + * @since 1.2 + */ + public static final int VK_CIRCUMFLEX = 0x0202; + + /** + * Constant for the "$" key. + * @since 1.2 + */ + public static final int VK_DOLLAR = 0x0203; + + /** + * Constant for the Euro currency sign key. + * @since 1.2 + */ + public static final int VK_EURO_SIGN = 0x0204; + + /** + * Constant for the "!" key. + * @since 1.2 + */ + public static final int VK_EXCLAMATION_MARK = 0x0205; + + /** + * Constant for the inverted exclamation mark key. + * @since 1.2 + */ + public static final int VK_INVERTED_EXCLAMATION_MARK = 0x0206; + + /** + * Constant for the "(" key. + * @since 1.2 + */ + public static final int VK_LEFT_PARENTHESIS = 0x0207; + + /** + * Constant for the "#" key. + * @since 1.2 + */ + public static final int VK_NUMBER_SIGN = 0x0208; + + /** + * Constant for the "+" key. + * @since 1.2 + */ + public static final int VK_PLUS = 0x0209; + + /** + * Constant for the ")" key. + * @since 1.2 + */ + public static final int VK_RIGHT_PARENTHESIS = 0x020A; + + /** + * Constant for the "_" key. + * @since 1.2 + */ + public static final int VK_UNDERSCORE = 0x020B; + + /** + * Constant for the Microsoft Windows "Windows" key. + * It is used for both the left and right version of the key. + * @see #getKeyLocation() + * @since 1.5 + */ + public static final int VK_WINDOWS = 0x020C; + + /** + * Constant for the Microsoft Windows Context Menu key. + * @since 1.5 + */ + public static final int VK_CONTEXT_MENU = 0x020D; + + /* for input method support on Asian Keyboards */ + + /* not clear what this means - listed in Microsoft Windows API */ + public static final int VK_FINAL = 0x0018; + + /** Constant for the Convert function key. */ + /* Japanese PC 106 keyboard, Japanese Solaris keyboard: henkan */ + public static final int VK_CONVERT = 0x001C; + + /** Constant for the Don't Convert function key. */ + /* Japanese PC 106 keyboard: muhenkan */ + public static final int VK_NONCONVERT = 0x001D; + + /** Constant for the Accept or Commit function key. */ + /* Japanese Solaris keyboard: kakutei */ + public static final int VK_ACCEPT = 0x001E; + + /* not clear what this means - listed in Microsoft Windows API */ + public static final int VK_MODECHANGE = 0x001F; + + /* replaced by VK_KANA_LOCK for Microsoft Windows and Solaris; + might still be used on other platforms */ + public static final int VK_KANA = 0x0015; + + /* replaced by VK_INPUT_METHOD_ON_OFF for Microsoft Windows and Solaris; + might still be used for other platforms */ + public static final int VK_KANJI = 0x0019; + + /** + * Constant for the Alphanumeric function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: eisuu */ + public static final int VK_ALPHANUMERIC = 0x00F0; + + /** + * Constant for the Katakana function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: katakana */ + public static final int VK_KATAKANA = 0x00F1; + + /** + * Constant for the Hiragana function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: hiragana */ + public static final int VK_HIRAGANA = 0x00F2; + + /** + * Constant for the Full-Width Characters function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: zenkaku */ + public static final int VK_FULL_WIDTH = 0x00F3; + + /** + * Constant for the Half-Width Characters function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: hankaku */ + public static final int VK_HALF_WIDTH = 0x00F4; + + /** + * Constant for the Roman Characters function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: roumaji */ + public static final int VK_ROMAN_CHARACTERS = 0x00F5; + + /** + * Constant for the All Candidates function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard - VK_CONVERT + ALT: zenkouho */ + public static final int VK_ALL_CANDIDATES = 0x0100; + + /** + * Constant for the Previous Candidate function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard - VK_CONVERT + SHIFT: maekouho */ + public static final int VK_PREVIOUS_CANDIDATE = 0x0101; + + /** + * Constant for the Code Input function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard - VK_ALPHANUMERIC + ALT: kanji bangou */ + public static final int VK_CODE_INPUT = 0x0102; + + /** + * Constant for the Japanese-Katakana function key. + * This key switches to a Japanese input method and selects its Katakana input mode. + * @since 1.2 + */ + /* Japanese Macintosh keyboard - VK_JAPANESE_HIRAGANA + SHIFT */ + public static final int VK_JAPANESE_KATAKANA = 0x0103; + + /** + * Constant for the Japanese-Hiragana function key. + * This key switches to a Japanese input method and selects its Hiragana input mode. + * @since 1.2 + */ + /* Japanese Macintosh keyboard */ + public static final int VK_JAPANESE_HIRAGANA = 0x0104; + + /** + * Constant for the Japanese-Roman function key. + * This key switches to a Japanese input method and selects its Roman-Direct input mode. + * @since 1.2 + */ + /* Japanese Macintosh keyboard */ + public static final int VK_JAPANESE_ROMAN = 0x0105; + + /** + * Constant for the locking Kana function key. + * This key locks the keyboard into a Kana layout. + * @since 1.3 + */ + /* Japanese PC 106 keyboard with special Windows driver - eisuu + Control; Japanese Solaris keyboard: kana */ + public static final int VK_KANA_LOCK = 0x0106; + + /** + * Constant for the input method on/off key. + * @since 1.3 + */ + /* Japanese PC 106 keyboard: kanji. Japanese Solaris keyboard: nihongo */ + public static final int VK_INPUT_METHOD_ON_OFF = 0x0107; + + /* for Sun keyboards */ + /** @since 1.2 */ + public static final int VK_CUT = 0xFFD1; + /** @since 1.2 */ + public static final int VK_COPY = 0xFFCD; + /** @since 1.2 */ + public static final int VK_PASTE = 0xFFCF; + /** @since 1.2 */ + public static final int VK_UNDO = 0xFFCB; + /** @since 1.2 */ + public static final int VK_AGAIN = 0xFFC9; + /** @since 1.2 */ + public static final int VK_FIND = 0xFFD0; + /** @since 1.2 */ + public static final int VK_PROPS = 0xFFCA; + /** @since 1.2 */ + public static final int VK_STOP = 0xFFC8; + + /** + * Constant for the Compose function key. + * @since 1.2 + */ + public static final int VK_COMPOSE = 0xFF20; + + /** + * Constant for the AltGraph function key. + * @since 1.2 + */ + public static final int VK_ALT_GRAPH = 0xFF7E; + + /** + * Constant for the Begin key. + * @since 1.5 + */ + public static final int VK_BEGIN = 0xFF58; + + /** + * This value is used to indicate that the keyCode is unknown. + * KEY_TYPED events do not have a keyCode value; this value + * is used instead. + */ + public static final int VK_UNDEFINED = 0x0; +} + diff --git a/src/newt/classes/com/sun/javafx/newt/KeyListener.java b/src/newt/classes/com/sun/javafx/newt/KeyListener.java new file mode 100644 index 000000000..6f022c45a --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/KeyListener.java @@ -0,0 +1,42 @@ +/* + * 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.sun.javafx.newt; + +public interface KeyListener extends EventListener +{ + public void keyPressed(KeyEvent e); + public void keyReleased(KeyEvent e); + public void keyTyped(KeyEvent e) ; +} + diff --git a/src/newt/classes/com/sun/javafx/newt/MouseEvent.java b/src/newt/classes/com/sun/javafx/newt/MouseEvent.java new file mode 100644 index 000000000..79e11b875 --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/MouseEvent.java @@ -0,0 +1,98 @@ +/* + * 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.sun.javafx.newt; + +public class MouseEvent extends InputEvent +{ + public static final int BUTTON1 = 1; + public static final int BUTTON2 = 2; + public static final int BUTTON3 = 3; + public static final int BUTTON4 = 4; + public static final int BUTTON5 = 5; + public static final int BUTTON6 = 6; + public static final int BUTTON_NUMBER = 6; + + protected MouseEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers, int x, int y, int clickCount, int button) + { + super(sysEvent, eventType, source, when, modifiers); + this.x=x; + this.y=y; + this.clickCount=clickCount; + this.button=button; + } + public MouseEvent(int eventType, Window source, long when, int modifiers, int x, int y, int clickCount, int button) { + this(false, eventType, source, when, modifiers, x, y, clickCount, button); + } + + public int getButton() { + return button; + } + public int getClickCount() { + return clickCount; + } + public int getX() { + return x; + } + public int getY() { + return y; + } + + public String toString() { + return "MouseEvent["+getEventTypeString(getEventType())+ + ", "+x+"/"+y+", button "+button+", count "+clickCount+", "+super.toString()+"]"; + } + + public static String getEventTypeString(int type) { + switch(type) { + case EVENT_MOUSE_CLICKED: return "EVENT_MOUSE_CLICKED"; + case EVENT_MOUSE_ENTERED: return "EVENT_MOUSE_ENTERED"; + case EVENT_MOUSE_EXITED: return "EVENT_MOUSE_EXITED"; + case EVENT_MOUSE_PRESSED: return "EVENT_MOUSE_PRESSED"; + case EVENT_MOUSE_RELEASED: return "EVENT_MOUSE_RELEASED"; + case EVENT_MOUSE_MOVED: return "EVENT_MOUSE_MOVED"; + case EVENT_MOUSE_DRAGGED: return "EVENT_MOUSE_DRAGGED"; + default: return "unknown (" + type + ")"; + } + } + + private int x, y, clickCount, button; + + public static final int EVENT_MOUSE_CLICKED = 200; + public static final int EVENT_MOUSE_ENTERED = 201; + public static final int EVENT_MOUSE_EXITED = 202; + public static final int EVENT_MOUSE_PRESSED = 203; + public static final int EVENT_MOUSE_RELEASED = 204; + public static final int EVENT_MOUSE_MOVED = 205; + public static final int EVENT_MOUSE_DRAGGED = 206; +} diff --git a/src/newt/classes/com/sun/javafx/newt/MouseListener.java b/src/newt/classes/com/sun/javafx/newt/MouseListener.java new file mode 100644 index 000000000..f707979ba --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/MouseListener.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.sun.javafx.newt; + +public interface MouseListener extends EventListener +{ + public void mouseClicked(MouseEvent e); + public void mouseEntered(MouseEvent e); + public void mouseExited(MouseEvent e); + public void mousePressed(MouseEvent e); + public void mouseReleased(MouseEvent e); + public void mouseMoved(MouseEvent e); + public void mouseDragged(MouseEvent e); +} + diff --git a/src/newt/classes/com/sun/javafx/newt/NewtFactory.java b/src/newt/classes/com/sun/javafx/newt/NewtFactory.java new file mode 100755 index 000000000..312c6f825 --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/NewtFactory.java @@ -0,0 +1,178 @@ +/* + * 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.sun.javafx.newt; + +import javax.media.nwi.NWCapabilities; +import java.util.ArrayList; +import java.util.Iterator; + +public abstract class NewtFactory { + /** OpenKODE window type */ + public static final String KD = "KD"; + + /** Microsoft Windows window type */ + public static final String WINDOWS = "Windows"; + + /** X11 window type */ + public static final String X11 = "X11"; + + /** Mac OS X window type */ + public static final String MACOSX = "MacOSX"; + + /** Generic AWT wrapped window type, if available */ + public static final String AWT = "AWT"; + + // Work-around for initialization order problems on Mac OS X + // between native Newt and (apparently) Fmod + static { + Window.init(getWindowType()); + } + + static int getPropertyIntValue(String propname) { + int i=0; + String s = System.getProperty(propname); + if(null!=s) { + try { + i = Integer.valueOf(s).intValue(); + } catch (NumberFormatException nfe) {} + } + return i; + } + + /** Creates a Window of the default type for the current operating system. */ + public static String getWindowType() { + String osName = System.getProperty("newt.ws.name"); + if(null==osName||osName.length()==0) { + osName = System.getProperty("os.name"); + } + String osNameLowerCase = osName.toLowerCase(); + String windowType; + if (osNameLowerCase.startsWith("kd")) { + windowType = KD; + } else if (osNameLowerCase.startsWith("wind")) { + windowType = WINDOWS; + } else if (osNameLowerCase.startsWith("mac os x") || + osNameLowerCase.startsWith("darwin")) { + windowType = MACOSX; + } else if (osNameLowerCase.equals("awt")) { + windowType = AWT; + } else { + windowType = X11; + } + return windowType; + } + + /** + * Create a Display entity, incl native creation + */ + public static Display createDisplay(String name) { + return Display.create(getWindowType(), name); + } + + /** + * Create a Display entity using the given implementation type, incl native creation + */ + public static Display createDisplay(String type, String name) { + return Display.create(type, name); + } + + /** + * Create a Screen entity, incl native creation + */ + public static Screen createScreen(Display display, int index) { + return Screen.create(getWindowType(), display, index); + } + + /** + * Create a Screen entity using the given implementation type, incl native creation + */ + public static Screen createScreen(String type, Display display, int index) { + return Screen.create(type, display, index); + } + + /** + * Create a Window entity, incl native creation + */ + public static Window createWindow(Screen screen, NWCapabilities caps) { + return Window.create(getWindowType(), screen, caps); + } + + public static Window createWindow(Screen screen, NWCapabilities caps, boolean undecorated) { + return Window.create(getWindowType(), screen, caps, undecorated); + } + + /** + * Create a Window entity using the given implementation type, incl native creation + */ + public static Window createWindow(String type, Screen screen, NWCapabilities caps) { + return Window.create(type, screen, caps); + } + + /** + * Instantiate a Display entity using the native handle. + */ + public static Display wrapDisplay(String name, long handle) { + return Display.wrapHandle(getWindowType(), name, handle); + } + + /** + * Instantiate a Screen entity using the native handle. + */ + public static Screen wrapScreen(Display display, int index, long handle) { + return Screen.wrapHandle(getWindowType(), display, index, handle); + } + + /** + * Instantiate a Window entity using the native handle. + */ + public static Window wrapWindow(Screen screen, NWCapabilities caps, long visualID, + long windowHandle, boolean fullscreen, boolean visible, + int x, int y, int width, int height) { + return Window.wrapHandle(getWindowType(), screen, caps, visualID, + windowHandle, fullscreen, visible, x, y, width, height); + } + + private static final boolean instanceOf(Object obj, String clazzName) { + Class clazz = obj.getClass(); + do { + if(clazz.getName().equals(clazzName)) { + return true; + } + clazz = clazz.getSuperclass(); + } while (clazz!=null); + return false; + } + +} + diff --git a/src/newt/classes/com/sun/javafx/newt/Screen.java b/src/newt/classes/com/sun/javafx/newt/Screen.java new file mode 100755 index 000000000..f35c04b61 --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/Screen.java @@ -0,0 +1,137 @@ +/* + * 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.sun.javafx.newt; + +public abstract class Screen { + + private static Class getScreenClass(String type) + throws ClassNotFoundException + { + Class screenClass = null; + if (NewtFactory.KD.equals(type)) { + screenClass = Class.forName("com.sun.javafx.newt.opengl.kd.KDScreen"); + } else if (NewtFactory.WINDOWS.equals(type)) { + screenClass = Class.forName("com.sun.javafx.newt.windows.WindowsScreen"); + } else if (NewtFactory.MACOSX.equals(type)) { + screenClass = Class.forName("com.sun.javafx.newt.macosx.MacScreen"); + } else if (NewtFactory.X11.equals(type)) { + screenClass = Class.forName("com.sun.javafx.newt.x11.X11Screen"); + } else if (NewtFactory.AWT.equals(type)) { + screenClass = Class.forName("com.sun.javafx.newt.awt.AWTScreen"); + } else { + throw new RuntimeException("Unknown window type \"" + type + "\""); + } + return screenClass; + } + + protected static Screen create(String type, Display display, int idx) { + try { + if(usrWidth<0 || usrHeight<0) { + usrWidth = NewtFactory.getPropertyIntValue("newt.ws.swidth"); + usrHeight = NewtFactory.getPropertyIntValue("newt.ws.sheight"); + System.out.println("User screen size "+usrWidth+"x"+usrHeight); + } + Class screenClass = getScreenClass(type); + Screen screen = (Screen) screenClass.newInstance(); + screen.display = display; + screen.index = idx; + screen.handle = 0; + screen.createNative(); + return screen; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected static Screen wrapHandle(String type, Display display, int idx, long handle) { + try { + Class screenClass = getScreenClass(type); + Screen screen = (Screen) screenClass.newInstance(); + screen.display = display; + screen.index = idx; + screen.handle = handle; + return screen; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected abstract void createNative(); + + public Display getDisplay() { + return display; + } + + public int getIndex() { + return index; + } + + public long getHandle() { + return handle; + } + + /** + * The actual implementation shall return the detected display value, + * if not we return 800. + * This can be overwritten with the user property 'newt.ws.swidth', + */ + public int getWidth() { + return (usrWidth>0) ? usrWidth : (width>0) ? width : 480; + } + + /** + * The actual implementation shall return the detected display value, + * if not we return 480. + * This can be overwritten with the user property 'newt.ws.sheight', + */ + public int getHeight() { + return (usrHeight>0) ? usrHeight : (height>0) ? height : 480; + } + + /** + * The actual implementation shall call this function + * to set the detected screen size + */ + public void setScreenSize(int w, int h) { + System.out.println("Detected screen size "+w+"x"+h); + width=w; height=h; + } + + protected Display display; + protected int index; + protected long handle; + protected int width=-1, height=-1; // detected values: set using setScreenSize + protected static int usrWidth=-1, usrHeight=-1; // property values: newt.ws.swidth and newt.ws.sheight +} + diff --git a/src/newt/classes/com/sun/javafx/newt/Window.java b/src/newt/classes/com/sun/javafx/newt/Window.java new file mode 100755 index 000000000..459022e4b --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/Window.java @@ -0,0 +1,634 @@ +/* + * 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.sun.javafx.newt; + +import com.sun.javafx.newt.impl.Debug; +import javax.media.nwi.NWCapabilities; +import javax.media.nwi.NativeWindow; +import javax.media.nwi.NativeWindowException; + +import java.util.ArrayList; +import java.util.Iterator; + +public abstract class Window implements NativeWindow +{ + public static final boolean DEBUG_MOUSE_EVENT = Debug.debug("Window.MouseEvent"); + public static final boolean DEBUG_KEY_EVENT = Debug.debug("Window.KeyEvent"); + public static final boolean DEBUG_WINDOW_EVENT = Debug.debug("Window.WindowEvent"); + public static final boolean DEBUG_IMPLEMENTATION = Debug.debug("Window"); + + // Workaround for initialization order problems on Mac OS X + // between native Newt and (apparently) Fmod -- if Fmod is + // initialized first then the connection to the window server + // breaks, leading to errors from deep within the AppKit + static void init(String type) { + if (NewtFactory.MACOSX.equals(type)) { + try { + getWindowClass(type); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + private static Class getWindowClass(String type) + throws ClassNotFoundException + { + Class windowClass = null; + if (NewtFactory.KD.equals(type)) { + windowClass = Class.forName("com.sun.javafx.newt.opengl.kd.KDWindow"); + } else if (NewtFactory.WINDOWS.equals(type)) { + windowClass = Class.forName("com.sun.javafx.newt.windows.WindowsWindow"); + } else if (NewtFactory.MACOSX.equals(type)) { + windowClass = Class.forName("com.sun.javafx.newt.macosx.MacWindow"); + } else if (NewtFactory.X11.equals(type)) { + windowClass = Class.forName("com.sun.javafx.newt.x11.X11Window"); + } else if (NewtFactory.AWT.equals(type)) { + windowClass = Class.forName("com.sun.javafx.newt.awt.AWTWindow"); + } else { + throw new NativeWindowException("Unknown window type \"" + type + "\""); + } + return windowClass; + } + + protected static Window create(String type, Screen screen, NWCapabilities caps) { + return create(type, screen, caps, false); + } + + protected static Window create(String type, Screen screen, NWCapabilities caps, boolean undecorated) { + try { + Class windowClass = getWindowClass(type); + Window window = (Window) windowClass.newInstance(); + window.invalidate(); + window.screen = screen; + window.visualID = 0; + window.setUndecorated(undecorated); + window.createNative(caps); + return window; + } catch (Throwable t) { + t.printStackTrace(); + throw new NativeWindowException(t); + } + } + + protected static Window wrapHandle(String type, Screen screen, NWCapabilities caps, long visualID, + long windowHandle, boolean fullscreen, boolean visible, + int x, int y, int width, int height) + { + try { + Class windowClass = getWindowClass(type); + Window window = (Window) windowClass.newInstance(); + window.invalidate(); + window.screen = screen; + window.chosenCaps = caps; + window.visualID = visualID; + window.windowHandle = windowHandle; + window.fullscreen=fullscreen; + window.visible=visible; + window.x=x; + window.y=y; + window.width=width; + window.height=height; + return window; + } catch (Throwable t) { + t.printStackTrace(); + throw new NativeWindowException(t); + } + } + + /** + * Create native windowHandle, ie creates a new native invisible window + * + * Shall use the capabilities to determine the visualID + * and shall set chosenCaps. + */ + protected abstract void createNative(NWCapabilities caps); + + protected abstract void closeNative(); + + public Screen getScreen() { + return screen; + } + + /** + * eventMask is a bitfield of EventListener event flags + */ + public void pumpMessages(int eventMask) { + if(this.eventMask!=eventMask && eventMask>0) { + this.eventMask=eventMask; + eventMask*=-1; + } + dispatchMessages(eventMask); + } + + public void pumpMessages() { + int em = 0; + if(windowListeners.size()>0) em |= EventListener.WINDOW; + if(mouseListeners.size()>0) em |= EventListener.MOUSE; + if(keyListeners.size()>0) em |= EventListener.KEY; + pumpMessages(em); + } + + protected abstract void dispatchMessages(int eventMask); + + public String toString() { + StringBuffer sb = new StringBuffer(); + + sb.append("NEWT-Window[windowHandle "+getWindowHandle()+ + ", surfaceHandle "+getSurfaceHandle()+ + ", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ + ", visible "+isVisible()+ + ", wrappedWindow "+getWrappedWindow()+ + ", visualID "+visualID+ + ", "+chosenCaps+ + ", screen handle/index "+getScreenHandle()+"/"+getScreenIndex() + + ", display handle "+getDisplayHandle()); + + sb.append(", WindowListeners num "+windowListeners.size()+" ["); + for (Iterator iter = windowListeners.iterator(); iter.hasNext(); ) { + sb.append(iter.next()+", "); + } + sb.append("], MouseListeners num "+mouseListeners.size()+" ["); + for (Iterator iter = mouseListeners.iterator(); iter.hasNext(); ) { + sb.append(iter.next()+", "); + } + sb.append("], KeyListeners num "+keyListeners.size()+" ["); + for (Iterator iter = keyListeners.iterator(); iter.hasNext(); ) { + sb.append(iter.next()+", "); + } + sb.append("]"); + return sb.toString(); + } + + protected Screen screen; + + /** + * The NWCapabilities shall be used to determine the visualID + */ + protected NWCapabilities chosenCaps; + /** + * The visualID shall be determined using the NWCapabilities + */ + protected long visualID; + protected long windowHandle; + protected boolean locked=false; + protected boolean fullscreen, visible; + protected int width, height, x, y; + protected int eventMask; + + protected String title = "Newt Window"; + protected boolean undecorated = false; + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setUndecorated(boolean value) { + undecorated = value; + } + + public boolean isUndecorated() { + return undecorated; + } + + + + // + // NativeWindow impl + // + + public int lockSurface() throws NativeWindowException { + if (locked) { + throw new NativeWindowException("Surface already locked"); + } + // locked = true; + // return LOCK_SUCCESS; + return LOCK_NOT_SUPPORTED; + } + + public void unlockSurface() { + if (locked) { + locked = false; + } + } + + public boolean isSurfaceLocked() { + return locked; + } + + public synchronized void destroy() { + if(DEBUG_WINDOW_EVENT) { + System.out.println("Window.destroy() start"); + } + windowListeners = new ArrayList(); + mouseListeners = new ArrayList(); + keyListeners = new ArrayList(); + closeNative(); + invalidate(); + if(DEBUG_WINDOW_EVENT) { + System.out.println("Window.destroy() end"); + } + } + + public void invalidate() { + invalidate(false); + } + + public void invalidate(boolean internal) { + unlockSurface(); + screen = null; + visualID = 0; + chosenCaps = null; + windowHandle = 0; + locked = false; + fullscreen=false; + visible=false; + eventMask = 0; + + // Default position and dimension will be re-set immediately by user + width = 100; + height = 100; + x=0; + y=0; + } + + protected void clearEventMask() { + eventMask=0; + } + + public long getDisplayHandle() { + if(null==screen || + null==screen.getDisplay()) { + return 0; + } + return screen.getDisplay().getHandle(); + } + + public long getScreenHandle() { + return (null!=screen)?screen.getHandle():0; + } + + public int getScreenIndex() { + return (null!=screen)?screen.getIndex():0; + } + + public long getWindowHandle() { + return windowHandle; + } + + public long getSurfaceHandle() { + return windowHandle; // default: return window handle + } + + public NWCapabilities getChosenCapabilities() { + if (chosenCaps == null) + return null; + + // Must return a new copy to avoid mutation by end user + return (NWCapabilities) chosenCaps.clone(); + } + + public long getVisualID() { + return visualID; + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + /** If this Window actually wraps one from another toolkit such as + the AWT, this will return a non-null value. */ + public Object getWrappedWindow() { + return null; + } + + // + // Additional methods + // + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public boolean isVisible() { + return visible; + } + + public boolean isFullscreen() { + return fullscreen; + } + + private boolean autoDrawableMember = false; + + /** + * If set to true, + * certain action will be performed by the owning + * AutoDrawable, ie the destroy() call within windowDestroyNotify() + */ + public void setAutoDrawableClient(boolean b) { + autoDrawableMember = b; + } + + protected void windowDestroyNotify() { + if(DEBUG_WINDOW_EVENT) { + System.out.println("Window.windowDestroyeNotify start"); + } + + sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY); + + if(!autoDrawableMember) { + destroy(); + } + + if(DEBUG_WINDOW_EVENT) { + System.out.println("Window.windowDestroyeNotify end"); + } + } + + protected void windowDestroyed() { + if(DEBUG_WINDOW_EVENT) { + System.out.println("Window.windowDestroyed"); + } + invalidate(); + } + + public abstract void setVisible(boolean visible); + public abstract void setSize(int width, int height); + public abstract void setPosition(int x, int y); + public abstract boolean setFullscreen(boolean fullscreen); + + // + // MouseListener Support + // + + public synchronized void addMouseListener(MouseListener l) { + if(l == null) { + return; + } + ArrayList newMouseListeners = (ArrayList) mouseListeners.clone(); + newMouseListeners.add(l); + mouseListeners = newMouseListeners; + } + + public synchronized void removeMouseListener(MouseListener l) { + if (l == null) { + return; + } + ArrayList newMouseListeners = (ArrayList) mouseListeners.clone(); + newMouseListeners.remove(l); + mouseListeners = newMouseListeners; + } + + public synchronized MouseListener[] getMouseListeners() { + return (MouseListener[]) mouseListeners.toArray(); + } + + private ArrayList mouseListeners = new ArrayList(); + private long lastMousePressed = 0; + private int lastMouseClickCount = 0; + public static final int ClickTimeout = 300; + private boolean[] buttonStates = new boolean[MouseEvent.BUTTON_NUMBER]; + + protected void sendMouseEvent(int eventType, int modifiers, int x, int y, int button) { + if(DEBUG_MOUSE_EVENT) { + System.out.println("sendMouseEvent: "+MouseEvent.getEventTypeString(eventType)+ + ", mod "+modifiers+", pos "+x+"/"+y+", button "+button); + } + if(button<0||button>MouseEvent.BUTTON_NUMBER) { + throw new NativeWindowException("Invalid mouse button number" + button); + } + long when = System.currentTimeMillis(); + MouseEvent eClicked = null; + MouseEvent e = null; + + if(MouseEvent.EVENT_MOUSE_PRESSED==eventType) { + if(when-lastMousePressed*/ events = new LinkedList(); + private boolean gotDisplaySize; + private int displayWidth; + private int displayHeight; + + public void setTitle(String title) { + super.setTitle(title); + if (frame != null) { + frame.setTitle(title); + } + } + + protected void createNative(NWCapabilities caps) { + chosenCaps = (NWCapabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID) + visualID = 0; // n/a + runOnEDT(new Runnable() { + public void run() { + frame = new Frame(getTitle()); + frame.setUndecorated(isUndecorated()); + frame.setLayout(new BorderLayout()); + canvas = new Canvas(); + Listener listener = new Listener(); + canvas.addMouseListener(listener); + canvas.addMouseMotionListener(listener); + canvas.addKeyListener(listener); + canvas.addComponentListener(listener); + frame.add(canvas, BorderLayout.CENTER); + frame.setSize(width, height); + frame.setLocation(x, y); + frame.addComponentListener(new MoveListener()); + } + }); + } + + protected void closeNative() { + runOnEDT(new Runnable() { + public void run() { + frame.dispose(); + frame = null; + } + }); + } + + public int getDisplayWidth() { + getDisplaySize(); + return displayWidth; + } + + public int getDisplayHeight() { + getDisplaySize(); + return displayHeight; + } + + private void getDisplaySize() { + if (!gotDisplaySize) { + DisplayMode mode = + GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode(); + displayWidth = mode.getWidth(); + displayHeight = mode.getHeight(); + gotDisplaySize = true; + } + } + + public void setVisible(final boolean visible) { + runOnEDT(new Runnable() { + public void run() { + frame.setVisible(visible); + } + }); + } + + public void setSize(final int width, final int height) { + this.width = width; + this.height = height; + runOnEDT(new Runnable() { + public void run() { + frame.setSize(width, height); + } + }); + } + + public void setPosition(final int x, final int y) { + this.x = x; + this.y = y; + runOnEDT(new Runnable() { + public void run() { + frame.setLocation(x, y); + } + }); + } + + public boolean setFullscreen(boolean fullscreen) { + // Ignore for now + return false; + } + + public Object getWrappedWindow() { + return canvas; + } + + public void dispatchMessages(int eventMask) { + AWTEventWrapper w; + do { + synchronized(this) { + if (!events.isEmpty()) { + w = (AWTEventWrapper) events.removeFirst(); + } else { + w = null; + } + } + if (w != null) { + switch (w.getType()) { + case com.sun.javafx.newt.WindowEvent.EVENT_WINDOW_RESIZED: + case com.sun.javafx.newt.WindowEvent.EVENT_WINDOW_MOVED: + if ((eventMask & com.sun.javafx.newt.EventListener.WINDOW) != 0) { + sendWindowEvent(w.getType()); + } + break; + + case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_CLICKED: + case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_ENTERED: + case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_EXITED: + case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_PRESSED: + case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_RELEASED: + case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_MOVED: + case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_DRAGGED: + if ((eventMask & com.sun.javafx.newt.EventListener.MOUSE) != 0) { + MouseEvent e = (MouseEvent) w.getEvent(); + sendMouseEvent(w.getType(), convertModifiers(e), + e.getX(), e.getY(), convertButton(e)); + } + break; + + case com.sun.javafx.newt.KeyEvent.EVENT_KEY_PRESSED: + case com.sun.javafx.newt.KeyEvent.EVENT_KEY_RELEASED: + case com.sun.javafx.newt.KeyEvent.EVENT_KEY_TYPED: + if ((eventMask & com.sun.javafx.newt.EventListener.KEY) != 0) { + KeyEvent e = (KeyEvent) w.getEvent(); + sendKeyEvent(w.getType(), convertModifiers(e), + e.getKeyCode(), e.getKeyChar()); + } + break; + + default: + throw new NativeWindowException("Unknown event type " + w.getType()); + } + if(DEBUG_MOUSE_EVENT) { + System.out.println("dispatchMessages: in event:"+w.getEvent()); + } + } + } while (w != null); + } + + private static int convertModifiers(InputEvent e) { + int newtMods = 0; + int mods = e.getModifiers(); + if ((mods & InputEvent.SHIFT_MASK) != 0) newtMods |= com.sun.javafx.newt.InputEvent.SHIFT_MASK; + if ((mods & InputEvent.CTRL_MASK) != 0) newtMods |= com.sun.javafx.newt.InputEvent.CTRL_MASK; + if ((mods & InputEvent.META_MASK) != 0) newtMods |= com.sun.javafx.newt.InputEvent.META_MASK; + if ((mods & InputEvent.ALT_MASK) != 0) newtMods |= com.sun.javafx.newt.InputEvent.ALT_MASK; + if ((mods & InputEvent.ALT_GRAPH_MASK) != 0) newtMods |= com.sun.javafx.newt.InputEvent.ALT_GRAPH_MASK; + return newtMods; + } + + private static int convertButton(MouseEvent e) { + switch (e.getButton()) { + case MouseEvent.BUTTON1: return com.sun.javafx.newt.MouseEvent.BUTTON1; + case MouseEvent.BUTTON2: return com.sun.javafx.newt.MouseEvent.BUTTON2; + case MouseEvent.BUTTON3: return com.sun.javafx.newt.MouseEvent.BUTTON3; + } + return 0; + } + + private static void runOnEDT(Runnable r) { + if (EventQueue.isDispatchThread()) { + r.run(); + } else { + try { + EventQueue.invokeAndWait(r); + } catch (Exception e) { + throw new NativeWindowException(e); + } + } + } + + private void enqueueEvent(int type, InputEvent e) { + AWTEventWrapper wrapper = new AWTEventWrapper(type, e); + synchronized(this) { + events.add(wrapper); + } + } + + private static final int WINDOW_EVENT = 1; + private static final int KEY_EVENT = 2; + private static final int MOUSE_EVENT = 3; + + static class AWTEventWrapper { + int type; + InputEvent e; + + AWTEventWrapper(int type, InputEvent e) { + this.type = type; + this.e = e; + } + + public int getType() { + return type; + } + + public InputEvent getEvent() { + return e; + } + } + + class MoveListener implements ComponentListener { + public void componentResized(ComponentEvent e) { + } + + public void componentMoved(ComponentEvent e) { + x = frame.getX(); + y = frame.getY(); + enqueueEvent(com.sun.javafx.newt.WindowEvent.EVENT_WINDOW_MOVED, null); + } + + public void componentShown(ComponentEvent e) { + } + + public void componentHidden(ComponentEvent e) { + } + + } + + class Listener implements ComponentListener, MouseListener, MouseMotionListener, KeyListener { + public void componentResized(ComponentEvent e) { + width = canvas.getWidth(); + height = canvas.getHeight(); + enqueueEvent(com.sun.javafx.newt.WindowEvent.EVENT_WINDOW_RESIZED, null); + } + + public void componentMoved(ComponentEvent e) { + } + + public void componentShown(ComponentEvent e) { + } + + public void componentHidden(ComponentEvent e) { + } + + public void mouseClicked(MouseEvent e) { + // We ignore these as we synthesize them ourselves out of + // mouse pressed and released events + } + + public void mouseEntered(MouseEvent e) { + enqueueEvent(com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_ENTERED, e); + } + + public void mouseExited(MouseEvent e) { + enqueueEvent(com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_EXITED, e); + } + + public void mousePressed(MouseEvent e) { + enqueueEvent(com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_PRESSED, e); + } + + public void mouseReleased(MouseEvent e) { + enqueueEvent(com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_RELEASED, e); + } + + public void mouseMoved(MouseEvent e) { + enqueueEvent(com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_MOVED, e); + } + + public void mouseDragged(MouseEvent e) { + enqueueEvent(com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_DRAGGED, e); + } + + public void keyPressed(KeyEvent e) { + enqueueEvent(com.sun.javafx.newt.KeyEvent.EVENT_KEY_PRESSED, e); + } + + public void keyReleased(KeyEvent e) { + enqueueEvent(com.sun.javafx.newt.KeyEvent.EVENT_KEY_RELEASED, e); + } + + public void keyTyped(KeyEvent e) { + enqueueEvent(com.sun.javafx.newt.KeyEvent.EVENT_KEY_TYPED, e); + } + } +} diff --git a/src/newt/classes/com/sun/javafx/newt/impl/Debug.java b/src/newt/classes/com/sun/javafx/newt/impl/Debug.java new file mode 100644 index 000000000..a901eafb1 --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/impl/Debug.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2003-2005 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. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.sun.javafx.newt.impl; + +import java.security.*; + +/** Helper routines for logging and debugging. */ + +public class Debug { + // Some common properties + private static boolean verbose; + private static boolean debugAll; + + static { + verbose = isPropertyDefined("newt.verbose"); + debugAll = isPropertyDefined("newt.debug"); + if (verbose) { + Package p = Package.getPackage("com.sun.javafx.newt"); + System.err.println("NEWT specification version " + p.getSpecificationVersion()); + System.err.println("NEWT implementation version " + p.getImplementationVersion()); + System.err.println("NEWT implementation vendor " + p.getImplementationVendor()); + } + } + + public static boolean getBooleanProperty(final String property) { + Boolean b = (Boolean) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + boolean val = Boolean.getBoolean(property); + return (val ? Boolean.TRUE : Boolean.FALSE); + } + }); + return b.booleanValue(); + } + + public static boolean isPropertyDefined(final String property) { + Boolean b = (Boolean) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String val = System.getProperty(property); + return (val != null ? Boolean.TRUE : Boolean.FALSE); + } + }); + return b.booleanValue(); + } + + public static boolean verbose() { + return verbose; + } + + public static boolean debugAll() { + return debugAll; + } + + public static boolean debug(String subcomponent) { + return debugAll() || isPropertyDefined("newt.debug." + subcomponent); + } +} diff --git a/src/newt/classes/com/sun/javafx/newt/impl/NativeLibLoader.java b/src/newt/classes/com/sun/javafx/newt/impl/NativeLibLoader.java new file mode 100644 index 000000000..7db04bb78 --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/impl/NativeLibLoader.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2003 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. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.sun.javafx.newt.impl; + +// FIXME: refactor Java SE dependencies +//import java.awt.Toolkit; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashSet; +import com.sun.nwi.impl.NativeLibLoaderBase; + +public class NativeLibLoader extends NativeLibLoaderBase { + + public static void loadNEWT() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String[] preload = { "nwi" }; + loadLibrary("newt", preload, true); + return null; + } + }); + } + + //---------------------------------------------------------------------- + // Support for the new JNLPAppletLauncher + // + + private static class NEWTAction implements NativeLibLoaderBase.LoaderAction { + public void loadLibrary(String libname, String[] preload, + boolean preloadIgnoreError) { + if (null!=preload) { + for (int i=0; i= 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); + // 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 native long createWindow(int x, int y, int w, int h, + int windowStyle, + int backingStoreType, + boolean deferCreation); + private native void makeKeyAndOrderFront(long window); + private native void orderOut(long window); + private native void close0(long window); + private native void setTitle0(long window, String title); + protected native void dispatchMessages(int eventMask); + private native long contentView(long window); + private native void setContentSize(long window, int w, int h); + private native void setFrameTopLeftPoint(long window, int x, int y); +} diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java b/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java new file mode 100644 index 000000000..a8fd648cc --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java @@ -0,0 +1,532 @@ +/* + * 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.sun.javafx.newt.opengl; + +import com.sun.javafx.newt.*; +import javax.media.nwi.*; +import javax.media.opengl.*; +import com.sun.opengl.impl.GLDrawableHelper; + +/** + * An implementation of {@link Window} which is customized for OpenGL + * use, and which implements the {@link + * javax.media.opengl.GLAutoDrawable} interface. For convenience, this + * window class guarantees that its OpenGL context is current inside + * the various EventListeners' callbacks (MouseListener, KeyListener, + * etc.). + */ +public class GLWindow extends Window implements GLAutoDrawable { + /** + * Event handling mode: EVENT_HANDLER_GL_NONE. + * No GL context is current, while calling the EventListener. + * This might be inconvenient, but don't impact the performance. + * + * @see com.sun.javafx.newt.GLWindow#setEventHandlerMode(int) + */ + public static final int EVENT_HANDLER_GL_NONE = 0; + + /** + * Event handling mode: EVENT_HANDLER_GL_CURRENT. + * The GL context is made current, while calling the EventListener. + * This might be convenient, but impacts the performance + * due to context switches. + * + * This is the default setting! + * + * @see com.sun.javafx.newt.GLWindow#setEventHandlerMode(int) + */ + public static final int EVENT_HANDLER_GL_CURRENT = (1 << 0); + + private Window window; + + /** Constructor. Do not call this directly -- use {@link + create()} instead. */ + protected GLWindow(Window window) { + this.window = window; + this.window.setAutoDrawableClient(true); + window.addWindowListener(new WindowListener() { + public void windowResized(WindowEvent e) { + sendReshape = true; + } + + public void windowMoved(WindowEvent e) { + } + + public void windowDestroyNotify(WindowEvent e) { + sendDispose = true; + } + }); + } + + /** Creates a new GLWindow on the local display, screen 0, with a + dummy visual ID, and with the default NWCapabilities. */ + public static GLWindow create() { + return create(null, null, false); + } + + public static GLWindow create(boolean undecorated) { + return create(null, null, undecorated); + } + + /** Creates a new GLWindow referring to the given window. */ + public static GLWindow create(Window window) { + return create(window, null, false); + } + public static GLWindow create(NWCapabilities caps) { + return create(null, caps, false); + } + + /** Creates a new GLWindow on the local display, screen 0, with a + dummy visual ID, and with the given NWCapabilities. */ + public static GLWindow create(NWCapabilities caps, boolean undecorated) { + return create(null, caps, undecorated); + } + + /** Creates a new GLWindow referring to the given window, and with the given NWCapabilities. */ + public static GLWindow create(Window window, NWCapabilities caps) { + return create(window, caps, false); + } + + public static GLWindow create(Window window, + NWCapabilities caps, + boolean undecorated) { + if (caps == null) { + caps = new NWCapabilities(); + } + if (window == null) { + Display display = NewtFactory.createDisplay(null); // local display + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + window = NewtFactory.createWindow(screen, caps, undecorated); + } + + return new GLWindow(window); + } + + protected void createNative(NWCapabilities caps) { + shouldNotCallThis(); + } + + protected void closeNative() { + shouldNotCallThis(); + } + + public synchronized void destroy() { + if(Window.DEBUG_WINDOW_EVENT) { + Exception e1 = new Exception("GLWindow.destroy 1: "+this); + e1.printStackTrace(); + } + + sendDisposeEvent(); + + if (context != null) { + context.destroy(); + } + if (drawable != null) { + drawable.setRealized(false); + } + + if(null!=window) { + window.destroy(); + } + + if(Window.DEBUG_WINDOW_EVENT) { + System.out.println("GLWindow.destroy fin: "+this); + } + + drawable = null; + context = null; + window = null; + } + + public boolean getPerfLogEnabled() { return perfLog; } + + public void enablePerfLog(boolean v) { + perfLog = v; + } + + /** + * Sets the event handling mode. + * + * @see com.sun.javafx.newt.GLWindow#EVENT_HANDLER_GL_NONE + * @see com.sun.javafx.newt.GLWindow#EVENT_HANDLER_GL_CURRENT + */ + public void setEventHandlerMode(int mode) { + eventHandlerMode = mode; + } + + public int getEventHandlerMode() { + return eventHandlerMode; + } + + public void pumpMessages(int eventMask) { + if( 0 == (eventHandlerMode & EVENT_HANDLER_GL_CURRENT) ) { + window.pumpMessages(eventMask); + } else { + pumpMessagesWithEventMaskAction.eventMask = eventMask; + pumpMessagesImpl(pumpMessagesWithEventMaskAction); + } + } + + public void pumpMessages() { + if( 0 == (eventHandlerMode & EVENT_HANDLER_GL_CURRENT) ) { + window.pumpMessages(); + } else { + pumpMessagesImpl(pumpMessagesAction); + } + } + + class PumpMessagesWithEventMaskAction implements Runnable { + private int eventMask; + + public void run() { + window.pumpMessages(eventMask); + } + } + private PumpMessagesWithEventMaskAction pumpMessagesWithEventMaskAction = new PumpMessagesWithEventMaskAction(); + + class PumpMessagesAction implements Runnable { + public void run() { + window.pumpMessages(); + } + } + private PumpMessagesAction pumpMessagesAction = new PumpMessagesAction(); + + private void pumpMessagesImpl(Runnable pumpMessagesAction) { + // pumpMessagesAction.run(); + + boolean autoSwapBuffer = helper.getAutoSwapBufferMode(); + helper.setAutoSwapBufferMode(false); + try { + helper.invokeGL(drawable, context, pumpMessagesAction, initAction); + } finally { + helper.setAutoSwapBufferMode(autoSwapBuffer); + } + + } + + protected void dispatchMessages(int eventMask) { + shouldNotCallThis(); + } + + public void setVisible(boolean visible) { + window.setVisible(visible); + if (visible && context == null) { + factory = GLDrawableFactory.getFactory(); + NativeWindow nw = window; + if (window.getWrappedWindow() != null) { + nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow()); + } + drawable = factory.createGLDrawable(nw, window.getChosenCapabilities(), null); + window.setVisible(true); + drawable.setRealized(true); + context = drawable.createContext(null); + } + } + + public void setTitle(String title) { + window.setTitle(title); + } + + public String getTitle() { + return window.getTitle(); + } + + public void setUndecorated(boolean value) { + window.setUndecorated(value); + } + + public boolean isUndecorated() { + return window.isUndecorated(); + } + + public void setSize(int width, int height) { + window.setSize(width, height); + } + + public void setPosition(int x, int y) { + window.setPosition(x, y); + } + + public boolean setFullscreen(boolean fullscreen) { + return window.setFullscreen(fullscreen); + } + + public boolean isVisible() { + return window.isVisible(); + } + + public int getX() { + return window.getX(); + } + + public int getY() { + return window.getY(); + } + + public int getWidth() { + return window.getWidth(); + } + + public int getHeight() { + return window.getHeight(); + } + + public boolean isFullscreen() { + return window.isFullscreen(); + } + + public void addMouseListener(MouseListener l) { + window.addMouseListener(l); + } + + public void removeMouseListener(MouseListener l) { + window.removeMouseListener(l); + } + + public MouseListener[] getMouseListeners() { + return window.getMouseListeners(); + } + + public void addKeyListener(KeyListener l) { + window.addKeyListener(l); + } + + public void removeKeyListener(KeyListener l) { + window.removeKeyListener(l); + } + + public KeyListener[] getKeyListeners() { + return window.getKeyListeners(); + } + + public void addWindowListener(WindowListener l) { + window.addWindowListener(l); + } + + public void removeWindowListener(WindowListener l) { + window.removeWindowListener(l); + } + + public WindowListener[] getWindowListeners() { + return window.getWindowListeners(); + } + + public String toString() { + return "NEWT-GLWindow[ "+drawable+", "+helper+", "+factory+"]"; + } + + //---------------------------------------------------------------------- + // OpenGL-related methods and state + // + + private int eventHandlerMode = EVENT_HANDLER_GL_CURRENT; + private GLDrawableFactory factory; + private GLDrawable drawable; + private GLContext context; + private GLDrawableHelper helper = new GLDrawableHelper(); + // To make reshape events be sent immediately before a display event + private boolean sendReshape=false; + private boolean sendDispose=false; + private boolean perfLog = false; + + public GLDrawableFactory getFactory() { + return factory; + } + + public void setContext(GLContext newCtx) { + context = newCtx; + } + + public GLContext getContext() { + return context; + } + + public GL getGL() { + if (context == null) { + return null; + } + return context.getGL(); + } + + public void setGL(GL gl) { + if (context != null) { + context.setGL(gl); + } + } + + public void addGLEventListener(GLEventListener listener) { + helper.addGLEventListener(listener); + } + + public void removeGLEventListener(GLEventListener listener) { + helper.removeGLEventListener(listener); + } + + public void display() { + if(window.getSurfaceHandle()!=0) { + pumpMessages(); + if (sendDispose) { + destroy(); + sendDispose=false; + } else { + helper.invokeGL(drawable, context, displayAction, initAction); + } + } + } + + private void sendDisposeEvent() { + if(disposeAction!=null && drawable!=null && context != null && window!=null && window.getSurfaceHandle()!=0) { + helper.invokeGL(drawable, context, disposeAction, null); + } + } + + public void setAutoSwapBufferMode(boolean onOrOff) { + helper.setAutoSwapBufferMode(onOrOff); + } + + public boolean getAutoSwapBufferMode() { + return helper.getAutoSwapBufferMode(); + } + + public void swapBuffers() { + if(window.getSurfaceHandle()!=0) { + if (context != null && context != GLContext.getCurrent()) { + // Assume we should try to make the context current before swapping the buffers + helper.invokeGL(drawable, context, swapBuffersAction, initAction); + } else { + drawable.swapBuffers(); + } + } + } + + class InitAction implements Runnable { + public void run() { + helper.init(GLWindow.this); + startTime = System.currentTimeMillis(); + curTime = startTime; + if(perfLog) { + lastCheck = startTime; + totalFrames = 0; lastFrames = 0; + } + } + } + private InitAction initAction = new InitAction(); + + class DisposeAction implements Runnable { + public void run() { + helper.dispose(GLWindow.this); + } + } + private DisposeAction disposeAction = new DisposeAction(); + + class DisplayAction implements Runnable { + public void run() { + if (sendReshape) { + int width = getWidth(); + int height = getHeight(); + getGL().glViewport(0, 0, width, height); + helper.reshape(GLWindow.this, 0, 0, width, height); + sendReshape = false; + } + + helper.display(GLWindow.this); + + curTime = System.currentTimeMillis(); + totalFrames++; + + if(perfLog) { + long dt0, dt1; + lastFrames++; + dt0 = curTime-lastCheck; + if ( dt0 > 5000 ) { + dt1 = curTime-startTime; + System.out.println(dt0/1000 +"s: "+ lastFrames + "f, " + (lastFrames*1000)/dt0 + " fps, "+dt0/lastFrames+" ms/f; "+ + "total: "+ dt1/1000+"s, "+(totalFrames*1000)/dt1 + " fps, "+dt1/totalFrames+" ms/f"); + lastCheck=curTime; + lastFrames=0; + } + } + } + } + + public long getStartTime() { return startTime; } + public long getCurrentTime() { return curTime; } + public long getDuration() { return curTime-startTime; } + public int getTotalFrames() { return totalFrames; } + + private long startTime = 0; + private long curTime = 0; + private long lastCheck = 0; + private int totalFrames = 0, lastFrames = 0; + + private DisplayAction displayAction = new DisplayAction(); + + class SwapBuffersAction implements Runnable { + public void run() { + drawable.swapBuffers(); + } + } + + private SwapBuffersAction swapBuffersAction = new SwapBuffersAction(); + + //---------------------------------------------------------------------- + // GLDrawable methods that are not really needed + // + + public GLContext createContext(GLContext shareWith) { + return drawable.createContext(shareWith); + } + + public void setRealized(boolean realized) { + } + + public NWCapabilities getChosenNWCapabilities() { + if (drawable == null) + return null; + + return drawable.getChosenNWCapabilities(); + } + + public NativeWindow getNativeWindow() { + return drawable.getNativeWindow(); + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private void shouldNotCallThis() { + throw new NativeWindowException("Should not call this"); + } +} diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDDisplay.java b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDDisplay.java new file mode 100755 index 000000000..70c8980d2 --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDDisplay.java @@ -0,0 +1,60 @@ +/* + * 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.sun.javafx.newt.opengl.kd; + +import com.sun.javafx.newt.*; +import com.sun.javafx.newt.impl.*; +import com.sun.opengl.impl.egl.*; +import javax.media.nwi.NativeWindowException; + +public class KDDisplay extends Display { + static { + NativeLibLoader.loadNEWT(); + } + + public KDDisplay() { + } + + protected void createNative() { + // FIXME: map name to EGL_*_DISPLAY + 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"); + } + } +} + diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDScreen.java b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDScreen.java new file mode 100755 index 000000000..b003efec7 --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDScreen.java @@ -0,0 +1,45 @@ +/* + * 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.sun.javafx.newt.opengl.kd; + +import com.sun.javafx.newt.*; + +public class KDScreen extends Screen { + public KDScreen() { + } + + protected void createNative() { + handle = 0; + } +} diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java new file mode 100755 index 000000000..8c1a7597e --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java @@ -0,0 +1,163 @@ +/* + * 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.sun.javafx.newt.opengl.kd; + +import com.sun.javafx.newt.*; +import com.sun.javafx.newt.impl.*; +import com.sun.opengl.impl.egl.*; +import javax.media.nwi.NWCapabilities; +import javax.media.opengl.GLProfile; +import javax.media.nwi.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 { + NativeLibLoader.loadNEWT(); + + if (!initIDs()) { + throw new NativeWindowException("Failed to initialize jmethodIDs"); + } + } + + public KDWindow() { + } + + protected void createNative(NWCapabilities caps) { + int eglRenderableType; + if(GLProfile.isGLES1()) { + eglRenderableType = EGL.EGL_OPENGL_ES_BIT; + } + else if(GLProfile.isGLES2()) { + eglRenderableType = EGL.EGL_OPENGL_ES2_BIT; + } else { + eglRenderableType = EGL.EGL_OPENGL_BIT; + } + EGLConfig config = new EGLConfig(getDisplayHandle(), caps); + visualID = config.getNativeConfigID(); + chosenCaps = config.getCapabilities(); + + windowHandle = 0; + windowID = ++_windowID; + eglWindowHandle = CreateWindow(windowID, getDisplayHandle(), config.getAttributeList()); + if (eglWindowHandle == 0) { + throw new NativeWindowException("Error creating egl window: "+eglWindowHandle); + } + setVisible0(eglWindowHandle, false); + /* + windowHandle = RealizeWindow(eglWindowHandle); + if (0 == windowHandle) { + throw new NativeWindowException("Error native Window Handle is null"); + } */ + windowHandleClose = eglWindowHandle; + } + + protected void closeNative() { + if(0!=windowHandleClose) { + CloseWindow(windowHandleClose); + } + } + + public void setVisible(boolean visible) { + if(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) { + 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(this.fullscreen!=fullscreen) { + this.fullscreen=fullscreen; + if(this.fullscreen) { + setFullScreen0(eglWindowHandle, true); + } else { + setFullScreen0(eglWindowHandle, false); + setSize0(eglWindowHandle, nfs_width, nfs_height); + } + } + return true; + } + + protected void dispatchMessages(int eventMask) { + DispatchMessages(windowID, eglWindowHandle, eventMask); + } + + //---------------------------------------------------------------------- + // Internals only + // + + private static native boolean initIDs(); + private native long CreateWindow(int owner, long displayHandle, int[] attributes); + private native long RealizeWindow(long eglWindowHandle); + private native int CloseWindow(long eglWindowHandle); + 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 native void DispatchMessages(int owner, long eglWindowHandle, int eventMask); + + private void sizeChanged(int newWidth, int newHeight) { + width = newWidth; + height = newHeight; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } else { + screen.setScreenSize(width, height); + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } + + private long eglWindowHandle; + private long windowHandleClose; + private int windowID; + private static int _windowID = 0; +} diff --git a/src/newt/classes/com/sun/javafx/newt/windows/WindowsDisplay.java b/src/newt/classes/com/sun/javafx/newt/windows/WindowsDisplay.java new file mode 100755 index 000000000..bfd928190 --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/windows/WindowsDisplay.java @@ -0,0 +1,45 @@ +/* + * 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.sun.javafx.newt.windows; + +import com.sun.javafx.newt.*; + +public class WindowsDisplay extends Display { + public WindowsDisplay() { + } + + protected void createNative() { + handle = 0; + } +} diff --git a/src/newt/classes/com/sun/javafx/newt/windows/WindowsScreen.java b/src/newt/classes/com/sun/javafx/newt/windows/WindowsScreen.java new file mode 100755 index 000000000..455d0ed60 --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/windows/WindowsScreen.java @@ -0,0 +1,45 @@ +/* + * 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.sun.javafx.newt.windows; + +import com.sun.javafx.newt.*; + +public class WindowsScreen extends Screen { + public WindowsScreen() { + } + + protected void createNative() { + handle = 0; + } +} diff --git a/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java new file mode 100755 index 000000000..2b3401a84 --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java @@ -0,0 +1,175 @@ +/* + * 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.sun.javafx.newt.windows; + +import javax.media.nwi.NWCapabilities; +import javax.media.nwi.NativeWindowException; + +import com.sun.javafx.newt.*; +import com.sun.javafx.newt.impl.*; + +public class WindowsWindow extends Window { + + private long hdc; + private long windowHandleClose; + + private static final String WINDOW_CLASS_NAME = "NewtWindow"; + static { + NativeLibLoader.loadNEWT(); + + if (!initIDs()) { + throw new NativeWindowException("Failed to initialize jmethodIDs"); + } + } + + public WindowsWindow() { + } + + public long getSurfaceHandle() { + if (hdc == 0) { + hdc = GetDC(windowHandle); + } + return hdc; + } + + protected void createNative(NWCapabilities caps) { + long wndClass = getWindowClass(); + chosenCaps = (NWCapabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID) + visualID = 0; // n/a + windowHandle = CreateWindow(WINDOW_CLASS_NAME, getHInstance(), visualID, x, y, width, height); + if (windowHandle == 0) { + throw new NativeWindowException("Error creating window"); + } + windowHandleClose = windowHandle; + } + + 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) { + this.visible=visible; + setVisible0(windowHandle, visible); + } + } + + public void setSize(int width, int height) { + setSize0(windowHandle, width, height); + } + + public void setPosition(int x, int y) { + } + + public boolean setFullscreen(boolean fullscreen) { + if(this.fullscreen!=fullscreen) { + boolean res = setFullScreen0(windowHandle, fullscreen); + if (fullscreen && res) { + this.fullscreen = true; + } else { + this.fullscreen = false; + } + return fullscreen; + } + return true; + } + + protected void dispatchMessages(int eventMask) { + DispatchMessages(windowHandle, eventMask); + } + + //---------------------------------------------------------------------- + // Internals only + // + + private static long windowClass; + private static synchronized long getWindowClass() { + if (windowClass == 0) { + windowClass = RegisterWindowClass(WINDOW_CLASS_NAME, getHInstance()); + if (windowClass == 0) { + throw new NativeWindowException("Error while registering window class"); + } + } + return windowClass; + } + private static long hInstance; + private static synchronized long getHInstance() { + if (hInstance == 0) { + hInstance = LoadLibraryW("newt"); + if (hInstance == 0) { + throw new NativeWindowException("Error finding HINSTANCE for \"newt\""); + } + } + return hInstance; + } + + private static native boolean initIDs(); + private static native long LoadLibraryW(String libraryName); + private static native long RegisterWindowClass(String windowClassName, long hInstance); + private native long CreateWindow(String windowClassName, long hInstance, long visualID, + 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 void setVisible0(long windowHandle, boolean visible); + private static native void DispatchMessages(long windowHandle, int eventMask); + private native void setSize0(long windowHandle, int width, int height); + private native boolean setFullScreen0(long windowHandle, boolean fullscreen); + + private void sizeChanged(int newWidth, int newHeight) { + width = newWidth; + height = newHeight; + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } + + private void positionChanged(int newX, int newY) { + x = newX; + y = newY; + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + } +} diff --git a/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java b/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java new file mode 100755 index 000000000..5486c9fb6 --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/x11/X11Display.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.sun.javafx.newt.x11; + +import com.sun.javafx.newt.*; +import com.sun.javafx.newt.impl.*; + +public class X11Display extends Display { + static { + NativeLibLoader.loadNEWT(); + } + + public X11Display() { + } + + protected void createNative() { + handle = CreateDisplay(name); + if (handle == 0 ) { + throw new RuntimeException("Error creating display: "+name); + } + } + + //---------------------------------------------------------------------- + // Internals only + // + + private native long CreateDisplay(String name); +} diff --git a/src/newt/classes/com/sun/javafx/newt/x11/X11Screen.java b/src/newt/classes/com/sun/javafx/newt/x11/X11Screen.java new file mode 100755 index 000000000..ede522685 --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/x11/X11Screen.java @@ -0,0 +1,64 @@ +/* + * 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.sun.javafx.newt.x11; + +import com.sun.javafx.newt.*; +import com.sun.javafx.newt.impl.*; + +public class X11Screen extends Screen { + static { + NativeLibLoader.loadNEWT(); + } + + public X11Screen() { + } + + protected void createNative() { + handle = GetScreen(display.getHandle(), index); + if (handle == 0 ) { + throw new RuntimeException("Error creating screen: "+index); + } + setScreenSize(getWidth0(display.getHandle(), index), + getHeight0(display.getHandle(), index)); + } + + //---------------------------------------------------------------------- + // 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/sun/javafx/newt/x11/X11Window.java b/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java new file mode 100755 index 000000000..8b2de8c03 --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java @@ -0,0 +1,164 @@ +/* + * 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.sun.javafx.newt.x11; + +import com.sun.javafx.newt.*; +import com.sun.javafx.newt.impl.*; +import javax.media.nwi.NWCapabilities; +import javax.media.nwi.NativeWindowException; + +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 { + NativeLibLoader.loadNEWT(); + + if (!initIDs()) { + throw new NativeWindowException("Failed to initialize jmethodIDs"); + } + } + + public X11Window() { + } + + protected void createNative(NWCapabilities caps) { + chosenCaps = (NWCapabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID) + visualID = 0; // n/a + long w = CreateWindow(getDisplayHandle(), getScreenHandle(), getScreenIndex(), visualID, x, y, width, height); + if (w == 0 || w!=windowHandle) { + throw new NativeWindowException("Error creating window: "+w); + } + windowHandleClose = windowHandle; + displayHandleClose = getDisplayHandle(); + } + + protected void closeNative() { + if(0!=displayHandleClose && 0!=windowHandleClose) { + CloseWindow(displayHandleClose, windowHandleClose); + windowHandleClose = 0; + displayHandleClose = 0; + } + } + + protected void windowDestroyed() { + windowHandleClose = 0; + displayHandleClose = 0; + super.windowDestroyed(); + } + + public void setVisible(boolean visible) { + if(this.visible!=visible) { + this.visible=visible; + setVisible0(getDisplayHandle(), windowHandle, visible); + clearEventMask(); + } + } + + public void setSize(int width, int height) { + setSize0(getDisplayHandle(), windowHandle, width, height, 0, visible); + } + + public void setPosition(int x, int y) { + setPosition0(getDisplayHandle(), windowHandle, x, y); + } + + 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; + } + setPosition0(getDisplayHandle(), windowHandle, x, y); + setSize0(getDisplayHandle(), windowHandle, w, h, fullscreen?-1:1, visible); + } + return true; + } + + protected void dispatchMessages(int eventMask) { + DispatchMessages(getDisplayHandle(), windowHandle, eventMask, windowDeleteAtom); + } + + //---------------------------------------------------------------------- + // Internals only + // + + private static native boolean initIDs(); + private native long CreateWindow(long display, long screen, int screen_index, + long visualID, int x, int y, int width, int height); + private native void CloseWindow(long display, long windowHandle); + private native void setVisible0(long display, long windowHandle, boolean visible); + private native void DispatchMessages(long display, long windowHandle, int eventMask, long windowDeleteAtom); + private native void setSize0(long display, long windowHandle, int width, int height, int decorationToggle, boolean isVisible); + private native void setPosition0(long display, long windowHandle, int x, int y); + + 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); + } + + private void windowCreated(long visualID, long windowHandle, long windowDeleteAtom) { + this.visualID = visualID; + this.windowHandle = windowHandle; + this.windowDeleteAtom=windowDeleteAtom; + } + + private long windowHandleClose; + private long displayHandleClose; + private long windowDeleteAtom; +} -- cgit v1.2.3