diff --git a/dist/README.txt b/dist/README.txt index 8b30f6a82..4c01ff24f 100644 --- a/dist/README.txt +++ b/dist/README.txt @@ -1,162 +1,3 @@ SwingJS distribution README.txt -3/15/2018 Bob Hanson hansonr@stolaf.edu - -SwingJS has been successfully tested in Eclipse Neon and Oxygen on Mac and Windows platforms. -(No reason to believe it would not also work for Linux; just haven't tried that recently.) - -INSTALLATION INSTRUCTIONS - -Eclipse Neon or higher is necessary. - ------------------------------------------------------------ -Installing the Java2Script transpiler as an Eclipse plug-in ------------------------------------------------------------ - -The Java2Script transpiler for SwingJS is in net.sf.j2s.core.jar. It parses the .java code and -creates .js files that match the standard .class files created by the Eclipse Java compiler. - -Note that both Java .class files (in bin/) and JavaScript .js files (in site/swingjs/j2s) are -created automatically anytime you do any building of your project. - - -1. Copy net.sf.j2s.core.jar from - -https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/dropins/net.sf.j2s.core.jar?raw=true - -into your eclipse/dropins directory. - -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 -entirely reinstalled every time you change versions. We do not know why this is necessary, -but it appears to be. If you leave the version in the name, Eclipse will not be able to replace it with a -newer version later. From what we can tell. So just always use dist/dropins/net.sf.j2s.core.jar. - -On Mac systems, the Eclipse directory is - -/Applications/Eclipse.app/Contents/Eclipse/dropins - -2. Restart Eclipse and check for the presence of the plug-in at - help...about Eclipse...installation details...Plug-ins...(wait several seconds for tabulation) - -search for "j2s" to find j2s.sourceforge.net Java2Script Core - -If that is not there, you don't have net.sf.j2s.core.jar in the proper directory. - - ----------------------------------- -Creating a new J2S/SwingJS project ----------------------------------- - -Create an Eclipse Java project for your work, if you have not done so already. -If your source code is not all already in src/, navigate to the project...properties... -Java Build Path...source and add all the source directories you need. - -Note that your project must not include any Jar file based dependencies. -All source code must be available. (Source code from decompiling .class files will work.) - - ---------------------------------------------------------------------- -Installing the SwingJS JavaScript version of the Java Virtual Machine ---------------------------------------------------------------------- - -All of the JavaScript produced will be in the project site/ directory. -You must prepopulate this site with all the JavaScript required by the -JavaScript version of the JVM. The most recent version of site/ is at - -https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip?raw=true - -Occasional additions to the java.* classes are made to the above-mentioned zip file. - -Simply download and unzip that file into your project, creating a top-level site/ directory. - - -------------------------------------------- -Enabling the Java2Script/SwingJS transpiler -------------------------------------------- - -1. Create in your Eclipse project the file: - -.j2s - -containing simply: - -j2s.compiler.status=enable - -2. Edit the .project file to indicate that the j2s transpiler is to be used -rather than the standard Java compiler by changing the buildSpec buildCommand from - - org.eclipse.jdt.core.javabuilder - -to - -net.sf.j2s.core.java2scriptbuilder - - --------------------- -Building the project --------------------- - -Build your project as you normally would. Java class files will be created as usual in the bin/ directory. -JavaScript equivalents of these files will be created in the site/swingjs/j2s directory. You might have to -do a project refresh to see these site files. - -Do take a look at the .js files created. You will notice that they are all the methods and fields of your -Java project *except* final static constants. SwingJS does not recreate those by name; it just uses them. -(The only thing this should affect is that java.lang.reflect.Field does not indicate these names.) - - ----------------------------------------------- -Testing the JavaScript version of your project ----------------------------------------------- - -The J2S transpiler will automatically set up for you in site/ a sample HTML page for any class -that subclasses JApplet or contains a public void main(String[] args) method. You will want to -associate those files with an external HTML browser. We recommend Firefox. - -Since you will be running AJAX locally within these browsers, you may need to enable local -file reading in your browser. Instructions for doing that can be found at -http://wiki.jmol.org/index.php/Troubleshooting/Local_Files - - ------------------------- -Adding more Java classes ------------------------- - -If you find you are missing a Java class, please contact me (Bob Hanson) at hansonr@stolaf.edu. -You can try adding these yourself by **temporarily** adding one or more of the Java classes found -at http://grepcode.com to the proper package in your project. For example, java/awt. - -If you do that, be sure to use the OpenJDK version. Most of the code in the SwingJS project started with -Java 6-b14 or 6-b27. Build your project, then delete these Java files, because you do not necessarily -want your Java code using that version, just JavaScript. - - ----------------- -Working projects ----------------- - -A full site with many examples is at https://chemapps.stolaf.edu/swingjs/site - -Falstad applets are in https://github.com/BobHanson/SwingJS-Examples -and appear at https://chemapps.stolaf.edu/swingjs/site - -VARNA development is at https://github.com/BobHanson/VARNA -working site is https://chemapps.stolaf.edu/swingjs/varna - -Physlets development is at https://github.com/BobHanson/Physlets-SwingJS -working site is https://chemapps.stolaf.edu/swingjs/physlets - -Phet applets have not been put on GitHub yet. - - - -As of Feb. 17, 2018, we are actively converting a variety of functioning Java applets. - -The physlets Animator, Doppler, and Optics are working. - -As of Jan. 2, 2018, all known Java-to-JavaScript issues have been dealt with. -Efficient Google Closure Compiler compression is in place. - -As of Dec. 17, 2017, SwingJS is fully operational in its "version 2" format, -which includes fully qualified method, array, and number typing. - \ No newline at end of file +See https://github.com/BobHanson/java2script/tree/master/sources/net.sf.j2s.core/dist/README.txt diff --git a/sources/net.sf.j2s.core/SwingJS-site.zip b/sources/net.sf.j2s.core/SwingJS-site.zip new file mode 100644 index 000000000..69e6c8e98 Binary files /dev/null and b/sources/net.sf.j2s.core/SwingJS-site.zip differ diff --git a/sources/net.sf.j2s.core/dist/README.txt b/sources/net.sf.j2s.core/dist/README.txt index 9fb1ffd39..40b16a111 100644 --- a/sources/net.sf.j2s.core/dist/README.txt +++ b/sources/net.sf.j2s.core/dist/README.txt @@ -1,128 +1,244 @@ -This is the main README file for the Java2Script/SwingJS distribution +https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/README.txt +Last updated 2018.09.13 by Bob Hanson hansonr@stolaf.edu -https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/README.txt +This is the main README file for the Java2Script/SwingJS distribution. +Everything you need to get started with a SwingJS project or start learning +what Java2Script/SwingJS involves is here. -8/14/2018 Bob Hanson hansonr@stolaf.edu +----------------------- +Java2Script and SwingJS +----------------------- -- allows for no-package applets and applications (which is quite common in the Java applet world). +Java2Script/SwingJS, as its name suggests, has two components: -- totally refactored, streamlined Java-to-JavaScript class name conversion, including the "j2s/_" (single underscore) package, which contains (originally) package-less applets and applications. All Java2ScriptVisitor "getFinal..." methods return JavaScript-ready names that are intended for immediate appending to the output buffer. Prior to that moment, all class names are maintained as their Java values. +--- The Java2Script compiler (sources\net.sf.j2s.core) -- more efficient anonymous class creation (including lambda methods, constructors, and expressions). +The Java2Script compiler is net.sf.j2s.core.jar. It sits in the eclipse/dropins +folder and rides along with the Eclipse Java compiler as a "CompilationParticipant" -- full support for method-local named classes. +https://help.eclipse.org/photon/index.jsp?topic=/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/compiler/CompilationParticipant.html -- full, efficient support for default interface methods. +listening for updates to the source files and converting them on the fly to .js files +that match the standard .class files created by the Eclipse Java compiler itself. +Note that both Java .class files (in bin/) and JavaScript .js files (in site/swingjs/j2s) are +created automatically any time you do any building of your project. -- fully qualified methods [ excluding Math.* and *.toString() ], so no conflict with any standard JavaScript objects. +--- The SwingJS JavaScript runtime library (sources\net.sf.j2s.java.core) is, effectively, +the Java Virtual Machine in JavaScript. Its two main JavaScript objects are -- bullet-proof "final or effectively final" variables. + Clazz (methods that emulate core java.lang methods) and + J2S (methods that provide an interface to the HTML5 document model) -- strongly anonymous-function scoped for "private" methods. +<<<<<<< HEAD +Raw JavaScript files are in site/swingjs/js, These files are concatenated into +site/swingjs/swingjs2.js, which your web page needs to call. For example: -- corrects several issues with java.util.function.* and java.util.stream.*. + + ... + + + ... -- adds ?j2sverbose option (former standard logging all class loading), with the default being "quiet" mode, which gives no indication of file loading. (Also settable as J2S._quiet = [true|false] +Besides that, all the java, javax, swingjs, and various other classes can be found +in the site/swingjs/j2s directory. They are loaded "just-in-time", only on demand. -- adds hooks into Clazz object loading, allowing page intervention just after Clazz itself has been loaded, but the core files have not been loaded, and also just after core files have been loaded. This could be useful for customization of the loading process -- for example, dynamically settable core file configuration. +jQuery is used extensively, and a slightly enhanced version of jQuery (see site/swingjs/js/j2sJQueryExt) +adds synchronous binary file transfer as well as "jQuery outside events". -- adds System.getProperty("user.home"), which defaults to https://./ (which isn't a standard protocol, but is passed through the Java system and interpreted in JavaScript as the document base). +The SwingJS runtime is distributed as SwingJS-site.zip, which you can unzip yourself into +your project site/ directory or let build-site.xml do that for you. -- reorganizes java2script project files for better version control. +------------------------- +INSTALLATION INSTRUCTIONS +------------------------- + +Eclipse Photon or higher is necessary. + + ---------------------------------------------------------- + Important note to users using 3.1.1 and upgrading to 3.2.x + ---------------------------------------------------------- + + net.sf.j2s.core_3.2.1.jar replaces net.sf.j2s.core_3.1.1.jar + + + These versions differ only in their internal workings relative to Eclipse (and new bug fixes). + + Most importantly, the requirement that the .project file be changed to + indicate a customized Java builder is dropped in version 3.2.1, which just uses + the standard Eclipse java builder, org.eclipse.jdt.core.javabuilder. + + If you are updating to 3.2.x from 3.1.1, be sure to open your .project file and change the + builder name from net.sf.j2s.core.java2scriptbuilder back to org.eclipse.jdt.core.javabuilder + or your project will no longer compile. + +--------------------------------------------------------- +Installing the Java2Script compiler as an Eclipse plug-in +--------------------------------------------------------- -- adds {project}/resources/ and {project}/libjs as standard places for non-Java resources and zip-equivalents of JAR files that are automatically copied into the {project}/site directory. +The easiest thing to do is to copy the contents of the dist/ directory +https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist -8/12/2018 Bob Hanson hansonr@stolaf.edu +into your project directory. It contains the following directories: -The dist/dropins folder has been renamed dist/swingjs +swingjs/ + -- contains the necessary Eclipse drop-in as well as the run-time + -- ver/ subfolder holds older versions +tools/ + -- contains ant-contrib.jar, used by build-site.xml +libjs/ + -- empty; reserved for foo.zip equivalents of dependency foo.jar files + -- these will be unzipped into site/ by build-site.xml +resources/ + -- empty; reserved for non-java resources your program might need + -- these will go into site/swingjs/j2s by build-site.xml - https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs +and files: -It holds the key files that are needed for a J2S project (see below). +.j2s -- a starter j2s configuration file +build-site.xml -- run this to build the site/ directory before or after you + update your Java code. - -Java2Script 3.2.2.03 introduces and checks more Java 8 capabilities. Use +The following instructions include instructions for doing some of this manually: - eclipsec -clean +1. Copy net.sf.j2s.core.jar from -to update to new versions of the transpiler. Otherwise although the transpiler is updated, it will -report out an incorrect version number. This can be checked on the last line of every JS file created: +https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs -Clazz.setTVer('3.2.2.03');//Created 2018-08-06 17:25:47 Java2ScriptVisitor version 3.2.2.03 net.sf.j2s.core.jar version 3.2.2.03 +specifically: +https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs/net.sf.j2s.core.jar?raw=true -7/20/2018 Bob Hanson hansonr@stolaf.edu +into your eclipse/dropins directory. -The base Java version is Java 6. However, many of the functionalities of Java 7 and Java 8 are included. -This includes +Also provided in that directory is a ver/ directory with previous core files. +These files have names that are purposely unversioned because some versions of Eclipse +will have to be entirely reinstalled every time you change versions if the names are different +from version to version. We do not know why this is necessary, but it appears to be. +This is an Eclipse bug. So just always use dist/swingjs/net.sf.j2s.core.jar. - the "::" operator - lambda expressions - java.util.function.* - java.util.stream.* - default methods in interfaces +On Mac systems, the Eclipse directory is generally -All projects compiled under 3.1.1 need to be recompiled using the Java2Script 3.2.x transpiler, as -described below. Note that if you use /** @j2sNative */ calls to interface methods that are singlets, -those methods all take just $ as a qualifier. It should be no problem to leave them -qualified, though, as the transpiler creates qualified and unqualified aliases. +/Applications/Eclipse.app/Contents/Eclipse/dropins -There are occasional situations where this use of $-unqualified method names can run into problems. -For example, in java.util.stream.ReferencePipeline, there are three different default declarations -of the functional interface method "accept". They are just for error reporting and have been removed. -My guess that this is a rarity, but I am not sure. +2. Restart Eclipse and check for the presence of the plug-in at + help...about Eclipse...installation details...Plug-ins...(wait several seconds for tabulation) -SwingJS has been successfully tested in Eclipse version Neon-Photon on Mac and Windows platforms. -(No reason to believe it would not also work for Linux; just haven't tried that recently.) -Java 8 is the target Java version for transpilation. Please report any missing classes or strange -errors. +Search for "j2s" to find j2s.sourceforge.net Java2Script Core +If that is not there, you don't have net.sf.j2s.core.jar in the proper directory. -3/15/2018 Bob Hanson hansonr@stolaf.edu + Note relating to updating to 3.2.x from 3.1.1 version of Java2Script: -net.sf.j2s.core_3.2.1.jar replaces net.sf.j2s.core_3.1.1.jar - -These versions differ only in their internal workings relative to Eclipse. -Most importantly, the requirement that the .project file be changed to -indicate a customized Java builder is dropped in version 3.2.1, which just uses -the standard Eclipse java builder, org.eclipse.jdt.core.javabuilder. + If the version on this readout does not match the version that is + reported at the end of each .js file created: -For v. 3.2.1, to get started with SwingJS, all you need are: + //Created 2018-07-15 04:35:10 net.sf.j2s.core.jar v. 3.2.1 -1) the latest transpiler (net.sf.j2s.core.jar) and run-time (Swingjs-site.zip) from + then there is no real problem, but you can correct that by restarting + Eclipse once with the -clean flag. -https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs +------------------------------------------------------- +Updating the Java2Script compiler or SwingJS run-time +------------------------------------------------------- -2) an empty .j2s file in your project directory. (The Java2Script transpiler will fill this in with -a default .j2s configuration when it runs the first time. Or, you could use the one in /dist to start) +If the Java2Script compiler is updated on GitHub, just update the swingjs/ directory from +GitHub, replace the eclipse/dropins/net.sf.j2s.core.jar file with the new one, and +restart Eclipse. -NOTE! If you are updating to 3.2.x from 3.1.1, be sure to open your .project file and change the -builder name from net.sf.j2s.core.java2scriptbuilder back to org.eclipse.jdt.core.javabuilder -or your project will no longer compile. +If the SwingJS runtime is updated on GitHub, update the swingjs/ directory from GitHub +and run build-site.xml. + +---------------------------------- +Creating a new J2S/SwingJS project +---------------------------------- -Comments below have been adjusted for these differences. +Creating a new J2S/SwingJS project is very simple. - -INSTALLATION INSTRUCTIONS +First create an Eclipse Java project for your work, if you have not done so already. +If your source code is not all already in src/, navigate to the project...properties... +Java Build Path...source and add all the source directories you need. -Eclipse Neon or higher is necessary. +Note that your project must not include any Jar file-based dependencies. +All source code must be available. (Source code from decompiling .class files will work, +but it is not automatic, and we have not explored that option yet.) ------------------------------------------------------------ -Installing the Java2Script transpiler as an Eclipse plug-in ------------------------------------------------------------ +--------------------------------------------------------------------- +Installing the SwingJS JavaScript version of the Java Virtual Machine +--------------------------------------------------------------------- -The Java2Script transpiler for SwingJS is net.sf.j2s.core.jar. It rides along with the -Eclipse Java compiler as a "CompilationParticipant" +Chrome users should consider using WebServer for Chrome to serve local files. -https://help.eclipse.org/photon/index.jsp?topic=/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/compiler/CompilationParticipant.html +https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb?hl=en -listening for updates to the source files and converting them on the fly to .js files -that match the standard .class files created by the Eclipse Java compiler itself. +It is very simple to set up. -Note that both Java .class files (in bin/) and JavaScript .js files (in site/swingjs/j2s) are -created automatically anytime you do any building of your project. +Firefox users need only set the about:config flag: + + security.fileuri.strict_origin_policy + +to "false". + +All of the JavaScript produced will be in the project site/ directory. +You must prepopulate this site with all the JavaScript required by the +SwingJS JavaScript version of the JVM. The most recent version of site/ is at +======= +Raw JavaScript files are in site/swingjs/js, These files are concatentated into +site/swingjs/swingjs2.js, which your web page needs to call. For example: + + + ... + + + ... + +Besides that, all the java, javax, swingjs, and various other classes can be found +in the site/swingjs/j2s directory. + +jQuery is used extensively, and a slightly enhanced version of jQuery (see site/swingjs/js/j2sJQueryExt) +adds synchronous binary file transfer as well as "jQuery outside events". + +The SwingJS runtime is distributed as SwingJS-site.zip, which you can unzip yourself into +your project site/ directory or let build-site.xml do that for you. + +------------------------- +INSTALLATION INSTRUCTIONS +------------------------- + +Eclipse Photon or higher is necessary. + + ---------------------------------------------------------- + Important note to users using 3.1.1 and upgrading to 3.2.x + ---------------------------------------------------------- + + net.sf.j2s.core_3.2.1.jar replaces net.sf.j2s.core_3.1.1.jar + + + These versions differ only in their internal workings relative to Eclipse (and new bug fixes). + + Most importantly, the requirement that the .project file be changed to + indicate a customized Java builder is dropped in version 3.2.1, which just uses + the standard Eclipse java builder, org.eclipse.jdt.core.javabuilder. + + For v. 3.2.1, to get started with SwingJS, all you need is in + + https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist + + Namely: + + 1) the latest compiler (net.sf.j2s.core.jar) and run-time (Swingjs-site.zip) + + 2) an empty .j2s file in your project directory. (The Java2Script compiler will fill this in with + a default .j2s configuration when it runs the first time. Or, you could use the one in /dist to start) + + NOTE! If you are updating to 3.2.x from 3.1.1, be sure to open your .project file and change the + builder name from net.sf.j2s.core.java2scriptbuilder back to org.eclipse.jdt.core.javabuilder + or your project will no longer compile. + +--------------------------------------------------------- +Installing the Java2Script compiler as an Eclipse plug-in +--------------------------------------------------------- The easiest thing to do is to copy the contents of the dist/ directory @@ -147,7 +263,6 @@ and files: .j2s -- a starter j2s configuration file build-site.xml -- run this to build the site/ directory before or after you update your Java code. - The following instructions include instructions for doing some of this manually: @@ -188,19 +303,30 @@ If that is not there, you don't have net.sf.j2s.core.jar in the proper directory then there is no real problem, but you can correct that by restarting Eclipse once with the -clean flag. +------------------------------------------------------- +Updating the Java2Script compiler or SwingJS run-time +------------------------------------------------------- + +If the Java2Script compiler is updated on GitHub, just update the swingjs/ directory from +GitHub, replace the eclipse/dropins/net.sf.j2s.core.jar file with the new one, and +restart Eclipse. + +If the SwingJS runtime is updated on GitHub, update the swingjs/ directory from GitHub +and run build-site.xml. ---------------------------------- Creating a new J2S/SwingJS project ---------------------------------- -Create an Eclipse Java project for your work, if you have not done so already. +Creating a new J2S/SwingJS project is very simple. + +First create an Eclipse Java project for your work, if you have not done so already. If your source code is not all already in src/, navigate to the project...properties... Java Build Path...source and add all the source directories you need. Note that your project must not include any Jar file-based dependencies. All source code must be available. (Source code from decompiling .class files will work.) - --------------------------------------------------------------------- Installing the SwingJS JavaScript version of the Java Virtual Machine --------------------------------------------------------------------- @@ -214,30 +340,31 @@ https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoe All of the JavaScript produced will be in the project site/ directory. You must prepopulate this site with all the JavaScript required by the JavaScript version of the JVM. The most recent version of site/ is at +>>>>>>> branch 'hanson1' of https://github.com/BobHanson/java2script.git https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip?raw=true Occasional additions to the java.* classes are made to the above-mentioned zip file. Simply download and unzip that file into your project, creating a top-level site/ directory. +Build-site.xml does this for you as well. - -------------------------------------------- -Enabling the Java2Script/SwingJS transpiler -------------------------------------------- +----------------------------------------- +Enabling the Java2Script/SwingJS compiler +----------------------------------------- 1. Create in your Eclipse project the empty file: .j2s -The next time you build the project, the transpiler will see that and +The next time you build the project, the compiler will see that and add to it: j2s.compiler.status=enable j2s.site.directory=site along with several other commented-out options. If you want, you can -add these two yourself before you run the transpiler. +add these two yourself before you run the compiler. -------------------- Building the project @@ -257,11 +384,13 @@ It just uses them. This means that the java.lang.reflect.Field methods will not Testing the JavaScript version of your project ---------------------------------------------- -The J2S transpiler will automatically set up for you in site/ a sample HTML page for any class +The J2S compiler will automatically set up for you in site/ a sample HTML page for any class that subclasses JApplet or contains a public void main(String[] args) method. You will want to -associate those files with an external HTML browser. We recommend Firefox. +associate those files with an external HTML browser. We recommend Firefox rather than Chrome, +primarily because Chrome (as of 9/2018) blocks completely on simple alert messages, while Firefox +does not. This can be very annoying. -Do not change these files, as they will be recreated each time the transpiler runs. If you want +Do not change these files, as they will be recreated each time the compiler runs. If you want a different configuration -- a different width or height, or some additional "applet" parameters, make a copy of this file and change within it the Info block: @@ -304,25 +433,30 @@ http://wiki.jmol.org/index.php/Troubleshooting/Local_Files Adding more Java classes ------------------------ -If you find you are missing a Java class, please contact me (Bob Hanson) at hansonr@stolaf.edu. -You can try adding these yourself by **temporarily** adding one or more of the Java classes found -at http://grepcode.com to the proper package in your project. For example, java/awt. +You may find that some Java classes you use are not supported yet. -If you do that, be sure to use the OpenJDK version. For example: +If you find you are missing a Java class, please contact me (Bob Hanson) at hansonr@stolaf.edu. +You can try adding these yourself by **temporarily** adding one or more of the Java classes +to the proper package in your project. If you do that, be sure to use the OpenJDK version. For example: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes -Most of the code in the SwingJS project started with Java 6-b14 or 6-b27. The goal is to -move these all to Java8 OpenJDK versions. - Build your project, then delete these Java files, because, should this file be added to an updated version of SwingJS, you should probably use the one provided, not your own. Your choice. +Note: The original coding of Java2Script by Zhou Renjian utilized Apache Java code. +Starting in 2012, we started adding code from OpenJDK Java 6-b14 or 6-b27. +Starting in 2018, we started introducing Java8 classes. So it is a bit messy. +The goal is to move these all to Java8 OpenJDK versions and at least get rid +of all the Apache code. + ---------------- Working projects ---------------- -A full site with many examples is at https://chemapps.stolaf.edu/swingjs/site +Note that some of these sites use an older v. 3.1.1 compiler and runtime. + +A full site with many examples mostly from 2016 is at https://chemapps.stolaf.edu/swingjs/site Falstad applets are in https://github.com/BobHanson/SwingJS-Examples and appear at https://chemapps.stolaf.edu/swingjs/site @@ -335,7 +469,93 @@ working site is https://chemapps.stolaf.edu/swingjs/physlets Phet applets have not been put on GitHub yet. -Note that these sites use an older v. 3.1.1 transpiler and runtime. + +-------------------------------------------------------------------------------------------- +Development updates +-------------------------------------------------------------------------------------------- + +9/13/2018 Bob Hanson hansonr@stolaf.edu + +JSlider minimum and preferred sizes fixed swingjs/plaf/JSSliderUI.java +JCheckBox vertical offset of check box fixed swingjs/plaf/JSRadioButtonUI.java + + +8/14/2018 Bob Hanson hansonr@stolaf.edu + +- allows for no-package applets and applications (which is quite common in the Java applet world). + +- totally refactored, streamlined Java-to-JavaScript class name conversion, including the "j2s/_" (single underscore) package, which contains (originally) package-less applets and applications. All Java2ScriptVisitor "getFinal..." methods return JavaScript-ready names that are intended for immediate appending to the output buffer. Prior to that moment, all class names are maintained as their Java values. + +- more efficient anonymous class creation (including lambda methods, constructors, and expressions). + +- full support for method-local named classes. + +- full, efficient support for default interface methods. + +- fully qualified methods [ excluding Math.* and *.toString() ], so no conflict with any standard JavaScript objects. + +- bullet-proof "final or effectively final" variables. + +- strongly anonymous-function scoped for "private" methods. + +- corrects several issues with java.util.function.* and java.util.stream.*. + +- adds ?j2sverbose option (former standard logging all class loading), with the default being "quiet" mode, which gives no indication of file loading. (Also settable as J2S._quiet = [true|false] + +- adds hooks into Clazz object loading, allowing page intervention just after Clazz itself has been loaded, but the core files have not been loaded, and also just after core files have been loaded. This could be useful for customization of the loading process -- for example, dynamically settable core file configuration. + +- adds System.getProperty("user.home"), which defaults to https://./ (which isn't a standard protocol, but is passed through the Java system and interpreted in JavaScript as the document base). + +- reorganizes java2script project files for better version control. + +- adds {project}/resources/ and {project}/libjs as standard places for non-Java resources and zip-equivalents of JAR files that are automatically copied into the {project}/site directory. + + +8/12/2018 Bob Hanson hansonr@stolaf.edu + +The dist/dropins folder has been renamed dist/swingjs + + https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs + +It holds the key files that are needed for a J2S project (see below). + + +Java2Script 3.2.2.03 introduces and checks more Java 8 capabilities. Use + + eclipsec -clean + +to update to new versions of the compiler. Otherwise although the compiler is updated, it will +report out an incorrect version number. This can be checked on the last line of every JS file created: + +Clazz.setTVer('3.2.2.03');//Created 2018-08-06 17:25:47 Java2ScriptVisitor version 3.2.2.03 net.sf.j2s.core.jar version 3.2.2.03 + + +7/20/2018 Bob Hanson hansonr@stolaf.edu + +The base Java version is Java 6. However, many of the functionalities of Java 7 and Java 8 are included. +This includes + + the "::" operator + lambda expressions + java.util.function.* + java.util.stream.* + default methods in interfaces + +All projects compiled under 3.1.1 need to be recompiled using the Java2Script 3.2.x compiler, as +described below. Note that if you use /** @j2sNative */ calls to interface methods that are singlets, +those methods all take just $ as a qualifier. It should be no problem to leave them +qualified, though, as the compiler creates qualified and unqualified aliases. + +There are occasional situations where this use of $-unqualified method names can run into problems. +For example, in java.util.stream.ReferencePipeline, there are three different default declarations +of the functional interface method "accept". They are just for error reporting and have been removed. +My guess that this is a rarity, but I am not sure. + +SwingJS has been successfully tested in Eclipse version Neon-Photon on Mac and Windows platforms. +(No reason to believe it would not also work for Linux; just haven't tried that recently.) +Java 8 is the target Java version for transpilation. Please report any missing classes or strange +errors. + Feb. 17, 2018 diff --git a/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip b/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip index caf47f373..69e6c8e98 100644 Binary files a/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip and b/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip differ diff --git a/sources/net.sf.j2s.core/dist/swingjs/timestamp b/sources/net.sf.j2s.core/dist/swingjs/timestamp index 86fdcc98b..be7cf525b 100644 --- a/sources/net.sf.j2s.core/dist/swingjs/timestamp +++ b/sources/net.sf.j2s.core/dist/swingjs/timestamp @@ -1 +1 @@ -20180901005436 +20180913053826 diff --git a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.2/SwingJS-site.zip b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.2/SwingJS-site.zip index caf47f373..69e6c8e98 100644 Binary files a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.2/SwingJS-site.zip and b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.2/SwingJS-site.zip differ diff --git a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.2/timestamp b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.2/timestamp index 86fdcc98b..be7cf525b 100644 --- a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.2/timestamp +++ b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.2/timestamp @@ -1 +1 @@ -20180901005436 +20180913053826 diff --git a/sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptCompiler.java b/sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptCompiler.java index c679d5dde..2698270e6 100644 --- a/sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptCompiler.java +++ b/sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptCompiler.java @@ -32,11 +32,11 @@ * @author Bob Hanson * */ -public class Java2ScriptCompiler { +class Java2ScriptCompiler { /** * The name of the J2S options file, aka as the "Dot-j2s" file. */ - public static final String J2S_OPTIONS_FILE_NAME = ".j2s"; + private static final String J2S_OPTIONS_FILE_NAME = ".j2s"; // BH: added "true".equals(getProperty(props, // "j2s.compiler.allow.compression")) to ensure compression only occurs when @@ -77,7 +77,7 @@ public class Java2ScriptCompiler { private IJavaProject project; - public static boolean isActive(IJavaProject project) { + static boolean isActive(IJavaProject project) { try { return new File(project.getProject().getLocation().toOSString(), J2S_OPTIONS_FILE_NAME).exists(); } catch (@SuppressWarnings("unused") Exception e) { @@ -85,7 +85,7 @@ public static boolean isActive(IJavaProject project) { } } - public Java2ScriptCompiler() { + Java2ScriptCompiler() { // initialized only once using CompilationParticipant; every time using // older Builder idea } @@ -94,7 +94,7 @@ public Java2ScriptCompiler() { * only for CompilationParticipant * @param isClean */ - public void startBuild(boolean isClean) { + void startBuild(boolean isClean) { // at the beginning of a clean build, clear data isCleanBuild = isClean; htmlTemplate = null; @@ -106,19 +106,7 @@ public void startBuild(boolean isClean) { } -// /** -// * old way from original builder -// * -// */ -// public void process(ICompilationUnit sourceUnit, IContainer binaryFolder) { -// if (!(sourceUnit instanceof SourceFile)) -// return; -// if (!initializeProject(binaryFolder.getProject(), false)) -// return; -// compileToJavaScript(((SourceFile) sourceUnit).resource); -// } - - /** + /** * from Java2ScriptCompilationParticipant.java * * get all necessary .j2s params for a build @@ -128,7 +116,7 @@ public void startBuild(boolean isClean) { * @return true if this is a j2s project and is enabled * */ - public boolean initializeProject(IJavaProject project, boolean isCompilationParticipant) { + boolean initializeProject(IJavaProject project, boolean isCompilationParticipant) { this.project = project; this.isCompilationParticipant = isCompilationParticipant; if (!isActive(project)) { @@ -246,7 +234,7 @@ public boolean initializeProject(IJavaProject project, boolean isCompilationPart * * @param javaSource */ - public boolean compileToJavaScript(IFile javaSource) { + boolean compileToJavaScript(IFile javaSource) { String fileName = new String(javaSource.getName()); if (lstExcludedPaths != null) { @@ -312,6 +300,9 @@ public boolean compileToJavaScript(IFile javaSource) { return true; } + //// private methods //// + + private void logMethods(String logCalled, String logDeclared, boolean doAppend) { if (htMethodsCalled != null) try { @@ -353,7 +344,7 @@ private String getProperty(String key) { return val; } - public void outputJavaScript(Java2ScriptVisitor visitor, + private void outputJavaScript(Java2ScriptVisitor visitor, // DependencyASTVisitor dvisitor, CompilationUnit fRoot, String j2sPath) { @@ -420,6 +411,8 @@ private void writeToFile(File file, String data) { /** * The default .j2s file. Replaces .j2s only if it is found but is empty. * + * OK, I know this should be a resource. + * * * */ diff --git a/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip b/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip index caf47f373..69e6c8e98 100644 Binary files a/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip and b/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip differ diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSRadioButtonUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSRadioButtonUI.java index 09fcdcf6e..e0a0ab1c4 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSRadioButtonUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSRadioButtonUI.java @@ -121,6 +121,7 @@ protected Dimension setHTMLSize(DOMNode obj, boolean addCSS) { } else { d = setHTMLSize1(obj, addCSS, false); DOMNode.setPositionAbsolute(textNode); + DOMNode.setPositionAbsolute(iconNode); DOMNode.setPositionAbsolute(buttonNode); // if (centeringNode != null) problems with vertical offset // DOMNode.setPositionAbsolute(centeringNode); diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSSliderUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSSliderUI.java index f58ccb569..d530a32c4 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSSliderUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSSliderUI.java @@ -378,6 +378,33 @@ void setScrollBarExtentAndCSS() { // ScrollBar subclass only } + + public Dimension getMinimumSize(JComponent c) { + return (isScrollBar ? super.getMinimumSize(c) + : isHoriz ? getMinimumHorizontalSize() : getMinimumVerticalSize()); + } + + private Dimension getMinimumHorizontalSize() { + Dimension horizDim = (Dimension) DefaultLookup.get(jSlider, this, + "Slider.minimumHorizontalSize"); + if (horizDim == null) { + horizDim = new Dimension(36, 21); + } + return horizDim; + } + + private Dimension getMinimumVerticalSize() { + Dimension vertDim = (Dimension) DefaultLookup.get(jSlider, this, + "Slider.minimumVerticalSize"); + if (vertDim == null) { + vertDim = new Dimension(21, 36); + } + return vertDim; + } + + public Dimension getPreferredSize(JComponent c) { + return (isScrollBar ? super.getPreferredSize(c) : isHoriz ? getPreferredHorizontalSize() : getPreferredVerticalSize()); + } public Dimension getPreferredHorizontalSize() { Dimension horizDim = (Dimension) DefaultLookup.get(jSlider, this,