# HG changeset patch # User Jaroslav Tulach # Date 1402299632 -7200 # Node ID 7271b051b13cbfe8c950bf3acaa831a44fda099a # Parent d3cbe257c4e9e91097d7851154147a37932bd834 One calculator demo is more than enough diff -r d3cbe257c4e9 -r 7271b051b13c javaquery/demo-calculator-dynamic/nbactions.xml --- a/javaquery/demo-calculator-dynamic/nbactions.xml Mon Jun 09 09:39:59 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ - - - - - run - - process-classes - bck2brwsr:brwsr - - - diff -r d3cbe257c4e9 -r 7271b051b13c javaquery/demo-calculator-dynamic/pom.xml --- a/javaquery/demo-calculator-dynamic/pom.xml Mon Jun 09 09:39:59 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ - - - 4.0.0 - - org.apidesign.bck2brwsr - demo.calculator - 0.9-SNAPSHOT - jar - - JavaQuery Demo - Calculator - http://maven.apache.org - - - UTF-8 - - - - - org.apidesign.bck2brwsr - bck2brwsr-maven-plugin - ${project.version} - - - - brwsr - - - - - org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.7 - 1.7 - - - - org.apache.maven.plugins - maven-jar-plugin - 2.4 - - - - true - lib/ - - - - - - org.apache.maven.plugins - maven-deploy-plugin - 2.7 - - true - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9 - - true - - - - maven-assembly-plugin - 2.4 - - - distro-assembly - package - - single - - - - src/main/assembly/bck2brwsr.xml - - - - - - - - - - - org.apidesign.bck2brwsr - emul - ${project.version} - rt - - - org.apidesign.bck2brwsr - javaquery.api - ${project.version} - - - org.testng - testng - 6.5.2 - test - - - org.apidesign.bck2brwsr - vm4brwsr - js - zip - ${project.version} - provided - - - diff -r d3cbe257c4e9 -r 7271b051b13c javaquery/demo-calculator-dynamic/src/main/assembly/bck2brwsr.xml --- a/javaquery/demo-calculator-dynamic/src/main/assembly/bck2brwsr.xml Mon Jun 09 09:39:59 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ - - - - - bck2brwsr - - zip - dir - - public_html - - - false - runtime - lib - - *:jar - *:rt - - - - false - provided - - *:js - - true - / - - - - - ${project.build.directory}/${project.build.finalName}.jar - / - - - ${project.build.directory}/classes/org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml - / - index.xhtml - - - - \ No newline at end of file diff -r d3cbe257c4e9 -r 7271b051b13c javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/Calc.java --- a/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/Calc.java Mon Jun 09 09:39:59 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +0,0 @@ -/** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012 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.demo.calc; - -import java.util.List; -import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty; -import org.apidesign.bck2brwsr.htmlpage.api.On; -import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*; -import org.apidesign.bck2brwsr.htmlpage.api.OnFunction; -import org.apidesign.bck2brwsr.htmlpage.api.Page; -import org.apidesign.bck2brwsr.htmlpage.api.Property; - -/** HTML5 & Java demo showing the power of - * annotation processors - * as well as other goodies. - * - * @author Jaroslav Tulach - */ -@Page(xhtml="Calculator.xhtml", properties = { - @Property(name = "memory", type = double.class), - @Property(name = "display", type = double.class), - @Property(name = "operation", type = String.class), - @Property(name = "hover", type = boolean.class), - @Property(name = "history", type = HistoryImpl.class, array = true) -}) -public class Calc { - static { - new Calculator().applyBindings().setOperation("plus"); - } - - @On(event = CLICK, id="clear") - static void clear(Calculator c) { - c.setMemory(0); - c.setOperation(null); - c.setDisplay(0); - } - - @On(event = CLICK, id= { "plus", "minus", "mul", "div" }) - static void applyOp(Calculator c, String id) { - c.setMemory(c.getDisplay()); - c.setOperation(id); - c.setDisplay(0); - } - - @On(event = MOUSE_OVER, id= { "result" }) - static void attemptingIn(Calculator c) { - c.setHover(true); - } - @On(event = MOUSE_OUT, id= { "result" }) - static void attemptingOut(Calculator c) { - c.setHover(false); - } - - @On(event = CLICK, id="result") - static void computeTheValue(Calculator c) { - final double newValue = compute( - c.getOperation(), - c.getMemory(), - c.getDisplay() - ); - c.setDisplay(newValue); - if (!containsValue(c.getHistory(), newValue)) { - History h = new History(); - h.setValue(newValue); - h.setOperation(c.getOperation()); - c.getHistory().add(h); - } - c.setMemory(0); - } - - @OnFunction - static void recoverMemory(Calculator c, History data) { - c.setDisplay(data.getValue()); - } - - @OnFunction - static void removeMemory(Calculator c, History data) { - c.getHistory().remove(data); - } - - private static double compute(String op, double memory, double display) { - switch (op) { - case "plus": return memory + display; - case "minus": return memory - display; - case "mul": return memory * display; - case "div": return memory / display; - default: throw new IllegalStateException(op); - } - } - - @On(event = CLICK, id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"}) - static void addDigit(String id, Calculator c) { - id = id.substring(1); - - double v = c.getDisplay(); - if (v == 0.0) { - c.setDisplay(Integer.parseInt(id)); - } else { - String txt = Double.toString(v); - if (txt.endsWith(".0")) { - txt = txt.substring(0, txt.length() - 2); - } - txt = txt + id; - c.setDisplay(Double.parseDouble(txt)); - } - } - - @ComputedProperty - public static String displayPreview( - double display, boolean hover, double memory, String operation - ) { - if (!hover) { - return "Type numbers and perform simple operations! Press '=' to get result."; - } - return "Attempt to compute " + memory + " " + operation + " " + display + " = " + compute(operation, memory, display); - } - - @ComputedProperty - static boolean emptyHistory(List history) { - return history.isEmpty(); - } - - private static boolean containsValue(List arr, final double newValue) { - for (History history : arr) { - if (history.getValue() == newValue) { - return true; - } - } - return false; - } -} diff -r d3cbe257c4e9 -r 7271b051b13c javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/HistoryImpl.java --- a/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/HistoryImpl.java Mon Jun 09 09:39:59 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012 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.demo.calc; - -import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty; -import org.apidesign.bck2brwsr.htmlpage.api.Model; -import org.apidesign.bck2brwsr.htmlpage.api.OnFunction; -import org.apidesign.bck2brwsr.htmlpage.api.Property; - -/** - * - * @author Jaroslav Tulach - */ -@Model(className = "History", properties = { - @Property(name = "value", type = double.class), - @Property(name = "operation", type = String.class) -}) -public class HistoryImpl { - @ComputedProperty - static String resultOf(String operation) { - return "result of " + operation; - } - - @OnFunction - static void twice(History data) { - data.setValue(2.0 * data.getValue()); - } -} diff -r d3cbe257c4e9 -r 7271b051b13c javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml --- a/javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml Mon Jun 09 09:39:59 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ - - - - - - Simple Calculator in HTML5 and Java - - - - -

