diff -r 000000000000 -r 621825e167d7 ko/kosample/client/src/main/java/org/apidesign/bck2brwsr/kosample/DataModel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ko/kosample/client/src/main/java/org/apidesign/bck2brwsr/kosample/DataModel.java Tue Apr 26 08:04:12 2016 +0200 @@ -0,0 +1,79 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012-2015 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.kosample; + +import net.java.html.json.ComputedProperty; +import net.java.html.json.Function; +import net.java.html.json.Model; +import net.java.html.json.Property; +import org.apidesign.bck2brwsr.kosample.js.Dialogs; + +/** Model annotation generates class Data with + * one message property, boolean property and read only words property + */ +@Model(className = "Data", targetId="", properties = { + @Property(name = "message", type = String.class), + @Property(name = "rotating", type = boolean.class) +}) +final class DataModel { + @ComputedProperty static java.util.List words(String message) { + String[] arr = new String[6]; + String[] words = message == null ? new String[0] : message.split(" ", 6); + for (int i = 0; i < 6; i++) { + arr[i] = words.length > i ? words[i] : "!"; + } + return java.util.Arrays.asList(arr); + } + + @Function static void turnAnimationOn(Data model) { + model.setRotating(true); + } + + @Function static void turnAnimationOff(final Data model) { + Dialogs.confirmByUser("Really turn off?", new Runnable() { + @Override + public void run() { + model.setRotating(false); + } + }); + } + + @Function static void rotate5s(final Data model) { + model.setRotating(true); + java.util.Timer timer = new java.util.Timer("Rotates a while"); + timer.schedule(new java.util.TimerTask() { + @Override + public void run() { + model.setRotating(false); + } + }, 5000); + } + + @Function static void showScreenSize(Data model) { + model.setMessage(Dialogs.screenSize()); + } + private static Data ui; + /** + * Called when the page is ready. + */ + static void onPageLoad() throws Exception { + ui = new Data(); + ui.setMessage("Hello World from HTML and Java!"); + ui.applyBindings(); + } +}