1 /* |
1 /* |
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
33 |
33 |
34 - (id)initWithEnv:(JNIEnv *)env withAccessibleAction:(jobject)accessibleAction withIndex:(jint)index withComponent:(jobject)component |
34 - (id)initWithEnv:(JNIEnv *)env withAccessibleAction:(jobject)accessibleAction withIndex:(jint)index withComponent:(jobject)component |
35 { |
35 { |
36 self = [super init]; |
36 self = [super init]; |
37 if (self) { |
37 if (self) { |
38 fAccessibleAction = JNFNewGlobalRef(env, accessibleAction); |
38 fAccessibleAction = JNFNewWeakGlobalRef(env, accessibleAction); |
39 fIndex = index; |
39 fIndex = index; |
40 fComponent = JNFNewGlobalRef(env, component); |
40 fComponent = JNFNewWeakGlobalRef(env, component); |
41 } |
41 } |
42 return self; |
42 return self; |
43 } |
43 } |
44 |
44 |
45 - (void)dealloc |
45 - (void)dealloc |
46 { |
46 { |
47 JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; |
47 JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; |
48 |
48 |
49 JNFDeleteGlobalRef(env, fAccessibleAction); |
49 JNFDeleteWeakGlobalRef(env, fAccessibleAction); |
50 fAccessibleAction = NULL; |
50 fAccessibleAction = NULL; |
51 |
51 |
52 JNFDeleteGlobalRef(env, fComponent); |
52 JNFDeleteWeakGlobalRef(env, fComponent); |
53 fComponent = NULL; |
53 fComponent = NULL; |
54 |
54 |
55 [super dealloc]; |
55 [super dealloc]; |
56 } |
56 } |
57 |
57 |
59 { |
59 { |
60 static JNF_STATIC_MEMBER_CACHE(jm_getAccessibleActionDescription, sjc_CAccessibility, "getAccessibleActionDescription", "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)Ljava/lang/String;"); |
60 static JNF_STATIC_MEMBER_CACHE(jm_getAccessibleActionDescription, sjc_CAccessibility, "getAccessibleActionDescription", "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)Ljava/lang/String;"); |
61 |
61 |
62 JNIEnv* env = [ThreadUtilities getJNIEnv]; |
62 JNIEnv* env = [ThreadUtilities getJNIEnv]; |
63 |
63 |
64 return JNFJavaToNSString(env, JNFCallStaticObjectMethod(env, jm_getAccessibleActionDescription, fAccessibleAction, fIndex, fComponent)); // AWT_THREADING Safe (AWTRunLoopMode) |
64 jobject fCompLocal = (*env)->NewLocalRef(env, fComponent); |
|
65 if ((*env)->IsSameObject(env, fCompLocal, NULL)) { |
|
66 return @"unknown"; |
|
67 } |
|
68 NSString *str = nil; |
|
69 jobject jstr = JNFCallStaticObjectMethod(env, jm_getAccessibleActionDescription, fAccessibleAction, fIndex, fCompLocal); |
|
70 if (jstr != NULL) { |
|
71 NSString *str = JNFJavaToNSString(env, jstr); // AWT_THREADING Safe (AWTRunLoopMode) |
|
72 (*env)->DeleteLocalRef(env, jstr); |
|
73 } |
|
74 (*env)->DeleteLocalRef(env, fCompLocal); |
|
75 return str == nil ? @"unknown" : str; |
65 } |
76 } |
66 |
77 |
67 - (void)perform |
78 - (void)perform |
68 { |
79 { |
69 static JNF_STATIC_MEMBER_CACHE(jm_doAccessibleAction, sjc_CAccessibility, "doAccessibleAction", "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)V"); |
80 static JNF_STATIC_MEMBER_CACHE(jm_doAccessibleAction, sjc_CAccessibility, "doAccessibleAction", "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)V"); |
80 |
91 |
81 - (id)initWithEnv:(JNIEnv *)env withTabGroup:(jobject)tabGroup withIndex:(jint)index withComponent:(jobject)component |
92 - (id)initWithEnv:(JNIEnv *)env withTabGroup:(jobject)tabGroup withIndex:(jint)index withComponent:(jobject)component |
82 { |
93 { |
83 self = [super init]; |
94 self = [super init]; |
84 if (self) { |
95 if (self) { |
85 fTabGroup = JNFNewGlobalRef(env, tabGroup); |
96 fTabGroup = JNFNewWeakGlobalRef(env, tabGroup); |
86 fIndex = index; |
97 fIndex = index; |
87 fComponent = JNFNewGlobalRef(env, component); |
98 fComponent = JNFNewWeakGlobalRef(env, component); |
88 } |
99 } |
89 return self; |
100 return self; |
90 } |
101 } |
91 |
102 |
92 - (void)dealloc |
103 - (void)dealloc |
93 { |
104 { |
94 JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; |
105 JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; |
95 |
106 |
96 JNFDeleteGlobalRef(env, fTabGroup); |
107 JNFDeleteWeakGlobalRef(env, fTabGroup); |
97 fTabGroup = NULL; |
108 fTabGroup = NULL; |
98 |
109 |
99 JNFDeleteGlobalRef(env, fComponent); |
110 JNFDeleteWeakGlobalRef(env, fComponent); |
100 fComponent = NULL; |
111 fComponent = NULL; |
101 |
112 |
102 [super dealloc]; |
113 [super dealloc]; |
103 } |
114 } |
104 |
115 |