aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/com/sun/javafx/newt
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes/com/sun/javafx/newt')
-rw-r--r--src/classes/com/sun/javafx/newt/EventListener.java39
-rw-r--r--src/classes/com/sun/javafx/newt/InputEvent.java95
-rw-r--r--src/classes/com/sun/javafx/newt/KeyEvent.java275
-rw-r--r--src/classes/com/sun/javafx/newt/KeyListener.java42
-rw-r--r--src/classes/com/sun/javafx/newt/MouseEvent.java86
-rw-r--r--src/classes/com/sun/javafx/newt/MouseListener.java46
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/Window.java149
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/windows/WindowsWindow.java64
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/x11/X11Window.java190
9 files changed, 977 insertions, 9 deletions
diff --git a/src/classes/com/sun/javafx/newt/EventListener.java b/src/classes/com/sun/javafx/newt/EventListener.java
new file mode 100644
index 000000000..881d66b87
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/EventListener.java
@@ -0,0 +1,39 @@
+/*
+ * 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
+{
+}
+
diff --git a/src/classes/com/sun/javafx/newt/InputEvent.java b/src/classes/com/sun/javafx/newt/InputEvent.java
new file mode 100644
index 000000000..e8644f953
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/InputEvent.java
@@ -0,0 +1,95 @@
+/*
+ * 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
+{
+ 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, Window source, long when, int modifiers) {
+ this.consumed=false;
+ this.sysEvent=sysEvent;
+ this.source=source;
+ this.when=when;
+ this.modifiers=modifiers;
+ }
+
+ protected boolean isSysEvent() {
+ return sysEvent;
+ }
+
+ public void consume() {
+ consumed=true;
+ }
+
+ public boolean isConsumed() {
+ return consumed;
+ }
+ public int getModifiers() {
+ return modifiers;
+ }
+ public long getWhen() {
+ return when;
+ }
+ 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[sys:"+sysEvent+", source:"+source+", when:"+when+", modifiers:"+modifiers+"]";
+ }
+
+ private boolean sysEvent, consumed;
+ private Window source;
+ private int modifiers;
+ private long when;
+
+}
+
diff --git a/src/classes/com/sun/javafx/newt/KeyEvent.java b/src/classes/com/sun/javafx/newt/KeyEvent.java
new file mode 100644
index 000000000..96df883df
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/KeyEvent.java
@@ -0,0 +1,275 @@
+/*
+ * 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
+{
+ protected KeyEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) {
+ super(sysEvent, source, when, modifiers);
+ this.eventType=eventType;
+ 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 int getEventType() {
+ return eventType;
+ }
+ public char getKeyChar() {
+ return keyChar;
+ }
+ public int getKeyCode() {
+ return keyCode;
+ }
+
+ public String toString() {
+ return "KeyEvent[code "+keyCode+", char "+keyChar+", "+super.toString();
+ }
+
+ 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 eventType;
+ private int keyCode;
+ private char keyChar;
+
+ public static final int EVENT_KEY_PRESSED = 1 << 0;
+ public static final int EVENT_KEY_RELEASED= 1 << 1;
+ public static final int EVENT_KEY_TYPED = 1 << 2;
+
+ /* 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 <b>left</b> arrow key.
+ */
+ public static final int VK_LEFT = 0x25;
+
+ /**
+ * Constant for the non-numpad <b>up</b> arrow key.
+ */
+ public static final int VK_UP = 0x26;
+
+ /**
+ * Constant for the non-numpad <b>right</b> arrow key.
+ */
+ public static final int VK_RIGHT = 0x27;
+
+ /**
+ * Constant for the non-numpad <b>down</b> arrow key.
+ */
+ public static final int VK_DOWN = 0x28;
+
+ /** 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;
+
+ public static final int VK_WINDOWS = 0x020C;
+}
+
diff --git a/src/classes/com/sun/javafx/newt/KeyListener.java b/src/classes/com/sun/javafx/newt/KeyListener.java
new file mode 100644
index 000000000..6f022c45a
--- /dev/null
+++ b/src/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/classes/com/sun/javafx/newt/MouseEvent.java b/src/classes/com/sun/javafx/newt/MouseEvent.java
new file mode 100644
index 000000000..99026bd7b
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/MouseEvent.java
@@ -0,0 +1,86 @@
+/*
+ * 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;
+
+ protected MouseEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers, int x, int y, int clickCount, int button)
+ {
+ super(sysEvent, source, when, modifiers);
+ this.eventType=eventType;
+ 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 getEventType() {
+ return eventType;
+ }
+ 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["+x+"/"+y+", button "+button+", count "+clickCount+", "+super.toString();
+ }
+
+ private int eventType, x, y, clickCount, button;
+
+ public static final int EVENT_MOUSE_CLICKED = 1 << 0;
+ public static final int EVENT_MOUSE_ENTERED = 1 << 1;
+ public static final int EVENT_MOUSE_EXITED = 1 << 2;
+ public static final int EVENT_MOUSE_PRESSED = 1 << 3;
+ public static final int EVENT_MOUSE_RELEASED = 1 << 4;
+ public static final int EVENT_MOUSE_MOVED = 1 << 5;
+ public static final int EVENT_MOUSE_DRAGGED = 1 << 6;
+
+}
+
diff --git a/src/classes/com/sun/javafx/newt/MouseListener.java b/src/classes/com/sun/javafx/newt/MouseListener.java
new file mode 100644
index 000000000..f707979ba
--- /dev/null
+++ b/src/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/classes/com/sun/javafx/newt/Window.java b/src/classes/com/sun/javafx/newt/Window.java
index c9437a196..2bfcf1265 100755
--- a/src/classes/com/sun/javafx/newt/Window.java
+++ b/src/classes/com/sun/javafx/newt/Window.java
@@ -33,6 +33,9 @@
package com.sun.javafx.newt;
+import java.util.ArrayList;
+import java.util.Iterator;
+
public abstract class Window {
/** OpenKODE window type */
public static final String KD = "KD";
@@ -47,7 +50,7 @@ public abstract class Window {
public static final String MACOSX = "MacOSX";
/** Creates a Window of the default type for the current operating system. */
- public static Window create() {
+ public static Window create(long visualID) {
String osName = System.getProperty("os.name");
String osNameLowerCase = osName.toLowerCase();
String windowType;
@@ -58,7 +61,9 @@ public abstract class Window {
} else {
windowType = X11;
}
- return create(windowType);
+ Window window = create(windowType);
+ window.initNative(visualID);
+ return window;
}
@@ -82,13 +87,149 @@ public abstract class Window {
}
}
- protected Window() {
- }
+ protected abstract void initNative(long visualID);
+ 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 isVisible();
public abstract int getWidth();
public abstract int getHeight();
+ public abstract int getX();
+ public abstract int getY();
public abstract boolean setFullscreen(boolean fullscreen);
+ public abstract boolean isFullscreen();
+ public abstract int getDisplayWidth();
+ public abstract int getDisplayHeight();
public abstract long getWindowHandle();
public abstract void pumpMessages();
+
+ //
+ // MouseListener Support
+ //
+
+ public synchronized void addMouseListener(MouseListener l) {
+ if(l == null) {
+ return;
+ }
+ mouseListener.add(l);
+ }
+
+ public synchronized void removeMouseListener(MouseListener l) {
+ if (l == null) {
+ return;
+ }
+ mouseListener.remove(l);
+ }
+
+ public synchronized MouseListener[] getMouseListeners() {
+ return (MouseListener[]) mouseListener.toArray();
+ }
+
+ private ArrayList mouseListener = new ArrayList();
+ private long lastMousePressed = 0;
+ private int lastMouseClickCount = 0;
+ public static final int ClickTimeout = 200;
+
+ private void sendMouseEvent(int eventType, int modifiers, int x, int y, int button) {
+ long when = System.currentTimeMillis();
+ MouseEvent eClicked = null;
+ MouseEvent e = null;
+
+ if(MouseEvent.EVENT_MOUSE_PRESSED==eventType) {
+ if(when-lastMousePressed<ClickTimeout) {
+ lastMouseClickCount++;
+ } else {
+ lastMouseClickCount=1;
+ }
+ lastMousePressed=when;
+ e = new MouseEvent(true, eventType, this, when,
+ modifiers, x, y, lastMouseClickCount, button);
+ } else if(MouseEvent.EVENT_MOUSE_RELEASED==eventType) {
+ e = new MouseEvent(true, eventType, this, when,
+ modifiers, x, y, lastMouseClickCount, button);
+ if(when-lastMousePressed<ClickTimeout) {
+ eClicked = new MouseEvent(true, MouseEvent.EVENT_MOUSE_CLICKED, this, when,
+ modifiers, x, y, lastMouseClickCount, button);
+ }
+ lastMouseClickCount=0;
+ lastMousePressed=0;
+ } else if(MouseEvent.EVENT_MOUSE_MOVED==eventType &&
+ 1==lastMouseClickCount) {
+ e = new MouseEvent(true, eventType, this, when,
+ modifiers, x, y, 1, button);
+ } else {
+ e = new MouseEvent(true, eventType, this, when,
+ modifiers, x, y, 0, button);
+ }
+
+ for(Iterator i = mouseListener.iterator(); i.hasNext(); ) {
+ switch(eventType) {
+ case MouseEvent.EVENT_MOUSE_ENTERED:
+ ((MouseListener)i.next()).mouseEntered(e);
+ break;
+ case MouseEvent.EVENT_MOUSE_EXITED:
+ ((MouseListener)i.next()).mouseExited(e);
+ break;
+ case MouseEvent.EVENT_MOUSE_PRESSED:
+ ((MouseListener)i.next()).mousePressed(e);
+ break;
+ case MouseEvent.EVENT_MOUSE_RELEASED:
+ ((MouseListener)i.next()).mouseReleased(e);
+ if(null!=eClicked) {
+ ((MouseListener)i.next()).mouseClicked(eClicked);
+ }
+ break;
+ case MouseEvent.EVENT_MOUSE_MOVED:
+ ((MouseListener)i.next()).mouseMoved(e);
+ break;
+ case MouseEvent.EVENT_MOUSE_DRAGGED:
+ ((MouseListener)i.next()).mouseDragged(e);
+ break;
+ }
+ }
+ }
+
+ //
+ // KeyListener Support
+ //
+
+ public synchronized void addKeyListener(KeyListener l) {
+ if(l == null) {
+ return;
+ }
+ keyListener.add(l);
+ }
+
+ public synchronized void removeKeyListener(KeyListener l) {
+ if (l == null) {
+ return;
+ }
+ keyListener.remove(l);
+ }
+
+ public synchronized KeyListener[] getKeyListeners() {
+ return (KeyListener[]) keyListener.toArray();
+ }
+
+ private ArrayList keyListener = new ArrayList();
+
+ private void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) {
+ KeyEvent e = new KeyEvent(true, eventType, this, System.currentTimeMillis(),
+ modifiers, keyCode, keyChar);
+ for(Iterator i = keyListener.iterator(); i.hasNext(); ) {
+ switch(eventType) {
+ case KeyEvent.EVENT_KEY_PRESSED:
+ ((KeyListener)i.next()).keyPressed(e);
+ break;
+ case KeyEvent.EVENT_KEY_RELEASED:
+ ((KeyListener)i.next()).keyReleased(e);
+ break;
+ case KeyEvent.EVENT_KEY_TYPED:
+ ((KeyListener)i.next()).keyTyped(e);
+ break;
+ }
+ }
+ }
}
+
diff --git a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
index dfe423096..faa26dcb7 100755
--- a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
+++ b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
@@ -37,12 +37,16 @@ import com.sun.javafx.newt.*;
import com.sun.opengl.impl.*;
public class WindowsWindow extends Window {
+ private boolean fullscreen, visible;
+ private long visualID;
private long window;
- private static final String WINDOW_CLASS_NAME = "NewtWindow";
// Default width and height -- will likely be re-set immediately by user
private int width = 100;
private int height = 100;
+ private int x=0;
+ private int y=0;
+ private static final String WINDOW_CLASS_NAME = "NewtWindow";
static {
NativeLibLoader.loadCore();
@@ -51,18 +55,45 @@ public class WindowsWindow extends Window {
}
}
- public WindowsWindow() {
+ protected WindowsWindow() {
+ }
+
+ protected void initNative(long visualID) {
long wndClass = getWindowClass();
- window = CreateWindow(WINDOW_CLASS_NAME, getHInstance(), width, height);
+ fullscreen=false;
+ visible=false;
+ window = CreateWindow(WINDOW_CLASS_NAME, getHInstance(), visualID, x, y, width, height);
if (window == 0) {
throw new RuntimeException("Error creating window");
}
}
+ public void setVisible(boolean visible) {
+ if(this.visible!=visible) {
+ this.visible=visible;
+ setVisible0(window, visible);
+ }
+ }
+
public void setSize(int width, int height) {
setSize0(window, width, height);
}
+ public void setPosition(int x, int y) {
+ }
+
+ public boolean isVisible() {
+ return visible;
+ }
+
+ public int getX() {
+ return x;
+ }
+
+ public int getY() {
+ return y;
+ }
+
public int getWidth() {
return width;
}
@@ -72,7 +103,23 @@ public class WindowsWindow extends Window {
}
public boolean setFullscreen(boolean fullscreen) {
- return setFullScreen0(window, fullscreen);
+ if(this.fullscreen!=fullscreen) {
+ this.fullscreen=fullscreen;
+ return setFullScreen0(window, fullscreen);
+ }
+ return true;
+ }
+
+ public boolean isFullscreen() {
+ return fullscreen;
+ }
+
+ public int getDisplayWidth() {
+ return 640; // FIXME
+ }
+
+ public int getDisplayHeight() {
+ return 480; // FIXME
}
public long getWindowHandle() {
@@ -112,7 +159,9 @@ public class WindowsWindow extends Window {
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, int width, int height);
+ private native long CreateWindow(String windowClassName, long hInstance, long visualID,
+ int x, int y, int width, int height);
+ private native void setVisible0(long window, boolean visible);
private static native void DispatchMessages(long window);
private native void setSize0(long window, int width, int height);
private native boolean setFullScreen0(long window, boolean fullscreen);
@@ -128,6 +177,11 @@ public class WindowsWindow extends Window {
height = newHeight;
}
+ private void positionChanged(int newX, int newY) {
+ x = newX;
+ y = newY;
+ }
+
private void windowClosed() {
}
diff --git a/src/classes/com/sun/javafx/newt/x11/X11Window.java b/src/classes/com/sun/javafx/newt/x11/X11Window.java
new file mode 100755
index 000000000..828f08eff
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/x11/X11Window.java
@@ -0,0 +1,190 @@
+/*
+ * 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.opengl.impl.*;
+
+public class X11Window extends Window {
+ private long visualID;
+ private long dpy, screen, window;
+ private static final String WINDOW_CLASS_NAME = "NewtWindow";
+ // Default width and height -- will likely be re-set immediately by user
+ private int width = 100;
+ private int height = 100;
+ private int x=0;
+ private int y=0;
+ // non fullscreen dimensions ..
+ private boolean fullscreen, visible;
+ private int nfs_width, nfs_height, nfs_x, nfs_y;
+
+ static {
+ NativeLibLoader.loadCore();
+
+ if (!initIDs()) {
+ throw new RuntimeException("Failed to initialize jmethodIDs");
+ }
+ }
+
+ protected X11Window() {
+ }
+
+ protected void initNative(long visualID) {
+ fullscreen=false;
+ visible=false;
+ long w = CreateWindow(visualID, x, y, width, height);
+ if (w == 0 || w!=window) {
+ throw new RuntimeException("Error creating window: "+w);
+ }
+ }
+
+ public void setVisible(boolean visible) {
+ if(this.visible!=visible) {
+ this.visible=visible;
+ setVisible0(dpy, window, visible);
+ }
+ }
+
+ public void setSize(int width, int height) {
+ setSize0(dpy, window, width, height);
+ }
+
+ public void setPosition(int x, int y) {
+ setPosition0(dpy, window, x, y);
+ }
+
+ public boolean isVisible() {
+ return visible;
+ }
+
+ public int getX() {
+ return x;
+ }
+
+ public int getY() {
+ return y;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+ public boolean setFullscreen(boolean fullscreen) {
+ if(this.fullscreen!=fullscreen) {
+ int x,y,w,h;
+ this.fullscreen=fullscreen;
+ if(this.fullscreen) {
+ x = 0; y = 0;
+ w = getDisplayWidth0(dpy, screen);
+ h = getDisplayHeight0(dpy, screen);
+ } else {
+ x = nfs_x;
+ y = nfs_y;
+ w = nfs_width;
+ h = nfs_height;
+ }
+ setPosition0(dpy, window, x, y);
+ setSize0(dpy, window, w, h);
+ }
+ return true;
+ }
+
+ public boolean isFullscreen() {
+ return fullscreen;
+ }
+
+ public long getWindowHandle() {
+ return window;
+ }
+
+ public void pumpMessages() {
+ DispatchMessages(dpy, window);
+ }
+
+ public int getDisplayWidth() {
+ return getDisplayWidth0(dpy, screen);
+ }
+
+ public int getDisplayHeight() {
+ return getDisplayHeight0(dpy, screen);
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+
+ private static native boolean initIDs();
+ private native long CreateWindow(long visualID, int x, int y, int width, int height);
+ private native void setVisible0(long display, long window, boolean visible);
+ private native void DispatchMessages(long display, long window);
+ private native void setSize0(long display, long window, int width, int height);
+ private native void setPosition0(long display, long window, int x, int y);
+ private native int getDisplayWidth0(long display, long screen);
+ private native int getDisplayHeight0(long display, long screen);
+
+ private void sizeChanged(int newWidth, int newHeight) {
+ width = newWidth;
+ height = newHeight;
+ if(!fullscreen) {
+ nfs_width=width;
+ nfs_height=height;
+ }
+ }
+
+ private void positionChanged(int newX, int newY) {
+ x = newX;
+ y = newY;
+ if(!fullscreen) {
+ nfs_x=x;
+ nfs_y=y;
+ }
+ }
+
+ private void windowCreated(long dpy, long scrn, long window) {
+ this.dpy = dpy;
+ this.screen = scrn;
+ this.window = window;
+ }
+
+ private void windowClosed() {
+ }
+
+ private void windowDestroyed() {
+ }
+
+}