From: hansonr Date: Tue, 18 Sep 2018 05:05:30 +0000 (-0500) Subject: Jmol/SwingJS update. Includes new transpiler and runtime X-Git-Tag: Release_2_11_4_0~45^2~18^2~444 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=b7e521af667bdc18f9071075d1face56367eab69;p=jalview.git Jmol/SwingJS update. Includes new transpiler and runtime install transpiler run build-site.xml --- diff --git a/.gitignore b/.gitignore index 0567460..116f2f1 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ TESTNG /sitev/ /.classpath *.class +/site1/ +/site2/ diff --git a/libjs/MiGLayout-site.zip b/libjs/MiGLayout-site.zip index 51aba46..4193638 100644 Binary files a/libjs/MiGLayout-site.zip and b/libjs/MiGLayout-site.zip differ diff --git a/libjs/VARNA-site.zip b/libjs/VARNA-site.zip index 3dff86e..95688a6 100644 Binary files a/libjs/VARNA-site.zip and b/libjs/VARNA-site.zip differ diff --git a/libjs/jmol-app.zip b/libjs/jmol-app.zip index 02efd09..505420c 100644 Binary files a/libjs/jmol-app.zip and b/libjs/jmol-app.zip differ diff --git a/libjs/json-site.zip b/libjs/json-site.zip index f2e1e96..e00b241 100644 Binary files a/libjs/json-site.zip and b/libjs/json-site.zip differ diff --git a/srcjar/javajs/api/js/J2SObjectInterface.java b/srcjar/javajs/api/js/J2SObjectInterface.java index 687f642..d3ee620 100644 --- a/srcjar/javajs/api/js/J2SObjectInterface.java +++ b/srcjar/javajs/api/js/J2SObjectInterface.java @@ -1,12 +1,12 @@ package javajs.api.js; /** - * methods in JSmol JavaScript accessed in Jmol + * methods in JSmol JavaScript accessed in Jmol */ public interface J2SObjectInterface { - Object _doAjax(Object url, String postOut, Object bytesOrStringOut, boolean isBinary); + Object doAjax(String url, String postOut, Object bytesOrStringOut, boolean isBinary); - void _apply(Object func, Object data); + void applyFunc(Object func, Object data); } diff --git a/srcjar/javajs/util/AU.java b/srcjar/javajs/util/AU.java index f873116..25acbfc 100644 --- a/srcjar/javajs/util/AU.java +++ b/srcjar/javajs/util/AU.java @@ -269,11 +269,11 @@ final public class AU { * */ { + n -= i0; + int[] t = new int[n]; + System.arraycopy(array, i0, t, 0, n); + return t; } - n -= i0; - int[] t = new int[n]; - System.arraycopy(array, i0, t, 0, n); - return t; } public static int[] arrayCopyRangeRevI(int[] array, int i0, int n) { @@ -285,13 +285,13 @@ final public class AU { * return Clazz.array(-1, array, i0, n).reverse(); */ { + int[] t = arrayCopyRangeI(array, i0, n); + if (n < 0) + n = array.length; + for (int i = n / 2; --i >= 0;) + swapInt(t, i, n - 1 - i); + return t; } - int[] t = arrayCopyRangeI(array, i0, n); - if (n < 0) - n = array.length; - for (int i = n / 2; --i >= 0;) - swapInt(t, i, n - 1 - i); - return t; } public static short[] arrayCopyShort(short[] array, int newLength) { diff --git a/srcjar/javajs/util/AjaxURLConnection.java b/srcjar/javajs/util/AjaxURLConnection.java index 0b038c3..3dcb3cd 100644 --- a/srcjar/javajs/util/AjaxURLConnection.java +++ b/srcjar/javajs/util/AjaxURLConnection.java @@ -3,6 +3,7 @@ package javajs.util; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; @@ -13,7 +14,7 @@ import javajs.api.js.J2SObjectInterface; * A method to allow a JavaScript Ajax * */ -public class AjaxURLConnection extends URLConnection { +public class AjaxURLConnection extends HttpURLConnection { protected AjaxURLConnection(URL url) { super(url); @@ -44,16 +45,8 @@ public class AjaxURLConnection extends URLConnection { */ @SuppressWarnings("null") private Object doAjax(boolean isBinary) { - J2SObjectInterface j2s = null; - /** - * @j2sNative - * - * j2s = J2S; - * - */ - { - } - return j2s._doAjax(url, postOut, bytesOut, isBinary); + J2SObjectInterface J2S = /** @j2sNative self.J2S || */ null; + return J2S.doAjax(url.toString(), postOut, bytesOut, isBinary); } @Override @@ -95,8 +88,6 @@ public class AjaxURLConnection extends URLConnection { * data = url._streamData; * if (andDelete) url._streamData = null; */ - { - } return (data == null ? null : Rdr.toBIS(data)); } @@ -117,4 +108,47 @@ public class AjaxURLConnection extends URLConnection { return doAjax(false); } + @Override + public int getResponseCode() throws IOException { + /* + * We're got the response code already + */ + if (responseCode != -1) { + return responseCode; + } + + /* + * Ensure that we have connected to the server. Record + * exception as we need to re-throw it if there isn't + * a status line. + */ + Exception exc = null; + try { + BufferedInputStream is = (BufferedInputStream) getInputStream(); + if (is.available() > 40) + return responseCode = HTTP_OK; + is.mark(15); + byte[] bytes = new byte[13]; + is.read(bytes); + is.reset(); + String s = new String(bytes); + if (s.startsWith("Network Error")) + return responseCode = HTTP_NOT_FOUND; + } catch (Exception e) { + exc = e; + } + return responseCode = HTTP_INTERNAL_ERROR; + } +@Override +public void disconnect() { + // TODO Auto-generated method stub + +} + +@Override +public boolean usingProxy() { + // TODO Auto-generated method stub + return false; +} + } diff --git a/srcjar/javajs/util/BC.java b/srcjar/javajs/util/BC.java index 5722efd..9a7c811 100644 --- a/srcjar/javajs/util/BC.java +++ b/srcjar/javajs/util/BC.java @@ -28,50 +28,68 @@ public class BC { | (bytes[j + 1] & 0xff) << 16 | (bytes[j] & 0xff) << 24 : (bytes[j++] & 0xff) | (bytes[j++] & 0xff) << 8 | (bytes[j++] & 0xff) << 16 | (bytes[j++] & 0xff) << 24); - /** - * @j2sNative - * - * return (n > 0x7FFFFFFF ? n - 0x100000000 : n); - * - */ - { - return n; - } + + return (/** @j2sNative (n|0) || */ n); +// /** +// * xxxxxxj2sNative +// * +// * return (n > 0x7FFFFFFF ? n - 0x100000000 : n); +// * +// */ +// { +// return n; +// } } public static int intToSignedInt(int n) { - /** - * @j2sNative - * - * return (n > 0x7FFFFFFF ? n - 0x100000000 : n); - * - */ - { - return n; - } + + return (/** @j2sNative n || */ n); + +// /** +// * xxxxxxj2sNative +// * +// * return (n > 0x7FFFFFFF ? n - 0x100000000 : n); +// * +// */ +// { +// return n; +// } } public static float intToFloat(int x) throws Exception { - /** - * see http://en.wikipedia.org/wiki/Binary32 - * - * [sign] [8 bits power] [23 bits fraction] - * 0x80000000 0x7F800000 0x7FFFFF - * - * (untested) - * - * @j2sNative - * - * if (x == 0) return 0; - * var o = javajs.util.BC; - * if (o.fracIEEE == null) - * o.setFracIEEE(); - * var m = ((x & 0x7F800000) >> 23); - * return ((x & 0x80000000) == 0 ? 1 : -1) * o.shiftIEEE$D$I((x & 0x7FFFFF) | 0x800000, m - 149); - * - */ - { + +// // see http://en.wikipedia.org/wiki/Binary32 +// // +// // [sign] [8 bits power] [23 bits fraction] +// // 0x80000000 0x7F800000 0x7FFFFF +// // +// // (untested) +// if (x == 0) +// return 0; +// boolean isJS = /** xxxxxxj2sNative true | */false; +// +// +// if (isJS) { +// if (fracIEEE == null) +// setFracIEEE(); +// int m = ((x & 0x7F800000) >> 23); +// * return ((x & 0x80000000) == 0 ? 1 : -1) * o.shiftIEEE$D$I((x & 0x7FFFFF) | 0x800000, m - 149); +// +// } +// /** +// * +// * xxxxxxj2sNative +// * +// * if (x == 0) return 0; +// * var o = javajs.util.BC; +// * if (o.fracIEEE$ == null) +// * o.setFracIEEE$(); +// * var m = ((x & 0x7F800000) >> 23); +// * return ((x & 0x80000000) == 0 ? 1 : -1) * o.shiftIEEE$D$I((x & 0x7FFFFF) | 0x800000, m - 149); +// * +// */ +// { return Float.intBitsToFloat(x); - } + // } } /** diff --git a/srcjar/javajs/util/DebugJS.java b/srcjar/javajs/util/DebugJS.java index ab22558..33a2258 100644 --- a/srcjar/javajs/util/DebugJS.java +++ b/srcjar/javajs/util/DebugJS.java @@ -7,22 +7,22 @@ package javajs.util; public class DebugJS { - /** - * Insert a JavaScript debug statement - * - */ - public static void _(String msg) { - /** - * @j2sNative - * - * if (Clazz._debugging) { - * - * debugger; - * - * } - * - */ - {} - } +// /** +// * Insert a JavaScript debug statement +// * +// */ +// public static void _(String msg) { +// /** +// * xxxxj2sNative +// * +// * if (Clazz._debugging) { +// * +// * debugger; +// * +// * } +// * +// */ +// {} +// } } diff --git a/srcjar/javajs/util/JSThread.java b/srcjar/javajs/util/JSThread.java index be94c00..56a500e 100644 --- a/srcjar/javajs/util/JSThread.java +++ b/srcjar/javajs/util/JSThread.java @@ -22,7 +22,7 @@ import javajs.api.JSFunction; * */ //@J2SRequireImport(swingjs.JSToolkit.class) -public abstract class JSThread extends Thread implements JSFunction { +public abstract class JSThread extends Thread { public static final int INIT = 0; public static final int LOOP = 1; @@ -30,7 +30,7 @@ public abstract class JSThread extends Thread implements JSFunction { public static int threadCount = 0; - protected boolean isJS; + protected boolean isJS = /** @j2sNative true || */false; public JSThread() { this(null, "JSThread-" + (++threadCount)); @@ -42,13 +42,7 @@ public abstract class JSThread extends Thread implements JSFunction { public JSThread(ThreadGroup group, String name) { super(group, name); - /** - * @j2sNative - * - * this.isJS = true; - */ - {} - } + } @Override public void run() { @@ -201,7 +195,7 @@ public abstract class JSThread extends Thread implements JSFunction { * * setTimeout( * function() { - * java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent$java_awt_AWTEvent( + * java.awt.Toolkit.getDefaultToolkit$().getSystemEventQueue$().postEvent$java_awt_AWTEvent( * Clazz.new_(java.awt.event.InvocationEvent.c$$O$Runnable,[me, r]))}, * delay); * diff --git a/srcjar/javajs/util/OC.java b/srcjar/javajs/util/OC.java index 98151d1..a63489c 100644 --- a/srcjar/javajs/util/OC.java +++ b/srcjar/javajs/util/OC.java @@ -60,6 +60,21 @@ public class OC extends OutputStream implements GenericOutputChannel { private byte[] bytes; // preset bytes; output only public boolean bigEndian = true; + + private boolean isTemp; + + /** + * Setting isTemp=true informs OC that this is a temporary file + * and not to send it to the user as a "download". Instead, the calling + * class can use .toByteArray() to retrieve the byte[] result. + * + * @param tf + */ + public void setTemp(boolean tf) { + isTemp = tf; + } + + @Override public boolean isBigEndian() { @@ -70,6 +85,17 @@ public class OC extends OutputStream implements GenericOutputChannel { bigEndian = TF; } + /** + * Set up an output channel. String or byte data can be added without problem. + * + * @param bytePoster a byte poster can take the output byte[] when closing and + * do something with them + * @param fileName TODO: It is possible that JavaScript will call this with a + * function name for fileName + * @param asWriter string-based + * @param os the desired target OutputStream - not the calling stream! + * @return + */ public OC setParams(BytePoster bytePoster, String fileName, boolean asWriter, OutputStream os) { this.bytePoster = bytePoster; @@ -301,12 +327,12 @@ public class OC extends OutputStream implements GenericOutputChannel { return (sb == null ? null : sb.toString()); } closed = true; - J2SObjectInterface jmol = null; + J2SObjectInterface J2S = null; Object _function = null; /** * @j2sNative * - * jmol = self.J2S || Jmol; _function = (typeof this.fileName == "function" ? + * J2S = self.J2S || self.Jmol; _function = (typeof this.fileName == "function" ? * this.fileName : null); * */ @@ -318,12 +344,15 @@ public class OC extends OutputStream implements GenericOutputChannel { return ret; } } - if (jmol != null) { + if (J2S != null && !isTemp) { + + // action here generally will be for the browser to display a download message + // temp files will not be sent this way. Object data = (sb == null ? toByteArray() : sb.toString()); if (_function == null) - jmol._doAjax(fileName, null, data, sb == null); + J2S.doAjax(fileName, null, data, sb == null); else - jmol._apply(_function, data); + J2S.applyFunc(_function, data); } return null; } @@ -337,7 +366,8 @@ public class OC extends OutputStream implements GenericOutputChannel { } public byte[] toByteArray() { - return (bytes != null ? bytes : os instanceof ByteArrayOutputStream ? ((ByteArrayOutputStream)os).toByteArray() : null); + return (bytes != null ? bytes : (bytes = os instanceof ByteArrayOutputStream ? ((ByteArrayOutputStream)os).toByteArray() : + sb == null ? null : sb.toBytes(0, sb.length()))); } @Override @@ -359,9 +389,14 @@ public class OC extends OutputStream implements GenericOutputChannel { return byteCount + " bytes"; } + /** + * We have constructed some sort of byte[] that needs to be posted to a remote site. + * We don't do that posting here -- we let the bytePoster do it. + * + * @return + */ private String postByteArray() { - byte[] bytes = (sb == null ? toByteArray() : sb.toString().getBytes()); - return bytePoster.postByteArray(fileName, bytes); + return bytePoster == null ? null : bytePoster.postByteArray(fileName, toByteArray()); } public final static String[] urlPrefixes = { "http:", "https:", "sftp:", "ftp:", diff --git a/srcjar/javajs/util/PT.java b/srcjar/javajs/util/PT.java index 81653cf..e50e558 100644 --- a/srcjar/javajs/util/PT.java +++ b/srcjar/javajs/util/PT.java @@ -313,18 +313,18 @@ public class PT { } public static int parseIntRadix(String s, int i) throws NumberFormatException { - /** - * - * JavaScript uses parseIntRadix - * - * @j2sNative - * - * return Integer.parseIntRadix(s, i); - * - */ - { +// /** +// * +// * JavaScript uses parseIntRadix +// * +// * @j2sNative +// * +// * return Integer.parseIntRadix(s, i); +// * +// */ +// { return Integer.parseInt(s, i); - } +// } } public static String[] getTokens(String line) { @@ -991,10 +991,11 @@ public class PT { */ public static String escF(float f) { String sf = "" + f; + // NaN, Infinity /** * @j2sNative * - * if (sf.indexOf(".") < 0 && sf.indexOf("e") < 0) + * if (sf.indexOf(".") < 0 && sf.indexOf("e") < 0 && sf.indexOf("N") < 0 && sf.indexOf("n") < 0) * sf += ".0"; */ { diff --git a/srcjar/javajs/util/Rdr.java b/srcjar/javajs/util/Rdr.java index 995a629..3ff08b7 100644 --- a/srcjar/javajs/util/Rdr.java +++ b/srcjar/javajs/util/Rdr.java @@ -199,14 +199,6 @@ public class Rdr implements GenericLineReader { private static Encoding getUTFEncodingForStream(BufferedInputStream is) throws IOException { -// /** -// * @j2sNative -// * -// * is.resetStream(); -// * -// */ -// { -// } byte[] abMagic = new byte[4]; abMagic[3] = 1; try{ @@ -303,14 +295,6 @@ public class Rdr implements GenericLineReader { public static byte[] getMagic(InputStream is, int n) { byte[] abMagic = new byte[n]; -// /** -// * @j2sNative -// * -// * is.resetStream(); -// * -// */ -// { -// } try { is.mark(n + 1); is.read(abMagic, 0, n); @@ -595,18 +579,11 @@ public class Rdr implements GenericLineReader { } public static BufferedWriter getBufferedWriter(OutputStream os, String charSetName) { - OutputStreamWriter osw = (OutputStreamWriter) Interface.getInstanceWithParams("java.io.OutputStreamWriter", - new Class[] { java.io.OutputStream.class, String.class }, - new Object[] { os, charSetName == null ? "UTF-8" : charSetName } - ); - /** - * @j2sNative - * return osw.getBufferedWriter(); - * - */ - { - return new BufferedWriter(osw); - } + OutputStreamWriter osw = (OutputStreamWriter) Interface.getInstanceWithParams("java.io.OutputStreamWriter", + new Class[] { java.io.OutputStream.class, String.class }, + new Object[] { os, charSetName == null ? "UTF-8" : charSetName }); + + return new BufferedWriter(osw); } diff --git a/srcjar/javajs/util/ZipTools.java b/srcjar/javajs/util/ZipTools.java index a4082ec..5c6e4ec 100644 --- a/srcjar/javajs/util/ZipTools.java +++ b/srcjar/javajs/util/ZipTools.java @@ -313,7 +313,7 @@ public class ZipTools implements GenericZipTools { @Override public Object getZipOutputStream(Object bos) { // /** -// * @j2sNative +// * xxxxj2sNative // * // * return javajs.api.Interface.getInterface( // * "java.util.zip.ZipOutputStream").setZOS(bos); diff --git a/swingjs/SwingJS-site.zip b/swingjs/SwingJS-site.zip index caf47f3..a3a1798 100644 Binary files a/swingjs/SwingJS-site.zip and b/swingjs/SwingJS-site.zip differ diff --git a/swingjs/net.sf.j2s.core.jar b/swingjs/net.sf.j2s.core.jar index 14a3232..4c3ed48 100644 Binary files a/swingjs/net.sf.j2s.core.jar and b/swingjs/net.sf.j2s.core.jar differ diff --git a/swingjs/timestamp b/swingjs/timestamp index 3e99e38..2f593ad 100644 --- a/swingjs/timestamp +++ b/swingjs/timestamp @@ -1 +1 @@ -20180827222513 +20180917232142 diff --git a/swingjs/ver/3.2.2/SwingJS-site.zip b/swingjs/ver/3.2.2/SwingJS-site.zip index caf47f3..a3a1798 100644 Binary files a/swingjs/ver/3.2.2/SwingJS-site.zip and b/swingjs/ver/3.2.2/SwingJS-site.zip differ diff --git a/swingjs/ver/3.2.2/net.sf.j2s.core.jar b/swingjs/ver/3.2.2/net.sf.j2s.core.jar index 14a3232..4c3ed48 100644 Binary files a/swingjs/ver/3.2.2/net.sf.j2s.core.jar and b/swingjs/ver/3.2.2/net.sf.j2s.core.jar differ diff --git a/swingjs/ver/3.2.2/timestamp b/swingjs/ver/3.2.2/timestamp index 3e99e38..2f593ad 100644 --- a/swingjs/ver/3.2.2/timestamp +++ b/swingjs/ver/3.2.2/timestamp @@ -1 +1 @@ -20180827222513 +20180917232142