# HG changeset patch # User Jaroslav Tulach # Date 1358781674 -3600 # Node ID 35e2c701e514537d2330e93cedef2133e57bf430 # Parent 1c3fda8898a1447f27f80cb34f7733ef4175c84a Moving to demo package diff -r 1c3fda8898a1 -r 35e2c701e514 javaquery/demo-calculator-dynamic/pom.xml --- a/javaquery/demo-calculator-dynamic/pom.xml Mon Jan 21 16:16:30 2013 +0100 +++ b/javaquery/demo-calculator-dynamic/pom.xml Mon Jan 21 16:21:14 2013 +0100 @@ -28,7 +28,7 @@ - org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml + org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml diff -r 1c3fda8898a1 -r 35e2c701e514 javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/Calc.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/Calc.java Mon Jan 21 16:21:14 2013 +0100 @@ -0,0 +1,112 @@ +/** + * 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.On; +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*; +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) +}) +public class Calc { + static { + new Calculator().applyBindings(); + } + + @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 op) { + c.setMemory(c.getDisplay()); + c.setOperation(op); + c.setDisplay(0); + } + + @On(event = MOUSE_OVER, id= { "result" }) + static void attemptingIn(Calculator c, String op) { + c.setHover(true); + } + @On(event = MOUSE_OUT, id= { "result" }) + static void attemptingOut(Calculator c, String op) { + c.setHover(false); + } + + @On(event = CLICK, id="result") + static void computeTheValue(Calculator c) { + c.setDisplay(compute( + c.getOperation(), + c.getMemory(), + c.getDisplay() + )); + c.setMemory(0); + } + + 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 digit, Calculator c) { + digit = digit.substring(1); + + double v = c.getDisplay(); + if (v == 0.0) { + c.setDisplay(Integer.parseInt(digit)); + } else { + String txt = Double.toString(v); + if (txt.endsWith(".0")) { + txt = txt.substring(0, txt.length() - 2); + } + txt = txt + digit; + 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); + } +} diff -r 1c3fda8898a1 -r 35e2c701e514 javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java --- a/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java Mon Jan 21 16:16:30 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +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.mavenhtml; - -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.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) -}) -public class App { - private static final Calculator CALC = new Calculator().applyBindings(); - - @On(event = CLICK, id="clear") - static void clear() { - CALC.setMemory(0); - CALC.setOperation(null); - CALC.setDisplay(0); - } - - @On(event = CLICK, id= { "plus", "minus", "mul", "div" }) - static void applyOp(String op) { - CALC.setMemory(CALC.getDisplay()); - CALC.setOperation(op); - CALC.setDisplay(0); - } - - @On(event = MOUSE_OVER, id= { "result" }) - static void attemptingIn(String op) { - CALC.setHover(true); - } - @On(event = MOUSE_OUT, id= { "result" }) - static void attemptingOut(String op) { - CALC.setHover(false); - } - - @On(event = CLICK, id="result") - static void computeTheValue() { - CALC.setDisplay(compute( - CALC.getOperation(), - CALC.getMemory(), - CALC.getDisplay() - )); - CALC.setMemory(0); - } - - 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 digit) { - digit = digit.substring(1); - - double v = CALC.getDisplay(); - if (v == 0.0) { - CALC.setDisplay(Integer.parseInt(digit)); - } else { - String txt = Double.toString(v); - if (txt.endsWith(".0")) { - txt = txt.substring(0, txt.length() - 2); - } - txt = txt + digit; - CALC.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); - } -} diff -r 1c3fda8898a1 -r 35e2c701e514 javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml Mon Jan 21 16:21:14 2013 +0100 @@ -0,0 +1,161 @@ + + + + + + Simple Calculator in HTML5 and Java + + + + +

Java and HTML5 - Together at Last!

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+

+

+