Java and HTML5 - Together at Last!

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
- -

Previous Results

- -
No results yet.
- - - - - -
- - diff -r d3cbe257c4e9 -r 7271b051b13c javaquery/demo-calculator-dynamic/src/test/java/org/apidesign/bck2brwsr/demo/calc/CalcTest.java --- a/javaquery/demo-calculator-dynamic/src/test/java/org/apidesign/bck2brwsr/demo/calc/CalcTest.java Mon Jun 09 09:39:59 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012 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.demo.calc; - -import static org.testng.Assert.*; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -/** Demonstrating POJO testing of HTML page model. - * - * @author Jaroslav Tulach - */ -public class CalcTest { - private Calculator model; - - - @BeforeMethod - public void initModel() { - model = new Calculator().applyBindings(); - } - - @Test - public void testSomeMethod() { - model.setDisplay(10); - Calc.applyOp(model, "plus"); - assertEquals(0.0, model.getDisplay(), "Cleared after pressing +"); - model.setDisplay(5); - Calc.computeTheValue(model); - assertEquals(15.0, model.getDisplay(), "Shows fifteen"); - } -} diff -r d3cbe257c4e9 -r 7271b051b13c javaquery/pom.xml --- a/javaquery/pom.xml Mon Jun 09 09:39:59 2014 +0200 +++ b/javaquery/pom.xml Mon Jun 09 09:40:32 2014 +0200 @@ -14,6 +14,5 @@ api demo-calculator - demo-calculator-dynamic