jaroslav@142: /** jaroslav@142: * Back 2 Browser Bytecode Translator jaroslav@142: * Copyright (C) 2012 Jaroslav Tulach jaroslav@142: * jaroslav@142: * This program is free software: you can redistribute it and/or modify jaroslav@142: * it under the terms of the GNU General Public License as published by jaroslav@142: * the Free Software Foundation, version 2 of the License. jaroslav@142: * jaroslav@142: * This program is distributed in the hope that it will be useful, jaroslav@142: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@142: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@142: * GNU General Public License for more details. jaroslav@142: * jaroslav@142: * You should have received a copy of the GNU General Public License jaroslav@142: * along with this program. Look for COPYING file in the top folder. jaroslav@142: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@142: */ jaroslav@141: package org.apidesign.bck2brwsr.mavenhtml; jaroslav@141: jaroslav@435: import org.apidesign.bck2brwsr.htmlpage.api.On; jaroslav@435: import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*; jaroslav@141: import org.apidesign.bck2brwsr.htmlpage.api.Page; jaroslav@492: import org.apidesign.bck2brwsr.htmlpage.api.Property; jaroslav@141: jaroslav@198: /** HTML5 & Java demo showing the power of jaroslav@198: * annotation processors jaroslav@198: * as well as other goodies. jaroslav@198: * jaroslav@198: * @author Jaroslav Tulach jaroslav@198: */ jaroslav@492: @Page(xhtml="Calculator.xhtml", properties = { jaroslav@492: @Property(name = "display", type = double.class) jaroslav@492: }) jaroslav@141: public class App { jtulach@197: private static double memory; jtulach@197: private static String operation; jaroslav@141: jaroslav@435: @On(event = CLICK, id="clear") jaroslav@141: static void clear() { jtulach@197: memory = 0; jtulach@197: operation = null; jaroslav@492: Calculator.setDisplay(0); jtulach@197: } jtulach@197: jaroslav@435: @On(event = CLICK, id= { "plus", "minus", "mul", "div" }) jtulach@197: static void applyOp(String op) { jaroslav@492: memory = Calculator.getDisplay(); jtulach@197: operation = op; jaroslav@492: Calculator.setDisplay(0); jtulach@197: } jtulach@197: jaroslav@435: @On(event = CLICK, id="result") jtulach@197: static void computeTheValue() { jtulach@197: switch (operation) { jaroslav@492: case "plus": Calculator.setDisplay(memory + Calculator.getDisplay()); break; jaroslav@492: case "minus": Calculator.setDisplay(memory - Calculator.getDisplay()); break; jaroslav@492: case "mul": Calculator.setDisplay(memory * Calculator.getDisplay()); break; jaroslav@492: case "div": Calculator.setDisplay(memory / Calculator.getDisplay()); break; jtulach@197: default: throw new IllegalStateException(operation); jtulach@197: } jtulach@197: } jtulach@197: jaroslav@435: @On(event = CLICK, id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"}) jtulach@197: static void addDigit(String digit) { jtulach@197: digit = digit.substring(1); jaroslav@492: jaroslav@492: double v = Calculator.getDisplay(); jaroslav@492: if (v == 0.0) { jaroslav@492: Calculator.setDisplay(Integer.parseInt(digit)); jtulach@197: } else { jaroslav@492: String txt = Double.toString(v) + digit; jaroslav@492: Calculator.setDisplay(Double.parseDouble(txt)); jtulach@197: } jaroslav@141: } jaroslav@141: jaroslav@492: jaroslav@492: static { jaroslav@492: Calculator.setDisplay(10.0); jaroslav@492: Calculator.applyBindings(); jaroslav@141: } jaroslav@141: }