branch | model |
changeset 885 | 4508b8b6b45b |
parent 878 | ecbd252fd3a7 |
child 890 | c8810910c311 |
1.1 --- a/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/Calc.java Fri Mar 22 17:03:32 2013 +0100 1.2 +++ b/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/Calc.java Mon Mar 25 14:15:09 2013 +0100 1.3 @@ -17,9 +17,11 @@ 1.4 */ 1.5 package org.apidesign.bck2brwsr.demo.calc; 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 @@ -34,12 +36,11 @@ 1.16 @Property(name = "display", type = double.class), 1.17 @Property(name = "operation", type = String.class), 1.18 @Property(name = "hover", type = boolean.class), 1.19 - @Property(name = "results", type = String.class, array = true) 1.20 + @Property(name = "history", type = double.class, array = true) 1.21 }) 1.22 public class Calc { 1.23 static { 1.24 - Calculator m = new Calculator(); 1.25 - m.applyBindings(); 1.26 + new Calculator().applyBindings().setOperation("plus"); 1.27 } 1.28 1.29 @On(event = CLICK, id="clear") 1.30 @@ -67,16 +68,26 @@ 1.31 1.32 @On(event = CLICK, id="result") 1.33 static void computeTheValue(Calculator c) { 1.34 - final double val = compute( 1.35 + final double newValue = compute( 1.36 c.getOperation(), 1.37 c.getMemory(), 1.38 c.getDisplay() 1.39 ); 1.40 - c.getResults().add("another result " + val); 1.41 - c.setDisplay(val); 1.42 + c.setDisplay(newValue); 1.43 + c.getHistory().add(newValue); 1.44 c.setMemory(0); 1.45 } 1.46 1.47 + @OnFunction 1.48 + static void recoverMemory(Calculator c, double data) { 1.49 + c.setDisplay(data); 1.50 + } 1.51 + 1.52 + @OnFunction 1.53 + static void removeMemory(Calculator c, double data) { 1.54 + c.getHistory().remove(data); 1.55 + } 1.56 + 1.57 private static double compute(String op, double memory, double display) { 1.58 switch (op) { 1.59 case "plus": return memory + display; 1.60 @@ -113,4 +124,9 @@ 1.61 } 1.62 return "Attempt to compute " + memory + " " + operation + " " + display + " = " + compute(operation, memory, display); 1.63 } 1.64 + 1.65 + @ComputedProperty 1.66 + static boolean emptyHistory(List<?> history) { 1.67 + return history.isEmpty(); 1.68 + } 1.69 }