Skip to content

Commit a7894d7

Browse files
committed
Component.getPeer() check -- fixes DnD problem in cases where DnD is set
before component is added to DOM
1 parent 232c114 commit a7894d7

File tree

9 files changed

+49
-41
lines changed

9 files changed

+49
-41
lines changed

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

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -772,22 +772,24 @@ public void setComponentZOrder(Component comp, int index) {
772772
*/
773773
@SuppressWarnings("deprecation")
774774
private void reparentTraverse(ContainerPeer parentPeer, Container child) {
775-
checkTreeLock();
776-
777-
for (int i = 0; i < child.getComponentCount(); i++) {
778-
Component comp = child.getComponent(i);
779-
if (comp.isLightweight()) {
780-
// If components is lightweight check if it is container
781-
// If it is container it might contain heavyweight children we need to reparent
782-
if (comp instanceof Container) {
783-
reparentTraverse(parentPeer, (Container)comp);
784-
}
785-
} else {
786-
// Q: Need to update NativeInLightFixer?
787-
comp.getPeer().reparent(parentPeer);
788-
}
789-
}
775+
// JSComponentUI.reparent is not implemented. It just gets tainted.
790776
}
777+
// checkTreeLock();
778+
//
779+
// for (int i = 0; i < child.getComponentCount(); i++) {
780+
// Component comp = child.getComponent(i);
781+
// if (comp.isLightweight()) {
782+
// // If components is lightweight check if it is container
783+
// // If it is container it might contain heavyweight children we need to reparent
784+
// if (comp instanceof Container) {
785+
// reparentTraverse(parentPeer, (Container)comp);
786+
// }
787+
// } else {
788+
// // Q: Need to update NativeInLightFixer?
789+
// comp.peer.reparent(parentPeer);
790+
// }
791+
// }
792+
// }
791793

792794
/**
793795
* Reparents child component peer to this container peer.
@@ -796,22 +798,24 @@ private void reparentTraverse(ContainerPeer parentPeer, Container child) {
796798
*/
797799
@SuppressWarnings("deprecation")
798800
private void reparentChild(Component comp) {
801+
// SwingJS does not need to worry about reparenting peers.
802+
//
799803
// checkTreeLock();
800-
if (comp == null) {
801-
return;
802-
}
803-
if (comp.isLightweight()) {
804-
805-
// never true in SwingJS
806-
807-
// If component is lightweight container we need to reparent all its explicit heavyweight children
808-
if (comp instanceof Container) {
809-
// Traverse component's tree till depth-first until encountering heavyweight component
810-
reparentTraverse((ContainerPeer)getPeer(), (Container)comp);
811-
}
812-
} else {
813-
comp.getPeer().reparent((ContainerPeer)getPeer());
814-
}
804+
// if (comp == null) {
805+
// return;
806+
// }
807+
// if (comp.isLightweight()) {
808+
//
809+
// // never true in SwingJS
810+
//
811+
// // If component is lightweight container we need to reparent all its explicit heavyweight children
812+
// if (comp instanceof Container) {
813+
// // Traverse component's tree till depth-first until encountering heavyweight component
814+
// reparentTraverse((ContainerPeer)peer, (Container)comp); // BH was getPeer()
815+
// }
816+
// } else {
817+
// comp.peer.reparent((ContainerPeer)peer);
818+
// }
815819
}
816820

817821
/**

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ protected void updatePeerVisibility(boolean isVisible) {
359359
* A peer in SwingJS can only be created after the ui is created.
360360
*/
361361
@Override
362-
protected ComponentPeer getOrCreatePeer() {
362+
public ComponentPeer getOrCreatePeer() {
363363
return (ui == null ? null : peer == null ? (peer = getToolkit().createComponent(this)) : peer);
364364
}
365365

@@ -799,5 +799,4 @@ public static enum ModalExclusionType {
799799
TOOLKIT_EXCLUDE
800800
}
801801

802-
803802
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ public void addNotify() {
697697
}
698698

699699
@Override
700-
protected ComponentPeer getOrCreatePeer() {
700+
public ComponentPeer getOrCreatePeer() {
701701
return (ui == null ? null : peer == null ? (peer = getToolkit().createDialog((Dialog) (Object) this)) : peer);
702702
}
703703
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ public void addNotify() {
495495
}
496496

497497
@Override
498-
protected ComponentPeer getOrCreatePeer() {
498+
public ComponentPeer getOrCreatePeer() {
499499
return (ui == null ? null : peer == null ? (peer = getToolkit().createFrame(this)) : peer);
500500
}
501501

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void addNotify() {
103103
}
104104

105105
@Override
106-
protected ComponentPeer getOrCreatePeer() {
106+
public ComponentPeer getOrCreatePeer() {
107107
return (ui == null ? null : peer == null ? (peer = getToolkit().createPanel((Panel) (Object) this)) : peer);
108108
}
109109

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,8 @@ public void addNotify() {
758758
}
759759

760760
@Override
761-
protected ComponentPeer getOrCreatePeer() {
761+
public ComponentPeer getOrCreatePeer() {
762+
// SwingJS this should have 秘
762763
return (ui == null ? null : peer == null ? (peer = getToolkit().createWindow(this)) : peer);
763764
}
764765

@@ -3521,9 +3522,8 @@ public void setOpaque(boolean opaque) {
35213522
// }
35223523
setLayersOpaque(this, opaque);
35233524
this.opaque = opaque;
3524-
WindowPeer peer = (WindowPeer)getPeer();
35253525
if (peer != null) {
3526-
peer.setOpaque(opaque);
3526+
((WindowPeer) peer).setOpaque(opaque);
35273527
}
35283528
}
35293529
}

sources/net.sf.j2s.java.core/src/java/awt/dnd/DropTarget.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.awt.HeadlessException;
3434
//import java.awt.HeadlessException;
3535
import java.awt.Insets;
36+
import java.awt.JSComponent;
3637
import java.awt.Point;
3738
import java.awt.Rectangle;
3839
import java.awt.Toolkit;
@@ -46,6 +47,7 @@
4647
import java.io.Serializable;
4748
import java.util.TooManyListenersException;
4849

50+
import javax.swing.JComponent;
4951
import javax.swing.Timer;
5052

5153

@@ -497,7 +499,7 @@ public void addNotify(ComponentPeer peer) {
497499

498500
for (Component c = component;
499501
c != null && peer instanceof LightweightPeer; c = c.getParent()) {
500-
peer = c.getPeer();
502+
peer = ((JSComponent) c).getOrCreatePeer(); // SwingJS was getPeer(), but this is only if attached.
501503
}
502504

503505
//if (peer instanceof DropTargetPeer) {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4245,7 +4245,7 @@ public void revalidate() {
42454245
// internal structural change.
42464246
if (ui != null)
42474247
((JSComponentUI)ui).setTainted();
4248-
if (getParent() == null && !isValidateRoot()) {
4248+
if (getParent() == null && !isValidateRoot() || !秘isTopLevelVisible()) {
42494249
// Note: We don't bother invalidating here as once added
42504250
// to a valid parent invalidate will be invoked (addImpl
42514251
// invokes addNotify which will invoke invalidate on the
@@ -4284,6 +4284,10 @@ public void run() {
42844284
}
42854285
}
42864286

4287+
boolean 秘isTopLevelVisible() {
4288+
Component c = 秘getTopInvokableAncestor(this, true);
4289+
return (c != null && c.isVisible());
4290+
}
42874291
/**
42884292
* If this method returns true, <code>revalidate</code> calls by descendants
42894293
* of this component will cause the entire tree beginning with this root to be

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3103,7 +3103,6 @@ public void destroyBuffers() {
31033103
@Override
31043104
public void reparent(ContainerPeer newContainer) {
31053105
JSUtil.notImplemented("");
3106-
31073106
}
31083107

31093108
@Override

0 commit comments

Comments
 (0)