diff --git a/sources/net.sf.j2s.core/dist/swingjs/timestamp b/sources/net.sf.j2s.core/dist/swingjs/timestamp index 623c2f5c4..fde5caea0 100644 --- a/sources/net.sf.j2s.core/dist/swingjs/timestamp +++ b/sources/net.sf.j2s.core/dist/swingjs/timestamp @@ -1 +1 @@ -20260627090323 +20260705081251 diff --git a/sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/timestamp b/sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/timestamp index 623c2f5c4..fde5caea0 100644 --- a/sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/timestamp +++ b/sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/timestamp @@ -1 +1 @@ -20260627090323 +20260705081251 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 e8f1ab3cb..4d41b9b9a 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/java/text/DateFormat.java b/sources/net.sf.j2s.java.core/src/java/text/DateFormat.java index 8a02267a8..afbffec51 100644 --- a/sources/net.sf.j2s.java.core/src/java/text/DateFormat.java +++ b/sources/net.sf.j2s.java.core/src/java/text/DateFormat.java @@ -607,9 +607,11 @@ public final static DateFormat getInstance() { */ public static Locale[] getAvailableLocales() { - LocaleServiceProviderPool pool = - LocaleServiceProviderPool.getPool(DateFormatProvider.class); - return pool.getAvailableLocales(); + // SwingJS just return US locale + return new Locale[] { Locale.US }; +// LocaleServiceProviderPool pool = +// LocaleServiceProviderPool.getPool(DateFormatProvider.class); +// return pool.getAvailableLocales(); } /** diff --git a/sources/net.sf.j2s.java.core/src/java/text/Format.java b/sources/net.sf.j2s.java.core/src/java/text/Format.java index 82bfc40db..1202c0364 100644 --- a/sources/net.sf.j2s.java.core/src/java/text/Format.java +++ b/sources/net.sf.j2s.java.core/src/java/text/Format.java @@ -140,6 +140,7 @@ public abstract class Format implements Serializable, Cloneable { private static final long serialVersionUID = -299282585814624189L; protected boolean isSimpleMMDDYY; + protected boolean isISO8601; diff --git a/sources/net.sf.j2s.java.core/src/java/text/SimpleDateFormat.java b/sources/net.sf.j2s.java.core/src/java/text/SimpleDateFormat.java index 3174b7e83..23eaed665 100644 --- a/sources/net.sf.j2s.java.core/src/java/text/SimpleDateFormat.java +++ b/sources/net.sf.j2s.java.core/src/java/text/SimpleDateFormat.java @@ -583,6 +583,7 @@ public SimpleDateFormat(String pattern, Locale locale, boolean allowNull) { this.pattern = pattern; this.locale = locale; this.isSimpleMMDDYY = isSimple(pattern, locale); + this.isISO8601 = pattern.startsWith("yyyy-MM-dd'T'HH:mm:ss"); // lazy calendar initialization for SwingJS // avoids loading 49 classes! // this.formatData = DateFormatSymbols.getInstance(locale); @@ -594,6 +595,8 @@ public SimpleDateFormat(String pattern, Locale locale, boolean allowNull) { /* Initialize compiledPattern and numberFormat fields */ private void initializeLocale() { + if (this.isSimpleMMDDYY || this.isISO8601) + return; if (locale == null) locale = Locale.getDefault(); // Verify and compile the given pattern. @@ -622,11 +625,10 @@ private static NumberFormat getCachedNumberFormatData(Locale key) { @Override public Calendar getCalendar() { - Calendar cal = super.getCalendar(); - if (cal == null) { + if (super.getCalendar() == null) { initializeCalendar(); } - return cal; + return calendar; } private void initializeCalendar() { @@ -894,11 +896,11 @@ public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition pos return format(date, toAppendTo, pos.getFieldDelegate()); } - @Override - public final String format (Object obj) { - return format(obj, new StringBuffer(), isSimpleMMDDYY ? null : new FieldPosition(0)).toString(); - } - + @Override + public final String format(Object obj) { + return format(obj, new StringBuffer(), isSimpleMMDDYY ? null : new FieldPosition(0)).toString(); + } + @Override public String format(Date date) { if (isSimpleMMDDYY) { @@ -923,8 +925,8 @@ private boolean isSimple(String pattern, Locale locale) { switch (ch) { case 'M': case 'd': - case 'H': // H Hour in day (0-23) - case 'k': // k Hour in day (1-24) + case 'H': // H Hour in day (0-23) + case 'k': // k Hour in day (1-24) case 'y': case 'h': case 'm': @@ -940,27 +942,29 @@ private boolean isSimple(String pattern, Locale locale) { // toISOString() returns a string in the // 1970-01-01T00:00:00.000Z - // 0.........1......... + // 0.........1......... // 01234567890123456789 // - //new Date().toString() + // new Date().toString() // Sun Mar 09 14:35:53 GMT-0500 2025" - // 0.........1......... + // 0.........1......... // 01234567890123456789 - private final static String[] fields = { "yyyy", "yy", "MM", "M", "dd", "d", "hh", "h", "HH", "H", "kk", "k", "mm", "m", "ss", "s" }; - private final static int[] fieldlens = { 4, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1 }; - private final static int[] fieldzero = { 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }; - private final static int[] adj = { 0, 0, 3, 3, 0, 0, 12, 12, 23, 23, 24, 24, 0, 0, 0, 0 }; - private final static int[] isopts = { 0, 2, 5, 5, 8, 8, 11, 11, 11, 11, 11, 11, 14, 14, 17, 17 }; - private final static int[] isolens = { 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; - private final static int[] locpts = { -4, -2, 4, 4, 8, 8, 11, 11, 11, 11, 11, 11, 14, 14, 17, 17 }; - private final static int[] loclens = { 4, 2, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; + private final static String[] fields = { "yyyy", "yy", "MM", "M", "dd", "d", "hh", "h", "HH", "H", "kk", "k", "mm", + "m", "ss", "s" }; + private final static int[] fieldlens = { 4, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1 }; + private final static int[] fieldzero = { 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }; + private final static int[] adj = { 0, 0, 3, 3, 0, 0, 12, 12, 23, 23, 24, 24, 0, 0, 0, 0 }; + private final static int[] isopts = { 0, 2, 5, 5, 8, 8, 11, 11, 11, 11, 11, 11, 14, 14, 17, 17 }; + private final static int[] isolens = { 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; + private final static int[] locpts = { -4, -2, 4, 4, 8, 8, 11, 11, 11, 11, 11, 11, 14, 14, 17, 17 }; + private final static int[] loclens = { 4, 2, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; private final static int fieldCount = fields.length; private Object formatSimpleJS(Date date, StringBuffer sb) { // considered doing this -- still could if we want GMT - //String iso = (/** @j2sNative date.toISOString() || */""); - String loc = (/** @j2sNative date.toString() || */""); + // String iso = (/** @j2sNative date.toISOString() || */""); + String loc = (/** @j2sNative date.toString() || */ + ""); String ret = pattern; for (int i = 0, l = 2; i < fieldCount; i++, l = 3 - l) { int pt = ret.indexOf(fields[i]); @@ -980,7 +984,7 @@ private String rep(String p, int pt, int flen, int fzero, String iso, int i0, in String v = (i0 < 0 ? iso.substring(iso.length() + i0) : iso.substring(i0, i0 + isolen)); int iv = -1; if (isoadj == 3) { - iv = (months.indexOf(v)/3 + 1); + iv = (months.indexOf(v) / 3 + 1); } else if (isoadj != 0) { iv = Integer.parseInt(v); switch (isoadj) { @@ -1085,17 +1089,19 @@ public AttributedCharacterIterator formatToCharacterIterator(Object obj) { // Maps from DecimalFormatSymbols index to Field constant private static Field[] PATTERN_INDEX_TO_DATE_FORMAT_FIELD_ID; - + private static Field[] getPatternIndexFieldIDs() { if (PATTERN_INDEX_TO_DATE_FORMAT_FIELD_ID == null) { PATTERN_INDEX_TO_DATE_FORMAT_FIELD_ID = new Field[] { Field.ERA, Field.YEAR, Field.MONTH, - Field.DAY_OF_MONTH, Field.HOUR_OF_DAY1, Field.HOUR_OF_DAY0, Field.MINUTE, Field.SECOND, Field.MILLISECOND, - Field.DAY_OF_WEEK, Field.DAY_OF_YEAR, Field.DAY_OF_WEEK_IN_MONTH, Field.WEEK_OF_YEAR, Field.WEEK_OF_MONTH, - Field.AM_PM, Field.HOUR1, Field.HOUR0, Field.TIME_ZONE, Field.TIME_ZONE, }; + Field.DAY_OF_MONTH, Field.HOUR_OF_DAY1, Field.HOUR_OF_DAY0, Field.MINUTE, Field.SECOND, + Field.MILLISECOND, Field.DAY_OF_WEEK, Field.DAY_OF_YEAR, Field.DAY_OF_WEEK_IN_MONTH, + Field.WEEK_OF_YEAR, Field.WEEK_OF_MONTH, Field.AM_PM, Field.HOUR1, Field.HOUR0, Field.TIME_ZONE, + Field.TIME_ZONE, }; } - return PATTERN_INDEX_TO_DATE_FORMAT_FIELD_ID; - + return PATTERN_INDEX_TO_DATE_FORMAT_FIELD_ID; + } + /** * Private member function that does the real date/time formatting. */ diff --git a/sources/net.sf.j2s.java.core/src/java/time/Instant.java b/sources/net.sf.j2s.java.core/src/java/time/Instant.java index 42e1b8df9..e6db03cc4 100644 --- a/sources/net.sf.j2s.java.core/src/java/time/Instant.java +++ b/sources/net.sf.j2s.java.core/src/java/time/Instant.java @@ -78,7 +78,7 @@ import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.Serializable; -import java.time.format.DateTimeFormatter; +//import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.time.temporal.ChronoField; import java.time.temporal.ChronoUnit; @@ -92,6 +92,7 @@ import java.time.temporal.TemporalUnit; import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; +import java.util.Date; import java.util.Objects; /** @@ -392,7 +393,9 @@ public static Instant from(TemporalAccessor temporal) { * @throws DateTimeParseException if the text cannot be parsed */ public static Instant parse(final CharSequence text) { - return DateTimeFormatter.ISO_INSTANT.parse(text, Instant::from); + long l = /** j2sNative new Date(text.toString()).getTime() || */0; + return ofEpochMilli(l); + //DateTimeFormatter.ISO_INSTANT.parse(text, Instant::from); } //----------------------------------------------------------------------- @@ -1321,45 +1324,57 @@ public int hashCode() { */ @Override public String toString() { - return DateTimeFormatter.ISO_INSTANT.format(this); - } - - // ----------------------------------------------------------------------- - /** - * Writes the object using a - * dedicated serialized form. - * @serialData - *
- * out.writeByte(2); // identifies an Instant - * out.writeLong(seconds); - * out.writeInt(nanos); - *- * - * @return the instance of {@code Ser}, not null - */ - private Object writeReplace() { - return new Ser(Ser.INSTANT_TYPE, this); - } - - /** - * Defend against malicious streams. - * - * @param s the stream to read - * @throws InvalidObjectException always - */ - private void readObject(ObjectInputStream s) throws InvalidObjectException { - throw new InvalidObjectException("Deserialization via serialization delegate"); - } - - void writeExternal(DataOutput out) throws IOException { - out.writeLong(seconds); - out.writeInt(nanos); - } - - static Instant readExternal(DataInput in) throws IOException { - long seconds = in.readLong(); - int nanos = in.readInt(); - return Instant.ofEpochSecond(seconds, nanos); + @SuppressWarnings("unused") + Date d = new Date(this.toEpochMilli()); + + /** + * + * @j2sNative + * + * return d.toISOString(); + */ + { + return null; +// return DateTimeFormatter.ISO_INSTANT.format(this); + } } +// // ----------------------------------------------------------------------- +// /** +// * Writes the object using a +// * dedicated serialized form. +// * @serialData +// *
+// * out.writeByte(2); // identifies an Instant +// * out.writeLong(seconds); +// * out.writeInt(nanos); +// *+// * +// * @return the instance of {@code Ser}, not null +// */ +// private Object writeReplace() { +// return new Ser(Ser.INSTANT_TYPE, this); +// } +// +// /** +// * Defend against malicious streams. +// * +// * @param s the stream to read +// * @throws InvalidObjectException always +// */ +// private void readObject(ObjectInputStream s) throws InvalidObjectException { +// throw new InvalidObjectException("Deserialization via serialization delegate"); +// } +// +// void writeExternal(DataOutput out) throws IOException { +// out.writeLong(seconds); +// out.writeInt(nanos); +// } +// +// static Instant readExternal(DataInput in) throws IOException { +// long seconds = in.readLong(); +// int nanos = in.readInt(); +// return Instant.ofEpochSecond(seconds, nanos); +// } +// } diff --git a/sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java b/sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java index cd559d296..9c2f26c20 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java @@ -61,8 +61,8 @@ import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; -import javajs.api.js.HTML5Applet.JSFunction; import javajs.api.js.HTML5Applet; +import javajs.api.js.HTML5Applet.JSFunction; import javajs.util.JSThread; import javajs.util.PT; import sun.awt.AppContext; @@ -930,58 +930,14 @@ else if (family.equals("monospaced")) * @param isoType null, 8824, or 8601, or a standard SimpleDataFormat format * @return formatted date */ - public static String getDateFormat(String isoType) { - String prefix = ""; - String suffix = ""; - /** - * - * Mon Jan 07 2013 19:54:39 GMT-0600 - * or YYYYMMDDHHmmssOHH'mm' - * - * @j2sNative - * - * if (isoType == null) { - * return ("" + (new Date())).split(" (")[0]; - * } - * if (isoType.indexOf("8824") >= 0) { - * var d = new Date(); - * var x = d.toString().split(" "); - * var MM = "0" + (1 + d.getMonth()); MM = MM.substring(MM.length - 2); - * var dd = "0" + d.getDate(); dd = dd.substring(dd.length - 2); - * return x[3] + MM + dd + x[4].replace(/\:/g,"") + x[5].substring(3,6) + "'" + x[5].substring(6,8) + "'" - * } - * if (isoType.indexOf("8601") >= 0){ - * var d = new Date(); - * var x = d.toString().split(" "); - * // Firefox now doing this? - * if (x.length == 1) - * return x; - * var MM = "0" + (1 + d.getMonth()); MM = MM.substring(MM.length - 2); - * var dd = "0" + d.getDate(); dd = dd.substring(dd.length - 2); - * return x[3] + '-' + MM + '-' + dd + 'T' + x[4] - * } - * - */ - { -// if (isoType == null) { -// isoType = "EEE dd MMM yyyy HH:mm:ss 'GMT'Z"; -// } else if (isoType.contains("8824")) { -// prefix = "D:"; -// suffix = "'00'"; -// isoType = "YYYYMMddHHmmssX"; -// } else if (isoType.contains("8601")) { -// isoType = "yyyy-MM-dd'T'HH:mm:ss"; -// } - Date date = (Date) Interface.getInstance("java.util.Date", true); - SimpleDateFormat format = (SimpleDateFormat) Interface.getInstanceWithParams("java.text.SimpleDateFormat", new Class>[] { String.class }, new Object[] { isoType}); - return prefix + format.format(date) + suffix; - } - } - - @Override - public void beep() { - System.out.println("JSToolkit.beep"); - } + public static String getDateFormat(String isoType) { + return JSUtil.getDateFormat(isoType); + } + + @Override + public void beep() { + System.out.println("JSToolkit.beep"); + } /** * Get a gnu.jpdf.PDFJob. diff --git a/sources/net.sf.j2s.java.core/src/swingjs/JSUtil.java b/sources/net.sf.j2s.java.core/src/swingjs/JSUtil.java index 95a9f79f7..4f5c5fe0f 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/JSUtil.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/JSUtil.java @@ -18,6 +18,8 @@ import java.net.MalformedURLException; import java.net.URI; import java.net.URL; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.HashMap; import java.util.Hashtable; import java.util.Locale; @@ -1311,5 +1313,58 @@ public static void loadScriptAsync(String url, Runnable success) { public void getMediaInfoAsync(byte[] data, String trackType, String path, Consumer