Skip to content

Commit ad3c00b

Browse files
committed
allows setting a frame's contentPane to an applet.
Still does not allow getContentPane().add(applet)
1 parent b3b4825 commit ad3c00b

10 files changed

Lines changed: 37 additions & 5 deletions

File tree

4.57 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200117045002
1+
20200118185024
4.57 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200117045002
1+
20200118185024

sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptVisitor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
21532153
case "java.awt.Component":
21542154
case "javax.swing.JComponent":
21552155
if (!class_fullName.startsWith("java.") && !class_fullName.startsWith("javax.")) {
2156+
// Component and Label are not opaque, Panel is, so we choose Label here
21562157
String s = superclassName.replace("Component", "Label");
21572158
log(">>class " + class_fullName + " extended " + superclassName + " now extends " + s);
21582159
superclassName = s;
4.57 KB
Binary file not shown.

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
import java.util.Arrays;
3535

3636
import javax.swing.Action;
37+
import javax.swing.JApplet;
3738
import javax.swing.JComponent;
39+
import javax.swing.JPanel;
3840
import javax.swing.JPopupMenu;
3941
import javax.swing.JRootPane;
4042
import javax.swing.RootPaneContainer;
@@ -116,7 +118,7 @@ public interface A2SWrappedComponent {
116118
public boolean 秘isRootPane, 秘isContentPane;
117119
// initially, we go with the current thread, but later we will pick up the actual JSAppletViewer
118120
public JSAppletViewer 秘appletViewer = Thread.currentThread().getThreadGroup().秘appletViewer;
119-
private JSFrameViewer 秘frameViewer, 秘topFrameViewer;
121+
public JSFrameViewer 秘frameViewer, 秘topFrameViewer;
120122
public HTML5Canvas 秘canvas;
121123
public ComponentUI ui; // from JComponent
122124

@@ -284,6 +286,7 @@ public JSFrameViewer setFrameViewer(JSFrameViewer viewer) {
284286
return 秘frameViewer = (viewer == null ? viewer = new JSFrameViewer().setForWindow((RootPaneContainer) this) : viewer);
285287
}
286288

289+
287290
public JSFrameViewer getFrameViewer() {
288291
JSComponent parent = null;
289292
return (秘topFrameViewer != null ? 秘topFrameViewer
@@ -735,4 +738,21 @@ protected boolean canPaint() {
735738
rootPane.addNotify(); // builds a peer for the root pane
736739
}
737740

741+
public JComponent 秘transferFrameTo(JComponent jc) {
742+
if (jc.秘frameViewer == 秘frameViewer)
743+
return jc;
744+
if (jc.getUIClassID() == "AppletUI") {
745+
System.out.println("JSComponent setContentPane to applet; using content.contentPane instead");
746+
// applet or frame or window of some sort
747+
// take just the content pane
748+
jc = (JComponent) jc.getRootPane().getContentPane();
749+
jc.getRootPane().setContentPane(new JPanel());
750+
}
751+
jc.秘frameViewer = 秘frameViewer;
752+
jc.秘topFrameViewer = 秘topFrameViewer;
753+
return jc;
754+
}
755+
756+
757+
738758
}

sources/net.sf.j2s.java.core/src/javajs/async/SwingJSUtils.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,16 @@ protected boolean nextStateIfUnchanged(Object oThis, Object runnable, int stateN
601601
levelNext == UNCHANGED ? me.level : levelNext);
602602
return true;
603603
}
604+
605+
/**
606+
* sleep and then execute the next state
607+
* @param ms
608+
*/
609+
public void sleep(int ms) {
610+
int next = stateNext;
611+
delayedState(ms, next);
612+
}
613+
604614
}
605615

606616
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,4 +820,5 @@ protected String paramString() {
820820
// return AccessibleRole.LAYERED_PANE;
821821
// }
822822
// }
823+
823824
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,9 @@ public void setContentPane(Container content) {
594594
"contentPane cannot be set to null.");
595595
if (contentPane != null && contentPane.getParent() == layeredPane)
596596
layeredPane.remove(contentPane);
597-
contentPane = content;
597+
content = 秘transferFrameTo((JComponent)content);
598598
content.秘isContentPane = true;
599-
599+
contentPane = content;
600600
layeredPane.add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
601601
}
602602

0 commit comments

Comments
 (0)