From 403e4a226edd6b777008721950c9f025349c4f66 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Sat, 24 May 2014 19:48:05 +0400 Subject: [PATCH] Fixes errors with week data --- .../org/teavm/classlib/impl/JCLPlugin.java | 2 +- .../util/LocaleSettingsNativeGenerator.java | 6 +++--- .../teavm/classlib/java/util/TCalendar.java | 4 ++-- .../main/java/org/teavm/samples/DateTime.java | 21 ++++++++++++++++--- .../src/main/resources/datetime.html | 8 ++++++- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java index 56b0803ea..43a7c6e78 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java @@ -47,7 +47,7 @@ public class JCLPlugin implements TeaVMPlugin { Generator localeGen = new LocaleSettingsNativeGenerator(host.getClassLoader(), host.getProperties()); host.add(new MethodReference("java.util.Locale", "readLanguagesFromCLDR", ValueType.VOID), localeGen); host.add(new MethodReference("java.util.Locale", "readCountriesFromCLDR", ValueType.VOID), localeGen); - host.add(new MethodReference("java.util.Calendar", "readWeeksFromCLDR", ValueType.VOID), localeGen); + host.add(new MethodReference("java.util.Calendar", "readWeeksFromCDLR", ValueType.VOID), localeGen); host.add(new MethodReference(CLDRHelper.class.getName(), "readLikelySubtagsFromCLDR", ValueType.VOID), localeGen); host.add(new MethodReference("java.util.Locale", "getDefaultLocale", ValueType.object("java.lang.String")), diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/LocaleSettingsNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/LocaleSettingsNativeGenerator.java index fba284a24..68e224ae5 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/LocaleSettingsNativeGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/LocaleSettingsNativeGenerator.java @@ -199,7 +199,7 @@ public class LocaleSettingsNativeGenerator implements Generator { case "readCountriesFromCLDR": generateReadCountriesFromCLDR(writer); break; - case "readWeeksFromCLDR": + case "readWeeksFromCDLR": generateReadWeeksFromCDLR(writer); break; case "readLikelySubtagsFromCLDR": @@ -310,14 +310,14 @@ public class LocaleSettingsNativeGenerator implements Generator { } first = false; writer.append('"').append(Renderer.escapeString(entry.getKey())).append('"').ws().append(':') - .ws().append('"').append(entry.getValue()).append('"'); + .ws().append(entry.getValue()); } writer.outdent().append("};").softNewLine(); } private void generateReadLikelySubtagsFromCLDR(SourceWriter writer) throws IOException { generateDefender(writer, "likelySubtags"); - writer.append("java.util.Locale").append(".$CLDR.likelySubtags = {").indent().softNewLine(); + writer.appendClass("java.util.Locale").append(".$CLDR.likelySubtags = {").indent().softNewLine(); boolean first = true; for (Map.Entry entry : likelySubtags.entrySet()) { if (!first) { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCalendar.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCalendar.java index 5b499dceb..5fdd0a53b 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCalendar.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCalendar.java @@ -181,7 +181,7 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl return day; } - @GeneratedBy(LocaleSettingsNativeGenerator.class) + @GeneratedBy(CalendarNativeGenerator.class) private static native int getFirstDayOfWeek(String localeCode); private static int resolveMinimalDaysInFirstWeek(TLocale locale) { @@ -193,7 +193,7 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl return days; } - @GeneratedBy(LocaleSettingsNativeGenerator.class) + @GeneratedBy(CalendarNativeGenerator.class) private static native int getMinimalDaysInFirstWeek(String localeCode); abstract public void add(int field, int value); diff --git a/teavm-samples/src/main/java/org/teavm/samples/DateTime.java b/teavm-samples/src/main/java/org/teavm/samples/DateTime.java index e6bf055a0..8d9ede9d3 100644 --- a/teavm-samples/src/main/java/org/teavm/samples/DateTime.java +++ b/teavm-samples/src/main/java/org/teavm/samples/DateTime.java @@ -16,6 +16,7 @@ package org.teavm.samples; import java.util.Date; +import java.util.GregorianCalendar; import java.util.Locale; import org.teavm.dom.browser.TimerHandler; import org.teavm.dom.browser.Window; @@ -34,7 +35,10 @@ import org.teavm.jso.JS; public class DateTime { private static Window window = (Window)JS.getGlobal(); private static HTMLDocument document = window.getDocument(); + private static HTMLSelectElement localeElem = (HTMLSelectElement)document.getElementById("locale"); private static Date currentDate; + private static Locale[] locales; + private static Locale currentLocale; public static void main(String[] args) { fillLocales(); @@ -44,11 +48,12 @@ public class DateTime { updateCurrentTime(); } }, 250); + updateCurrentLocale(); } private static void fillLocales() { - final HTMLSelectElement localeElem = (HTMLSelectElement)document.getElementById("locale"); - for (Locale locale : Locale.getAvailableLocales()) { + locales = Locale.getAvailableLocales(); + for (Locale locale : locales) { HTMLOptionElement option = (HTMLOptionElement)document.createElement("option"); option.setValue(locale.toString()); option.setLabel(locale.getDisplayName(Locale.getDefault())); @@ -56,11 +61,21 @@ public class DateTime { } localeElem.addEventListener("change", new EventListener() { @Override public void handleEvent(Event evt) { - // Don't do anything + updateCurrentLocale(); + updateCurrentTimeText(); } }); } + private static void updateCurrentLocale() { + currentLocale = locales[localeElem.getSelectedIndex()]; + GregorianCalendar calendar = new GregorianCalendar(currentLocale); + HTMLInputElement weekStartElem = (HTMLInputElement)document.getElementById("week-start"); + weekStartElem.setValue(String.valueOf(calendar.getFirstDayOfWeek())); + HTMLInputElement weekLengthElem = (HTMLInputElement)document.getElementById("week-length"); + weekLengthElem.setValue(String.valueOf(calendar.getMinimalDaysInFirstWeek())); + } + private static void updateCurrentTime() { setCurrentTime(new Date()); } diff --git a/teavm-samples/src/main/resources/datetime.html b/teavm-samples/src/main/resources/datetime.html index 4fb748678..3598c8f3c 100644 --- a/teavm-samples/src/main/resources/datetime.html +++ b/teavm-samples/src/main/resources/datetime.html @@ -13,7 +13,13 @@
- + +
+
+ + + +