From ccb7213cdcef177eabf7538b7c0d1c3e34915640 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 6 Nov 2011 02:41:25 +0100 Subject: NativeWindow/JOGL: NativeSurface adds add/remove SurfaceUpdateListener - SurfaceUpdateHelper contains impl. used by NativeSurface implementations. --- src/newt/classes/jogamp/newt/WindowImpl.java | 65 +++++----------------------- 1 file changed, 12 insertions(+), 53 deletions(-) (limited to 'src/newt/classes/jogamp') diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 7df326e8e..aadb89679 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -72,6 +72,8 @@ import javax.media.nativewindow.util.InsetsImmutable; import javax.media.nativewindow.util.Point; import javax.media.nativewindow.util.Rectangle; +import jogamp.nativewindow.SurfaceUpdatedHelper; + public abstract class WindowImpl implements Window, NEWTEventConsumer { public static final boolean DEBUG_TEST_REPARENT_INCOMPATIBLE = Debug.isPropertyDefined("newt.test.Window.reparent.incompatible", true); @@ -109,9 +111,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer private RequestFocusAction requestFocusAction = new RequestFocusAction(); private FocusRunnable focusAction = null; - private Object surfaceUpdatedListenersLock = new Object(); - private ArrayList surfaceUpdatedListeners = new ArrayList(); - + private SurfaceUpdatedHelper surfaceUpdatedHelper = new SurfaceUpdatedHelper(); + private Object childWindowsLock = new Object(); private ArrayList childWindows = new ArrayList(); @@ -1487,9 +1488,9 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer "\n, WrappedWindow "+getWrappedWindow()+ "\n, ChildWindows "+childWindows.size()); - sb.append(", SurfaceUpdatedListeners num "+surfaceUpdatedListeners.size()+" ["); - for (int i = 0; i < surfaceUpdatedListeners.size(); i++ ) { - sb.append(surfaceUpdatedListeners.get(i)+", "); + sb.append(", SurfaceUpdatedListeners num "+surfaceUpdatedHelper.size()+" ["); + for (int i = 0; i < surfaceUpdatedHelper.size(); i++ ) { + sb.append(surfaceUpdatedHelper.get(i)+", "); } sb.append("], WindowListeners num "+windowListeners.size()+" ["); for (int i = 0; i < windowListeners.size(); i++ ) { @@ -1824,62 +1825,20 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer // // SurfaceUpdatedListener Support // - public void addSurfaceUpdatedListener(SurfaceUpdatedListener l) { - addSurfaceUpdatedListener(-1, l); + surfaceUpdatedHelper.addSurfaceUpdatedListener(l); } - public void addSurfaceUpdatedListener(int index, SurfaceUpdatedListener l) - throws IndexOutOfBoundsException - { - if(l == null) { - return; - } - synchronized(surfaceUpdatedListenersLock) { - if(0>index) { - index = surfaceUpdatedListeners.size(); - } - surfaceUpdatedListeners.add(index, l); - } + public void addSurfaceUpdatedListener(int index, SurfaceUpdatedListener l) throws IndexOutOfBoundsException { + surfaceUpdatedHelper.addSurfaceUpdatedListener(index, l); } public void removeSurfaceUpdatedListener(SurfaceUpdatedListener l) { - if (l == null) { - return; - } - synchronized(surfaceUpdatedListenersLock) { - surfaceUpdatedListeners.remove(l); - } - } - - public void removeAllSurfaceUpdatedListener() { - synchronized(surfaceUpdatedListenersLock) { - surfaceUpdatedListeners = new ArrayList(); - } - } - - public SurfaceUpdatedListener getSurfaceUpdatedListener(int index) { - synchronized(surfaceUpdatedListenersLock) { - if(0>index) { - index = surfaceUpdatedListeners.size()-1; - } - return surfaceUpdatedListeners.get(index); - } - } - - public SurfaceUpdatedListener[] getSurfaceUpdatedListeners() { - synchronized(surfaceUpdatedListenersLock) { - return (SurfaceUpdatedListener[]) surfaceUpdatedListeners.toArray(); - } + surfaceUpdatedHelper.removeSurfaceUpdatedListener(l); } public void surfaceUpdated(Object updater, NativeSurface ns, long when) { - synchronized(surfaceUpdatedListenersLock) { - for(int i = 0; i < surfaceUpdatedListeners.size(); i++ ) { - SurfaceUpdatedListener l = surfaceUpdatedListeners.get(i); - l.surfaceUpdated(updater, ns, when); - } - } + surfaceUpdatedHelper.surfaceUpdated(updater, ns, when); } // -- cgit v1.2.3