提交 6322a2b0 编写于 作者: D dcherepanov

6824169: Need to remove some AWT class dependencies

Reviewed-by: art, anthony, igor, alexp
上级 f1f69f85
...@@ -32,6 +32,7 @@ import java.awt.peer.LightweightPeer; ...@@ -32,6 +32,7 @@ import java.awt.peer.LightweightPeer;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.logging.Level; import java.util.logging.Level;
import sun.awt.AWTAccessor;
/** /**
* The root event class for all AWT events. * The root event class for all AWT events.
...@@ -230,6 +231,12 @@ public abstract class AWTEvent extends EventObject { ...@@ -230,6 +231,12 @@ public abstract class AWTEvent extends EventObject {
if (!GraphicsEnvironment.isHeadless()) { if (!GraphicsEnvironment.isHeadless()) {
initIDs(); initIDs();
} }
AWTAccessor.setAWTEventAccessor(
new AWTAccessor.AWTEventAccessor() {
public void setPosted(AWTEvent ev) {
ev.isPosted = true;
}
});
} }
private static synchronized Field get_InputEvent_CanAccessSystemClipboard() { private static synchronized Field get_InputEvent_CanAccessSystemClipboard() {
......
...@@ -861,6 +861,17 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -861,6 +861,17 @@ public abstract class Component implements ImageObserver, MenuContainer,
public boolean isVisible_NoClientCode(Component comp) { public boolean isVisible_NoClientCode(Component comp) {
return comp.isVisible_NoClientCode(); return comp.isVisible_NoClientCode();
} }
public void setRequestFocusController
(RequestFocusController requestController)
{
Component.setRequestFocusController(requestController);
}
public AppContext getAppContext(Component comp) {
return comp.appContext;
}
public void setAppContext(Component comp, AppContext appContext) {
comp.appContext = appContext;
}
}); });
} }
...@@ -9824,31 +9835,6 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -9824,31 +9835,6 @@ public abstract class Component implements ImageObserver, MenuContainer,
// ****************** END OF MIXING CODE ******************************** // ****************** END OF MIXING CODE ********************************
private static boolean doesClassImplement(Class cls, String interfaceName) {
if (cls == null) return false;
for (Class c : cls.getInterfaces()) {
if (c.getName().equals(interfaceName)) {
return true;
}
}
return doesClassImplement(cls.getSuperclass(), interfaceName);
}
/**
* Checks that the given object implements the given interface.
* @param obj Object to be checked
* @param interfaceName The name of the interface. Must be fully-qualified interface name.
* @return true, if this object implements the given interface,
* false, otherwise, or if obj or interfaceName is null
*/
static boolean doesImplement(Object obj, String interfaceName) {
if (obj == null) return false;
if (interfaceName == null) return false;
return doesClassImplement(obj.getClass(), interfaceName);
}
// Note that the method is overriden in the Window class, // Note that the method is overriden in the Window class,
// a window doesn't need to be updated in the Z-order. // a window doesn't need to be updated in the Z-order.
void updateZOrder() { void updateZOrder() {
......
...@@ -262,12 +262,6 @@ public class Dialog extends Window { ...@@ -262,12 +262,6 @@ public class Dialog extends Window {
TOOLKIT_EXCLUDE TOOLKIT_EXCLUDE
}; };
/**
* @since 1.6
*/
private final static ModalExclusionType DEFAULT_MODAL_EXCLUSION_TYPE =
ModalExclusionType.APPLICATION_EXCLUDE;
/* operations with this list should be synchronized on tree lock*/ /* operations with this list should be synchronized on tree lock*/
transient static IdentityArrayList<Dialog> modalDialogs = new IdentityArrayList<Dialog>(); transient static IdentityArrayList<Dialog> modalDialogs = new IdentityArrayList<Dialog>();
......
...@@ -43,6 +43,7 @@ import sun.awt.AWTAutoShutdown; ...@@ -43,6 +43,7 @@ import sun.awt.AWTAutoShutdown;
import sun.awt.PeerEvent; import sun.awt.PeerEvent;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
import sun.awt.EventQueueItem; import sun.awt.EventQueueItem;
import sun.awt.AWTAccessor;
/** /**
* <code>EventQueue</code> is a platform-independent class * <code>EventQueue</code> is a platform-independent class
...@@ -154,6 +155,18 @@ public class EventQueue { ...@@ -154,6 +155,18 @@ public class EventQueue {
private static final Logger eventLog = Logger.getLogger("java.awt.event.EventQueue"); private static final Logger eventLog = Logger.getLogger("java.awt.event.EventQueue");
static {
AWTAccessor.setEventQueueAccessor(
new AWTAccessor.EventQueueAccessor() {
public EventQueue getNextQueue(EventQueue eventQueue) {
return eventQueue.nextQueue;
}
public Thread getDispatchThread(EventQueue eventQueue) {
return eventQueue.dispatchThread;
}
});
}
public EventQueue() { public EventQueue() {
for (int i = 0; i < NUM_PRIORITIES; i++) { for (int i = 0; i < NUM_PRIORITIES; i++) {
queues[i] = new Queue(); queues[i] = new Queue();
......
...@@ -30,6 +30,7 @@ import java.io.IOException; ...@@ -30,6 +30,7 @@ import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import sun.awt.AppContext; import sun.awt.AppContext;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
import sun.awt.AWTAccessor;
import javax.accessibility.*; import javax.accessibility.*;
/** /**
...@@ -109,6 +110,22 @@ public abstract class MenuComponent implements java.io.Serializable { ...@@ -109,6 +110,22 @@ public abstract class MenuComponent implements java.io.Serializable {
*/ */
private static final long serialVersionUID = -4536902356223894379L; private static final long serialVersionUID = -4536902356223894379L;
static {
AWTAccessor.setMenuComponentAccessor(
new AWTAccessor.MenuComponentAccessor() {
public AppContext getAppContext(MenuComponent menuComp) {
return menuComp.appContext;
}
public void setAppContext(MenuComponent menuComp,
AppContext appContext) {
menuComp.appContext = appContext;
}
public MenuContainer getParent(MenuComponent menuComp) {
return menuComp.parent;
}
});
}
/** /**
* Creates a <code>MenuComponent</code>. * Creates a <code>MenuComponent</code>.
* @exception HeadlessException if * @exception HeadlessException if
......
...@@ -28,6 +28,7 @@ package java.awt; ...@@ -28,6 +28,7 @@ package java.awt;
import java.awt.peer.PopupMenuPeer; import java.awt.peer.PopupMenuPeer;
import javax.accessibility.*; import javax.accessibility.*;
import sun.awt.AWTAccessor;
/** /**
* A class that implements a menu which can be dynamically popped up * A class that implements a menu which can be dynamically popped up
...@@ -48,6 +49,15 @@ public class PopupMenu extends Menu { ...@@ -48,6 +49,15 @@ public class PopupMenu extends Menu {
transient boolean isTrayIconPopup = false; transient boolean isTrayIconPopup = false;
static {
AWTAccessor.setPopupMenuAccessor(
new AWTAccessor.PopupMenuAccessor() {
public boolean isTrayIconPopup(PopupMenu popupMenu) {
return popupMenu.isTrayIconPopup;
}
});
}
/* /*
* JDK 1.1 serialVersionUID * JDK 1.1 serialVersionUID
*/ */
......
...@@ -3658,7 +3658,7 @@ public class Window extends Container implements Accessible { ...@@ -3658,7 +3658,7 @@ public class Window extends Container implements Accessible {
private static void setLayersOpaque(Component component, boolean isOpaque) { private static void setLayersOpaque(Component component, boolean isOpaque) {
// Shouldn't use instanceof to avoid loading Swing classes // Shouldn't use instanceof to avoid loading Swing classes
// if it's a pure AWT application. // if it's a pure AWT application.
if (Component.doesImplement(component, "javax.swing.RootPaneContainer")) { if (SunToolkit.isInstanceOf(component, "javax.swing.RootPaneContainer")) {
javax.swing.RootPaneContainer rpc = (javax.swing.RootPaneContainer)component; javax.swing.RootPaneContainer rpc = (javax.swing.RootPaneContainer)component;
javax.swing.JRootPane root = rpc.getRootPane(); javax.swing.JRootPane root = rpc.getRootPane();
javax.swing.JLayeredPane lp = root.getLayeredPane(); javax.swing.JLayeredPane lp = root.getLayeredPane();
...@@ -3797,6 +3797,10 @@ public class Window extends Container implements Accessible { ...@@ -3797,6 +3797,10 @@ public class Window extends Container implements Accessible {
{ {
return window.calculateSecurityWarningPosition(x, y, w, h); return window.calculateSecurityWarningPosition(x, y, w, h);
} }
public void setLWRequestStatus(Window changed, boolean status) {
changed.syncLWRequests = status;
}
}); // WindowAccessor }); // WindowAccessor
} // static } // static
......
...@@ -36,6 +36,7 @@ import java.util.logging.*; ...@@ -36,6 +36,7 @@ import java.util.logging.*;
import sun.awt.SubRegionShowable; import sun.awt.SubRegionShowable;
import sun.java2d.SunGraphics2D; import sun.java2d.SunGraphics2D;
import sun.security.action.GetPropertyAction; import sun.security.action.GetPropertyAction;
import sun.awt.SunToolkit;
/** /**
* A PaintManager implementation that uses a BufferStrategy for * A PaintManager implementation that uses a BufferStrategy for
...@@ -579,8 +580,9 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager { ...@@ -579,8 +580,9 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager {
rootJ = c; rootJ = c;
root = c; root = c;
xOffset = yOffset = 0; xOffset = yOffset = 0;
while (root != null && (!(root instanceof Window) && while (root != null &&
!(root instanceof Applet))) { (!(root instanceof Window) &&
!SunToolkit.isInstanceOf(root, "java.applet.Applet"))) {
xOffset += root.getX(); xOffset += root.getX();
yOffset += root.getY(); yOffset += root.getY();
root = root.getParent(); root = root.getParent();
...@@ -853,7 +855,7 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager { ...@@ -853,7 +855,7 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager {
new ImageCapabilities(true), new ImageCapabilities(true),
type); type);
BufferStrategy bs = null; BufferStrategy bs = null;
if (root instanceof Applet) { if (SunToolkit.isInstanceOf(root, "java.applet.Applet")) {
try { try {
getCreateBufferStrategyMethod().invoke(root, 2, caps); getCreateBufferStrategyMethod().invoke(root, 2, caps);
bs = (BufferStrategy)getGetBufferStrategyMethod(). bs = (BufferStrategy)getGetBufferStrategyMethod().
......
...@@ -30,6 +30,7 @@ import java.util.Hashtable; ...@@ -30,6 +30,7 @@ import java.util.Hashtable;
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Rectangle; import java.awt.Rectangle;
import sun.awt.SunToolkit;
import javax.accessibility.*; import javax.accessibility.*;
...@@ -195,9 +196,12 @@ public class JLayeredPane extends JComponent implements Accessible { ...@@ -195,9 +196,12 @@ public class JLayeredPane extends JComponent implements Accessible {
for (Component c : getComponents()) { for (Component c : getComponents()) {
layer = null; layer = null;
if(c instanceof JInternalFrame || (c instanceof JComponent &&
(layer = (Integer)((JComponent)c).getClientProperty( if(SunToolkit.isInstanceOf(c, "javax.swing.JInternalFrame") ||
LAYER_PROPERTY)) != null)) { (c instanceof JComponent &&
(layer = (Integer)((JComponent)c).
getClientProperty(LAYER_PROPERTY)) != null))
{
if(layer != null && layer.equals(FRAME_CONTENT_LAYER)) if(layer != null && layer.equals(FRAME_CONTENT_LAYER))
continue; continue;
layeredComponentFound = true; layeredComponentFound = true;
......
...@@ -29,6 +29,7 @@ import java.awt.Container; ...@@ -29,6 +29,7 @@ import java.awt.Container;
import java.awt.ComponentOrientation; import java.awt.ComponentOrientation;
import java.util.Comparator; import java.util.Comparator;
import java.io.*; import java.io.*;
import sun.awt.SunToolkit;
/** /**
...@@ -226,11 +227,11 @@ public class LayoutFocusTraversalPolicy extends SortingFocusTraversalPolicy ...@@ -226,11 +227,11 @@ public class LayoutFocusTraversalPolicy extends SortingFocusTraversalPolicy
protected boolean accept(Component aComponent) { protected boolean accept(Component aComponent) {
if (!super.accept(aComponent)) { if (!super.accept(aComponent)) {
return false; return false;
} else if (aComponent instanceof JTable) { } else if (SunToolkit.isInstanceOf(aComponent, "javax.swing.JTable")) {
// JTable only has ancestor focus bindings, we thus force it // JTable only has ancestor focus bindings, we thus force it
// to be focusable by returning true here. // to be focusable by returning true here.
return true; return true;
} else if (aComponent instanceof JComboBox) { } else if (SunToolkit.isInstanceOf(aComponent, "javax.swing.JComboBox")) {
JComboBox box = (JComboBox)aComponent; JComboBox box = (JComboBox)aComponent;
return box.getUI().isFocusTraversable(box); return box.getUI().isFocusTraversable(box);
} else if (aComponent instanceof JComponent) { } else if (aComponent instanceof JComponent) {
......
...@@ -32,6 +32,7 @@ import java.awt.Color; ...@@ -32,6 +32,7 @@ import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.SystemColor; import java.awt.SystemColor;
import java.awt.Toolkit; import java.awt.Toolkit;
import sun.awt.SunToolkit;
import javax.swing.text.*; import javax.swing.text.*;
import javax.swing.border.*; import javax.swing.border.*;
...@@ -271,7 +272,7 @@ public abstract class LookAndFeel ...@@ -271,7 +272,7 @@ public abstract class LookAndFeel
// this is a special case because the JPasswordField's ancestor heirarchy // this is a special case because the JPasswordField's ancestor heirarchy
// includes a class outside of javax.swing, thus we cannot call setUIProperty // includes a class outside of javax.swing, thus we cannot call setUIProperty
// directly. // directly.
if (c instanceof JPasswordField) { if (SunToolkit.isInstanceOf(c, "javax.swing.JPasswordField")) {
if (!((JPasswordField)c).customSetUIProperty(propertyName, propertyValue)) { if (!((JPasswordField)c).customSetUIProperty(propertyName, propertyValue)) {
c.setUIProperty(propertyName, propertyValue); c.setUIProperty(propertyName, propertyValue);
} }
......
...@@ -40,6 +40,7 @@ import sun.reflect.misc.MethodUtil; ...@@ -40,6 +40,7 @@ import sun.reflect.misc.MethodUtil;
import sun.swing.SwingUtilities2; import sun.swing.SwingUtilities2;
import sun.awt.AppContext; import sun.awt.AppContext;
import sun.swing.*; import sun.swing.*;
import sun.awt.SunToolkit;
/** /**
* This class is used to handle the transfer of a <code>Transferable</code> * This class is used to handle the transfer of a <code>Transferable</code>
...@@ -283,19 +284,9 @@ public class TransferHandler implements Serializable { ...@@ -283,19 +284,9 @@ public class TransferHandler implements Serializable {
? ((DropTargetDragEvent)source).getLocation() ? ((DropTargetDragEvent)source).getLocation()
: ((DropTargetDropEvent)source).getLocation(); : ((DropTargetDropEvent)source).getLocation();
if (component instanceof JTextComponent) { if (SunToolkit.isInstanceOf(component, "javax.swing.text.JTextComponent")) {
try { dropLocation = SwingAccessor.getJTextComponentAccessor().
AccessibleMethod method dropLocationForPoint((JTextComponent)component, p);
= new AccessibleMethod(JTextComponent.class,
"dropLocationForPoint",
Point.class);
dropLocation =
(DropLocation)method.invokeNoChecked(component, p);
} catch (NoSuchMethodException e) {
throw new AssertionError(
"Couldn't locate method JTextComponent.dropLocationForPoint");
}
} else if (component instanceof JComponent) { } else if (component instanceof JComponent) {
dropLocation = ((JComponent)component).dropLocationForPoint(p); dropLocation = ((JComponent)component).dropLocationForPoint(p);
} }
...@@ -1373,22 +1364,9 @@ public class TransferHandler implements Serializable { ...@@ -1373,22 +1364,9 @@ public class TransferHandler implements Serializable {
? null ? null
: support.getDropLocation(); : support.getDropLocation();
if (component instanceof JTextComponent) { if (SunToolkit.isInstanceOf(component, "javax.swing.text.JTextComponent")) {
try { state = SwingAccessor.getJTextComponentAccessor().
AccessibleMethod method = setDropLocation((JTextComponent)component, dropLocation, state, forDrop);
new AccessibleMethod(JTextComponent.class,
"setDropLocation",
DropLocation.class,
Object.class,
Boolean.TYPE);
state =
method.invokeNoChecked(component, dropLocation,
state, forDrop);
} catch (NoSuchMethodException e) {
throw new AssertionError(
"Couldn't locate method JTextComponet.setDropLocation");
}
} else if (component instanceof JComponent) { } else if (component instanceof JComponent) {
state = ((JComponent)component).setDropLocation(dropLocation, state, forDrop); state = ((JComponent)component).setDropLocation(dropLocation, state, forDrop);
} }
......
...@@ -60,6 +60,7 @@ import sun.swing.SwingUtilities2; ...@@ -60,6 +60,7 @@ import sun.swing.SwingUtilities2;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import sun.awt.AppContext; import sun.awt.AppContext;
import sun.awt.AWTAccessor;
/** /**
...@@ -1472,21 +1473,7 @@ public class UIManager implements Serializable ...@@ -1472,21 +1473,7 @@ public class UIManager implements Serializable
return false; return false;
} }
}); });
try { AWTAccessor.getComponentAccessor().
Method setRequestFocusControllerM = java.security.AccessController.doPrivileged( setRequestFocusController(JComponent.focusController);
new java.security.PrivilegedExceptionAction<Method>() {
public Method run() throws Exception {
Method method =
Component.class.getDeclaredMethod("setRequestFocusController",
sun.awt.RequestFocusController.class);
method.setAccessible(true);
return method;
}
});
setRequestFocusControllerM.invoke(null, JComponent.focusController);
} catch (Exception e) {
// perhaps we should log this
assert false;
}
} }
} }
...@@ -76,6 +76,7 @@ import sun.awt.AppContext; ...@@ -76,6 +76,7 @@ import sun.awt.AppContext;
import sun.swing.PrintingStatus; import sun.swing.PrintingStatus;
import sun.swing.SwingUtilities2; import sun.swing.SwingUtilities2;
import sun.swing.text.TextComponentPrintable; import sun.swing.text.TextComponentPrintable;
import sun.swing.SwingAccessor;
/** /**
* <code>JTextComponent</code> is the base class for swing text * <code>JTextComponent</code> is the base class for swing text
...@@ -761,6 +762,23 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A ...@@ -761,6 +762,23 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A
return dropMode; return dropMode;
} }
static {
SwingAccessor.setJTextComponentAccessor(
new SwingAccessor.JTextComponentAccessor() {
public TransferHandler.DropLocation dropLocationForPoint(JTextComponent textComp,
Point p)
{
return textComp.dropLocationForPoint(p);
}
public Object setDropLocation(JTextComponent textComp,
TransferHandler.DropLocation location,
Object state, boolean forDrop)
{
return textComp.setDropLocation(location, state, forDrop);
}
});
}
/** /**
* Calculates a drop location in this component, representing where a * Calculates a drop location in this component, representing where a
......
...@@ -30,6 +30,7 @@ import java.awt.geom.Point2D; ...@@ -30,6 +30,7 @@ import java.awt.geom.Point2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import sun.misc.Unsafe; import sun.misc.Unsafe;
import java.awt.peer.ComponentPeer;
/** /**
* The AWTAccessor utility class. * The AWTAccessor utility class.
...@@ -98,6 +99,21 @@ public final class AWTAccessor { ...@@ -98,6 +99,21 @@ public final class AWTAccessor {
* any client code. * any client code.
*/ */
boolean isVisible_NoClientCode(Component comp); boolean isVisible_NoClientCode(Component comp);
/**
* Sets the RequestFocusController.
*/
void setRequestFocusController(RequestFocusController requestController);
/**
* Returns the appContext of the component.
*/
AppContext getAppContext(Component comp);
/**
* Sets the appContext of the component.
*/
void setAppContext(Component comp, AppContext appContext);
} }
/* /*
...@@ -153,23 +169,21 @@ public final class AWTAccessor { ...@@ -153,23 +169,21 @@ public final class AWTAccessor {
*/ */
Point2D calculateSecurityWarningPosition(Window window, Point2D calculateSecurityWarningPosition(Window window,
double x, double y, double w, double h); double x, double y, double w, double h);
/** Sets the synchronous status of focus requests on lightweight
* components in the specified window to the specified value.
*/
void setLWRequestStatus(Window changed, boolean status);
} }
/* /*
* An accessor for the AWTEvent class. * An accessor for the AWTEvent class.
*/ */
public interface AWTEventAccessor { public interface AWTEventAccessor {
/* /**
* * Marks the event as posted.
* Sets the flag on this AWTEvent indicating that it was
* generated by the system.
*/
void setSystemGenerated(AWTEvent ev);
/*
*
* Indicates whether this AWTEvent was generated by the system.
*/ */
boolean isSystemGenerated(AWTEvent ev); void setPosted(AWTEvent ev);
} }
/* /*
...@@ -215,6 +229,51 @@ public final class AWTAccessor { ...@@ -215,6 +229,51 @@ public final class AWTAccessor {
void removeLastFocusRequest(Component heavyweight); void removeLastFocusRequest(Component heavyweight);
} }
/*
* An accessor for the MenuComponent class.
*/
public interface MenuComponentAccessor {
/**
* Returns the appContext of the menu component.
*/
AppContext getAppContext(MenuComponent menuComp);
/**
* Sets the appContext of the menu component.
*/
void setAppContext(MenuComponent menuComp, AppContext appContext);
/**
* Returns the menu container of the menu component
*/
MenuContainer getParent(MenuComponent menuComp);
}
/*
* An accessor for the EventQueue class
*/
public interface EventQueueAccessor {
/*
* Gets the next event queue.
*/
EventQueue getNextQueue(EventQueue eventQueue);
/*
* Gets the event dispatch thread.
*/
Thread getDispatchThread(EventQueue eventQueue);
}
/*
* An accessor for the PopupMenu class
*/
public interface PopupMenuAccessor {
/*
* Returns whether the popup menu is attached to a tray
*/
boolean isTrayIconPopup(PopupMenu popupMenu);
}
/* /*
* The java.awt.Component class accessor object. * The java.awt.Component class accessor object.
*/ */
...@@ -240,6 +299,21 @@ public final class AWTAccessor { ...@@ -240,6 +299,21 @@ public final class AWTAccessor {
*/ */
private static KeyboardFocusManagerAccessor kfmAccessor; private static KeyboardFocusManagerAccessor kfmAccessor;
/*
* The java.awt.MenuComponent class accessor object.
*/
private static MenuComponentAccessor menuComponentAccessor;
/*
* The java.awt.EventQueue class accessor object.
*/
private static EventQueueAccessor eventQueueAccessor;
/*
* The java.awt.PopupMenu class accessor object.
*/
private static PopupMenuAccessor popupMenuAccessor;
/* /*
* Set an accessor object for the java.awt.Component class. * Set an accessor object for the java.awt.Component class.
*/ */
...@@ -286,6 +360,9 @@ public final class AWTAccessor { ...@@ -286,6 +360,9 @@ public final class AWTAccessor {
* Retrieve the accessor object for the java.awt.AWTEvent class. * Retrieve the accessor object for the java.awt.AWTEvent class.
*/ */
public static AWTEventAccessor getAWTEventAccessor() { public static AWTEventAccessor getAWTEventAccessor() {
if (awtEventAccessor == null) {
unsafe.ensureClassInitialized(AWTEvent.class);
}
return awtEventAccessor; return awtEventAccessor;
} }
...@@ -322,4 +399,55 @@ public final class AWTAccessor { ...@@ -322,4 +399,55 @@ public final class AWTAccessor {
} }
return kfmAccessor; return kfmAccessor;
} }
/*
* Set an accessor object for the java.awt.MenuComponent class.
*/
public static void setMenuComponentAccessor(MenuComponentAccessor mca) {
menuComponentAccessor = mca;
}
/*
* Retrieve the accessor object for the java.awt.MenuComponent class.
*/
public static MenuComponentAccessor getMenuComponentAccessor() {
if (menuComponentAccessor == null) {
unsafe.ensureClassInitialized(MenuComponent.class);
}
return menuComponentAccessor;
}
/*
* Set an accessor object for the java.awt.EventQueue class.
*/
public static void setEventQueueAccessor(EventQueueAccessor eqa) {
eventQueueAccessor = eqa;
}
/*
* Retrieve the accessor object for the java.awt.EventQueue class.
*/
public static EventQueueAccessor getEventQueueAccessor() {
if (eventQueueAccessor == null) {
unsafe.ensureClassInitialized(EventQueue.class);
}
return eventQueueAccessor;
}
/*
* Set an accessor object for the java.awt.PopupMenu class.
*/
public static void setPopupMenuAccessor(PopupMenuAccessor pma) {
popupMenuAccessor = pma;
}
/*
* Retrieve the accessor object for the java.awt.PopupMenu class.
*/
public static PopupMenuAccessor getPopupMenuAccessor() {
if (popupMenuAccessor == null) {
unsafe.ensureClassInitialized(PopupMenu.class);
}
return popupMenuAccessor;
}
} }
...@@ -77,14 +77,7 @@ public abstract class SunToolkit extends Toolkit ...@@ -77,14 +77,7 @@ public abstract class SunToolkit extends Toolkit
*/ */
public static final int GRAB_EVENT_MASK = 0x80000000; public static final int GRAB_EVENT_MASK = 0x80000000;
private static Field syncLWRequestsField;
private static Method wakeupMethod; private static Method wakeupMethod;
private static Field componentKeyField;
private static Field menuComponentKeyField;
private static Field trayIconKeyField;
private static Field componentAppContextField;
private static Field menuComponentAppContextField;
private static Field isPostedField;
/* The key to put()/get() the PostEventQueue into/from the AppContext. /* The key to put()/get() the PostEventQueue into/from the AppContext.
*/ */
private static final String POST_EVENT_QUEUE_KEY = "PostEventQueue"; private static final String POST_EVENT_QUEUE_KEY = "PostEventQueue";
...@@ -422,32 +415,21 @@ public abstract class SunToolkit extends Toolkit ...@@ -422,32 +415,21 @@ public abstract class SunToolkit extends Toolkit
private static final Map appContextMap = private static final Map appContextMap =
Collections.synchronizedMap(new WeakHashMap()); Collections.synchronizedMap(new WeakHashMap());
/** /**
* Sets the appContext field of target. If target is not a Component or * Sets the appContext field of target. If target is not a Component or
* MenuComponent, this returns false. * MenuComponent, this returns false.
*/ */
private static boolean setAppContext(Object target, AppContext context) private static boolean setAppContext(Object target,
{ AppContext context) {
if (!(target instanceof Component) && !(target instanceof MenuComponent)) { if (target instanceof Component) {
AWTAccessor.getComponentAccessor().
setAppContext((Component)target, context);
} else if (target instanceof MenuComponent) {
AWTAccessor.getMenuComponentAccessor().
setAppContext((MenuComponent)target, context);
} else {
return false; return false;
} }
try{
if (target instanceof Component){
if (componentAppContextField == null) {
componentAppContextField = getField(Component.class, "appContext");
}
componentAppContextField.set(target, context);
} else if (target instanceof MenuComponent) {
if (menuComponentAppContextField == null) {
menuComponentAppContextField = getField(MenuComponent.class, "appContext");
}
menuComponentAppContextField.set(target, context);
}
} catch( IllegalAccessException e){
assert false;
}
return true; return true;
} }
...@@ -456,23 +438,15 @@ public abstract class SunToolkit extends Toolkit ...@@ -456,23 +438,15 @@ public abstract class SunToolkit extends Toolkit
* Component or MenuComponent this returns null. * Component or MenuComponent this returns null.
*/ */
private static AppContext getAppContext(Object target) { private static AppContext getAppContext(Object target) {
AppContext retObj = null; if (target instanceof Component) {
try{ return AWTAccessor.getComponentAccessor().
if (target instanceof Component){ getAppContext((Component)target);
if (componentAppContextField == null) { } else if (target instanceof MenuComponent) {
componentAppContextField = getField(Component.class, "appContext"); return AWTAccessor.getMenuComponentAccessor().
} getAppContext((MenuComponent)target);
retObj = (AppContext) componentAppContextField.get(target); } else {
} else if (target instanceof MenuComponent) { return null;
if (menuComponentAppContextField == null) {
menuComponentAppContextField = getField(MenuComponent.class, "appContext");
}
retObj = (AppContext) menuComponentAppContextField.get(target);
}
} catch( IllegalAccessException e){
assert false;
} }
return retObj;
} }
/* /*
...@@ -520,16 +494,7 @@ public abstract class SunToolkit extends Toolkit ...@@ -520,16 +494,7 @@ public abstract class SunToolkit extends Toolkit
*/ */
public static void setLWRequestStatus(Window changed,boolean status){ public static void setLWRequestStatus(Window changed,boolean status){
if (syncLWRequestsField == null){ AWTAccessor.getWindowAccessor().setLWRequestStatus(changed, status);
syncLWRequestsField = getField(Window.class, "syncLWRequests");
}
try{
if (syncLWRequestsField != null){
syncLWRequestsField.setBoolean(changed, status);
}
} catch( IllegalAccessException e){
assert false;
}
}; };
public static void checkAndSetPolicy(Container cont, boolean isSwingCont) public static void checkAndSetPolicy(Container cont, boolean isSwingCont)
...@@ -637,18 +602,9 @@ public abstract class SunToolkit extends Toolkit ...@@ -637,18 +602,9 @@ public abstract class SunToolkit extends Toolkit
* Post AWTEvent of high priority. * Post AWTEvent of high priority.
*/ */
public static void postPriorityEvent(final AWTEvent e) { public static void postPriorityEvent(final AWTEvent e) {
if (isPostedField == null) {
isPostedField = getField(AWTEvent.class, "isPosted");
}
PeerEvent pe = new PeerEvent(Toolkit.getDefaultToolkit(), new Runnable() { PeerEvent pe = new PeerEvent(Toolkit.getDefaultToolkit(), new Runnable() {
public void run() { public void run() {
try { AWTAccessor.getAWTEventAccessor().setPosted(e);
isPostedField.setBoolean(e, true);
} catch (IllegalArgumentException e) {
assert(false);
} catch (IllegalAccessException e) {
assert(false);
}
((Component)e.getSource()).dispatchEvent(e); ((Component)e.getSource()).dispatchEvent(e);
} }
}, PeerEvent.ULTIMATE_PRIORITY_EVENT); }, PeerEvent.ULTIMATE_PRIORITY_EVENT);
...@@ -756,36 +712,6 @@ public abstract class SunToolkit extends Toolkit ...@@ -756,36 +712,6 @@ public abstract class SunToolkit extends Toolkit
} }
} }
/*
* Returns next queue for the given EventQueue which has private access
*/
private static EventQueue getNextQueue(final Object o) {
EventQueue result = null;
try{
Field nextQueueField = getField(EventQueue.class,
"nextQueue");
result = (EventQueue)nextQueueField.get(o);
} catch( IllegalAccessException e){
assert false;
}
return result;
}
/*
* Returns dispatch thread for the given EventQueue which has private access
*/
private static Thread getDispatchThread(final Object o) {
Thread result = null;
try{
Field dispatchThreadField = getField(EventQueue.class,
"dispatchThread");
result = (Thread)dispatchThreadField.get(o);
} catch( IllegalAccessException e){
assert false;
}
return result;
}
/* /*
* Returns true if the calling thread is the event dispatch thread * Returns true if the calling thread is the event dispatch thread
* contained within AppContext which associated with the given target. * contained within AppContext which associated with the given target.
...@@ -796,13 +722,14 @@ public abstract class SunToolkit extends Toolkit ...@@ -796,13 +722,14 @@ public abstract class SunToolkit extends Toolkit
AppContext appContext = targetToAppContext(target); AppContext appContext = targetToAppContext(target);
EventQueue eq = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY); EventQueue eq = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
EventQueue next = getNextQueue(eq); AWTAccessor.EventQueueAccessor accessor = AWTAccessor.getEventQueueAccessor();
EventQueue next = accessor.getNextQueue(eq);
while (next != null) { while (next != null) {
eq = next; eq = next;
next = getNextQueue(eq); next = accessor.getNextQueue(eq);
} }
return (Thread.currentThread() == getDispatchThread(eq)); return (Thread.currentThread() == accessor.getDispatchThread(eq));
} }
public Dimension getScreenSize() { public Dimension getScreenSize() {
...@@ -1356,22 +1283,7 @@ public abstract class SunToolkit extends Toolkit ...@@ -1356,22 +1283,7 @@ public abstract class SunToolkit extends Toolkit
return false; return false;
} }
private static Dialog.ModalExclusionType DEFAULT_MODAL_EXCLUSION_TYPE; private static Dialog.ModalExclusionType DEFAULT_MODAL_EXCLUSION_TYPE = null;
static {
DEFAULT_MODAL_EXCLUSION_TYPE = (Dialog.ModalExclusionType)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
Dialog.ModalExclusionType defaultType = Dialog.ModalExclusionType.NO_EXCLUDE;
try {
java.lang.reflect.Field f = Dialog.class.getDeclaredField("DEFAULT_MODAL_EXCLUSION_TYPE");
f.setAccessible(true);
defaultType = (Dialog.ModalExclusionType)f.get(null);
} catch (Exception e) {
}
return defaultType;
}
});
}
/** /**
* Returns whether the XEmbed server feature is requested by * Returns whether the XEmbed server feature is requested by
...@@ -1430,6 +1342,9 @@ public abstract class SunToolkit extends Toolkit ...@@ -1430,6 +1342,9 @@ public abstract class SunToolkit extends Toolkit
*/ */
public static void setModalExcluded(Window window) public static void setModalExcluded(Window window)
{ {
if (DEFAULT_MODAL_EXCLUSION_TYPE == null) {
DEFAULT_MODAL_EXCLUSION_TYPE = Dialog.ModalExclusionType.APPLICATION_EXCLUDE;
}
window.setModalExclusionType(DEFAULT_MODAL_EXCLUSION_TYPE); window.setModalExclusionType(DEFAULT_MODAL_EXCLUSION_TYPE);
} }
...@@ -1451,6 +1366,9 @@ public abstract class SunToolkit extends Toolkit ...@@ -1451,6 +1366,9 @@ public abstract class SunToolkit extends Toolkit
*/ */
public static boolean isModalExcluded(Window window) public static boolean isModalExcluded(Window window)
{ {
if (DEFAULT_MODAL_EXCLUSION_TYPE == null) {
DEFAULT_MODAL_EXCLUSION_TYPE = Dialog.ModalExclusionType.APPLICATION_EXCLUDE;
}
return window.getModalExclusionType().compareTo(DEFAULT_MODAL_EXCLUSION_TYPE) >= 0; return window.getModalExclusionType().compareTo(DEFAULT_MODAL_EXCLUSION_TYPE) >= 0;
} }
...@@ -2104,6 +2022,42 @@ public abstract class SunToolkit extends Toolkit ...@@ -2104,6 +2022,42 @@ public abstract class SunToolkit extends Toolkit
public int getNumberOfButtons(){ public int getNumberOfButtons(){
return 3; return 3;
} }
/**
* Checks that the given object implements/extends the given
* interface/class.
*
* Note that using the instanceof operator causes a class to be loaded.
* Using this method doesn't load a class and it can be used instead of
* the instanceof operator for performance reasons.
*
* @param obj Object to be checked
* @param type The name of the interface/class. Must be
* fully-qualified interface/class name.
* @return true, if this object implements/extends the given
* interface/class, false, otherwise, or if obj or type is null
*/
public static boolean isInstanceOf(Object obj, String type) {
if (obj == null) return false;
if (type == null) return false;
return isInstanceOf(obj.getClass(), type);
}
private static boolean isInstanceOf(Class cls, String type) {
if (cls == null) return false;
if (cls.getName().equals(type)) {
return true;
}
for (Class c : cls.getInterfaces()) {
if (c.getName().equals(type)) {
return true;
}
}
return isInstanceOf(cls.getSuperclass(), type);
}
} // class SunToolkit } // class SunToolkit
......
...@@ -202,8 +202,16 @@ public abstract class ShellFolder extends File { ...@@ -202,8 +202,16 @@ public abstract class ShellFolder extends File {
private static ShellFolderManager shellFolderManager; private static ShellFolderManager shellFolderManager;
static { static {
Class managerClass = (Class)Toolkit.getDefaultToolkit(). String managerClassName = (String)Toolkit.getDefaultToolkit().
getDesktopProperty("Shell.shellFolderManager"); getDesktopProperty("Shell.shellFolderManager");
Class managerClass = null;
try {
managerClass = Class.forName(managerClassName);
// swallow the exceptions below and use default shell folder
} catch(ClassNotFoundException e) {
} catch(NullPointerException e) {
}
if (managerClass == null) { if (managerClass == null) {
managerClass = ShellFolderManager.class; managerClass = ShellFolderManager.class;
} }
......
/*
* Copyright 2005-2008 Sun Microsystems, Inc. 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package sun.swing;
import java.security.*;
import java.lang.reflect.*;
/**
* A utility for accessing and invoking methods, via reflection,
* that would otherwise be unaccessible.
*
* @author Shannon Hickey
*/
public class AccessibleMethod {
private final Method method;
/**
* Construct an instance for the given params.
*
* @param klass the class to which the method belongs
* @param methodName the name of the method
* @param paramTypes the paramater type array
* @throws NullPointerException if <code>klass</code>
* or <code>name</code> is <code>null</code>
* @throws NoSuchMethodException if the method can't be found
*/
public AccessibleMethod(Class klass,
String methodName,
Class ... paramTypes) throws NoSuchMethodException {
try {
method = AccessController.doPrivileged(
new AccessMethodAction(klass, methodName, paramTypes));
} catch (PrivilegedActionException e) {
throw (NoSuchMethodException)e.getCause();
}
}
/**
* Invoke the method that this object represents.
* Has the same behavior and throws the same exceptions as
* <code>java.lang.reflect.Method.invoke</code> with one
* exception: This method does not throw
* <code>IllegalAccessException</code> since the target
* method has already been made accessible.
*
* @param obj the object the underlying method is invoked from
* @param args the arguments used for the method call
* @return the result of dispatching the method represented by
* this object on <code>obj</code> with parameters
* <code>args</code>
* @see java.lang.reflect.Method#invoke
*/
public Object invoke(Object obj, Object ... args)
throws IllegalArgumentException, InvocationTargetException {
try {
return method.invoke(obj, args);
} catch (IllegalAccessException e) {
// should never happen since we've made it accessible
throw new AssertionError("accessible method inaccessible");
}
}
/**
* Invoke the method that this object represents, with the
* expectation that the method being called throws no
* checked exceptions.
* <p>
* Simply calls <code>this.invoke(obj, args)</code>
* but catches any <code>InvocationTargetException</code>
* and returns the cause wrapped in a runtime exception.
*
* @param obj the object the underlying method is invoked from
* @param args the arguments used for the method call
* @return the result of dispatching the method represented by
* this object on <code>obj</code> with parameters
* <code>args</code>
* @see #invoke
*/
public Object invokeNoChecked(Object obj, Object ... args) {
try {
return invoke(obj, args);
} catch (InvocationTargetException ex) {
if (ex.getCause() instanceof RuntimeException) {
throw (RuntimeException)ex.getCause();
} else {
throw new RuntimeException(ex.getCause());
}
}
}
/** The action used to fetch the method and make it accessible */
private static class AccessMethodAction implements PrivilegedExceptionAction<Method> {
private final Class<?> klass;
private final String methodName;
private final Class[] paramTypes;
public AccessMethodAction(Class klass,
String methodName,
Class ... paramTypes) {
this.klass = klass;
this.methodName = methodName;
this.paramTypes = paramTypes;
}
public Method run() throws NoSuchMethodException {
Method method = klass.getDeclaredMethod(methodName, paramTypes);
method.setAccessible(true);
return method;
}
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package sun.swing;
import sun.misc.Unsafe;
import java.awt.Point;
import javax.swing.text.JTextComponent;
import javax.swing.TransferHandler;
/**
* The SwingAccessor utility class.
* The main purpose of this class is to enable accessing
* private and package-private fields of classes from
* different classes/packages. See sun.misc.SharedSecretes
* for another example.
*/
public final class SwingAccessor {
private static final Unsafe unsafe = Unsafe.getUnsafe();
/**
* We don't need any objects of this class.
* It's rather a collection of static methods
* and interfaces.
*/
private SwingAccessor() {
}
/**
* An accessor for the JTextComponent class.
* Note that we intentionally introduce the JTextComponentAccessor,
* and not the JComponentAccessor because the needed methods
* aren't override methods.
*/
public interface JTextComponentAccessor {
/**
* Calculates a custom drop location for the text component,
* representing where a drop at the given point should insert data.
*/
TransferHandler.DropLocation dropLocationForPoint(JTextComponent textComp, Point p);
/**
* Called to set or clear the drop location during a DnD operation.
*/
Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location,
Object state, boolean forDrop);
}
/**
* The javax.swing.text.JTextComponent class accessor object.
*/
private static JTextComponentAccessor jtextComponentAccessor;
/**
* Set an accessor object for the javax.swing.text.JTextComponent class.
*/
public static void setJTextComponentAccessor(JTextComponentAccessor jtca) {
jtextComponentAccessor = jtca;
}
/**
* Retrieve the accessor object for the javax.swing.text.JTextComponent class.
*/
public static JTextComponentAccessor getJTextComponentAccessor() {
if (jtextComponentAccessor == null) {
unsafe.ensureClassInitialized(JTextComponent.class);
}
return jtextComponentAccessor;
}
}
...@@ -1436,9 +1436,14 @@ public final class XToolkit extends UNIXToolkit implements Runnable { ...@@ -1436,9 +1436,14 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
return timeStamp; return timeStamp;
} }
protected void initializeDesktopProperties() { protected void initializeDesktopProperties() {
desktopProperties.put("DnD.Autoscroll.initialDelay", Integer.valueOf(50)); desktopProperties.put("DnD.Autoscroll.initialDelay",
desktopProperties.put("DnD.Autoscroll.interval", Integer.valueOf(50)); Integer.valueOf(50));
desktopProperties.put("DnD.Autoscroll.cursorHysteresis", Integer.valueOf(5)); desktopProperties.put("DnD.Autoscroll.interval",
Integer.valueOf(50));
desktopProperties.put("DnD.Autoscroll.cursorHysteresis",
Integer.valueOf(5));
desktopProperties.put("Shell.shellFolderManager",
"sun.awt.shell.ShellFolderManager");
// Don't want to call getMultiClickTime() if we are headless // Don't want to call getMultiClickTime() if we are headless
if (!GraphicsEnvironment.isHeadless()) { if (!GraphicsEnvironment.isHeadless()) {
desktopProperties.put("awt.multiClickInterval", desktopProperties.put("awt.multiClickInterval",
......
...@@ -417,6 +417,15 @@ public abstract class WComponentPeer extends WObjectPeer ...@@ -417,6 +417,15 @@ public abstract class WComponentPeer extends WObjectPeer
replaceSurfaceData(this.numBackBuffers, this.backBufferCaps); replaceSurfaceData(this.numBackBuffers, this.backBufferCaps);
} }
public void createScreenSurface(boolean isResize)
{
Win32GraphicsConfig gc = (Win32GraphicsConfig)getGraphicsConfiguration();
ScreenUpdateManager mgr = ScreenUpdateManager.getInstance();
surfaceData = mgr.createScreenSurface(gc, this, numBackBuffers, isResize);
}
/** /**
* Multi-buffer version of replaceSurfaceData. This version is called * Multi-buffer version of replaceSurfaceData. This version is called
* by createBuffers(), which needs to acquire the same locks in the same * by createBuffers(), which needs to acquire the same locks in the same
...@@ -434,13 +443,10 @@ public abstract class WComponentPeer extends WObjectPeer ...@@ -434,13 +443,10 @@ public abstract class WComponentPeer extends WObjectPeer
return; return;
} }
numBackBuffers = newNumBackBuffers; numBackBuffers = newNumBackBuffers;
Win32GraphicsConfig gc =
(Win32GraphicsConfig)getGraphicsConfiguration();
ScreenUpdateManager mgr = ScreenUpdateManager.getInstance(); ScreenUpdateManager mgr = ScreenUpdateManager.getInstance();
oldData = surfaceData; oldData = surfaceData;
mgr.dropScreenSurface(oldData); mgr.dropScreenSurface(oldData);
surfaceData = createScreenSurface(true);
mgr.createScreenSurface(gc, this, numBackBuffers, true);
if (oldData != null) { if (oldData != null) {
oldData.invalidate(); oldData.invalidate();
} }
...@@ -449,6 +455,8 @@ public abstract class WComponentPeer extends WObjectPeer ...@@ -449,6 +455,8 @@ public abstract class WComponentPeer extends WObjectPeer
if (numBackBuffers > 0) { if (numBackBuffers > 0) {
// set the caps first, they're used when creating the bb // set the caps first, they're used when creating the bb
backBufferCaps = caps; backBufferCaps = caps;
Win32GraphicsConfig gc =
(Win32GraphicsConfig)getGraphicsConfiguration();
backBuffer = gc.createBackBuffer(this); backBuffer = gc.createBackBuffer(this);
} else if (backBuffer != null) { } else if (backBuffer != null) {
backBufferCaps = null; backBufferCaps = null;
...@@ -711,11 +719,8 @@ public abstract class WComponentPeer extends WObjectPeer ...@@ -711,11 +719,8 @@ public abstract class WComponentPeer extends WObjectPeer
create(parentPeer); create(parentPeer);
// fix for 5088782: check if window object is created successfully // fix for 5088782: check if window object is created successfully
checkCreation(); checkCreation();
this.winGraphicsConfig =
(Win32GraphicsConfig)getGraphicsConfiguration(); createScreenSurface(false);
ScreenUpdateManager mgr = ScreenUpdateManager.getInstance();
this.surfaceData = mgr.createScreenSurface(winGraphicsConfig, this,
numBackBuffers, false);
initialize(); initialize();
start(); // Initialize enable/disable state, turn on callbacks start(); // Initialize enable/disable state, turn on callbacks
} }
......
...@@ -211,9 +211,10 @@ public class WEmbeddedFrame extends EmbeddedFrame { ...@@ -211,9 +211,10 @@ public class WEmbeddedFrame extends EmbeddedFrame {
*/ */
public void notifyModalBlocked(Dialog blocker, boolean blocked) { public void notifyModalBlocked(Dialog blocker, boolean blocked) {
try { try {
notifyModalBlockedImpl((WEmbeddedFramePeer)ComponentAccessor.getPeer(this), ComponentPeer thisPeer = (ComponentPeer)WToolkit.targetToPeer(this);
(WWindowPeer)ComponentAccessor.getPeer(blocker), ComponentPeer blockerPeer = (ComponentPeer)WToolkit.targetToPeer(blocker);
blocked); notifyModalBlockedImpl((WEmbeddedFramePeer)thisPeer,
(WWindowPeer)blockerPeer, blocked);
} catch (Exception z) { } catch (Exception z) {
z.printStackTrace(System.err); z.printStackTrace(System.err);
} }
......
...@@ -237,4 +237,11 @@ public class WFileDialogPeer extends WWindowPeer implements FileDialogPeer { ...@@ -237,4 +237,11 @@ public class WFileDialogPeer extends WWindowPeer implements FileDialogPeer {
public void setOpacity(float opacity) {} public void setOpacity(float opacity) {}
public void setOpaque(boolean isOpaque) {} public void setOpaque(boolean isOpaque) {}
public void updateWindow(java.awt.image.BufferedImage backBuffer) {} public void updateWindow(java.awt.image.BufferedImage backBuffer) {}
// the file/print dialogs are native dialogs and
// the native system does their own rendering
@Override
public void createScreenSurface(boolean isResize) {}
@Override
public void replaceSurfaceData() {}
} }
...@@ -29,33 +29,25 @@ import java.awt.peer.*; ...@@ -29,33 +29,25 @@ import java.awt.peer.*;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
import sun.awt.AWTAccessor;
public class WPopupMenuPeer extends WMenuPeer implements PopupMenuPeer { public class WPopupMenuPeer extends WMenuPeer implements PopupMenuPeer {
// We can't use target.getParent() for TrayIcon popup // We can't use target.getParent() for TrayIcon popup
// because this method should return null for the TrayIcon // because this method should return null for the TrayIcon
// popup regardless of that whether it has parent or not. // popup regardless of that whether it has parent or not.
private static Field f_parent;
private static Field f_isTrayIconPopup;
static {
f_parent = SunToolkit.getField(MenuComponent.class, "parent");
f_isTrayIconPopup = SunToolkit.getField(PopupMenu.class, "isTrayIconPopup");
}
public WPopupMenuPeer(PopupMenu target) { public WPopupMenuPeer(PopupMenu target) {
this.target = target; this.target = target;
MenuContainer parent = null; MenuContainer parent = null;
boolean isTrayIconPopup = false;
try { // We can't use target.getParent() for TrayIcon popup
isTrayIconPopup = ((Boolean)f_isTrayIconPopup.get(target)).booleanValue(); // because this method should return null for the TrayIcon
if (isTrayIconPopup) { // popup regardless of that whether it has parent or not.
parent = (MenuContainer)f_parent.get(target); boolean isTrayIconPopup = AWTAccessor.getPopupMenuAccessor().isTrayIconPopup(target);
} else { if (isTrayIconPopup) {
parent = target.getParent(); parent = AWTAccessor.getMenuComponentAccessor().getParent(target);
} } else {
} catch (IllegalAccessException iae) { parent = target.getParent();
iae.printStackTrace();
return;
} }
if (parent instanceof Component) { if (parent instanceof Component) {
......
...@@ -150,4 +150,11 @@ public class WPrintDialogPeer extends WWindowPeer implements DialogPeer { ...@@ -150,4 +150,11 @@ public class WPrintDialogPeer extends WWindowPeer implements DialogPeer {
public void setOpacity(float opacity) {} public void setOpacity(float opacity) {}
public void setOpaque(boolean isOpaque) {} public void setOpaque(boolean isOpaque) {}
public void updateWindow(java.awt.image.BufferedImage backBuffer) {} public void updateWindow(java.awt.image.BufferedImage backBuffer) {}
// the file/print dialogs are native dialogs and
// the native system does their own rendering
@Override
public void createScreenSurface(boolean isResize) {}
@Override
public void replaceSurfaceData() {}
} }
...@@ -38,8 +38,6 @@ import sun.awt.SunHints; ...@@ -38,8 +38,6 @@ import sun.awt.SunHints;
import sun.awt.Win32GraphicsConfig; import sun.awt.Win32GraphicsConfig;
import sun.awt.Win32GraphicsDevice; import sun.awt.Win32GraphicsDevice;
import sun.awt.windows.WComponentPeer; import sun.awt.windows.WComponentPeer;
import sun.awt.windows.WFileDialogPeer;
import sun.awt.windows.WPrintDialogPeer;
import sun.java2d.ScreenUpdateManager; import sun.java2d.ScreenUpdateManager;
import sun.java2d.SunGraphics2D; import sun.java2d.SunGraphics2D;
import sun.java2d.SurfaceData; import sun.java2d.SurfaceData;
...@@ -264,17 +262,7 @@ public class GDIWindowSurfaceData extends SurfaceData { ...@@ -264,17 +262,7 @@ public class GDIWindowSurfaceData extends SurfaceData {
this.graphicsConfig = this.graphicsConfig =
(Win32GraphicsConfig) peer.getGraphicsConfiguration(); (Win32GraphicsConfig) peer.getGraphicsConfiguration();
this.solidloops = graphicsConfig.getSolidLoops(sType); this.solidloops = graphicsConfig.getSolidLoops(sType);
if (peer instanceof WFileDialogPeer ||
peer instanceof WPrintDialogPeer )
{
// REMIND: Awful hack. The right fix for this problem
// would be for these type of Peers to not even use a
// GDIWindowSurfaceData object since they never do any
// rendering. Or they could actually implement the
// functionality needed in initOps. But this seems
// to work for now. See bug 4391928 for more info.
return;
}
Win32GraphicsDevice gd = Win32GraphicsDevice gd =
(Win32GraphicsDevice)graphicsConfig.getDevice(); (Win32GraphicsDevice)graphicsConfig.getDevice();
initOps(peer, depth, rMask, gMask, bMask, gd.getScreen()); initOps(peer, depth, rMask, gMask, bMask, gd.getScreen());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册