diff options
author | Michael Bien <[email protected]> | 2010-06-02 14:54:13 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-06-02 14:54:13 +0200 |
commit | 51abf405624f4f9bd3031842fac858f77671b838 (patch) | |
tree | 6daa72408b17f18794dc0791d77dbea05d1259e0 /src | |
parent | 1c4dadcc23b3920b0c612254af361da370d86cb8 (diff) | |
parent | 42dbcf2a74eb91d4a165f815429c121c4beb0501 (diff) |
Merge branch 'master' of github.com:sgothel/jogl
Diffstat (limited to 'src')
-rwxr-xr-x | src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java | 45 | ||||
-rwxr-xr-x | src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java | 2 |
2 files changed, 36 insertions, 11 deletions
diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java index 9b9dca2e4..861dc7a6c 100755 --- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java +++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java @@ -35,6 +35,7 @@ package com.jogamp.newt.impl.macosx; import javax.media.nativewindow.*; import javax.media.nativewindow.macosx.*; +import com.jogamp.common.util.ReflectionUtil; import com.jogamp.newt.*; import com.jogamp.newt.impl.*; import com.jogamp.newt.util.MainThread; @@ -67,16 +68,7 @@ public class MacDisplay extends Display { private DispatchAction dispatchAction = new DispatchAction(); protected void dispatchMessagesNative() { - if (false && MainThread.isRunning()) { - MainThread.invoke(false, dispatchAction); - } else { - try { - java.awt.EventQueue.invokeLater(dispatchAction); - // java.awt.EventQueue.invokeAndWait(dispatchAction); - } catch (Exception ie) { - ie.printStackTrace(); - } - } + runOnMainThread(false, dispatchAction); } protected void createNative() { @@ -91,6 +83,39 @@ public class MacDisplay extends Display { public EDTUtil getEDTUtil() { return null; }*/ + + protected static void runOnMainThread(boolean wait, Runnable r) { + if (MainThread.isRunning()) { + MainThread.invoke(wait, r); + } else if(!runOnAWTEDT(wait, r)) { + throw new NativeWindowException("Neither MainThread is running nor AWT EDT available"); + } + } + + protected static boolean runOnAWTEDT(boolean wait, Runnable r) { + if(ReflectionUtil.isClassAvailable("java.awt.EventQueue")) { + try { + if(wait) { + ReflectionUtil.callStaticMethod( + "java.awt.EventQueue", + "invokeAndWait", + new Class[] { java.lang.Runnable.class }, + new Object[] { r } ); + } else { + ReflectionUtil.callStaticMethod( + "java.awt.EventQueue", + "invokeLater", + new Class[] { java.lang.Runnable.class }, + new Object[] { r } ); + } + } catch (Exception e) { + throw new NativeWindowException(e); + } + return true; + } + return false; + } + private static native boolean initNSApplication0(); protected native void dispatchMessages0(); } diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java index c45a30bc7..b6328b02f 100755 --- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java @@ -450,7 +450,7 @@ public class MacWindow extends Window { } try { - java.awt.EventQueue.invokeAndWait(new Runnable() { + MacDisplay.runOnMainThread(true, new Runnable() { public void run() { if(0!=windowHandle) { // save the view .. close the window |