diff --git a/samples/settings.gradle.kts b/samples/settings.gradle.kts index fffa70ed9..30f440da7 100644 --- a/samples/settings.gradle.kts +++ b/samples/settings.gradle.kts @@ -58,8 +58,7 @@ include("benchmark") include("pi") include("kotlin") include("scala") -include("video") -include("storage") +include("web-apis") gradle.allprojects { apply() diff --git a/samples/storage/src/main/webapp/WEB-INF/web.xml b/samples/storage/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index bfc410b12..000000000 --- a/samples/storage/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - \ No newline at end of file diff --git a/samples/video/src/main/webapp/WEB-INF/web.xml b/samples/video/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 6471cd77a..000000000 --- a/samples/video/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - \ No newline at end of file diff --git a/samples/video/build.gradle.kts b/samples/web-apis/build.gradle.kts similarity index 93% rename from samples/video/build.gradle.kts rename to samples/web-apis/build.gradle.kts index e49ec2b02..c077ddbe3 100644 --- a/samples/video/build.gradle.kts +++ b/samples/web-apis/build.gradle.kts @@ -26,5 +26,5 @@ dependencies { teavm.js { addedToWebApp.set(true) - mainClass.set("org.teavm.samples.video.Player") + mainClass.set("org.teavm.samples.webapis.Main") } \ No newline at end of file diff --git a/samples/storage/build.gradle.kts b/samples/web-apis/src/main/java/org/teavm/samples/webapis/Main.java similarity index 64% rename from samples/storage/build.gradle.kts rename to samples/web-apis/src/main/java/org/teavm/samples/webapis/Main.java index b8acd11b5..5d7b4f5e1 100644 --- a/samples/storage/build.gradle.kts +++ b/samples/web-apis/src/main/java/org/teavm/samples/webapis/Main.java @@ -13,18 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package org.teavm.samples.webapis; -plugins { - java - war - id("org.teavm") -} +public final class Main { + private Main() { + } -dependencies { - teavm(teavm.libs.jsoApis) -} - -teavm.js { - addedToWebApp.set(true) - mainClass.set("org.teavm.samples.storage.Application") + public static void main(String[] args) { + switch (args[0]) { + case "storage": + Storage.run(); + break; + case "video": + Video.run(); + break; + } + } } diff --git a/samples/storage/src/main/java/org/teavm/samples/storage/Application.java b/samples/web-apis/src/main/java/org/teavm/samples/webapis/Storage.java similarity index 69% rename from samples/storage/src/main/java/org/teavm/samples/storage/Application.java rename to samples/web-apis/src/main/java/org/teavm/samples/webapis/Storage.java index 20d993522..8e568b445 100644 --- a/samples/storage/src/main/java/org/teavm/samples/storage/Application.java +++ b/samples/web-apis/src/main/java/org/teavm/samples/webapis/Storage.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Alexey Andreev. + * Copyright 2023 Alexey Andreev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,35 +13,33 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.samples.storage; +package org.teavm.samples.webapis; -import org.teavm.jso.browser.Storage; import org.teavm.jso.browser.Window; import org.teavm.jso.dom.html.HTMLButtonElement; import org.teavm.jso.dom.html.HTMLDocument; -import org.teavm.jso.dom.html.HTMLElement; import org.teavm.jso.dom.html.HTMLInputElement; /** * * @author Junji Takakura */ -public final class Application { +public final class Storage { private static HTMLDocument document = Window.current().getDocument(); - private static Storage storage = Window.current().getSessionStorage(); + private static org.teavm.jso.browser.Storage storage = Window.current().getSessionStorage(); - private Application() { + private Storage() { } - public static void main(String[] args) { + public static void run() { if (storage == null) { Window.alert("storage is not supported."); } HTMLButtonElement saveButton = document.getElementById("save-button").cast(); saveButton.listenClick(e -> { - String key = document.getElementById("key").cast().getValue(); - String value = document.getElementById("value").cast().getValue(); + var key = document.getElementById("key").cast().getValue(); + var value = document.getElementById("value").cast().getValue(); if (key != null && key.length() > 0 && value != null && value.length() > 0) { storage.setItem(key, value); @@ -65,19 +63,19 @@ public final class Application { } private static void draw() { - HTMLElement tbody = document.getElementById("list"); + var tbody = document.getElementById("list"); while (tbody.getFirstChild() != null) { tbody.removeChild(tbody.getFirstChild()); } for (int i = 0; i < storage.getLength(); i++) { - String key = storage.key(i); - String value = storage.getItem(key); + var key = storage.key(i); + var value = storage.getItem(key); - HTMLElement tdKey = document.createElement("td").withText(key); - HTMLElement tdValue = document.createElement("td").withText(value); - HTMLElement tr = document.createElement("tr").withChild(tdKey).withChild(tdValue); + var tdKey = document.createElement("td").withText(key); + var tdValue = document.createElement("td").withText(value); + var tr = document.createElement("tr").withChild(tdKey).withChild(tdValue); tbody.appendChild(tr); } diff --git a/samples/video/src/main/java/org/teavm/samples/video/Player.java b/samples/web-apis/src/main/java/org/teavm/samples/webapis/Video.java similarity index 90% rename from samples/video/src/main/java/org/teavm/samples/video/Player.java rename to samples/web-apis/src/main/java/org/teavm/samples/webapis/Video.java index 49f048740..7020ddf21 100644 --- a/samples/video/src/main/java/org/teavm/samples/video/Player.java +++ b/samples/web-apis/src/main/java/org/teavm/samples/webapis/Video.java @@ -13,22 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.samples.video; +package org.teavm.samples.webapis; import org.teavm.jso.browser.Window; -import org.teavm.jso.dom.html.HTMLBodyElement; import org.teavm.jso.dom.html.HTMLDocument; -import org.teavm.jso.dom.html.HTMLElement; import org.teavm.jso.dom.html.HTMLSourceElement; import org.teavm.jso.dom.html.HTMLVideoElement; -public final class Player { +public final class Video { private static HTMLDocument document = Window.current().getDocument(); - private Player() { + private Video() { } - public static void main(String[] args) { + public static void run() { HTMLSourceElement sourceMp4 = document.createElement("source").cast(); sourceMp4.setSrc("http://media.w3.org/2010/05/sintel/trailer.mp4"); sourceMp4.setAttribute("type", "video/mp4"); @@ -41,7 +39,7 @@ public final class Player { sourceOgv.setSrc("http://media.w3.org/2010/05/sintel/trailer.ogv"); sourceOgv.setAttribute("type", "video/ogg"); - HTMLElement p = document.createElement("p"); + var p = document.createElement("p"); p.appendChild(document.createTextNode("Your user agent does not support the HTML5 Video element.")); HTMLVideoElement video = document.createElement("video").cast(); @@ -54,10 +52,10 @@ public final class Player { video.appendChild(sourceOgv); video.appendChild(p); - HTMLElement divVideo = document.createElement("div"); + var divVideo = document.createElement("div"); divVideo.appendChild(video); - HTMLElement divButtons = document.createElement("div") + var divButtons = document.createElement("div") .withAttr("id", "button") .withChild("button", elem -> elem.withText("load()").listenClick(evt -> video.load())) .withChild("button", elem -> elem.withText("play()").listenClick(evt -> video.play())) @@ -84,7 +82,7 @@ public final class Player { .withChild("button", elem -> elem.withText("mute").listenClick(evt -> video.setMuted(true))) .withChild("button", elem -> elem.withText("unmute").listenClick(evt -> video.setMuted(false))); - HTMLBodyElement body = document.getBody(); + var body = document.getBody(); body.appendChild(divVideo); body.appendChild(divButtons); } diff --git a/samples/web-apis/src/main/webapp/index.html b/samples/web-apis/src/main/webapp/index.html new file mode 100644 index 000000000..5224e43b4 --- /dev/null +++ b/samples/web-apis/src/main/webapp/index.html @@ -0,0 +1,30 @@ + + + + + + Web APIs demo app + + + +

Please, select a demo

+ + + \ No newline at end of file diff --git a/samples/storage/src/main/webapp/index.html b/samples/web-apis/src/main/webapp/storage.html similarity index 90% rename from samples/storage/src/main/webapp/index.html rename to samples/web-apis/src/main/webapp/storage.html index 13f703379..d6eef74ae 100644 --- a/samples/storage/src/main/webapp/index.html +++ b/samples/web-apis/src/main/webapp/storage.html @@ -18,9 +18,9 @@ Web Storage web application - + - +

Web Storage web application

diff --git a/samples/video/src/main/webapp/style.css b/samples/web-apis/src/main/webapp/video.css similarity index 100% rename from samples/video/src/main/webapp/style.css rename to samples/web-apis/src/main/webapp/video.css diff --git a/samples/video/src/main/webapp/index.html b/samples/web-apis/src/main/webapp/video.html similarity index 82% rename from samples/video/src/main/webapp/index.html rename to samples/web-apis/src/main/webapp/video.html index 855ed36de..181ca8d59 100644 --- a/samples/video/src/main/webapp/index.html +++ b/samples/web-apis/src/main/webapp/video.html @@ -18,10 +18,10 @@ HTML5 Video web application - - + + - +

HTML5 Video web application

\ No newline at end of file