diff options
author | Sven Gothel <[email protected]> | 2010-06-02 14:41:11 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-06-02 14:41:11 +0200 |
commit | 42dbcf2a74eb91d4a165f815429c121c4beb0501 (patch) | |
tree | 65494f0a6ea00eec2428117a81e1bf7a99ace933 /src | |
parent | ede9386de45b63f46c206aaed27ddeafe8fe96fa (diff) |
NEWT/MacOSX: Use Reflectionutil and a common runOnMainThread method
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 |