Skip to content

Commit 019cfee

Browse files
committed
Merge branch 'hanson1' of https://github.com/BobHanson/java2script.git into hanson1
2 parents 6b15914 + cfcf8af commit 019cfee

File tree

7 files changed

+109
-72
lines changed

7 files changed

+109
-72
lines changed

README-developers.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,5 @@
22

33
These notes are for developers of SwingJS, not for users of SwingJS.
44

5-
```
6-
cd workspace (where workspace is your Eclipse Neon Workspace)
7-
git clone https://github.com/BobHanson/java2script.git
8-
git checkout swingjs
9-
```
5+
see https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/doc/howItWorks.md
106

11-
Then, open Eclipse, open Navigator, and hit Refresh. java2script will show up as a blank generic trunk without a name (i.e. 'trunk[]')
12-
13-
![Eclipse Refresh](https://68.media.tumblr.com/47add4de1bc35f07f0e709fd6634289d/tumblr_or8mhqHsje1s5a4bko3_1280.png)
14-
15-
![Eclipse trunk](https://68.media.tumblr.com/866cc531b6b9d1c3dca8071732a66a26/tumblr_or8mihapDW1s5a4bko1_540.png)
16-
17-
Or, do the equivalent tasks on Eclipse's graphical git tool.
18-
19-
Go to net.sf.j2s.core directory, Clean Project, then export as a Deployable plug-ins and fragments.
20-
21-
![Eclipse Deployable](https://68.media.tumblr.com/c5714cadb166c7a887fbd00110e19afc/tumblr_or8mhqHsje1s5a4bko1_1280.png)
22-
23-
![Eclipse Optionsj](https://68.media.tumblr.com/0a7d77765983c11ca59b4739307359ee/tumblr_or8mhqHsje1s5a4bko2_1280.png)
24-
25-
Core is the only thing that was affected. Hence, everything else can be built the same exact way it was built before (assuming you were using the HEAD of the master branch of j2s).

README.md

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Note
22

3+
java2script/java2script is the overall master of the project. However, all active devlopment should be forked from BobHanson/java2script, as that is the current development fork. That said, pushing to java2script/java2script is done regularly, so BobHanson/java2script should not ever be too far ahead of java2script/java2script.
34

45
These notes are for Java developers who want to convert their Java applets or Java applications to
56
JavaScript, allowing continued, simultaneous one-source development of both Java and JavaScript.
@@ -17,7 +18,7 @@ in Java. Using the java2script/SwingJS Eclipse plug-in, both Java .class files a
1718

1819

1920
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),
21+
(see https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs),
2122
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)
2223
to allow the rapid and
2324
automated production of browser-ready JavaScript versions of Java applications and applets.
@@ -27,18 +28,63 @@ automated production of browser-ready JavaScript versions of Java applications a
2728

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

31+
# Relationship to Alternatives
32+
33+
A number of alternative methods of using Java to create JavaScript have been proposed and developed to one extent or another. The following discussion compares java2script/SwingJS to these other methods, based on my own limited understanding of them as of Dec. 2019.
34+
35+
## Google Web Toolkit ##
36+
37+
http://www.gwtproject.org/ "GWT is a development toolkit for building and optimizing complex browser-based applications. Its goal is to enable productive development of high-performance web applications without the developer having to be an expert in browser quirks, XMLHttpRequest, and JavaScript."
38+
39+
I know that GWT has been successfully employed for relatively simple application conversions from Java to JavaScript. It implements a reasonably large set of JRE classes [http://www.gwtproject.org/doc/latest/RefJreEmulation.html], but not really a sufficiently large number of classes to support developed Java projects. For example, Class.forName() is missing, so that means no dynamic class loading; File, FileInputStream, and FileOutputStream are missing, meaning no standard file i/o. Most significantly, java.awt and javax.swing are missing. This means that whatever user interface is built must be built from scratch with JavaScript only in mind.
40+
41+
In contrast, java2script/SwingJS supports an HTML5-based "platform look and feel" (plaf) that leverages all the native features of HTML5 to match the Java AWT and Swing UI. For example, virtually all the Swing and AWT frame, window, panel, dialog, border, and layout classes have been implemented. There are no additional specialized classes that a developer needs to add to his or her project. Rather than using a working Java program as the basis for a JavaScript-specific application, as in GWT, java2script/SwingJS allows for parallel co-production of distributable Java and JavaScript _equivalent_ applications.
42+
43+
## TeaVM ##
44+
45+
http://teavm.org/ "TeaVM is an ahead-of-time compiler for Java bytecode that emits JavaScript and WebAssembly that runs in a browser. Its close relative is the well-known GWT. The main difference is that TeaVM does not require source code, only compiled class files. Moreover, the source code is not required to be Java, so TeaVM successfully compiles Kotlin and Scala."
46+
47+
I can only find a very few examples of TeaVM use. But from what I can see, TeaVM is still at "concept" stage. It appears that they are hand writing "pseudo" Java as they go. For example, we see at
48+
49+
https://github.com/konsoletyper/teavm/tree/master/classlib/src/main/java/org/teavm/classlib
50+
51+
that "java.awt" contains three classes: TColor, TDimension, and TPoint. TColor has exactly four methods: getRed(), getGreen(), getBlue(), and getAlpha(). It appears to me that the developer has hand-written a decent collection of 800 files as org.teavm.classlib.java. Apparently, the idea is that you would take your Java project and swap in these pseudo-java classes. But this is not scalable. One can't expect a 100,000-line Java program to be retooled or limited to this small hand-crafted set of classes.
52+
53+
In the author's own words, "There are Java APIs that are impossible to implement without generating inefficient JavaScript. Some of these APIs are: reflection, resources, class loaders, and JNI. TeaVM restricts usage of these APIs. Generally, you’ll have to manually rewrite your code to fit into TeaVM constraints." OK, but java2script/SwingJS implements reflection, does just-in-time class loading, uses property files and resource bundles, loads images, and much more. There are only minimal constraints that require modifying Java code. Yes, modal dialogs and Thread.sleep() do require refactoring a bit, but we have had no problem with this on over 500,000 lines of code in multiple projects. So it doesn't seem to be a major impediment.
54+
55+
## CheerpJ ##
56+
57+
https://www.leaningtech.com/cheerpj/ "CheerpJ converts Java applications or libraries into JavaScript. Works on bytecode, does not require access to the source code. Compatible with 100% of Java including reflection and dynamic classes. Existing Java archives can be converted to Web applications effortlessly"
58+
59+
This sounds terrific. Very straightforward -- just convert the Java class files to JavaScript. I don't doubt that most of what is written here is true. I am dubious about that "100%" claim, as there are plenty of problems in Java that would take considerably more work than just using class files directly. The Java Reporter demonstration at https://www.leaningtech.com/cheerpj/demos/ crashed both Firefox and Chrome for me, so I cannot really evaluate what I see here.
60+
61+
The primary differences between java2script/SwingJS and CheerpJ, to the best of my knowledge, include:
62+
63+
- implementing a true HTML5 UI rather than just painting a canvas the way Java does
64+
- delivering an easily interpretable and debuggable JavaScript translation of Java classes, with little or no obscurification (unless that is desired)
65+
- well-designed JavaScript-friendly Java core classes that leverage the considerable power of HTML5 rather than ignoring that completely
66+
- open source and completely extensible
67+
68+
# History - 2019-
69+
70+
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.
71+
72+
Examples include:
73+
74+
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.
75+
3076
# History - 2017-
3177

3278

3379
https://github.com/BobHanson/java2script (development master)
3480

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.
81+
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.
3682

3783
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.
3884

3985
Unlike Version 2, Version 3 requires minimal reworking of Java classes - primarily just for performance and threading* reasons, maximizing JavaScript performance without compromising any Java performance and making Java-to-JavaScript conversion almost trivial. (Of course, we are still finding occasional bugs in the transpiler and run-time "JavaScript-JVM.")
4086

41-
*Note that java2script/SwingJS cannot not support Thread.wait(), Thread.notify(), or Thread.sleep(). Nonetheless, in all cases we have found simple state-based alternatives that essentially reproduce this behavior in JavaScript using javax.Swing.Timer. These methods work equally well in Java and JavaScript, requiring just a bit of redesign of Java methods.
87+
*Note that java2script/SwingJS cannot support Thread.wait(), Thread.notify(), or Thread.sleep(). Nonetheless, in all cases we have found simple state-based alternatives that essentially reproduce this behavior in JavaScript using javax.Swing.Timer. These methods work equally well in Java and JavaScript, requiring just a bit of redesign of Java methods.
4288

4389
Examples include:
4490

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

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

68-
Examples can be found at https://chemapps.stolaf.edu/swingjs/phet/site/swingjs/examples
69-
and https://chemapps.stolaf.edu/jmol/jsmol
114+
Examples include:
115+
116+
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.
117+
118+
JSmol: https://chemapps.stolaf.edu/jmol/jsmol Non-AWT, Non-Swing version, our initial application of Java2Script technology.
119+
120+
Falstad Math and Physics Applets (https://www.falstad.com/mathphysics.html) Source available.
70121

71122
# History - 2005-2010
72123

docs/Gemfile.lock

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ GEM
2525
execjs (2.7.0)
2626
faraday (0.14.0)
2727
multipart-post (>= 1.2, < 3)
28-
ffi (1.9.23)
28+
ffi (~> 1.9.24)
2929
forwardable-extended (2.6.0)
3030
gemoji (3.0.0)
3131
github-pages (180)
3232
activesupport (= 4.2.9)
3333
github-pages-health-check (= 1.4.0)
34-
jekyll (= 3.7.3)
34+
jekyll (~> 3.7.4)
3535
jekyll-avatar (= 0.5.0)
3636
jekyll-coffeescript (= 1.1.1)
3737
jekyll-commonmark-ghpages (= 0.1.5)
@@ -70,7 +70,7 @@ GEM
7070
listen (= 3.1.5)
7171
mercenary (~> 0.3)
7272
minima (= 2.4.0)
73-
nokogiri (>= 1.8.1, < 2.0)
73+
nokogiri (>= 1.8.5, < 2.0)
7474
rouge (= 2.2.1)
7575
terminal-table (~> 1.4)
7676
github-pages-health-check (1.4.0)
@@ -81,11 +81,11 @@ GEM
8181
typhoeus (~> 1.3)
8282
html-pipeline (2.7.1)
8383
activesupport (>= 2)
84-
nokogiri (>= 1.4)
84+
nokogiri (>= 1.8.5)
8585
http_parser.rb (0.6.0)
8686
i18n (0.9.5)
8787
concurrent-ruby (~> 1.0)
88-
jekyll (3.7.3)
88+
jekyll (~> 3.7.4)
8989
addressable (~> 2.4)
9090
colorator (~> 1.0)
9191
em-websocket (~> 0.5)
@@ -99,99 +99,99 @@ GEM
9999
rouge (>= 1.7, < 4)
100100
safe_yaml (~> 1.0)
101101
jekyll-avatar (0.5.0)
102-
jekyll (~> 3.0)
102+
jekyll (~> 3.7.4)
103103
jekyll-coffeescript (1.1.1)
104104
coffee-script (~> 2.2)
105105
coffee-script-source (~> 1.11.1)
106106
jekyll-commonmark (1.2.0)
107107
commonmarker (~> 0.14)
108-
jekyll (>= 3.0, < 4.0)
108+
jekyll (~> 3.7.4)
109109
jekyll-commonmark-ghpages (0.1.5)
110110
commonmarker (~> 0.17.6)
111111
jekyll-commonmark (~> 1)
112112
rouge (~> 2)
113113
jekyll-default-layout (0.1.4)
114-
jekyll (~> 3.0)
114+
jekyll (~> 3.7.4)
115115
jekyll-feed (0.9.3)
116-
jekyll (~> 3.3)
116+
jekyll (~> 3.7.4)
117117
jekyll-gist (1.5.0)
118118
octokit (~> 4.2)
119119
jekyll-github-metadata (2.9.4)
120-
jekyll (~> 3.1)
120+
jekyll (~> 3.7.4)
121121
octokit (~> 4.0, != 4.4.0)
122122
jekyll-mentions (1.3.0)
123123
activesupport (~> 4.0)
124124
html-pipeline (~> 2.3)
125-
jekyll (~> 3.0)
125+
jekyll (~> 3.7.4)
126126
jekyll-optional-front-matter (0.3.0)
127-
jekyll (~> 3.0)
127+
jekyll (~> 3.7.4)
128128
jekyll-paginate (1.1.0)
129129
jekyll-readme-index (0.2.0)
130-
jekyll (~> 3.0)
130+
jekyll (~> 3.7.4)
131131
jekyll-redirect-from (0.13.0)
132-
jekyll (~> 3.3)
132+
jekyll (~> 3.7.4)
133133
jekyll-relative-links (0.5.3)
134-
jekyll (~> 3.3)
134+
jekyll (~> 3.7.4)
135135
jekyll-remote-theme (0.2.3)
136-
jekyll (~> 3.5)
136+
jekyll (~> 3.7.4)
137137
rubyzip (>= 1.2.1, < 3.0)
138138
typhoeus (>= 0.7, < 2.0)
139139
jekyll-sass-converter (1.5.2)
140140
sass (~> 3.4)
141141
jekyll-seo-tag (2.4.0)
142-
jekyll (~> 3.3)
142+
jekyll (~> 3.7.4)
143143
jekyll-sitemap (1.2.0)
144-
jekyll (~> 3.3)
144+
jekyll (~> 3.7.4)
145145
jekyll-swiss (0.4.0)
146146
jekyll-theme-architect (0.1.0)
147-
jekyll (~> 3.5)
147+
jekyll (~> 3.7.4)
148148
jekyll-seo-tag (~> 2.0)
149149
jekyll-theme-cayman (0.1.0)
150-
jekyll (~> 3.5)
150+
jekyll (~> 3.7.4)
151151
jekyll-seo-tag (~> 2.0)
152152
jekyll-theme-dinky (0.1.0)
153-
jekyll (~> 3.5)
153+
jekyll (~> 3.7.4)
154154
jekyll-seo-tag (~> 2.0)
155155
jekyll-theme-hacker (0.1.0)
156-
jekyll (~> 3.5)
156+
jekyll (~> 3.7.4)
157157
jekyll-seo-tag (~> 2.0)
158158
jekyll-theme-leap-day (0.1.0)
159-
jekyll (~> 3.5)
159+
jekyll (~> 3.7.4)
160160
jekyll-seo-tag (~> 2.0)
161161
jekyll-theme-merlot (0.1.0)
162-
jekyll (~> 3.5)
162+
jekyll (~> 3.7.4)
163163
jekyll-seo-tag (~> 2.0)
164164
jekyll-theme-midnight (0.1.0)
165-
jekyll (~> 3.5)
165+
jekyll (~> 3.7.4)
166166
jekyll-seo-tag (~> 2.0)
167167
jekyll-theme-minimal (0.1.0)
168-
jekyll (~> 3.5)
168+
jekyll (~> 3.7.4)
169169
jekyll-seo-tag (~> 2.0)
170170
jekyll-theme-modernist (0.1.0)
171-
jekyll (~> 3.5)
171+
jekyll (~> 3.7.4)
172172
jekyll-seo-tag (~> 2.0)
173173
jekyll-theme-primer (0.5.2)
174-
jekyll (~> 3.5)
174+
jekyll (~> 3.7.4)
175175
jekyll-github-metadata (~> 2.9)
176176
jekyll-seo-tag (~> 2.2)
177177
jekyll-theme-slate (0.1.0)
178-
jekyll (~> 3.5)
178+
jekyll (~> 3.7.4)
179179
jekyll-seo-tag (~> 2.0)
180180
jekyll-theme-tactile (0.1.0)
181-
jekyll (~> 3.5)
181+
jekyll (~> 3.7.4)
182182
jekyll-seo-tag (~> 2.0)
183183
jekyll-theme-time-machine (0.1.0)
184-
jekyll (~> 3.5)
184+
jekyll (~> 3.7.4)
185185
jekyll-seo-tag (~> 2.0)
186186
jekyll-titles-from-headings (0.5.1)
187-
jekyll (~> 3.3)
187+
jekyll (~> 3.7.4)
188188
jekyll-watch (2.0.0)
189189
listen (~> 3.0)
190190
jemoji (0.9.0)
191191
activesupport (~> 4.0, >= 4.2.9)
192192
gemoji (~> 3.0)
193193
html-pipeline (~> 2.2)
194-
jekyll (~> 3.0)
194+
jekyll (~> 3.7.4)
195195
kramdown (1.16.2)
196196
liquid (4.0.0)
197197
listen (3.1.5)
@@ -201,13 +201,13 @@ GEM
201201
mercenary (0.3.6)
202202
mini_portile2 (2.3.0)
203203
minima (2.4.0)
204-
jekyll (~> 3.5)
204+
jekyll (~> 3.7.4)
205205
jekyll-feed (~> 0.9)
206206
jekyll-seo-tag (~> 2.1)
207207
minitest (5.11.3)
208208
multipart-post (2.0.0)
209209
net-dns (0.8.0)
210-
nokogiri (1.8.2)
210+
nokogiri (>= 1.8.5)
211211
mini_portile2 (~> 2.3.0)
212212
octokit (4.8.0)
213213
sawyer (~> 0.8.0, >= 0.5.3)
@@ -221,7 +221,7 @@ GEM
221221
ruby-enum (0.7.2)
222222
i18n
223223
ruby_dep (1.5.0)
224-
rubyzip (1.2.1)
224+
rubyzip (~> 1.2.2)
225225
safe_yaml (1.0.4)
226226
sass (3.5.6)
227227
sass-listen (~> 4.0.0)

docs/README

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
This directory contains the content of the Java2Script project website,
2-
implemented through GitHub Pages.
31

4-
For details on GitHub Pages see https://pages.github.com.
5-
For details on Jekyll, used by GitHub Pages, see
6-
https://jekyllrb.com and
7-
https://help.github.com/articles/using-jekyll-as-a-static-site-generator-with-github-pages
8-
2+
See https://github.com/BobHanson/java2script/tree/master/sources/net.sf.j2s.core/dist for installation instructions.
93

10-
If you want to setup site locally with Jekyll see:
11-
https://help.github.com/articles/setting-up-your-github-pages-site-locally-with-jekyll/
124

docs/quickstart.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
## Installation
66

7+
see https://github.com/BobHanson/java2script/tree/master/sources/net.sf.j2s.core/dist for installation instructions.
8+
9+
The instructions given here are for a much earlier version.
10+
711
### Prerequisites
812

913
- Eclipse Neon (4.6) or higher.

sources/net.sf.j2s.java.core/src/java/util/stream/ReferencePipeline.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,11 @@ public final <A> A[] toArray(IntFunction<A[]> generator) {
435435
// super type of U an ArrayStoreException will be thrown.
436436
@SuppressWarnings("rawtypes")
437437
IntFunction rawGenerator = (IntFunction) generator;
438-
return (A[]) Nodes.flatten(evaluateToArrayNode(rawGenerator), rawGenerator)
439-
.asArray(rawGenerator);
438+
// using extra temporary variable 'node' with explicit type 'Node<A>' required as Eclipse 4.7.3a reports error
439+
// 'The method flatten(Node<T>, IntFunction<T[]>) in the type Nodes is not applicable for the arguments (Node, IntFunction)'
440+
// when directly using 'evaluateToArrayNode(rawGenerator)' in call to 'Nodes.flatten'.
441+
Node<A> node = evaluateToArrayNode(rawGenerator);
442+
return (A[]) Nodes.flatten(node, rawGenerator).asArray(rawGenerator);
440443
}
441444

442445
@Override

sources/net.sf.j2s.java.core/src/swingjs/JSGraphics2D.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,12 @@ public void drawDirect(int[] pixels, int x, int y, int width, int height, boolea
607607
nx = width;
608608
ny = height;
609609
}
610+
double[] m = new double[6];
611+
transform.getMatrix(m);
612+
if (m[0] != 1 || m[1] != 0 || m[2] != 0 || m[3] != 1)
613+
System.err.println("Unsupported transform");
614+
x += m[4];
615+
y += m[5];
610616
for (int pt = 0, i = 0, n = Math.min(buf8.length / 4, pixels.length); i < n; i++) {
611617
int argb = pixels[i];
612618
buf8[pt++] = (argb >> 16) & 0xFF;

0 commit comments

Comments
 (0)