mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-03 05:44:10 -08:00
Samples: merge storage and video into one module
This commit is contained in:
parent
bdbce01b9a
commit
670f24a4af
|
@ -58,8 +58,7 @@ include("benchmark")
|
|||
include("pi")
|
||||
include("kotlin")
|
||||
include("scala")
|
||||
include("video")
|
||||
include("storage")
|
||||
include("web-apis")
|
||||
|
||||
gradle.allprojects {
|
||||
apply<WarPlugin>()
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright 2014 Alexey Andreev.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
||||
version="3.0">
|
||||
</web-app>
|
|
@ -1,21 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright 2015 Alexey Andreev.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
||||
version="3.0">
|
||||
</web-app>
|
|
@ -26,5 +26,5 @@ dependencies {
|
|||
|
||||
teavm.js {
|
||||
addedToWebApp.set(true)
|
||||
mainClass.set("org.teavm.samples.video.Player")
|
||||
mainClass.set("org.teavm.samples.webapis.Main")
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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").<HTMLInputElement>cast().getValue();
|
||||
String value = document.getElementById("value").<HTMLInputElement>cast().getValue();
|
||||
var key = document.getElementById("key").<HTMLInputElement>cast().getValue();
|
||||
var value = document.getElementById("value").<HTMLInputElement>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);
|
||||
}
|
|
@ -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);
|
||||
}
|
30
samples/web-apis/src/main/webapp/index.html
Normal file
30
samples/web-apis/src/main/webapp/index.html
Normal file
|
@ -0,0 +1,30 @@
|
|||
<!--
|
||||
~ 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.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Web APIs demo app</title>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Please, select a demo</h1>
|
||||
<ul>
|
||||
<li><a href="storage.html">Storage</a></li>
|
||||
<li><a href="video.html">Video</a></li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
|
@ -18,9 +18,9 @@
|
|||
<head>
|
||||
<title>Web Storage web application</title>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||
<script type="text/javascript" charset="utf-8" src="js/storage.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="js/web-apis.js"></script>
|
||||
</head>
|
||||
<body onload="main()">
|
||||
<body onload="main(['storage'])">
|
||||
<h1>Web Storage web application</h1>
|
||||
<input type="text" id="key">
|
||||
<input type="text" id="value">
|
|
@ -18,10 +18,10 @@
|
|||
<head>
|
||||
<title>HTML5 Video web application</title>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||
<script type="text/javascript" charset="utf-8" src="js/video.js"></script>
|
||||
<link href="style.css" rel="stylesheet" type="text/css">
|
||||
<script type="text/javascript" charset="utf-8" src="js/web-apis.js"></script>
|
||||
<link href="video.css" rel="stylesheet" type="text/css">
|
||||
</head>
|
||||
<body onload="main()">
|
||||
<body onload="main(['video'])">
|
||||
<h1>HTML5 Video web application</h1>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user