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 net.java.html.json.ComputedProperty;
21 import net.java.html.json.Function;
22 import net.java.html.json.Model;
23 import net.java.html.json.Property;
24 import org.apidesign.bck2brwsr.kosample.js.Dialogs;
26 /** Model annotation generates class Data with
27 * one message property, boolean property and read only words property
29 @Model(className = "Data", targetId="", properties = {
30 @Property(name = "message", type = String.class),
31 @Property(name = "rotating", type = boolean.class)
33 final class DataModel {
34 @ComputedProperty static java.util.List<String> words(String message) {
35 String[] arr = new String[6];
36 String[] words = message == null ? new String[0] : message.split(" ", 6);
37 for (int i = 0; i < 6; i++) {
38 arr[i] = words.length > i ? words[i] : "!";
40 return java.util.Arrays.asList(arr);
43 @Function static void turnAnimationOn(Data model) {
44 model.setRotating(true);
47 @Function static void turnAnimationOff(final Data model) {
48 Dialogs.confirmByUser("Really turn off?", new Runnable() {
51 model.setRotating(false);
56 @Function static void rotate5s(final Data model) {
57 model.setRotating(true);
58 java.util.Timer timer = new java.util.Timer("Rotates a while");
59 timer.schedule(new java.util.TimerTask() {
62 model.setRotating(false);
67 @Function static void showScreenSize(Data model) {
68 model.setMessage(Dialogs.screenSize());
70 private static Data ui;
72 * Called when the page is ready.
74 static void onPageLoad() throws Exception {
76 ui.setMessage("Hello World from HTML and Java!");