Skip to content

Commit 7da9cea

Browse files
hansonrhansonr
authored andcommitted
comp.isJ2SWindowButNotJInternalFrame()
1 parent 554dba0 commit 7da9cea

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,7 +2094,7 @@ public void reshape(int x, int y, int width, int height) {
20942094
// windows here as it is done from peer or native code when
20952095
// the window is really resized or moved, otherwise some
20962096
// events may be sent twice
2097-
if (this instanceof Window && !(this instanceof JInternalFrame)) {
2097+
if (isJ2SWindowButNotJInternalFrame()) {
20982098
needNotify = false;
20992099
}
21002100
// }
@@ -3995,7 +3995,7 @@ boolean dispatchMouseWheelToAncestor(MouseWheelEvent e) {
39953995
newX += anc.getX();
39963996
newY += anc.getY();
39973997

3998-
if (!(anc instanceof Window)) {
3998+
if (!anc.isWindowOrJSApplet()) {
39993999
anc = anc.getParent();
40004000
} else {
40014001
break;
@@ -6546,7 +6546,7 @@ final boolean requestFocusHelper(boolean temporary, boolean focusedWindowChangeA
65466546
KeyboardFocusManager.setMostRecentFocusOwner(this);
65476547

65486548
Component window = this;
6549-
while ((window != null) && !(window instanceof Window || window instanceof JSApplet)) {
6549+
while ((window != null) && !window.isWindowOrJSApplet()) {
65506550
if (!window.isVisible()) {
65516551
return false;
65526552
}
@@ -6574,6 +6574,15 @@ final boolean requestFocusHelper(boolean temporary, boolean focusedWindowChangeA
65746574
return success;
65756575
}
65766576

6577+
public boolean isWindowOrJSApplet() {
6578+
// SwingJS treating embedded applet as window here
6579+
return this instanceof Window || this instanceof JSApplet;
6580+
}
6581+
6582+
public boolean isJ2SWindowButNotJInternalFrame() {
6583+
return this instanceof Window && ((JSComponent) this).getUIClassID() != "InternalFrameUI";
6584+
}
6585+
65776586
private boolean isRequestFocusAccepted(boolean temporary, boolean focusedWindowChangeAllowed,
65786587
CausedFocusEvent.Cause cause) {
65796588
if (!isFocusable() || !isVisible()) {
@@ -7948,8 +7957,9 @@ Point getLocationOnWindow() {
79487957
// checkTreeLock();
79497958
Point curLocation = getLocation();
79507959

7960+
// BH changed this to include applet here
79517961
for (Container parent = getContainer(); parent != null
7952-
&& !(parent instanceof Window); parent = parent.getContainer()) {
7962+
&& !parent.isWindowOrJSApplet(); parent = parent.getContainer()) {
79537963
curLocation.x += parent.getX();
79547964
curLocation.y += parent.getY();
79557965
}

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,14 @@ private void checkAddToSelf(Component comp){
452452
}
453453
}
454454

455-
/**
456-
* Checks that the component is not a Window instance.
457-
*/
458-
private void checkNotAWindow(Component comp){
459-
if (comp instanceof Window && ((JSComponent) comp).getUIClassID() != "InternalFrameUI") {
460-
throw new IllegalArgumentException("adding a window to a container");
461-
}
462-
}
455+
// /**
456+
// * Checks that the component is not a Window instance.
457+
// */
458+
// private void checkNotAWindow(Component comp){
459+
// if (comp instanceof Window && ((JSComponent) comp).getUIClassID() != "InternalFrameUI") {
460+
// throw new IllegalArgumentException("adding a window to a container");
461+
// }
462+
// }
463463

464464
// /**
465465
// * Checks that the component comp can be added to this container
@@ -1085,7 +1085,12 @@ protected Component addImplCont(Component comp, Object constraints, int index) {
10851085
"illegal component position");
10861086
}
10871087
checkAddToSelf(comp);
1088-
checkNotAWindow(comp);
1088+
// Here we do not allow JSApplet, but we do allow JInternalFrame, which is a JFrame now
1089+
if (comp.isJ2SWindowButNotJInternalFrame()) {
1090+
throw new IllegalArgumentException("adding a window to a container");
1091+
}
1092+
1093+
// checkNotAWindow(comp);
10891094
// if (thisGC != null) {
10901095
// comp.checkGD(thisGC.getDevice().getIDstring());
10911096
// }
@@ -1145,6 +1150,8 @@ protected Component addImplCont(Component comp, Object constraints, int index) {
11451150
return comp;
11461151
}
11471152

1153+
1154+
11481155
/**
11491156
* Checks that all Components that this Container contains are on
11501157
* the same GraphicsDevice as this Container. If not, throws an
@@ -3245,12 +3252,12 @@ final boolean containsFocus() {
32453252
* @param comp a component in test, must not be null
32463253
*/
32473254
private boolean isParentOf(Component comp) {
3248-
synchronized(getTreeLock()) {
3249-
while (comp != null && comp != this && !(comp instanceof Window)) {
3255+
// synchronized(getTreeLock()) {
3256+
while (comp != null && comp != this && !comp.isWindowOrJSApplet()) {
32503257
comp = comp.getParent();
32513258
}
32523259
return (comp == this);
3253-
}
3260+
// }
32543261
}
32553262

32563263
@Override
@@ -4575,7 +4582,8 @@ public void eventDispatched(AWTEvent e) {
45754582
// see 5083555
45764583
// check if srcComponent is in any modal blocked window
45774584
Component c = nativeContainer;
4578-
while ((c != null) && !(c instanceof Window)) {
4585+
//SwingJS TODO Q: no check for applet here?
4586+
while (c != null && !(c instanceof Window)) {
45794587
c = c.getParent_NoClientCode();
45804588
}
45814589
if ((c == null) || ((Window)c).isModalBlocked()) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,15 +583,15 @@ protected boolean accept(Component aComponent) {
583583
// Verify that the Component is recursively enabled. Disabling a
584584
// heavyweight Container disables its children, whereas disabling
585585
// a lightweight Container does not.
586-
if (!(aComponent instanceof Window)) {
586+
if (!aComponent.isWindowOrJSApplet()) {
587587
for (Container enableTest = aComponent.getParent();
588588
enableTest != null;
589589
enableTest = enableTest.getParent())
590590
{
591591
if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
592592
return false;
593593
}
594-
if (enableTest instanceof Window) {
594+
if (enableTest.isWindowOrJSApplet()) {
595595
break;
596596
}
597597
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ protected boolean accept(Component aComponent) {
103103
// Verify that the Component is recursively enabled. Disabling a
104104
// heavyweight Container disables its children, whereas disabling
105105
// a lightweight Container does not.
106-
if (!(aComponent instanceof Window)) {
106+
if (!aComponent.isWindowOrJSApplet()) {
107107
for (Container enableTest = aComponent.getParent();
108108
enableTest != null;
109109
enableTest = enableTest.getParent())
110110
{
111111
if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
112112
return false;
113113
}
114-
if (enableTest instanceof Window) {
114+
if (enableTest.isWindowOrJSApplet()) {
115115
break;
116116
}
117117
}

0 commit comments

Comments
 (0)