javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calc.java
1.1 --- a/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calc.java Fri Mar 22 17:03:32 2013 +0100
1.2 +++ b/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calc.java Mon Mar 25 11:50:36 2013 +0100
1.3 @@ -17,9 +17,11 @@
1.4 */
1.5 package org.apidesign.bck2brwsr.demo.calc.staticcompilation;
1.6
1.7 +import java.util.List;
1.8 import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
1.9 import org.apidesign.bck2brwsr.htmlpage.api.On;
1.10 import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
1.11 +import org.apidesign.bck2brwsr.htmlpage.api.OnFunction;
1.12 import org.apidesign.bck2brwsr.htmlpage.api.Page;
1.13 import org.apidesign.bck2brwsr.htmlpage.api.Property;
1.14
1.15 @@ -38,7 +40,7 @@
1.16 })
1.17 public class Calc {
1.18 static {
1.19 - new Calculator().applyBindings();
1.20 + new Calculator().applyBindings().setOperation("plus");
1.21 }
1.22
1.23 @On(event = CLICK, id="clear")
1.24 @@ -76,6 +78,16 @@
1.25 c.setMemory(0);
1.26 }
1.27
1.28 + @OnFunction
1.29 + static void recoverMemory(Calculator c, double data) {
1.30 + c.setDisplay(data);
1.31 + }
1.32 +
1.33 + @OnFunction
1.34 + static void removeMemory(Calculator c, double data) {
1.35 + c.getHistory().remove(data);
1.36 + }
1.37 +
1.38 private static double compute(String op, double memory, double display) {
1.39 switch (op) {
1.40 case "plus": return memory + display;
1.41 @@ -112,4 +124,9 @@
1.42 }
1.43 return "Attempt to compute " + memory + " " + operation + " " + display + " = " + compute(operation, memory, display);
1.44 }
1.45 +
1.46 + @ComputedProperty
1.47 + static boolean emptyHistory(List<?> history) {
1.48 + return history.isEmpty();
1.49 + }
1.50 }