< prev index next >
test/jdk/java/awt/Window/MainKeyWindowTest/libTestMainKeyWindow.m
Print this page
rev 54093 : 8257858: [macOS]: Remove JNF dependency from libosxsecurity/KeystoreImpl.m
8257860: [macOS]: Remove JNF dependency from libosxkrb5/SCDynamicStoreConfig.m
rev 54098 : 8260616: Removing remaining JNF dependencies in the java.desktop module
8259729: Missed JNFInstanceOf -> IsInstanceOf conversion
*** 22,44 ****
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#import <Cocoa/Cocoa.h>
! #import <JavaNativeFoundation/JavaNativeFoundation.h>
static NSWindow *testWindow;
static NSColorPanel *colorPanel;
/*
* Class: TestMainKeyWindow
* Method: setup
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_TestMainKeyWindow_setup(JNIEnv *env, jclass cl)
{
! JNF_COCOA_ENTER(env);
void (^block)() = ^(){
NSScreen *mainScreen = [NSScreen mainScreen];
NSRect screenFrame = [mainScreen frame];
NSRect frame = NSMakeRect(130, screenFrame.size.height - 280, 200, 100);
--- 22,78 ----
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#import <Cocoa/Cocoa.h>
! #import <jni_util.h>
static NSWindow *testWindow;
static NSColorPanel *colorPanel;
+ #define JNI_COCOA_ENTER(env) \
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \
+ @try {
+
+ #define JNI_COCOA_EXIT(env) \
+ } \
+ @catch (NSException *e) { \
+ NSLog(@"%@", [e callStackSymbols]); \
+ } \
+ @finally { \
+ [pool drain]; \
+ };
+
+ /*
+ * Pass the block to a selector of a class that extends NSObject
+ * There is no need to copy the block since this class always waits.
+ */
+ @interface BlockRunner : NSObject { }
+
+ + (void)invokeBlock:(void (^)())block;
+ @end
+
+ @implementation BlockRunner
+
+ + (void)invokeBlock:(void (^)())block{
+ block();
+ }
+
+ + (void)performBlock:(void (^)())block {
+ [self performSelectorOnMainThread:@selector(invokeBlock:) withObject:block waitUntilDone:YES];
+ }
+
+ @end
+
/*
* Class: TestMainKeyWindow
* Method: setup
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_TestMainKeyWindow_setup(JNIEnv *env, jclass cl)
{
! JNI_COCOA_ENTER(env);
void (^block)() = ^(){
NSScreen *mainScreen = [NSScreen mainScreen];
NSRect screenFrame = [mainScreen frame];
NSRect frame = NSMakeRect(130, screenFrame.size.height - 280, 200, 100);
*** 66,89 ****
};
if ([NSThread isMainThread]) {
block();
} else {
! [JNFRunLoop performOnMainThreadWaiting:YES withBlock:block];
}
! JNF_COCOA_EXIT(env);
}
/*
* Class: TestMainKeyWindow
* Method: takedown
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_TestMainKeyWindow_takedown(JNIEnv *env, jclass cl)
{
! JNF_COCOA_ENTER(env);
void (^block)() = ^(){
if (testWindow != nil) {
[testWindow close];
testWindow = nil;
--- 100,123 ----
};
if ([NSThread isMainThread]) {
block();
} else {
! [BlockRunner performBlock:block];
}
! JNI_COCOA_EXIT(env);
}
/*
* Class: TestMainKeyWindow
* Method: takedown
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_TestMainKeyWindow_takedown(JNIEnv *env, jclass cl)
{
! JNI_COCOA_ENTER(env);
void (^block)() = ^(){
if (testWindow != nil) {
[testWindow close];
testWindow = nil;
*** 95,123 ****
};
if ([NSThread isMainThread]) {
block();
} else {
! [JNFRunLoop performOnMainThreadWaiting:YES withBlock:block];
}
! JNF_COCOA_EXIT(env);
}
/*
* Class: TestMainKeyWindow
* Method: activateApplication
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_TestMainKeyWindow_activateApplication
(JNIEnv *env, jclass cl)
{
! JNF_COCOA_ENTER(env);
void (^block)() = ^(){
[NSApp activateIgnoringOtherApps:YES];
};
! [JNFRunLoop performOnMainThreadWaiting:YES withBlock:block];
! JNF_COCOA_EXIT(env);
}
--- 129,157 ----
};
if ([NSThread isMainThread]) {
block();
} else {
! [BlockRunner performBlock:block];
}
! JNI_COCOA_EXIT(env);
}
/*
* Class: TestMainKeyWindow
* Method: activateApplication
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_TestMainKeyWindow_activateApplication
(JNIEnv *env, jclass cl)
{
! JNI_COCOA_ENTER(env);
void (^block)() = ^(){
[NSApp activateIgnoringOtherApps:YES];
};
! [BlockRunner performBlock:block];
! JNI_COCOA_EXIT(env);
}
< prev index next >