--- old/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java 2012-04-26 19:48:59.000000000 +0400 +++ new/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java 2012-04-26 19:48:58.000000000 +0400 @@ -27,9 +27,9 @@ import sun.awt.datatransfer.ToolkitThreadBlockedHandler; -// TODO:BG this class is really a NOOP right now, but should be filled in if needed. - final class CToolkitThreadBlockedHandler implements ToolkitThreadBlockedHandler { + private final LWCToolkit toolkit = (LWCToolkit)java.awt.Toolkit.getDefaultToolkit(); + public void lock() { } @@ -41,9 +41,10 @@ } public void enter() { + toolkit.startNativeEventLoop(); } public void exit() { + toolkit.stopNativeEventLoop(); } - } --- old/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java 2012-04-26 19:49:01.000000000 +0400 +++ new/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java 2012-04-26 19:49:01.000000000 +0400 @@ -63,6 +63,10 @@ private static native void initIDs(); + static native void startNativeEventLoop(); + + static native void stopNativeEventLoop(); + private static CInputMethodDescriptor sInputMethodDescriptor; static { --- old/src/macosx/native/sun/awt/LWCToolkit.m 2012-04-26 19:49:05.000000000 +0400 +++ new/src/macosx/native/sun/awt/LWCToolkit.m 2012-04-26 19:49:04.000000000 +0400 @@ -42,6 +42,7 @@ @implementation AWTToolkit static long eventCount; +static bool shouldKeepRunningNestedLoop = NO; + (long) getEventCount{ return eventCount; @@ -456,3 +457,36 @@ { } + +/* + * Class: sun_lwawt_macosx_LWCToolkit + * Method: startNativeEventLoop + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_startNativeEventLoop +(JNIEnv *env, jclass cls) +{ + if(!shouldKeepRunningNestedLoop) { + NSRunLoop *theRL = [NSRunLoop currentRunLoop]; + NSApplication * app = [NSApplication sharedApplication]; + shouldKeepRunningNestedLoop = YES; + while (shouldKeepRunningNestedLoop && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]) + { + NSEvent * event = [app nextEventMatchingMask: 0xFFFFFFFF untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES]; + if (event != nil) { + [app sendEvent: event]; + } + } + } +} + +/* + * Class: sun_lwawt_macosx_LWCToolkit + * Method: stopNativeEventLoop + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_stopNativeEventLoop +(JNIEnv *env, jclass cls) +{ + shouldKeepRunningNestedLoop = NO; +}