javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java
1.1 --- a/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java Mon Jan 21 13:43:40 2013 +0100
1.2 +++ b/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java Mon Jan 21 15:57:30 2013 +0100
1.3 @@ -36,39 +36,41 @@
1.4 @Property(name = "hover", type = boolean.class)
1.5 })
1.6 public class App {
1.7 - private static final Calculator CALC = new Calculator().applyBindings();
1.8 + static {
1.9 + new Calculator().applyBindings();
1.10 + }
1.11
1.12 @On(event = CLICK, id="clear")
1.13 - static void clear() {
1.14 - CALC.setMemory(0);
1.15 - CALC.setOperation(null);
1.16 - CALC.setDisplay(0);
1.17 + static void clear(Calculator c) {
1.18 + c.setMemory(0);
1.19 + c.setOperation(null);
1.20 + c.setDisplay(0);
1.21 }
1.22
1.23 @On(event = CLICK, id= { "plus", "minus", "mul", "div" })
1.24 - static void applyOp(String op) {
1.25 - CALC.setMemory(CALC.getDisplay());
1.26 - CALC.setOperation(op);
1.27 - CALC.setDisplay(0);
1.28 + static void applyOp(Calculator c, String op) {
1.29 + c.setMemory(c.getDisplay());
1.30 + c.setOperation(op);
1.31 + c.setDisplay(0);
1.32 }
1.33
1.34 @On(event = MOUSE_OVER, id= { "result" })
1.35 - static void attemptingIn(String op) {
1.36 - CALC.setHover(true);
1.37 + static void attemptingIn(Calculator c, String op) {
1.38 + c.setHover(true);
1.39 }
1.40 @On(event = MOUSE_OUT, id= { "result" })
1.41 - static void attemptingOut(String op) {
1.42 - CALC.setHover(false);
1.43 + static void attemptingOut(Calculator c, String op) {
1.44 + c.setHover(false);
1.45 }
1.46
1.47 @On(event = CLICK, id="result")
1.48 - static void computeTheValue() {
1.49 - CALC.setDisplay(compute(
1.50 - CALC.getOperation(),
1.51 - CALC.getMemory(),
1.52 - CALC.getDisplay()
1.53 + static void computeTheValue(Calculator c) {
1.54 + c.setDisplay(compute(
1.55 + c.getOperation(),
1.56 + c.getMemory(),
1.57 + c.getDisplay()
1.58 ));
1.59 - CALC.setMemory(0);
1.60 + c.setMemory(0);
1.61 }
1.62
1.63 private static double compute(String op, double memory, double display) {
1.64 @@ -82,19 +84,19 @@
1.65 }
1.66
1.67 @On(event = CLICK, id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"})
1.68 - static void addDigit(String digit) {
1.69 + static void addDigit(String digit, Calculator c) {
1.70 digit = digit.substring(1);
1.71
1.72 - double v = CALC.getDisplay();
1.73 + double v = c.getDisplay();
1.74 if (v == 0.0) {
1.75 - CALC.setDisplay(Integer.parseInt(digit));
1.76 + c.setDisplay(Integer.parseInt(digit));
1.77 } else {
1.78 String txt = Double.toString(v);
1.79 if (txt.endsWith(".0")) {
1.80 txt = txt.substring(0, txt.length() - 2);
1.81 }
1.82 txt = txt + digit;
1.83 - CALC.setDisplay(Double.parseDouble(txt));
1.84 + c.setDisplay(Double.parseDouble(txt));
1.85 }
1.86 }
1.87