Skip to content

Commit e428355

Browse files
authored
Merge pull request #25 from BobHanson/yadav1
Yadav1
2 parents bac9709 + f44df32 commit e428355

File tree

22 files changed

+1078
-242
lines changed

22 files changed

+1078
-242
lines changed

sources/net.sf.j2s.core/dist/README.txt

Lines changed: 107 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
SwingJS distribution README.txt
1+
SwingJS distribution README.txt
2+
3+
3/15/2018 Bob Hanson hansonr@stolaf.edu
24

35
SwingJS has been successfully tested in Eclipse Neon and Oxygen on Mac and Windows platforms.
46
(No reason to believe it would not also work for Linux; just haven't tried that recently.)
@@ -7,69 +9,147 @@ INSTALLATION INSTRUCTIONS
79

810
Eclipse Neon or higher is necessary.
911

10-
1. net.sf.j2s.core_3.1.1.jar should be copied to the eclipse/dropins
11-
directory **AS net.sf.j2s.core.jar dropping the version info**
12-
because otherwise Eclipse will not recognize an update.
12+
-----------------------------------------------------------
13+
Installing the Java2Script transpiler as an Eclipse plug-in
14+
-----------------------------------------------------------
15+
16+
The Java2Script transpiler for SwingJS is in net.sf.j2s.core.jar. It parses the .java code and
17+
creates .js files that match the standard .class files created by the Eclipse Java compiler.
18+
19+
Note that both Java .class files (in bin/) and JavaScript .js files (in site/swingjs/j2s) are
20+
created automatically anytime you do any building of your project.
21+
22+
23+
1. Copy net.sf.j2s.core.jar from
1324

14-
We do not know why this is necessary, but it appears to be. If you leave
15-
the version in the name, Eclipse will not be able to replace it with a
16-
newer version later. From what we can tell.
25+
https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/dropins/net.sf.j2s.core.jar?raw=true
1726

18-
On Mac systems, this directory is
27+
into your eclipse/dropins directory.
28+
29+
Do not use net.sf.j2s.core_x.x.x.jar for this, as, if you do that, some versions of Eclipse will have to be
30+
entirely reinstalled every time you change versions. We do not know why this is necessary,
31+
but it appears to be. If you leave the version in the name, Eclipse will not be able to replace it with a
32+
newer version later. From what we can tell. So just always use dist/dropins/net.sf.j2s.core.jar.
33+
34+
On Mac systems, the Eclipse directory is
1935

2036
/Applications/Eclipse.app/Contents/Eclipse/dropins
2137

22-
2. restart Eclipse and check for the presence of the plug-in at
38+
2. Restart Eclipse and check for the presence of the plug-in at
2339
help...about Eclipse...installation details...Plug-ins...(wait several seconds for tabulation)
2440

2541
search for "j2s" to find j2s.sourceforge.net Java2Script Core
2642

2743
If that is not there, you don't have net.sf.j2s.core.jar in the proper directory.
2844

29-
3. Create an Eclipse Java project for your work, if you have not done so already.
30-
If your source code is not all already in src/, navigate to the project...properties...Java Build Path...source
31-
and add all the source directories you need.
3245

33-
4. Create in the Eclipse project the file:
46+
----------------------------------
47+
Creating a new J2S/SwingJS project
48+
----------------------------------
49+
50+
Create an Eclipse Java project for your work, if you have not done so already.
51+
If your source code is not all already in src/, navigate to the project...properties...
52+
Java Build Path...source and add all the source directories you need.
53+
54+
Note that your project must not include any Jar file based dependencies.
55+
All source code must be available. (Source code from decompiling .class files will work.)
56+
57+
58+
---------------------------------------------------------------------
59+
Installing the SwingJS JavaScript version of the Java Virtual Machine
60+
---------------------------------------------------------------------
61+
62+
All of the JavaScript produced will be in the project site/ directory.
63+
You must prepopulate this site with all the JavaScript required by the
64+
JavaScript version of the JVM. The most recent version of site/ is at
65+
66+
https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.java.core/SwingJS-site.zip?raw=true
67+
68+
Occasional additions to the java.* classes are made to the above-mentioned zip file.
69+
70+
Simply download and unzip that file into your project, creating a top-level site/ directory.
71+
72+
73+
-------------------------------------------
74+
Enabling the Java2Script/SwingJS transpiler
75+
-------------------------------------------
76+
77+
1. Create in your Eclipse project the file:
3478

3579
.j2s
3680

3781
containing simply:
3882

3983
j2s.compiler.status=enable
4084

41-
5. Modify the .project file to indicate the j2s transpiler is to be used,
42-
changing the buildSpec buildCommand from
85+
2. Edit the .project file to indicate that the j2s transpiler is to be used
86+
rather than the standard Java compiler by changing the buildSpec buildCommand from
4387

44-
org.eclipse.jdt.core.javabuilder
88+
org.eclipse.jdt.core.javabuilder
4589

4690
to
4791

4892
net.sf.j2s.core.java2scriptbuilder
4993

50-
6. All of the JavaScript produced will be in the project site/ directory.
51-
You must prepopulate this site with all the JavaScript required by the
52-
JavaScript version of the JVM. The most recent version of site/ is at
5394

54-
https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.java.core/SwingJS-site.zip?raw=true
95+
--------------------
96+
Building the project
97+
--------------------
5598

56-
Occasional additions to the java.* classes are made to the above-mentioned zip file.
99+
Build your project as you normally would. Java class files will be created as usual in the bin/ directory.
100+
JavaScript equivalents of these files will be created in the site/swingjs/j2s directory. You might have to
101+
do a project refresh to see these site files.
102+
103+
Do take a look at the .js files created. You will notice that they are all the methods and fields of your
104+
Java project *except* final static constants. SwingJS does not recreate those by name; it just uses them.
105+
(The only thing this should affect is that java.lang.reflect.Field does not indicate these names.)
106+
107+
108+
----------------------------------------------
109+
Testing the JavaScript version of your project
110+
----------------------------------------------
111+
112+
The J2S transpiler will automatically set up for you in site/ a sample HTML page for any class
113+
that subclasses JApplet or contains a public void main(String[] args) method. You will want to
114+
associate those files with an external HTML browser. We recommend Firefox.
57115

58-
If you find you are missing a class, please contact me (Bob Hanson) at hansonr@stolaf.edu.
59-
You can try adding these yourself by **temporarily** adding one or more of the
60-
Java classes found at http://grepcode.com to the proper package. If you do that, be sure
61-
to use the OpenJDK version. Most of the code in the SwingJS project started with Java 6-b14 or 6-b27.
62-
Build your project, then delete these Java files, because you do not necessarily want your Java
63-
code using that version, just JavaScript.
116+
Since you will be running AJAX locally within these browsers, you may need to enable local
117+
file reading in your browser. Instructions for doing that can be found at
118+
http://wiki.jmol.org/index.php/Troubleshooting/Local_Files
119+
120+
121+
------------------------
122+
Adding more Java classes
123+
------------------------
124+
125+
If you find you are missing a Java class, please contact me (Bob Hanson) at hansonr@stolaf.edu.
126+
You can try adding these yourself by **temporarily** adding one or more of the Java classes found
127+
at http://grepcode.com to the proper package in your project. For example, java/awt.
128+
129+
If you do that, be sure to use the OpenJDK version. Most of the code in the SwingJS project started with
130+
Java 6-b14 or 6-b27. Build your project, then delete these Java files, because you do not necessarily
131+
want your Java code using that version, just JavaScript.
132+
133+
134+
----------------
135+
Working projects
136+
----------------
64137

65138
A full site with many examples is at https://chemapps.stolaf.edu/swingjs/site
66139

140+
Falstad applets are in https://github.com/BobHanson/SwingJS-Examples
141+
and appear at https://chemapps.stolaf.edu/swingjs/site
142+
67143
VARNA development is at https://github.com/BobHanson/VARNA
68144
working site is https://chemapps.stolaf.edu/swingjs/varna
69145

70146
Physlets development is at https://github.com/BobHanson/Physlets-SwingJS
71147
working site is https://chemapps.stolaf.edu/swingjs/physlets
72148

149+
Phet applets have not been put on GitHub yet.
150+
151+
152+
73153
As of Feb. 17, 2018, we are actively converting a variety of functioning Java applets.
74154

75155
The physlets Animator, Doppler, and Optics are working.
-12 Bytes
Binary file not shown.
-12 Bytes
Binary file not shown.

sources/net.sf.j2s.core/src/net/sf/j2s/core/compiler/Java2ScriptCompiler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ private static void addHTML(ArrayList<String> appList, String siteFolder, String
369369

370370
@Override
371371
public boolean accept(File pathname) {
372+
//System.out.println("accept " + pathname + " " +pathname.isDirectory());
372373
return pathname.isDirectory() || !pathname.getName().endsWith(".java");
373374
}
374375

@@ -382,7 +383,7 @@ private static void copyNonclassFiles(File dir, File target) {
382383
if (dir.equals(target))
383384
return;
384385
File[] files = dir.listFiles(filter);
385-
System.out.println("copy nonclassFiles " + dir + " to " + target + " [" + (files != null ? files.length : "") + "]");
386+
System.err.println("copy nonclassFiles " + dir + " to " + target + " [" + (files != null ? files.length : "") + "]");
386387
File f = null;
387388
if (files != null)
388389
try {
-303 KB
Binary file not shown.

sources/net.sf.j2s.java.core/build_core_applet.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@
287287
</concat>
288288

289289
<echo>copying srcjs files into site</echo>
290-
<copy todir="site/swingjs/js">
290+
<copy todir="site/swingjs">
291291
<fileset dir="srcjs"/>
292292
</copy>
293293

sources/net.sf.j2s.java.core/src/a2s/Applet.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import javax.swing.JApplet;
99
import javax.swing.JPanel;
1010

11-
@SuppressWarnings("serial")
1211
public class Applet extends JApplet implements A2SContainer {
1312

1413

@@ -23,18 +22,14 @@ public void paintComponent(Graphics g) {
2322
super.paintComponent(g);
2423
// System.out.println("init " + this.getSize());
2524
try {
25+
// The content pane's paintComponent method has not been overridden.
26+
// There may be no problem, but it also could mean that the applet
27+
// is not painting properly.
2628
if (this.getWidth() > 0)
27-
paintMe(g);
29+
paintComponent_(g);
2830
} catch (Throwable e) {
29-
System.out.println(e);
31+
System.out.println("There was a problem in Applet.paintComponent(g) " + e);
3032
e.printStackTrace();
31-
/**
32-
* @j2sNative
33-
*
34-
* debugger;
35-
*/
36-
{
37-
}
3833
}
3934
}
4035
});
@@ -57,9 +52,9 @@ public A2SListener getA2SListener() {
5752

5853
private boolean paintMeNotified;
5954

60-
protected void paintMe(Graphics g) {
55+
protected void paintComponent_(Graphics g) {
6156
if (!paintMeNotified) {
62-
System.out.println("paintMe has not been implemented for " + this);
57+
System.out.println("JComponent.paintComponent(g) has not been overridden (including a super.paintComponent(g)) \nfor the " + this.getClass().getName() + " AWT applet.\nThis many be no problem, or it may mean the applet is not displaying properly.\n See https://docs.oracle.com/javase/tutorial/uiswing/painting/refining.html\n and https://docs.oracle.com/javase/tutorial/uiswing/painting/closer.html");
6358
paintMeNotified = true;
6459
}
6560
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,16 @@ public void setVisible(boolean b) {
219219
*/
220220
@Override
221221
public void resize(int width, int height) {
222-
if (appletViewer == null) {
222+
// no resizing if we have a stub -- embedded in a page
223+
if (stub == null)
223224
resizeOriginal(width, height);
224-
} else {
225-
// use J2S.Applet._resizeApplet.
225+
}
226+
227+
public void resizeHTML(int width, int height) {
228+
if (appletViewer != null)
226229
appletViewer.html5Applet._resizeApplet(new int[] {width, height});
227-
}
228230
}
229-
231+
230232
@SuppressWarnings("deprecation")
231233
public void resizeOriginal(int width, int height) {
232234
Dimension d = size();

0 commit comments

Comments
 (0)