mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-21 19:08:31 +00:00
8030052: Remove reflection from JOptionPane
Reviewed-by: serb, pchelko
This commit is contained in:
parent
282ac72515
commit
a9d59730a6
@ -263,6 +263,16 @@ public class Container extends Component {
|
||||
boolean ignoreEnabled) {
|
||||
return cont.findComponentAt(x, y, ignoreEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startLWModal(Container cont) {
|
||||
cont.startLWModal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopLWModal(Container cont) {
|
||||
cont.stopLWModal();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -56,6 +56,7 @@ import javax.swing.event.InternalFrameEvent;
|
||||
import javax.swing.event.InternalFrameAdapter;
|
||||
import javax.accessibility.*;
|
||||
import static javax.swing.ClientPropertyKey.PopupFactory_FORCE_HEAVYWEIGHT_POPUP;
|
||||
import sun.awt.AWTAccessor;
|
||||
|
||||
/**
|
||||
* <code>JOptionPane</code> makes it easy to pop up a standard dialog box that
|
||||
@ -1306,17 +1307,7 @@ public class JOptionPane extends JComponent implements Accessible
|
||||
}
|
||||
}
|
||||
|
||||
// Use reflection to get Container.startLWModal.
|
||||
try {
|
||||
Method method = AccessController.doPrivileged(new ModalPrivilegedAction(
|
||||
Container.class, "startLWModal"));
|
||||
if (method != null) {
|
||||
method.invoke(dialog, (Object[])null);
|
||||
}
|
||||
} catch (IllegalAccessException ex) {
|
||||
} catch (IllegalArgumentException ex) {
|
||||
} catch (InvocationTargetException ex) {
|
||||
}
|
||||
AWTAccessor.getContainerAccessor().startLWModal(dialog);
|
||||
|
||||
if (parentComponent instanceof JInternalFrame) {
|
||||
try {
|
||||
@ -1451,17 +1442,7 @@ public class JOptionPane extends JComponent implements Accessible
|
||||
}
|
||||
}
|
||||
|
||||
// Use reflection to get Container.startLWModal.
|
||||
try {
|
||||
Method method = AccessController.doPrivileged(new ModalPrivilegedAction(
|
||||
Container.class, "startLWModal"));
|
||||
if (method != null) {
|
||||
method.invoke(dialog, (Object[])null);
|
||||
}
|
||||
} catch (IllegalAccessException ex) {
|
||||
} catch (IllegalArgumentException ex) {
|
||||
} catch (InvocationTargetException ex) {
|
||||
}
|
||||
AWTAccessor.getContainerAccessor().startLWModal(dialog);
|
||||
|
||||
if (parentComponent instanceof JInternalFrame) {
|
||||
try {
|
||||
@ -1535,18 +1516,7 @@ public class JOptionPane extends JComponent implements Accessible
|
||||
if (iFrame.isVisible() &&
|
||||
event.getSource() == JOptionPane.this &&
|
||||
event.getPropertyName().equals(VALUE_PROPERTY)) {
|
||||
// Use reflection to get Container.stopLWModal().
|
||||
try {
|
||||
Method method = AccessController.doPrivileged(
|
||||
new ModalPrivilegedAction(
|
||||
Container.class, "stopLWModal"));
|
||||
if (method != null) {
|
||||
method.invoke(iFrame, (Object[])null);
|
||||
}
|
||||
} catch (IllegalAccessException ex) {
|
||||
} catch (IllegalArgumentException ex) {
|
||||
} catch (InvocationTargetException ex) {
|
||||
}
|
||||
AWTAccessor.getContainerAccessor().stopLWModal(iFrame);
|
||||
|
||||
try {
|
||||
iFrame.setClosed(true);
|
||||
@ -2512,33 +2482,6 @@ public class JOptionPane extends JComponent implements Accessible
|
||||
",wantsInput=" + wantsInputString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a method from the provided class and makes it accessible.
|
||||
*/
|
||||
private static class ModalPrivilegedAction implements PrivilegedAction<Method> {
|
||||
private Class<?> clazz;
|
||||
private String methodName;
|
||||
|
||||
public ModalPrivilegedAction(Class<?> clazz, String methodName) {
|
||||
this.clazz = clazz;
|
||||
this.methodName = methodName;
|
||||
}
|
||||
|
||||
public Method run() {
|
||||
Method method = null;
|
||||
try {
|
||||
method = clazz.getDeclaredMethod(methodName, (Class[])null);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
}
|
||||
if (method != null) {
|
||||
method.setAccessible(true);
|
||||
}
|
||||
return method;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////
|
||||
// Accessibility support
|
||||
///////////////////
|
||||
|
||||
@ -272,6 +272,16 @@ public final class AWTAccessor {
|
||||
* bypasses disabled Components during the search.
|
||||
*/
|
||||
Component findComponentAt(Container cont, int x, int y, boolean ignoreEnabled);
|
||||
|
||||
/**
|
||||
* Starts LW Modal.
|
||||
*/
|
||||
void startLWModal(Container cont);
|
||||
|
||||
/**
|
||||
* Starts LW Modal.
|
||||
*/
|
||||
void stopLWModal(Container cont);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user