66 */
67 public class AWTKeyStroke implements Serializable {
68 static final long serialVersionUID = -6430539691155161871L;
69
70 private static Map<String, Integer> modifierKeywords;
71 /**
72 * Associates VK_XXX (as a String) with code (as Integer). This is
73 * done to avoid the overhead of the reflective call to find the
74 * constant.
75 */
76 private static VKCollection vks;
77
78 //A key for the collection of AWTKeyStrokes within AppContext.
79 private static Object APP_CONTEXT_CACHE_KEY = new Object();
80 //A key withing the cache
81 private static AWTKeyStroke APP_CONTEXT_KEYSTROKE_KEY = new AWTKeyStroke();
82
83 /*
84 * Reads keystroke class from AppContext and if null, puts there the
85 * AWTKeyStroke class.
86 * Must be called under locked AWTKeyStro
87 */
88 private static Class<AWTKeyStroke> getAWTKeyStrokeClass() {
89 @SuppressWarnings("unchecked")
90 Class<AWTKeyStroke> clazz = (Class<AWTKeyStroke>)AppContext.getAppContext().get(AWTKeyStroke.class);
91 if (clazz == null) {
92 clazz = AWTKeyStroke.class;
93 AppContext.getAppContext().put(AWTKeyStroke.class, AWTKeyStroke.class);
94 }
95 return clazz;
96 }
97
98 private char keyChar = KeyEvent.CHAR_UNDEFINED;
99 private int keyCode = KeyEvent.VK_UNDEFINED;
100 private int modifiers;
101 private boolean onKeyRelease;
102
103 static {
104 /* ensure that the necessary native libraries are loaded */
105 Toolkit.loadLibraries();
106 }
208 }
209 } catch (NoSuchMethodError e) {
210 throw new IllegalArgumentException(couldNotInstantiate);
211 } catch (ExceptionInInitializerError e) {
212 throw new IllegalArgumentException(couldNotInstantiate);
213 } catch (InstantiationException e) {
214 throw new IllegalArgumentException(couldNotInstantiate);
215 } catch (IllegalAccessException e) {
216 throw new IllegalArgumentException(couldNotInstantiate);
217 } catch (InvocationTargetException e) {
218 throw new IllegalArgumentException(couldNotInstantiate);
219 }
220
221 synchronized (AWTKeyStroke.class) {
222 AppContext.getAppContext().put(AWTKeyStroke.class, subclass);
223 AppContext.getAppContext().remove(APP_CONTEXT_CACHE_KEY);
224 AppContext.getAppContext().remove(APP_CONTEXT_KEYSTROKE_KEY);
225 }
226 }
227
228 /* returns noarg Constructor for class with accessible flag. No security
229 threat as accessible flag is set only for this Constructor object,
230 not for Class constructor.
231 */
232 private static Constructor<?> getCtor(final Class<?> clazz)
233 {
234 Constructor<?> ctor = AccessController.doPrivileged(new PrivilegedAction<Constructor<?>>() {
235 public Constructor<?> run() {
236 try {
237 Constructor<?> ctor = clazz.getDeclaredConstructor((Class<?>[]) null);
238 if (ctor != null) {
239 ctor.setAccessible(true);
240 }
241 return ctor;
242 } catch (SecurityException e) {
243 } catch (NoSuchMethodException e) {
244 }
245 return null;
246 }
247 });
248 return ctor;
|
66 */
67 public class AWTKeyStroke implements Serializable {
68 static final long serialVersionUID = -6430539691155161871L;
69
70 private static Map<String, Integer> modifierKeywords;
71 /**
72 * Associates VK_XXX (as a String) with code (as Integer). This is
73 * done to avoid the overhead of the reflective call to find the
74 * constant.
75 */
76 private static VKCollection vks;
77
78 //A key for the collection of AWTKeyStrokes within AppContext.
79 private static Object APP_CONTEXT_CACHE_KEY = new Object();
80 //A key withing the cache
81 private static AWTKeyStroke APP_CONTEXT_KEYSTROKE_KEY = new AWTKeyStroke();
82
83 /*
84 * Reads keystroke class from AppContext and if null, puts there the
85 * AWTKeyStroke class.
86 * Must be called under locked AWTKeyStroke
87 */
88 private static Class<AWTKeyStroke> getAWTKeyStrokeClass() {
89 @SuppressWarnings("unchecked")
90 Class<AWTKeyStroke> clazz = (Class<AWTKeyStroke>)AppContext.getAppContext().get(AWTKeyStroke.class);
91 if (clazz == null) {
92 clazz = AWTKeyStroke.class;
93 AppContext.getAppContext().put(AWTKeyStroke.class, AWTKeyStroke.class);
94 }
95 return clazz;
96 }
97
98 private char keyChar = KeyEvent.CHAR_UNDEFINED;
99 private int keyCode = KeyEvent.VK_UNDEFINED;
100 private int modifiers;
101 private boolean onKeyRelease;
102
103 static {
104 /* ensure that the necessary native libraries are loaded */
105 Toolkit.loadLibraries();
106 }
208 }
209 } catch (NoSuchMethodError e) {
210 throw new IllegalArgumentException(couldNotInstantiate);
211 } catch (ExceptionInInitializerError e) {
212 throw new IllegalArgumentException(couldNotInstantiate);
213 } catch (InstantiationException e) {
214 throw new IllegalArgumentException(couldNotInstantiate);
215 } catch (IllegalAccessException e) {
216 throw new IllegalArgumentException(couldNotInstantiate);
217 } catch (InvocationTargetException e) {
218 throw new IllegalArgumentException(couldNotInstantiate);
219 }
220
221 synchronized (AWTKeyStroke.class) {
222 AppContext.getAppContext().put(AWTKeyStroke.class, subclass);
223 AppContext.getAppContext().remove(APP_CONTEXT_CACHE_KEY);
224 AppContext.getAppContext().remove(APP_CONTEXT_KEYSTROKE_KEY);
225 }
226 }
227
228 /* returns no-arg Constructor for class with accessible flag. No security
229 threat as accessible flag is set only for this Constructor object,
230 not for Class constructor.
231 */
232 private static Constructor<?> getCtor(final Class<?> clazz)
233 {
234 Constructor<?> ctor = AccessController.doPrivileged(new PrivilegedAction<Constructor<?>>() {
235 public Constructor<?> run() {
236 try {
237 Constructor<?> ctor = clazz.getDeclaredConstructor((Class<?>[]) null);
238 if (ctor != null) {
239 ctor.setAccessible(true);
240 }
241 return ctor;
242 } catch (SecurityException e) {
243 } catch (NoSuchMethodException e) {
244 }
245 return null;
246 }
247 });
248 return ctor;
|