@@ -145,7 +145,7 @@ public static Rectangle getLocalBounds(Component aComponent) {
145145 */
146146 public static Window getWindowAncestor (Component c ) {
147147 for (Container p = c .getParent (); p != null ; p = p .getParent ()) {
148- if (p instanceof Window ) {
148+ if (p . isWindowOrJSApplet () ) {
149149 return (Window )p ;
150150 }
151151 }
@@ -158,7 +158,7 @@ public static Window getWindowAncestor(Component c) {
158158 */
159159 static Point convertScreenLocationToParent (Container parent ,int x , int y ) {
160160 for (Container p = parent ; p != null ; p = p .getParent ()) {
161- if (p instanceof Window ) {
161+ if (p != null && p . isWindowOrJSApplet () ) {
162162 Point point = new Point (x , y );
163163
164164 SwingUtilities .convertPointFromScreen (point , parent );
@@ -380,13 +380,12 @@ else if (sourceEvent instanceof MenuDragMouseEvent) {
380380 public static void convertPointToScreen (Point p ,Component c ) {
381381// Rectangle b;
382382 int x ,y ;
383-
383+ boolean done = false ;
384384 do {
385385 if (c instanceof JComponent ) {
386386 x = ((JComponent )c ).getX ();
387387 y = ((JComponent )c ).getY ();
388- } else if (c instanceof JSApplet ||
389- c instanceof Window ) {
388+ } else if ((done = c .isWindowOrJSApplet ())) {
390389 try {
391390 Point pp = c .getLocationOnScreen ();
392391 x = pp .x ;
@@ -402,11 +401,8 @@ public static void convertPointToScreen(Point p,Component c) {
402401
403402 p .x += x ;
404403 p .y += y ;
405-
406- if (c instanceof Window || c instanceof JSApplet )
407- break ;
408404 c = c .getParent ();
409- } while (c != null );
405+ } while (c != null && ! done );
410406 }
411407
412408 /**
@@ -424,8 +420,7 @@ public static void convertPointFromScreen(Point p,Component c) {
424420 if (c instanceof JComponent ) {
425421 x = ((JComponent )c ).getX ();
426422 y = ((JComponent )c ).getY ();
427- } else if (c instanceof JSApplet ||
428- c instanceof Window ) {
423+ } else if (c .isWindowOrJSApplet ()) {
429424 try {
430425 Point pp = c .getLocationOnScreen ();
431426 x = pp .x ;
@@ -442,7 +437,7 @@ public static void convertPointFromScreen(Point p,Component c) {
442437 p .x -= x ;
443438 p .y -= y ;
444439
445- if (c instanceof Window || c instanceof JSApplet )
440+ if (c . isWindowOrJSApplet () )
446441 break ;
447442 c = c .getParent ();
448443 } while (c != null );
@@ -1530,7 +1525,7 @@ public static Component findFocusOwner(Component c) {
15301525
15311526 // verify focusOwner is a descendant of c
15321527 for (Component temp = focusOwner ; temp != null ;
1533- temp = (temp instanceof Window ) ? null : temp .getParent ())
1528+ temp = (temp . isWindowOrJSApplet ( ) ? null : temp .getParent () ))
15341529 {
15351530 if (temp == c ) {
15361531 return focusOwner ;
@@ -1563,16 +1558,12 @@ public static JRootPane getRootPane(Component c) {
15631558 * @return the first ancestor of c that's a Window or the last Applet ancestor
15641559 */
15651560 public static Component getRoot (Component c ) {
1566- Component applet = null ;
15671561 for (Component p = c ; p != null ; p = p .getParent ()) {
1568- if (p instanceof Window ) {
1562+ if (p . isWindowOrJSApplet () ) {
15691563 return p ;
15701564 }
1571- if (p instanceof JSApplet ) {
1572- applet = p ;
1573- }
15741565 }
1575- return applet ;
1566+ return null ;
15761567 }
15771568
15781569 // SwingJS never used - see JComponent
0 commit comments