2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.kosample;
20 import java.util.TimerTask;
21 import net.java.html.json.ComputedProperty;
22 import net.java.html.json.Function;
23 import net.java.html.json.Model;
24 import net.java.html.json.Property;
25 import org.apidesign.bck2brwsr.kosample.js.Dialogs;
27 /** Model annotation generates class Data with
28 * one message property, boolean property and read only words property
30 @Model(className = "Data", targetId="", properties = {
31 @Property(name = "message", type = String.class),
32 @Property(name = "rotating", type = boolean.class)
34 final class DataModel {
35 @ComputedProperty static java.util.List<String> words(String message) {
36 String[] arr = new String[6];
37 String[] words = message == null ? new String[0] : message.split(" ", 6);
38 for (int i = 0; i < 6; i++) {
39 arr[i] = words.length > i ? words[i] : "!";
41 return java.util.Arrays.asList(arr);
44 @Function static void turnAnimationOn(Data model) {
45 model.setRotating(true);
48 @Function static void turnAnimationOff(final Data model) {
49 Dialogs.confirmByUser("Really turn off?", new Runnable() {
52 model.setRotating(false);
57 private static java.util.Timer TIMER = new java.util.Timer("Pending tasks");
58 private static void schedule(Runnable run, long delay) {
59 TIMER.schedule(new TimerTask() {
67 @Function static void rotate5s(final Data model) {
68 model.setRotating(true);
69 schedule(() -> model.setRotating(false), 5000);
72 @Function static void showScreenSize(Data model) {
73 model.setMessage(Dialogs.screenSize());
75 private static Data ui;
77 * Called when the page is ready.
79 static void onPageLoad() throws Exception {
81 ui.setMessage("Hello World from HTML and Java!");