44 import java.awt.image.VolatileImage;
45 import java.awt.event.*;
46 import java.io.Serializable;
47 import java.io.ObjectOutputStream;
48 import java.io.ObjectInputStream;
49 import java.io.IOException;
50 import java.beans.PropertyChangeListener;
51 import java.beans.PropertyChangeSupport;
52 import java.beans.Transient;
53 import java.awt.im.InputContext;
54 import java.awt.im.InputMethodRequests;
55 import java.awt.dnd.DropTarget;
56 import java.lang.reflect.InvocationTargetException;
57 import java.lang.reflect.Method;
58 import java.security.AccessController;
59 import java.security.PrivilegedAction;
60 import java.security.AccessControlContext;
61 import javax.accessibility.*;
62 import java.applet.Applet;
63
64 import sun.security.action.GetPropertyAction;
65 import sun.awt.AppContext;
66 import sun.awt.AWTAccessor;
67 import sun.awt.ConstrainableGraphics;
68 import sun.awt.SubRegionShowable;
69 import sun.awt.SunToolkit;
70 import sun.awt.CausedFocusEvent;
71 import sun.awt.EmbeddedFrame;
72 import sun.awt.dnd.SunDropTargetEvent;
73 import sun.awt.im.CompositionArea;
74 import sun.font.FontManager;
75 import sun.font.FontManagerFactory;
76 import sun.font.SunFontManager;
77 import sun.java2d.SunGraphics2D;
78 import sun.java2d.pipe.Region;
79 import sun.awt.image.VSyncedBSManager;
80 import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
81 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
82 import sun.awt.RequestFocusController;
83 import sun.java2d.SunGraphicsEnvironment;
1212 * is moved from one frame to another, the toolkit it uses may change.
1213 * @return the toolkit of this component
1214 * @since 1.0
1215 */
1216 public Toolkit getToolkit() {
1217 return getToolkitImpl();
1218 }
1219
1220 /*
1221 * This is called by the native code, so client code can't
1222 * be called on the toolkit thread.
1223 */
1224 final Toolkit getToolkitImpl() {
1225 Container parent = this.parent;
1226 if (parent != null) {
1227 return parent.getToolkitImpl();
1228 }
1229 return Toolkit.getDefaultToolkit();
1230 }
1231
1232 /**
1233 * Determines whether this component is valid. A component is valid
1234 * when it is correctly sized and positioned within its parent
1235 * container and all its children are also valid.
1236 * In order to account for peers' size requirements, components are invalidated
1237 * before they are first shown on the screen. By the time the parent container
1238 * is fully realized, all its components will be valid.
1239 * @return <code>true</code> if the component is valid, <code>false</code>
1240 * otherwise
1241 * @see #validate
1242 * @see #invalidate
1243 * @since 1.0
1244 */
1245 public boolean isValid() {
1246 return (peer != null) && valid;
1247 }
1248
1249 /**
1250 * Determines whether this component is displayable. A component is
1251 * displayable when it is connected to a native screen resource.
1309 Point pointRelativeToComponent(Point absolute) {
1310 Point compCoords = getLocationOnScreen();
1311 return new Point(absolute.x - compCoords.x,
1312 absolute.y - compCoords.y);
1313 }
1314
1315 /**
1316 * Assuming that mouse location is stored in PointerInfo passed
1317 * to this method, it finds a Component that is in the same
1318 * Window as this Component and is located under the mouse pointer.
1319 * If no such Component exists, null is returned.
1320 * NOTE: this method should be called under the protection of
1321 * tree lock, as it is done in Component.getMousePosition() and
1322 * Container.getMousePosition(boolean).
1323 */
1324 Component findUnderMouseInWindow(PointerInfo pi) {
1325 if (!isShowing()) {
1326 return null;
1327 }
1328 Window win = getContainingWindow();
1329 if (!Toolkit.getDefaultToolkit().getMouseInfoPeer().isWindowUnderMouse(win)) {
1330 return null;
1331 }
1332 final boolean INCLUDE_DISABLED = true;
1333 Point relativeToWindow = win.pointRelativeToComponent(pi.getLocation());
1334 Component inTheSameWindow = win.findComponentAt(relativeToWindow.x,
1335 relativeToWindow.y,
1336 INCLUDE_DISABLED);
1337 return inTheSameWindow;
1338 }
1339
1340 /**
1341 * Returns the position of the mouse pointer in this <code>Component</code>'s
1342 * coordinate space if the <code>Component</code> is directly under the mouse
1343 * pointer, otherwise returns <code>null</code>.
1344 * If the <code>Component</code> is not showing on the screen, this method
1345 * returns <code>null</code> even if the mouse pointer is above the area
1346 * where the <code>Component</code> would be displayed.
1347 * If the <code>Component</code> is partially or fully obscured by other
1348 * <code>Component</code>s or native windows, this method returns a non-null
1349 * value only if the mouse pointer is located above the unobscured part of the
6940 * Makes this <code>Component</code> displayable by connecting it to a
6941 * native screen resource.
6942 * This method is called internally by the toolkit and should
6943 * not be called directly by programs.
6944 * <p>
6945 * This method changes layout-related information, and therefore,
6946 * invalidates the component hierarchy.
6947 *
6948 * @see #isDisplayable
6949 * @see #removeNotify
6950 * @see #invalidate
6951 * @since 1.0
6952 */
6953 public void addNotify() {
6954 synchronized (getTreeLock()) {
6955 ComponentPeer peer = this.peer;
6956 if (peer == null || peer instanceof LightweightPeer){
6957 if (peer == null) {
6958 // Update both the Component's peer variable and the local
6959 // variable we use for thread safety.
6960 this.peer = peer = getToolkit().createComponent(this);
6961 }
6962
6963 // This is a lightweight component which means it won't be
6964 // able to get window-related events by itself. If any
6965 // have been enabled, then the nearest native container must
6966 // be enabled.
6967 if (parent != null) {
6968 long mask = 0;
6969 if ((mouseListener != null) || ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0)) {
6970 mask |= AWTEvent.MOUSE_EVENT_MASK;
6971 }
6972 if ((mouseMotionListener != null) ||
6973 ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0)) {
6974 mask |= AWTEvent.MOUSE_MOTION_EVENT_MASK;
6975 }
6976 if ((mouseWheelListener != null ) ||
6977 ((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0)) {
6978 mask |= AWTEvent.MOUSE_WHEEL_EVENT_MASK;
6979 }
6980 if (focusListener != null || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0) {
|
44 import java.awt.image.VolatileImage;
45 import java.awt.event.*;
46 import java.io.Serializable;
47 import java.io.ObjectOutputStream;
48 import java.io.ObjectInputStream;
49 import java.io.IOException;
50 import java.beans.PropertyChangeListener;
51 import java.beans.PropertyChangeSupport;
52 import java.beans.Transient;
53 import java.awt.im.InputContext;
54 import java.awt.im.InputMethodRequests;
55 import java.awt.dnd.DropTarget;
56 import java.lang.reflect.InvocationTargetException;
57 import java.lang.reflect.Method;
58 import java.security.AccessController;
59 import java.security.PrivilegedAction;
60 import java.security.AccessControlContext;
61 import javax.accessibility.*;
62 import java.applet.Applet;
63
64 import sun.awt.ComponentFactory;
65 import sun.security.action.GetPropertyAction;
66 import sun.awt.AppContext;
67 import sun.awt.AWTAccessor;
68 import sun.awt.ConstrainableGraphics;
69 import sun.awt.SubRegionShowable;
70 import sun.awt.SunToolkit;
71 import sun.awt.CausedFocusEvent;
72 import sun.awt.EmbeddedFrame;
73 import sun.awt.dnd.SunDropTargetEvent;
74 import sun.awt.im.CompositionArea;
75 import sun.font.FontManager;
76 import sun.font.FontManagerFactory;
77 import sun.font.SunFontManager;
78 import sun.java2d.SunGraphics2D;
79 import sun.java2d.pipe.Region;
80 import sun.awt.image.VSyncedBSManager;
81 import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
82 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
83 import sun.awt.RequestFocusController;
84 import sun.java2d.SunGraphicsEnvironment;
1213 * is moved from one frame to another, the toolkit it uses may change.
1214 * @return the toolkit of this component
1215 * @since 1.0
1216 */
1217 public Toolkit getToolkit() {
1218 return getToolkitImpl();
1219 }
1220
1221 /*
1222 * This is called by the native code, so client code can't
1223 * be called on the toolkit thread.
1224 */
1225 final Toolkit getToolkitImpl() {
1226 Container parent = this.parent;
1227 if (parent != null) {
1228 return parent.getToolkitImpl();
1229 }
1230 return Toolkit.getDefaultToolkit();
1231 }
1232
1233 final ComponentFactory getComponentFactory() {
1234 final Toolkit toolkit = getToolkit();
1235 if (toolkit instanceof ComponentFactory) {
1236 return (ComponentFactory) toolkit;
1237 }
1238 throw new AWTError("Unsupported toolkit: " + toolkit);
1239 }
1240
1241 /**
1242 * Determines whether this component is valid. A component is valid
1243 * when it is correctly sized and positioned within its parent
1244 * container and all its children are also valid.
1245 * In order to account for peers' size requirements, components are invalidated
1246 * before they are first shown on the screen. By the time the parent container
1247 * is fully realized, all its components will be valid.
1248 * @return <code>true</code> if the component is valid, <code>false</code>
1249 * otherwise
1250 * @see #validate
1251 * @see #invalidate
1252 * @since 1.0
1253 */
1254 public boolean isValid() {
1255 return (peer != null) && valid;
1256 }
1257
1258 /**
1259 * Determines whether this component is displayable. A component is
1260 * displayable when it is connected to a native screen resource.
1318 Point pointRelativeToComponent(Point absolute) {
1319 Point compCoords = getLocationOnScreen();
1320 return new Point(absolute.x - compCoords.x,
1321 absolute.y - compCoords.y);
1322 }
1323
1324 /**
1325 * Assuming that mouse location is stored in PointerInfo passed
1326 * to this method, it finds a Component that is in the same
1327 * Window as this Component and is located under the mouse pointer.
1328 * If no such Component exists, null is returned.
1329 * NOTE: this method should be called under the protection of
1330 * tree lock, as it is done in Component.getMousePosition() and
1331 * Container.getMousePosition(boolean).
1332 */
1333 Component findUnderMouseInWindow(PointerInfo pi) {
1334 if (!isShowing()) {
1335 return null;
1336 }
1337 Window win = getContainingWindow();
1338 Toolkit toolkit = Toolkit.getDefaultToolkit();
1339 if (!(toolkit instanceof ComponentFactory)) {
1340 return null;
1341 }
1342 if (!((ComponentFactory) toolkit).getMouseInfoPeer().isWindowUnderMouse(win)) {
1343 return null;
1344 }
1345 final boolean INCLUDE_DISABLED = true;
1346 Point relativeToWindow = win.pointRelativeToComponent(pi.getLocation());
1347 Component inTheSameWindow = win.findComponentAt(relativeToWindow.x,
1348 relativeToWindow.y,
1349 INCLUDE_DISABLED);
1350 return inTheSameWindow;
1351 }
1352
1353 /**
1354 * Returns the position of the mouse pointer in this <code>Component</code>'s
1355 * coordinate space if the <code>Component</code> is directly under the mouse
1356 * pointer, otherwise returns <code>null</code>.
1357 * If the <code>Component</code> is not showing on the screen, this method
1358 * returns <code>null</code> even if the mouse pointer is above the area
1359 * where the <code>Component</code> would be displayed.
1360 * If the <code>Component</code> is partially or fully obscured by other
1361 * <code>Component</code>s or native windows, this method returns a non-null
1362 * value only if the mouse pointer is located above the unobscured part of the
6953 * Makes this <code>Component</code> displayable by connecting it to a
6954 * native screen resource.
6955 * This method is called internally by the toolkit and should
6956 * not be called directly by programs.
6957 * <p>
6958 * This method changes layout-related information, and therefore,
6959 * invalidates the component hierarchy.
6960 *
6961 * @see #isDisplayable
6962 * @see #removeNotify
6963 * @see #invalidate
6964 * @since 1.0
6965 */
6966 public void addNotify() {
6967 synchronized (getTreeLock()) {
6968 ComponentPeer peer = this.peer;
6969 if (peer == null || peer instanceof LightweightPeer){
6970 if (peer == null) {
6971 // Update both the Component's peer variable and the local
6972 // variable we use for thread safety.
6973 this.peer = peer = getComponentFactory().createComponent(this);
6974 }
6975
6976 // This is a lightweight component which means it won't be
6977 // able to get window-related events by itself. If any
6978 // have been enabled, then the nearest native container must
6979 // be enabled.
6980 if (parent != null) {
6981 long mask = 0;
6982 if ((mouseListener != null) || ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0)) {
6983 mask |= AWTEvent.MOUSE_EVENT_MASK;
6984 }
6985 if ((mouseMotionListener != null) ||
6986 ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0)) {
6987 mask |= AWTEvent.MOUSE_MOTION_EVENT_MASK;
6988 }
6989 if ((mouseWheelListener != null ) ||
6990 ((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0)) {
6991 mask |= AWTEvent.MOUSE_WHEEL_EVENT_MASK;
6992 }
6993 if (focusListener != null || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0) {
|