jdk/src/macosx/native/sun/awt/LWCToolkit.m
changeset 23681 2044c9d2b681
parent 23651 e41298d0da2f
child 23893 1a92335b55bb
child 24169 4efa892f600b
--- a/jdk/src/macosx/native/sun/awt/LWCToolkit.m	Thu Mar 20 12:10:53 2014 +0400
+++ b/jdk/src/macosx/native/sun/awt/LWCToolkit.m	Thu Mar 20 16:58:58 2014 +0400
@@ -82,6 +82,39 @@
 
 @end
 
+@interface JavaRunnable : NSObject { }
+@property jobject runnable;
+- (id)initWithRunnable:(jobject)gRunnable;
+- (void)perform;
+@end
+
+@implementation JavaRunnable
+@synthesize runnable = _runnable;
+
+- (id)initWithRunnable:(jobject)gRunnable {
+    if (self = [super init]) {
+        self.runnable = gRunnable;
+    }
+    return self;
+}
+
+- (void)dealloc {
+    JNIEnv *env = [ThreadUtilities getJNIEnv];
+    if (self.runnable) {
+        (*env)->DeleteGlobalRef(env, self.runnable);
+    }
+    [super dealloc];
+}
+
+- (void)perform {
+    JNIEnv* env = [ThreadUtilities getJNIEnv];
+    static JNF_CLASS_CACHE(sjc_Runnable, "java/lang/Runnable");
+    static JNF_MEMBER_CACHE(jm_Runnable_run, sjc_Runnable, "run", "()V");
+    JNFCallVoidMethod(env, self.runnable, jm_Runnable_run);
+    [self release];
+}
+@end
+
 /*
  * Class:     sun_lwawt_macosx_LWCToolkit
  * Method:    nativeSyncQueue
@@ -359,6 +392,25 @@
 
 /*
  * Class:     sun_lwawt_macosx_LWCToolkit
+ * Method:    performOnMainThreadAfterDelay
+ * Signature: (Ljava/lang/Runnable;J)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_performOnMainThreadAfterDelay
+(JNIEnv *env, jclass clz, jobject runnable, jlong delay)
+{
+JNF_COCOA_ENTER(env);
+    jobject gRunnable = (*env)->NewGlobalRef(env, runnable);
+    CHECK_NULL(gRunnable);
+    [ThreadUtilities performOnMainThreadWaiting:NO block:^() {
+        JavaRunnable* performer = [[JavaRunnable alloc] initWithRunnable:gRunnable];
+        [performer performSelector:@selector(perform) withObject:nil afterDelay:(delay/1000.0)];
+    }];
+JNF_COCOA_EXIT(env);
+}
+
+
+/*
+ * Class:     sun_lwawt_macosx_LWCToolkit
  * Method:    isCapsLockOn
  * Signature: ()Z
  */
@@ -433,4 +485,3 @@
 {
 
 }
-