Skip to content

Commit 9affb1d

Browse files
authored
Merge pull request #144 from BobHanson/hanson1
work in relation to OpenSourcePhysics
2 parents b1d0700 + 28414eb commit 9affb1d

33 files changed

+932
-273
lines changed
6.6 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200117045002
1+
20200119225004
6.6 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200117045002
1+
20200119225004

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;
6.6 KB
Binary file not shown.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1867,17 +1867,21 @@ public Point getLocationOnScreen() {
18671867
*/
18681868
final Point getLocationOnScreen_NoTreeLock() {
18691869
if (isShowing()) {
1870-
if (isLightweight()) {// peer instanceof LightweightPeer) { // SwingJS will return FALSE
1870+
if (isLightweight()) {
18711871
// lightweight component location needs to be translated
18721872
// relative to a native component.
18731873
Container host = getNativeContainer();
1874+
if (host.peer == null)
1875+
return null;
18741876
Point pt = host.peer.getLocationOnScreen();
18751877
for (Component c = this; c != host; c = c.getParent()) {
18761878
pt.x += c.x;
18771879
pt.y += c.y;
18781880
}
18791881
return pt;
18801882
} else {
1883+
if (peer == null)
1884+
return null;
18811885
Point pt = peer.getLocationOnScreen();
18821886
return pt;
18831887
}

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

Lines changed: 24 additions & 3 deletions
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;
@@ -103,8 +105,8 @@ public interface A2SWrappedComponent {
103105
*/
104106
public Action 秘keyAction;
105107

106-
protected boolean 秘isAppletFrame;
107-
public boolean 秘isFramedApplet;
108+
// protected boolean 秘isAppletFrame;
109+
// public boolean 秘isFramedApplet;
108110

109111
public String 秘htmlName;
110112

@@ -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,22 @@ 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.秘isContentPane = false;
750+
jc.getRootPane().setContentPane(new JPanel());
751+
}
752+
jc.秘frameViewer = 秘frameViewer;
753+
jc.秘topFrameViewer = 秘topFrameViewer;
754+
return jc;
755+
}
756+
757+
758+
738759
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3081,14 +3081,16 @@ public void setLocationRelativeTo(Component c) {
30813081
}
30823082
}
30833083

3084-
if ((c != null && !c.isShowing()) || root == null || !root.isShowing()) {
3084+
Point invokerScreenLocation;
3085+
if (c != null && !c.isShowing()
3086+
|| root == null
3087+
|| !root.isShowing()
3088+
|| (invokerScreenLocation = c.getLocationOnScreen()) == null) {
30853089
Dimension paneSize = getSize();
30863090
Point centerPoint = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
30873091
setLocation(centerPoint.x - paneSize.width / 2, centerPoint.y - paneSize.height / 2);
30883092
} else {
30893093
Dimension invokerSize = c.getSize();
3090-
Point invokerScreenLocation = c.getLocationOnScreen();
3091-
30923094
Rectangle windowBounds = getBounds();
30933095
int dx = invokerScreenLocation.x + ((invokerSize.width - windowBounds.width) >> 1);
30943096
int dy = invokerScreenLocation.y + ((invokerSize.height - windowBounds.height) >> 1);

sources/net.sf.j2s.java.core/src/java/io/File.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,12 @@ private static String slashify(String path, boolean isDirectory) {
701701
// */
702702
public URI toURI() {
703703
try {
704-
File f = getAbsoluteFile();
705-
String sp = slashify(f.getPath(), f.isDirectory());
704+
String sp = slashify(getAbsoluteFile().getPath(), false);
706705
if (sp.startsWith("//"))
707706
sp = "//" + sp;
708-
return new URI("file", null, sp, null);
707+
URI uri = new URI("file", null, sp, null);
708+
uri.秘bytes = 秘bytes;
709+
return uri;
709710
} catch (URISyntaxException x) {
710711
throw new Error(x); // Can't happen
711712
}

0 commit comments

Comments
 (0)