Skip to content

Commit c212b01

Browse files
authored
Merge pull request #104 from BobHanson/master
Hanson1 - AWT work, primarily
2 parents 5a884b2 + 0d2c6b3 commit c212b01

File tree

89 files changed

+2545
-761
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+2545
-761
lines changed

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ in Java. Using the java2script/SwingJS Eclipse plug-in, both Java .class files a
1717

1818

1919
java2script/SwingJS includes an Eclipse plug-in (technically a "drop-in"), net.sf.j2s.core.zip
20-
(see https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/dropins),
20+
(see https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs),
2121
along with a JavaScript version of the Java Virtual Machine (SwingJS, https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.java.core/SwingJS-site.zip)
2222
to allow the rapid and
2323
automated production of browser-ready JavaScript versions of Java applications and applets.
@@ -27,12 +27,20 @@ automated production of browser-ready JavaScript versions of Java applications a
2727

2828
See https://github.com/BobHanson/java2script/tree/master/sources/net.sf.j2s.core/dist and the README file in that directory.
2929

30+
# History - 2019-
31+
32+
SwingJS is now more than just "Swing"-JS. AWT applets and applications are now supported. A test suite of over 500 AWT applets has been used to refine the AWT runtime classes with great success. Many thanks to Karsten Blankenagel (University of Wuppertal) for access to this source code set.
33+
34+
Examples include:
35+
36+
MathePrisma (http://www.matheprisma.uni-wuppertal.de/) This site is still using the Java applets as of 2019.03.12; JavaScript versions still in development.
37+
3038
# History - 2017-
3139

3240

3341
https://github.com/BobHanson/java2script (development master)
3442

35-
Current development "Version 3 development master" involve a completely rewritten transpiler (2017) “CompilationParticipant” that follows the Eclipse Java compiler. The implementation nearly perfectly emulates the Java Virtual Machine. It includes fully qualified methods, compile-time method binding, generic methods and classes, Java 8 lambda functions and streams, Java reflection and dynamic class loading for efficient modular just-in-time performance, Java Swing components, modal and nonmodel dialogs, audio, jpdf, the AWT event thread, and many other added packages. Java applications and applets can both be run in JavaScript in any browser.
43+
Current development "Version 3 development master" involves a completely rewritten transpiler (2017) “CompilationParticipant” that follows the Eclipse Java compiler. The implementation nearly perfectly emulates the Java Virtual Machine. It includes fully qualified methods, compile-time method binding, generic methods and classes, Java 8 lambda functions and streams, Java reflection and dynamic class loading for efficient modular just-in-time performance, Java Swing components, modal and nonmodel dialogs, audio, jpdf, the AWT event thread, and many other added packages. Java applications and applets can both be run in JavaScript in any browser.
3644

3745
Version 3 also implements real-time creation of HTML test files for immediate JavaScript testing of any changes made to the Java code. Basically, when the source file is saved in Eclipse (Photon), the JavaScript updates automatically, and a reload of the page in the browser shows the changes immediately. This makes for very easy side-by-side Java and JavaScript debugging.
3846

@@ -65,8 +73,13 @@ However, this version did not produce "fully qualified" method signatures, resul
6573

6674
Synchronized with https://github.com/BobHanson/java2script as the stable master version in 2018.
6775

68-
Examples can be found at https://chemapps.stolaf.edu/swingjs/phet/site/swingjs/examples
69-
and https://chemapps.stolaf.edu/jmol/jsmol
76+
Examples include:
77+
78+
Phet, Falstad, and other tests https://chemapps.stolaf.edu/swingjs/phet/site/swingjs/examples Initial SwingJS tests converting AWT to Swing in Java, then transpiling.
79+
80+
JSmol: https://chemapps.stolaf.edu/jmol/jsmol Non-AWT, Non-Swing version, our initial application of Java2Script technology.
81+
82+
Falstad Math and Physics Applets (https://www.falstad.com/mathphysics.html) Source available.
7083

7184
# History - 2005-2010
7285

9.1 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190307200127
1+
20190315122942
9.1 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190307200127
1+
20190315122942
9.1 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/applet/JSApplet.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import java.awt.HeadlessException;
3434
import java.awt.Image;
3535
import java.awt.JSPanel;
36+
import java.awt.Window;
37+
import java.awt.event.WindowListener;
3638
import java.net.MalformedURLException;
3739
import java.net.URL;
3840
import java.util.Locale;
@@ -94,15 +96,25 @@ public JSApplet() {
9496
* @return true
9597
*/
9698
public boolean isFocusableWindow() {
97-
// mascarading as Window here
99+
// masquerading as Window here
98100
return true;
99101
}
100102

101103
public Dialog getModalBlocker() {
102-
// mascarading as Window here
104+
// masquerading as Window here
103105
return null; //??
104106
}
105107

108+
109+
public void addWindowListener(WindowListener w) {
110+
// from popup
111+
}
112+
public void addOwnedWindow(Window w) {
113+
// from popup
114+
}
115+
116+
void removeOwnedWindow(Window weakWindow) {
117+
}
106118

107119
/**
108120
* Holds the reference to the component which last had focus in this window

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public abstract class Component implements ImageObserver/*
180180
*
181181
* @see #getParent
182182
*/
183-
protected transient Container parent;
183+
public transient Container parent;
184184

185185
/**
186186
* The <code>AppContext</code> of the component. Applets/Plugin may change the
@@ -2385,10 +2385,13 @@ protected Dimension prefSizeComp() {
23852385
Dimension dim = prefSize;
23862386
if (dim == null || !(isPreferredSizeSet() || isValid())) {
23872387
// synchronized (getTreeLock()) {
2388+
2389+
// SwingJS TODO: it is not clear that we should deliver getMinimumSize here.
2390+
//
23882391
prefSize = // (
23892392
// peer != null) ?
23902393
// peer.preferredSize() :
2391-
getMinimumSize();
2394+
(width == 0 && height == 0 ? getMinimumSize() : new Dimension(width, height));
23922395
dim = prefSize;
23932396
}
23942397
// }

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

Lines changed: 79 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ public Insets insets() {
392392
*
393393
*/
394394
public Component add(Component comp) {
395-
return addImpl(comp, null, -1);
395+
addImpl(comp, null, -1);
396+
return comp;
396397
}
397398

398399
/**
@@ -406,7 +407,8 @@ public Component add(Component comp) {
406407
*
407408
*/
408409
public Component add(String name, Component comp) {
409-
return addImpl(comp, name, -1);
410+
addImpl(comp, name, -1);
411+
return comp;
410412
}
411413

412414
/**
@@ -435,7 +437,8 @@ public Component add(String name, Component comp) {
435437
*
436438
*/
437439
public Component add(Component comp, int index) {
438-
return addImpl(comp, null, index);
440+
addImpl(comp, null, index);
441+
return comp;
439442
}
440443

441444
/**
@@ -998,7 +1001,8 @@ public void add(Component comp, Object constraints) {
9981001
*/
9991002

10001003
public Component add(Component comp, Object constraints, int index) {
1001-
return addImpl(comp, constraints, index);
1004+
addImpl(comp, constraints, index);
1005+
return comp;
10021006
}
10031007

10041008
/**
@@ -1062,93 +1066,86 @@ public Component add(Component comp, Object constraints, int index) {
10621066
* @see LayoutManager2
10631067
* @since JDK1.1
10641068
*/
1065-
protected Component addImpl(Component comp, Object constraints, int index) {
1066-
return addImplCont(comp, constraints, index);
1069+
protected void addImpl(Component comp, Object constraints, int index) {
1070+
addImplCont(comp, constraints, index);
10671071
}
10681072

1069-
protected Component addImplCont(Component comp, Object constraints, int index) {
1070-
synchronized (getTreeLock()) {
1071-
1072-
//SwingJS used for all add methods
1073-
1074-
/* Check for correct arguments: index in bounds,
1075-
* comp cannot be one of this container's parents,
1076-
* and comp cannot be a window.
1077-
* comp and container must be on the same GraphicsDevice.
1078-
* if comp is container, all sub-components must be on
1079-
* same GraphicsDevice.
1080-
*/
1073+
protected void addImplCont(Component comp, Object constraints, int index) {
1074+
synchronized (getTreeLock()) {
1075+
1076+
// SwingJS used for all add methods
1077+
1078+
/*
1079+
* Check for correct arguments: index in bounds, comp cannot be one of this
1080+
* container's parents, and comp cannot be a window. comp and container must be
1081+
* on the same GraphicsDevice. if comp is container, all sub-components must be
1082+
* on same GraphicsDevice.
1083+
*/
10811084
// GraphicsConfiguration thisGC = this.getGraphicsConfiguration();
10821085

1083-
if (index > component.size() || (index < 0 && index != -1)) {
1084-
throw new IllegalArgumentException(
1085-
"illegal component position");
1086-
}
1087-
checkAddToSelf(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-
}
1086+
if (index > component.size() || (index < 0 && index != -1)) {
1087+
throw new IllegalArgumentException("illegal component position");
1088+
}
1089+
checkAddToSelf(comp);
1090+
// Here we do not allow JSApplet, but we do allow JInternalFrame, which is a
1091+
// JFrame now
1092+
if (comp.isJ2SWindowButNotJInternalFrame()) {
1093+
throw new IllegalArgumentException("adding a window to a container");
1094+
}
10921095

10931096
// checkNotAWindow(comp);
10941097
// if (thisGC != null) {
10951098
// comp.checkGD(thisGC.getDevice().getIDstring());
10961099
// }
10971100

1098-
/* Reparent the component and tidy up the tree's state. */
1099-
if (comp.parent != null) {
1100-
comp.parent.remove(comp);
1101-
if (index > component.size()) {
1102-
throw new IllegalArgumentException("illegal component position");
1103-
}
1104-
}
1105-
1106-
//index == -1 means add to the end.
1107-
if (index == -1) {
1108-
component.add(comp);
1109-
} else {
1110-
component.add(index, comp);
1111-
}
1112-
_childTainted = true;
1113-
comp.parent = this;
1114-
1115-
adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK,
1116-
comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK));
1117-
adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
1118-
comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
1119-
adjustDescendants(comp.countHierarchyMembers());
1120-
1121-
invalidateIfValid();
1122-
if (peer != null) {
1123-
comp.addNotify();
1124-
}
1125-
1126-
/* Notify the layout manager of the added component. */
1127-
if (layoutMgr != null) {
1128-
if (layoutMgr instanceof LayoutManager2) {
1129-
((LayoutManager2)layoutMgr).addLayoutComponent(comp, constraints);
1130-
} else if (constraints instanceof String) {
1131-
layoutMgr.addLayoutComponent((String)constraints, comp);
1132-
}
1133-
}
1134-
if (containerListener != null ||
1135-
(eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
1136-
Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
1137-
ContainerEvent e = new ContainerEvent(this,
1138-
ContainerEvent.COMPONENT_ADDED,
1139-
comp);
1140-
dispatchEvent(e);
1141-
}
1142-
1143-
comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp,
1144-
this, HierarchyEvent.PARENT_CHANGED,
1145-
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
1146-
if (peer != null && layoutMgr == null && isVisible()) {
1147-
updateCursorImmediately();
1148-
}
1149-
}
1150-
return comp;
1101+
/* Reparent the component and tidy up the tree's state. */
1102+
if (comp.parent != null) {
1103+
comp.parent.remove(comp);
1104+
if (index > component.size()) {
1105+
throw new IllegalArgumentException("illegal component position");
1106+
}
1107+
}
1108+
1109+
// index == -1 means add to the end.
1110+
if (index == -1) {
1111+
component.add(comp);
1112+
} else {
1113+
component.add(index, comp);
1114+
}
1115+
_childTainted = true;
1116+
comp.parent = this;
1117+
1118+
adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK, comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK));
1119+
adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
1120+
comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
1121+
adjustDescendants(comp.countHierarchyMembers());
1122+
1123+
invalidateIfValid();
1124+
if (peer != null) {
1125+
comp.addNotify();
1126+
}
1127+
1128+
/* Notify the layout manager of the added component. */
1129+
if (layoutMgr != null) {
1130+
if (layoutMgr instanceof LayoutManager2) {
1131+
((LayoutManager2) layoutMgr).addLayoutComponent(comp, constraints);
1132+
} else if (constraints instanceof String) {
1133+
layoutMgr.addLayoutComponent((String) constraints, comp);
1134+
}
1135+
}
1136+
if (containerListener != null || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0
1137+
|| Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
1138+
ContainerEvent e = new ContainerEvent(this, ContainerEvent.COMPONENT_ADDED, comp);
1139+
dispatchEvent(e);
1140+
}
1141+
1142+
comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp, this, HierarchyEvent.PARENT_CHANGED,
1143+
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
1144+
if (peer != null && layoutMgr == null && isVisible()) {
1145+
updateCursorImmediately();
1146+
}
11511147
}
1148+
}
11521149

11531150

11541151

@@ -1716,9 +1713,9 @@ protected Dimension preferredSizeContainer() {
17161713
Dimension dim = prefSize;
17171714
if (dim == null || !(isPreferredSizeSet() || isValid())) {
17181715
synchronized (getTreeLock()) {
1719-
prefSize = (layoutMgr != null) ?
1716+
prefSize = (layoutMgr != null ?
17201717
layoutMgr.preferredLayoutSize(this) :
1721-
prefSizeComp();
1718+
prefSizeComp());
17221719
dim = prefSize;
17231720
}
17241721
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ public class Menu extends swingjs.a2s.Menu {//MenuItem implements MenuContainer,
103103
// */
104104
// private static final long serialVersionUID = -8809584163345499784L;
105105

106-
/**
106+
public boolean isHelpMenu;
107+
108+
/**
107109
* Constructs a new menu with an empty label. This menu is not
108110
* a tear-off menu.
109111
* @exception HeadlessException if GraphicsEnvironment.isHeadless()

0 commit comments

Comments
 (0)