--- a/jdk/src/share/classes/sun/awt/SunToolkit.java Tue Jul 31 21:01:56 2012 +0400
+++ b/jdk/src/share/classes/sun/awt/SunToolkit.java Thu Aug 30 13:11:23 2012 -0700
@@ -51,14 +51,8 @@
import sun.awt.image.*;
import sun.security.action.GetPropertyAction;
import sun.security.action.GetBooleanAction;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
public abstract class SunToolkit extends Toolkit
implements WindowClosingSupport, WindowClosingListener,
@@ -80,7 +74,6 @@
*/
public static final int GRAB_EVENT_MASK = 0x80000000;
- private static Method wakeupMethod;
/* The key to put()/get() the PostEventQueue into/from the AppContext.
*/
private static final String POST_EVENT_QUEUE_KEY = "PostEventQueue";
@@ -295,52 +288,8 @@
return appContext;
}
- public static Field getField(final Class<?> klass, final String fieldName) {
- return AccessController.doPrivileged(new PrivilegedAction<Field>() {
- public Field run() {
- try {
- Field field = klass.getDeclaredField(fieldName);
- assert (field != null);
- field.setAccessible(true);
- return field;
- } catch (SecurityException e) {
- assert false;
- } catch (NoSuchFieldException e) {
- assert false;
- }
- return null;
- }//run
- });
- }
-
static void wakeupEventQueue(EventQueue q, boolean isShutdown){
- if (wakeupMethod == null){
- wakeupMethod = AccessController.doPrivileged(new PrivilegedAction<Method>() {
- public Method run() {
- try {
- Method method = EventQueue.class.getDeclaredMethod("wakeup",new Class [] {Boolean.TYPE} );
- if (method != null) {
- method.setAccessible(true);
- }
- return method;
- } catch (NoSuchMethodException e) {
- assert false;
- } catch (SecurityException e) {
- assert false;
- }
- return null;
- }//run
- });
- }
- try{
- if (wakeupMethod != null){
- wakeupMethod.invoke(q, new Object[]{Boolean.valueOf(isShutdown)});
- }
- } catch (InvocationTargetException e){
- assert false;
- } catch (IllegalAccessException e) {
- assert false;
- }
+ AWTAccessor.getEventQueueAccessor().wakeup(q, isShutdown);
}
/*
@@ -1460,22 +1409,6 @@
|| comp instanceof Window);
}
- public static Method getMethod(final Class<?> clz, final String methodName, final Class[] params) {
- Method res = null;
- try {
- res = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
- public Method run() throws Exception {
- Method m = clz.getDeclaredMethod(methodName, params);
- m.setAccessible(true);
- return m;
- }
- });
- } catch (PrivilegedActionException ex) {
- ex.printStackTrace();
- }
- return res;
- }
-
@SuppressWarnings("serial")
public static class OperationTimedOut extends RuntimeException {
public OperationTimedOut(String msg) {
@@ -1622,21 +1555,9 @@
private boolean queueEmpty = false;
private final Object waitLock = "Wait Lock";
- static Method eqNoEvents;
-
private boolean isEQEmpty() {
EventQueue queue = getSystemEventQueueImpl();
- synchronized(SunToolkit.class) {
- if (eqNoEvents == null) {
- eqNoEvents = getMethod(java.awt.EventQueue.class, "noEvents", null);
- }
- }
- try {
- return (Boolean)eqNoEvents.invoke(queue);
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
+ return AWTAccessor.getEventQueueAccessor().noEvents(queue);
}
/**
@@ -1892,20 +1813,14 @@
* consumeNextKeyTyped() method is not currently used,
* however Swing could use it in the future.
*/
- private static Method consumeNextKeyTypedMethod = null;
public static synchronized void consumeNextKeyTyped(KeyEvent keyEvent) {
- if (consumeNextKeyTypedMethod == null) {
- consumeNextKeyTypedMethod = getMethod(DefaultKeyboardFocusManager.class,
- "consumeNextKeyTyped",
- new Class<?>[] {KeyEvent.class});
- }
try {
- consumeNextKeyTypedMethod.invoke(KeyboardFocusManager.getCurrentKeyboardFocusManager(),
- keyEvent);
- } catch (IllegalAccessException iae) {
- iae.printStackTrace();
- } catch (InvocationTargetException ite) {
- ite.printStackTrace();
+ AWTAccessor.getDefaultKeyboardFocusManagerAccessor().consumeNextKeyTyped(
+ (DefaultKeyboardFocusManager)KeyboardFocusManager.
+ getCurrentKeyboardFocusManager(),
+ keyEvent);
+ } catch (ClassCastException cce) {
+ cce.printStackTrace();
}
}
@@ -1925,24 +1840,6 @@
return (Window)comp;
}
- /**
- * Returns the value of the system property indicated by the specified key.
- */
- public static String getSystemProperty(final String key) {
- return AccessController.doPrivileged(new PrivilegedAction<String>() {
- public String run() {
- return System.getProperty(key);
- }
- });
- }
-
- /**
- * Returns the boolean value of the system property indicated by the specified key.
- */
- protected static Boolean getBooleanSystemProperty(String key) {
- return AccessController.doPrivileged(new GetBooleanAction(key));
- }
-
private static Boolean sunAwtDisableMixing = null;
/**
@@ -1951,7 +1848,8 @@
*/
public synchronized static boolean getSunAwtDisableMixing() {
if (sunAwtDisableMixing == null) {
- sunAwtDisableMixing = getBooleanSystemProperty("sun.awt.disableMixing");
+ sunAwtDisableMixing = AccessController.doPrivileged(
+ new GetBooleanAction("sun.awt.disableMixing"));
}
return sunAwtDisableMixing.booleanValue();
}