src/java.desktop/share/classes/java/awt/Component.java

Print this page

        

@@ -59,10 +59,11 @@
 import java.security.PrivilegedAction;
 import java.security.AccessControlContext;
 import javax.accessibility.*;
 import java.applet.Applet;
 
+import sun.awt.ComponentFactory;
 import sun.security.action.GetPropertyAction;
 import sun.awt.AppContext;
 import sun.awt.AWTAccessor;
 import sun.awt.ConstrainableGraphics;
 import sun.awt.SubRegionShowable;

@@ -1227,10 +1228,18 @@
             return parent.getToolkitImpl();
         }
         return Toolkit.getDefaultToolkit();
     }
 
+    final ComponentFactory getComponentFactory() {
+        final Toolkit toolkit = getToolkit();
+        if (toolkit instanceof ComponentFactory) {
+            return (ComponentFactory) toolkit;
+        }
+        throw new AWTError("Unsupported toolkit: " + toolkit);
+    }
+
     /**
      * Determines whether this component is valid. A component is valid
      * when it is correctly sized and positioned within its parent
      * container and all its children are also valid.
      * In order to account for peers' size requirements, components are invalidated

@@ -1324,11 +1333,15 @@
     Component findUnderMouseInWindow(PointerInfo pi) {
         if (!isShowing()) {
             return null;
         }
         Window win = getContainingWindow();
-        if (!Toolkit.getDefaultToolkit().getMouseInfoPeer().isWindowUnderMouse(win)) {
+        Toolkit toolkit = Toolkit.getDefaultToolkit();
+        if (!(toolkit instanceof ComponentFactory)) {
+            return null;
+        }
+        if (!((ComponentFactory) toolkit).getMouseInfoPeer().isWindowUnderMouse(win)) {
             return null;
         }
         final boolean INCLUDE_DISABLED = true;
         Point relativeToWindow = win.pointRelativeToComponent(pi.getLocation());
         Component inTheSameWindow = win.findComponentAt(relativeToWindow.x,

@@ -6955,11 +6968,11 @@
             ComponentPeer peer = this.peer;
             if (peer == null || peer instanceof LightweightPeer){
                 if (peer == null) {
                     // Update both the Component's peer variable and the local
                     // variable we use for thread safety.
-                    this.peer = peer = getToolkit().createComponent(this);
+                    this.peer = peer = getComponentFactory().createComponent(this);
                 }
 
                 // This is a lightweight component which means it won't be
                 // able to get window-related events by itself.  If any
                 // have been enabled, then the nearest native container must