mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-20 02:17:53 +00:00
8029960: Remove reflection from Swing classes
Reviewed-by: serb, pchelko
This commit is contained in:
parent
57f20fcdc9
commit
d9b649e6cb
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -976,6 +976,17 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
||||
public void revalidateSynchronously(Component comp) {
|
||||
comp.revalidateSynchronously();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createBufferStrategy(Component comp, int numBuffers,
|
||||
BufferCapabilities caps) throws AWTException {
|
||||
comp.createBufferStrategy(numBuffers, caps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferStrategy getBufferStrategy(Component comp) {
|
||||
return comp.getBufferStrategy();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -298,6 +298,10 @@ public abstract class InputEvent extends ComponentEvent {
|
||||
public int[] getButtonDownMasks() {
|
||||
return InputEvent.getButtonDownMasks();
|
||||
}
|
||||
|
||||
public boolean canAccessSystemClipboard(InputEvent event) {
|
||||
return event.canAccessSystemClipboard;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -32,6 +32,9 @@ import java.lang.ref.WeakReference;
|
||||
import java.util.*;
|
||||
|
||||
import com.sun.java.swing.SwingUtilities3;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import sun.awt.AWTAccessor;
|
||||
|
||||
import sun.awt.SubRegionShowable;
|
||||
import sun.java2d.SunGraphics2D;
|
||||
@ -69,12 +72,6 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager {
|
||||
// if we get a blit strategy.
|
||||
//
|
||||
|
||||
//
|
||||
// Methods used to create BufferStrategy for Applets.
|
||||
//
|
||||
private static Method COMPONENT_CREATE_BUFFER_STRATEGY_METHOD;
|
||||
private static Method COMPONENT_GET_BUFFER_STRATEGY_METHOD;
|
||||
|
||||
private static final PlatformLogger LOGGER = PlatformLogger.getLogger(
|
||||
"javax.swing.BufferStrategyPaintManager");
|
||||
|
||||
@ -143,44 +140,6 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager {
|
||||
*/
|
||||
private boolean disposeBufferOnEnd;
|
||||
|
||||
private static Method getGetBufferStrategyMethod() {
|
||||
if (COMPONENT_GET_BUFFER_STRATEGY_METHOD == null) {
|
||||
getMethods();
|
||||
}
|
||||
return COMPONENT_GET_BUFFER_STRATEGY_METHOD;
|
||||
}
|
||||
|
||||
private static Method getCreateBufferStrategyMethod() {
|
||||
if (COMPONENT_CREATE_BUFFER_STRATEGY_METHOD == null) {
|
||||
getMethods();
|
||||
}
|
||||
return COMPONENT_CREATE_BUFFER_STRATEGY_METHOD;
|
||||
}
|
||||
|
||||
private static void getMethods() {
|
||||
java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
try {
|
||||
COMPONENT_CREATE_BUFFER_STRATEGY_METHOD = Component.class.
|
||||
getDeclaredMethod("createBufferStrategy",
|
||||
new Class[] { int.class,
|
||||
BufferCapabilities.class });
|
||||
COMPONENT_CREATE_BUFFER_STRATEGY_METHOD.
|
||||
setAccessible(true);
|
||||
COMPONENT_GET_BUFFER_STRATEGY_METHOD = Component.class.
|
||||
getDeclaredMethod("getBufferStrategy");
|
||||
COMPONENT_GET_BUFFER_STRATEGY_METHOD.setAccessible(true);
|
||||
} catch (SecurityException e) {
|
||||
assert false;
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
assert false;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
BufferStrategyPaintManager() {
|
||||
bufferInfos = new ArrayList<BufferInfo>(1);
|
||||
}
|
||||
@ -766,16 +725,7 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager {
|
||||
componentBS = ((Window)root).getBufferStrategy();
|
||||
}
|
||||
else {
|
||||
try {
|
||||
componentBS = (BufferStrategy)
|
||||
getGetBufferStrategyMethod().invoke(root);
|
||||
} catch (InvocationTargetException ite) {
|
||||
assert false;
|
||||
} catch (IllegalArgumentException iae) {
|
||||
assert false;
|
||||
} catch (IllegalAccessException iae2) {
|
||||
assert false;
|
||||
}
|
||||
componentBS = AWTAccessor.getComponentAccessor().getBufferStrategy(root);
|
||||
}
|
||||
if (componentBS != ourBS) {
|
||||
// Component has a different BS, dispose ours.
|
||||
@ -839,19 +789,16 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager {
|
||||
BufferStrategy bs = null;
|
||||
if (SunToolkit.isInstanceOf(root, "java.applet.Applet")) {
|
||||
try {
|
||||
getCreateBufferStrategyMethod().invoke(root, 2, caps);
|
||||
bs = (BufferStrategy)getGetBufferStrategyMethod().
|
||||
invoke(root);
|
||||
} catch (InvocationTargetException ite) {
|
||||
AWTAccessor.ComponentAccessor componentAccessor
|
||||
= AWTAccessor.getComponentAccessor();
|
||||
componentAccessor.createBufferStrategy(root, 2, caps);
|
||||
bs = componentAccessor.getBufferStrategy(root);
|
||||
} catch (AWTException e) {
|
||||
// Type is not supported
|
||||
if (LOGGER.isLoggable(PlatformLogger.Level.FINER)) {
|
||||
LOGGER.finer("createBufferStratety failed",
|
||||
ite);
|
||||
e);
|
||||
}
|
||||
} catch (IllegalArgumentException iae) {
|
||||
assert false;
|
||||
} catch (IllegalAccessException iae2) {
|
||||
assert false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@ -34,6 +34,7 @@ import java.awt.event.InputEvent;
|
||||
import java.awt.event.InvocationEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.image.BufferStrategy;
|
||||
import java.awt.peer.ComponentPeer;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -243,6 +244,16 @@ public final class AWTAccessor {
|
||||
*/
|
||||
void revalidateSynchronously(Component comp);
|
||||
|
||||
/**
|
||||
* Creates a new strategy for multi-buffering on this component.
|
||||
*/
|
||||
void createBufferStrategy(Component comp, int numBuffers,
|
||||
BufferCapabilities caps) throws AWTException;
|
||||
|
||||
/**
|
||||
* returns the buffer strategy used by this component.
|
||||
*/
|
||||
BufferStrategy getBufferStrategy(Component comp);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -375,6 +386,11 @@ public final class AWTAccessor {
|
||||
* Accessor for InputEvent.getButtonDownMasks()
|
||||
*/
|
||||
int[] getButtonDownMasks();
|
||||
|
||||
/*
|
||||
* Accessor for InputEvent.canAccessSystemClipboard field
|
||||
*/
|
||||
boolean canAccessSystemClipboard(InputEvent event);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -189,7 +189,6 @@ public class SwingUtilities2 {
|
||||
new StringUIClientPropertyKey ("maxTextOffset");
|
||||
|
||||
// security stuff
|
||||
private static Field inputEvent_CanAccessSystemClipboard_Field = null;
|
||||
private static final String UntrustedClipboardAccess =
|
||||
"UNTRUSTED_CLIPBOARD_ACCESS_KEY";
|
||||
|
||||
@ -1262,41 +1261,6 @@ public class SwingUtilities2 {
|
||||
|| canEventAccessSystemClipboard(e, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns canAccessSystemClipboard field from InputEvent
|
||||
*
|
||||
* @param ie InputEvent to get the field from
|
||||
*/
|
||||
private static synchronized boolean inputEvent_canAccessSystemClipboard(InputEvent ie) {
|
||||
if (inputEvent_CanAccessSystemClipboard_Field == null) {
|
||||
inputEvent_CanAccessSystemClipboard_Field =
|
||||
AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction<Field>() {
|
||||
public Field run() {
|
||||
try {
|
||||
Field field = InputEvent.class.
|
||||
getDeclaredField("canAccessSystemClipboard");
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (SecurityException e) {
|
||||
} catch (NoSuchFieldException e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (inputEvent_CanAccessSystemClipboard_Field == null) {
|
||||
return false;
|
||||
}
|
||||
boolean ret = false;
|
||||
try {
|
||||
ret = inputEvent_CanAccessSystemClipboard_Field.
|
||||
getBoolean(ie);
|
||||
} catch(IllegalAccessException e) {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given event is corrent gesture for
|
||||
* accessing clipboard
|
||||
@ -1350,7 +1314,8 @@ public class SwingUtilities2 {
|
||||
*/
|
||||
if (e instanceof InputEvent
|
||||
&& (! checkGesture || isAccessClipboardGesture((InputEvent)e))) {
|
||||
return inputEvent_canAccessSystemClipboard((InputEvent)e);
|
||||
return AWTAccessor.getInputEventAccessor().
|
||||
canAccessSystemClipboard((InputEvent) e);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user