Skip to content

Commit 0b7213f

Browse files
hansonrhansonr
authored andcommitted
.isWindowOrJSApplet()
1 parent a8ab1e9 commit 0b7213f

File tree

7 files changed

+41
-44
lines changed

7 files changed

+41
-44
lines changed

sources/net.sf.j2s.java.core/src/java/awt/KeyboardFocusManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ protected void setGlobalFocusOwner(Component focusOwner) throws SecurityExceptio
511511
if (focusOwner != null && (getCurrentFocusCycleRoot() == null
512512
|| !focusOwner.isFocusCycleRoot(getCurrentFocusCycleRoot()))) {
513513
Container rootAncestor = focusOwner.getFocusCycleRootAncestor();
514-
if (rootAncestor == null && (focusOwner instanceof Window)) {
514+
if (rootAncestor == null && focusOwner.isWindowOrJSApplet()) {
515515
rootAncestor = (Container) focusOwner;
516516
}
517517
if (rootAncestor != null) {
@@ -1707,7 +1707,7 @@ protected java.util.List<KeyEventPostProcessor> getKeyEventPostProcessors() {
17071707

17081708
public static void setMostRecentFocusOwner(Component component) {
17091709
Component window = component;
1710-
while (window != null && !(window instanceof Window) && !(window instanceof JSApplet)) {
1710+
while (window != null && !window.isWindowOrJSApplet()) {
17111711
window = window.parent;
17121712
}
17131713
if (window != null) {
@@ -1736,7 +1736,7 @@ public static void clearMostRecentFocusOwner(Component comp) {
17361736

17371737
// synchronized (comp.getTreeLock()) {
17381738
window = comp.getParent();
1739-
while (window != null && !(window instanceof Window)) {
1739+
while (window != null && !window.isWindowOrJSApplet()) {
17401740
window = window.getParent();
17411741
}
17421742
// }

sources/net.sf.j2s.java.core/src/javax/swing/AncestorNotifier.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ void addListeners(Component ancestor, boolean addToFirst) {
154154
jAncestor.addPropertyChangeListener(this);
155155
}
156156
}
157-
if (!a.isVisible() || a.getParent() == null || a instanceof Window) {
157+
if (!a.isVisible() || a.getParent() == null || a.isWindowOrJSApplet()) {
158158
firstInvisibleAncestor = a;
159159
}
160160
}
161-
if (firstInvisibleAncestor instanceof Window &&
161+
if (firstInvisibleAncestor != null && firstInvisibleAncestor.isWindowOrJSApplet() &&
162162
firstInvisibleAncestor.isVisible()) {
163163
firstInvisibleAncestor = null;
164164
}
@@ -172,7 +172,7 @@ void removeListeners(Component ancestor) {
172172
JComponent jAncestor = (JComponent)a;
173173
jAncestor.removePropertyChangeListener(this);
174174
}
175-
if (a == firstInvisibleAncestor || a instanceof Window) {
175+
if (a == firstInvisibleAncestor || a.isWindowOrJSApplet()) {
176176
break;
177177
}
178178
}
@@ -207,7 +207,7 @@ public void componentHidden(ComponentEvent e) {
207207
Component ancestor = e.getComponent();
208208
boolean needsNotify = firstInvisibleAncestor == null;
209209

210-
if ( !(ancestor instanceof Window) ) {
210+
if ( !ancestor.isWindowOrJSApplet() ) {
211211
removeListeners(ancestor.getParent());
212212
}
213213
firstInvisibleAncestor = ancestor;

sources/net.sf.j2s.java.core/src/javax/swing/JViewport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ private void validateView() {
463463
if (!c.isLightweight()) {
464464
return;
465465
}
466-
if ((c instanceof Window) || (c instanceof JSApplet)) {
466+
if (c.isWindowOrJSApplet()) {
467467
root = c;
468468
break;
469469
}

sources/net.sf.j2s.java.core/src/javax/swing/LayoutComparator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public int compare(Object o1, Object o2) {
7575

7676
for(aAncestory = new LinkedList(); a != null; a = a.getParent()) {
7777
aAncestory.add(a);
78-
if (a instanceof Window) {
78+
if (a.isWindowOrJSApplet()) {
7979
break;
8080
}
8181
}
@@ -86,7 +86,7 @@ public int compare(Object o1, Object o2) {
8686

8787
for(bAncestory = new LinkedList(); b != null; b = b.getParent()) {
8888
bAncestory.add(b);
89-
if (b instanceof Window) {
89+
if (b.isWindowOrJSApplet()) {
9090
break;
9191
}
9292
}

sources/net.sf.j2s.java.core/src/javax/swing/PopupFactory.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,7 @@ boolean fitsOnScreen() {
625625
r.x = p.x;
626626
r.y = p.y;
627627
return r.contains(x, y, width, height);
628-
} else if (parent instanceof Window ||
629-
parent instanceof JSApplet) {
628+
} else if (parent instanceof Window) {
630629
// No suitable swing component found
631630
break;
632631
}
@@ -938,8 +937,7 @@ public void show() {
938937
if it has a layered pane,
939938
add to that, otherwise
940939
add to the window. */
941-
while (!(parent instanceof Window || parent instanceof JSApplet) &&
942-
(parent!=null)) {
940+
while (parent != null && !parent.isWindowOrJSApplet()) {
943941
parent = parent.getParent();
944942
}
945943
// Set the visibility to false before adding to workaround a

sources/net.sf.j2s.java.core/src/javax/swing/RepaintManager.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public synchronized void addInvalidComponent(JComponent invalidComponent) {
379379
//System.out.println("RM noVisibleParent");
380380
return;
381381
}
382-
if ((c instanceof Window) || (c instanceof JSApplet)) {
382+
if (c.isWindowOrJSApplet()) {
383383
root = c;
384384
break;
385385
}
@@ -413,13 +413,14 @@ public synchronized void addInvalidComponent(JComponent invalidComponent) {
413413
}
414414

415415
/**
416-
* The deal here is that I added Window to subclass JComponent so that
416+
* SwingJS The deal here is that I added Window to subclass JComponent so that
417417
* JInternalFrame could subclass Frame and still be a JComponent
418418
*
419419
* @param c
420420
* @return
421421
*/
422422
private boolean isStandardJComponent(Component c) {
423+
// TODO Q How about Applet here?
423424
return (c instanceof JComponent && !(c instanceof Window));
424425
}
425426

@@ -474,7 +475,7 @@ private void addDirtyRegion0(Container c, int x, int y, int w, int h) {
474475
if (!p.isVisible() || p.getPeer() == null) {
475476
return;
476477
}
477-
if ((p instanceof Window) || (p instanceof JSApplet)) {
478+
if (p.isWindowOrJSApplet()) {
478479
// Iconified frames are still visible!
479480
if (p instanceof JSFrame
480481
&& (((JSFrame) p).getExtendedState() & JSFrame.ICONIFIED) == JSFrame.ICONIFIED) {
@@ -580,10 +581,8 @@ void scheduleHeavyWeightPaints() {
580581
}
581582
for (Container hw : hws.keySet()) {
582583
Rectangle dirty = hws.get(hw);
583-
if (hw instanceof Window) {
584+
if (hw.isWindowOrJSApplet()) {
584585
addDirtyRegion((Window) hw, dirty.x, dirty.y, dirty.width, dirty.height);
585-
} else if (hw instanceof JSApplet) {
586-
addDirtyRegion((JSApplet) hw, dirty.x, dirty.y, dirty.width, dirty.height);
587586
} else { // SwingHeavyWeight
588587
addDirtyRegion0(hw, dirty.x, dirty.y, dirty.width, dirty.height);
589588
}
@@ -776,7 +775,7 @@ private Map<Component, Rectangle> updateWindows(
776775
Set<Component> dirtyComps = dirtyComponents.keySet();
777776
for (Iterator<Component> it = dirtyComps.iterator(); it.hasNext();) {
778777
Component dirty = it.next();
779-
Window window = dirty instanceof Window ? (Window) dirty : SwingUtilities
778+
Window window = dirty.isWindowOrJSApplet() ? (Window) dirty : SwingUtilities
780779
.getWindowAncestor(dirty);
781780

782781
if (window != null && !AWTAccessor.getWindowAccessor().isOpaque(window)) {

sources/net.sf.j2s.java.core/src/sun/awt/SunToolkit.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,28 +1489,28 @@ public static boolean isModalExcluded(Window window) {
14891489
// End Plug-in code
14901490
// /////////////////////////////////////////////////////////////////////////
14911491

1492-
public static boolean isLightweightOrUnknown(Component comp) {
1493-
// SwingJS - not tested; probably never called
1494-
// if (false || !true)...
1495-
if (comp.isLightweight() || !(getDefaultToolkit() instanceof SunToolkit)) {
1496-
return true;
1497-
}
1498-
// SwingJS no idea what this is for
1499-
return !(
1500-
// comp instanceof Button
1501-
// || comp instanceof Canvas
1502-
// || comp instanceof Checkbox
1503-
// || comp instanceof Choice
1504-
// || comp instanceof Label
1505-
// || comp instanceof List
1506-
// ||
1507-
comp instanceof Panel
1508-
// || comp instanceof Scrollbar
1509-
// || comp instanceof ScrollPane
1510-
// || comp instanceof TextArea
1511-
// || comp instanceof TextField
1512-
|| comp instanceof Window);
1513-
}
1492+
// public static boolean isLightweightOrUnknown(Component comp) {
1493+
// // SwingJS - not tested; probably never called
1494+
// // if (false || !true)...
1495+
// if (comp.isLightweight() || !(getDefaultToolkit() instanceof SunToolkit)) {
1496+
// return true;
1497+
// }
1498+
// // SwingJS no idea what this is for
1499+
// return !(
1500+
// // comp instanceof Button
1501+
// // || comp instanceof Canvas
1502+
// // || comp instanceof Checkbox
1503+
// // || comp instanceof Choice
1504+
// // || comp instanceof Label
1505+
// // || comp instanceof List
1506+
// // ||
1507+
// comp instanceof Panel
1508+
// // || comp instanceof Scrollbar
1509+
// // || comp instanceof ScrollPane
1510+
// // || comp instanceof TextArea
1511+
// // || comp instanceof TextField
1512+
// || comp.isWindowOrJSApplet());
1513+
// }
15141514

15151515
// public static class OperationTimedOut extends RuntimeException {
15161516
// public OperationTimedOut(String msg) {
@@ -1940,7 +1940,7 @@ protected RenderingHints getDesktopAAHints() {
19401940
* Window; null, if component is not a part of window hierarchy
19411941
*/
19421942
public static Window getContainingWindow(Component comp) {
1943-
while (comp != null && !(comp instanceof Window || comp instanceof JSApplet)) {
1943+
while (comp != null && !comp.isWindowOrJSApplet()) {
19441944
comp = comp.getParent();
19451945
}
19461946
return (Window) comp;

0 commit comments

Comments
 (0)