+ + + + + +
+
+    package org.apidesign.bck2brwsr.mavenhtml;
+
+    import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
+    import org.apidesign.bck2brwsr.htmlpage.api.Page;
+
+    /** HTML5 & Java demo showing the power of annotation processors
+     * as well as other goodies, including type-safe association between
+     * an XHTML page and Java.
+     * 
+     * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
+     */
+    @Page(xhtml="Calculator.xhtml")
+    public class App {
+        private static double memory;
+        private static String operation;
+
+        @OnClick(id="clear")
+        static void clear() {
+            memory = 0;
+            operation = null;
+            Calculator.DISPLAY.setValue("0");
+        }
+
+        @OnClick(id= { "plus", "minus", "mul", "div" })
+        static void applyOp(String op) {
+            memory = getValue();
+            operation = op;
+            Calculator.DISPLAY.setValue("0");
+        }
+
+        @OnClick(id="result")
+        static void computeTheValue() {
+            switch (operation) {
+                case "plus": setValue(memory + getValue()); break;
+                case "minus": setValue(memory - getValue()); break;
+                case "mul": setValue(memory * getValue()); break;
+                case "div": setValue(memory / getValue()); break;
+                default: throw new IllegalStateException(operation);
+            }
+        }
+
+        @OnClick(id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"}) 
+        static void addDigit(String digit) {
+            digit = digit.substring(1);
+            String v = Calculator.DISPLAY.getValue();
+            if (getValue() == 0.0) {
+                Calculator.DISPLAY.setValue(digit);
+            } else {
+                Calculator.DISPLAY.setValue(v + digit);
+            }
+        }
+
+        private static void setValue(double v) {
+            StringBuilder sb = new StringBuilder();
+            sb.append(v);
+            Calculator.DISPLAY.setValue(sb.toString());
+        }
+
+        private static double getValue() {
+            try {
+                return Double.parseDouble(Calculator.DISPLAY.getValue());
+            } catch (NumberFormatException ex) {
+                Calculator.DISPLAY.setValue("err");
+                return 0.0;
+            }
+        }
+    }
+
+    
+ + diff -r 1c3fda8898a1 -r 35e2c701e514 javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml --- a/javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml Mon Jan 21 16:16:30 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,159 +0,0 @@ - - - - - - Simple Calculator in HTML5 and Java - - - - -

Java and HTML5 - Together at Last!

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - - - -
-
-    package org.apidesign.bck2brwsr.mavenhtml;
-
-    import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
-    import org.apidesign.bck2brwsr.htmlpage.api.Page;
-
-    /** HTML5 & Java demo showing the power of annotation processors
-     * as well as other goodies, including type-safe association between
-     * an XHTML page and Java.
-     * 
-     * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
-     */
-    @Page(xhtml="Calculator.xhtml")
-    public class App {
-        private static double memory;
-        private static String operation;
-
-        @OnClick(id="clear")
-        static void clear() {
-            memory = 0;
-            operation = null;
-            Calculator.DISPLAY.setValue("0");
-        }
-
-        @OnClick(id= { "plus", "minus", "mul", "div" })
-        static void applyOp(String op) {
-            memory = getValue();
-            operation = op;
-            Calculator.DISPLAY.setValue("0");
-        }
-
-        @OnClick(id="result")
-        static void computeTheValue() {
-            switch (operation) {
-                case "plus": setValue(memory + getValue()); break;
-                case "minus": setValue(memory - getValue()); break;
-                case "mul": setValue(memory * getValue()); break;
-                case "div": setValue(memory / getValue()); break;
-                default: throw new IllegalStateException(operation);
-            }
-        }
-
-        @OnClick(id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"}) 
-        static void addDigit(String digit) {
-            digit = digit.substring(1);
-            String v = Calculator.DISPLAY.getValue();
-            if (getValue() == 0.0) {
-                Calculator.DISPLAY.setValue(digit);
-            } else {
-                Calculator.DISPLAY.setValue(v + digit);
-            }
-        }
-
-        private static void setValue(double v) {
-            StringBuilder sb = new StringBuilder();
-            sb.append(v);
-            Calculator.DISPLAY.setValue(sb.toString());
-        }
-
-        private static double getValue() {
-            try {
-                return Double.parseDouble(Calculator.DISPLAY.getValue());
-            } catch (NumberFormatException ex) {
-                Calculator.DISPLAY.setValue("err");
-                return 0.0;
-            }
-        }
-    }
-
-    
- -