diff options
author | Kenneth Russel <[email protected]> | 2008-06-30 20:12:47 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2008-06-30 20:12:47 +0000 |
commit | 252efbfd61fb62883df028cba5743e458a5b18c7 (patch) | |
tree | a5f5d87bca24309a4c6c5ac48497a30a70cd442c /src/classes/com/sun/javafx/newt/Window.java | |
parent | 7be2d71e458dd37789ceac43dede4b308eff45c2 (diff) |
Refactored more C compiler setup into gluegen-cpptasks.xml to make it
easier to build native sources via Ant. Provided new
gluegen.cpptasks.setup.compiler target which sets up
platform-independent compiler and linker IDs and other properties
which can be used in other projects' build files. Refactored JOGL
build to use some of these new properties and eliminate duplication;
more code savings possible. Added new GLWindow class to Newt
implementing GLAutoDrawable to increase code sharing, and supporting
making OpenGL calls inside of EventListener callbacks. Moved repaint()
method from GLAutoDrawable to AWTGLAutoDrawable. Added WindowEvent and
WindowListener interfaces to Newt, currently implemented on Windows
and AWT backends (X11 backend would need to support and watch for
window resizes -- FIXME added). Refactored common functionality into
Newt Event class. Renumbered event IDs to avoid collisions. Fixed
potential problems with removing event listeners inside of
EventListener callbacks.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1702 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/javafx/newt/Window.java')
-rwxr-xr-x | src/classes/com/sun/javafx/newt/Window.java | 92 |
1 files changed, 76 insertions, 16 deletions
diff --git a/src/classes/com/sun/javafx/newt/Window.java b/src/classes/com/sun/javafx/newt/Window.java index 1486091e8..a5bdf0806 100755 --- a/src/classes/com/sun/javafx/newt/Window.java +++ b/src/classes/com/sun/javafx/newt/Window.java @@ -43,6 +43,7 @@ public abstract class Window implements NativeWindow { public static final boolean DEBUG_MOUSE_EVENT = false; public static final boolean DEBUG_KEY_EVENT = false; + public static final boolean DEBUG_WINDOW_EVENT = false; public static final boolean DEBUG_IMPLEMENTATION = false; private static Class getWindowClass(String type) @@ -131,9 +132,9 @@ public abstract class Window implements NativeWindow public void pumpMessages() { int em = 0; - //if(windowistener.size()>0) em |= EventListener.WINDOW; - if(mouseListener.size()>0) em |= EventListener.MOUSE; - if(keyListener.size()>0) em |= EventListener.KEY; + if(windowListeners.size()>0) em |= EventListener.WINDOW; + if(mouseListeners.size()>0) em |= EventListener.MOUSE; + if(keyListeners.size()>0) em |= EventListener.KEY; pumpMessages(em); } @@ -271,25 +272,25 @@ public abstract class Window implements NativeWindow if(l == null) { return; } - ArrayList newMouseListeners = (ArrayList) mouseListener.clone(); + ArrayList newMouseListeners = (ArrayList) mouseListeners.clone(); newMouseListeners.add(l); - mouseListener = newMouseListeners; + mouseListeners = newMouseListeners; } public synchronized void removeMouseListener(MouseListener l) { if (l == null) { return; } - ArrayList newMouseListeners = (ArrayList) mouseListener.clone(); + ArrayList newMouseListeners = (ArrayList) mouseListeners.clone(); newMouseListeners.remove(l); - mouseListener = newMouseListeners; + mouseListeners = newMouseListeners; } public synchronized MouseListener[] getMouseListeners() { - return (MouseListener[]) mouseListener.toArray(); + return (MouseListener[]) mouseListeners.toArray(); } - private ArrayList mouseListener = new ArrayList(); + private ArrayList mouseListeners = new ArrayList(); private long lastMousePressed = 0; private int lastMouseClickCount = 0; public static final int ClickTimeout = 200; @@ -346,7 +347,7 @@ public abstract class Window implements NativeWindow ArrayList listeners = null; synchronized(this) { - listeners = mouseListener; + listeners = mouseListeners; } for(Iterator i = listeners.iterator(); i.hasNext(); ) { MouseListener l = (MouseListener) i.next(); @@ -389,21 +390,25 @@ public abstract class Window implements NativeWindow if(l == null) { return; } - keyListener.add(l); + ArrayList newKeyListeners = (ArrayList) keyListeners.clone(); + newKeyListeners.add(l); + keyListeners = newKeyListeners; } public synchronized void removeKeyListener(KeyListener l) { if (l == null) { return; } - keyListener.remove(l); + ArrayList newKeyListeners = (ArrayList) keyListeners.clone(); + newKeyListeners.remove(l); + keyListeners = newKeyListeners; } public synchronized KeyListener[] getKeyListeners() { - return (KeyListener[]) keyListener.toArray(); + return (KeyListener[]) keyListeners.toArray(); } - private ArrayList keyListener = new ArrayList(); + private ArrayList keyListeners = new ArrayList(); protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { KeyEvent e = new KeyEvent(true, eventType, this, System.currentTimeMillis(), @@ -411,7 +416,11 @@ public abstract class Window implements NativeWindow if(DEBUG_KEY_EVENT) { System.out.println("sendKeyEvent: "+e); } - for(Iterator i = keyListener.iterator(); i.hasNext(); ) { + ArrayList listeners = null; + synchronized(this) { + listeners = keyListeners; + } + for(Iterator i = listeners.iterator(); i.hasNext(); ) { KeyListener l = (KeyListener) i.next(); switch(eventType) { case KeyEvent.EVENT_KEY_PRESSED: @@ -428,5 +437,56 @@ public abstract class Window implements NativeWindow } } } -} + // + // WindowListener Support + // + + private ArrayList windowListeners = new ArrayList(); + + public synchronized void addWindowListener(WindowListener l) { + if(l == null) { + return; + } + ArrayList newWindowListeners = (ArrayList) windowListeners.clone(); + newWindowListeners.add(l); + windowListeners = newWindowListeners; + } + + public synchronized void removeWindowListener(WindowListener l) { + if (l == null) { + return; + } + ArrayList newWindowListeners = (ArrayList) windowListeners.clone(); + newWindowListeners.remove(l); + windowListeners = newWindowListeners; + } + + public synchronized WindowListener[] getWindowListeners() { + return (WindowListener[]) windowListeners.toArray(); + } + + protected void sendWindowEvent(int eventType) { + WindowEvent e = new WindowEvent(true, eventType, this, System.currentTimeMillis()); + if(DEBUG_WINDOW_EVENT) { + System.out.println("sendWindowEvent: "+e); + } + ArrayList listeners = null; + synchronized(this) { + listeners = windowListeners; + } + for(Iterator i = listeners.iterator(); i.hasNext(); ) { + WindowListener l = (WindowListener) i.next(); + switch(eventType) { + case WindowEvent.EVENT_WINDOW_RESIZED: + l.windowResized(e); + break; + case WindowEvent.EVENT_WINDOW_MOVED: + l.windowMoved(e); + break; + default: + throw new RuntimeException("Unexpected window event type " + e.getEventType()); + } + } + } +} |