javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java
branchmodel
changeset 513 35e2c701e514
parent 512 1c3fda8898a1
child 514 f761555d8312
     1.1 --- a/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java	Mon Jan 21 16:16:30 2013 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,110 +0,0 @@
     1.4 -/**
     1.5 - * Back 2 Browser Bytecode Translator
     1.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     1.7 - *
     1.8 - * This program is free software: you can redistribute it and/or modify
     1.9 - * it under the terms of the GNU General Public License as published by
    1.10 - * the Free Software Foundation, version 2 of the License.
    1.11 - *
    1.12 - * This program is distributed in the hope that it will be useful,
    1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 - * GNU General Public License for more details.
    1.16 - *
    1.17 - * You should have received a copy of the GNU General Public License
    1.18 - * along with this program. Look for COPYING file in the top folder.
    1.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    1.20 - */
    1.21 -package org.apidesign.bck2brwsr.mavenhtml;
    1.22 -
    1.23 -import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
    1.24 -import org.apidesign.bck2brwsr.htmlpage.api.On;
    1.25 -import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
    1.26 -import org.apidesign.bck2brwsr.htmlpage.api.Page;
    1.27 -import org.apidesign.bck2brwsr.htmlpage.api.Property;
    1.28 -
    1.29 -/** HTML5 & Java demo showing the power of 
    1.30 - * <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
    1.31 - * as well as other goodies.
    1.32 - * 
    1.33 - * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    1.34 - */
    1.35 -@Page(xhtml="Calculator.xhtml", properties = {
    1.36 -    @Property(name = "memory", type = double.class),
    1.37 -    @Property(name = "display", type = double.class),
    1.38 -    @Property(name = "operation", type = String.class),
    1.39 -    @Property(name = "hover", type = boolean.class)
    1.40 -})
    1.41 -public class App {
    1.42 -    private static final Calculator CALC = new Calculator().applyBindings();
    1.43 -    
    1.44 -    @On(event = CLICK, id="clear")
    1.45 -    static void clear() {
    1.46 -        CALC.setMemory(0);
    1.47 -        CALC.setOperation(null);
    1.48 -        CALC.setDisplay(0);
    1.49 -    }
    1.50 -    
    1.51 -    @On(event = CLICK, id= { "plus", "minus", "mul", "div" })
    1.52 -    static void applyOp(String op) {
    1.53 -        CALC.setMemory(CALC.getDisplay());
    1.54 -        CALC.setOperation(op);
    1.55 -        CALC.setDisplay(0);
    1.56 -    }
    1.57 -
    1.58 -    @On(event = MOUSE_OVER, id= { "result" })
    1.59 -    static void attemptingIn(String op) {
    1.60 -        CALC.setHover(true);
    1.61 -    }
    1.62 -    @On(event = MOUSE_OUT, id= { "result" })
    1.63 -    static void attemptingOut(String op) {
    1.64 -        CALC.setHover(false);
    1.65 -    }
    1.66 -    
    1.67 -    @On(event = CLICK, id="result")
    1.68 -    static void computeTheValue() {
    1.69 -        CALC.setDisplay(compute(
    1.70 -            CALC.getOperation(), 
    1.71 -            CALC.getMemory(), 
    1.72 -            CALC.getDisplay()
    1.73 -        ));
    1.74 -        CALC.setMemory(0);
    1.75 -    }
    1.76 -    
    1.77 -    private static double compute(String op, double memory, double display) {
    1.78 -        switch (op) {
    1.79 -            case "plus": return memory + display;
    1.80 -            case "minus": return memory - display;
    1.81 -            case "mul": return memory * display;
    1.82 -            case "div": return memory / display;
    1.83 -            default: throw new IllegalStateException(op);
    1.84 -        }
    1.85 -    }
    1.86 -    
    1.87 -    @On(event = CLICK, id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"}) 
    1.88 -    static void addDigit(String digit) {
    1.89 -        digit = digit.substring(1);
    1.90 -        
    1.91 -        double v = CALC.getDisplay();
    1.92 -        if (v == 0.0) {
    1.93 -            CALC.setDisplay(Integer.parseInt(digit));
    1.94 -        } else {
    1.95 -            String txt = Double.toString(v);
    1.96 -            if (txt.endsWith(".0")) {
    1.97 -                txt = txt.substring(0, txt.length() - 2);
    1.98 -            }
    1.99 -            txt = txt + digit;
   1.100 -            CALC.setDisplay(Double.parseDouble(txt));
   1.101 -        }
   1.102 -    }
   1.103 -
   1.104 -    @ComputedProperty
   1.105 -    public static String displayPreview(
   1.106 -        double display, boolean hover, double memory, String operation
   1.107 -    ) {
   1.108 -        if (!hover) {
   1.109 -            return "Type numbers and perform simple operations! Press '=' to get result.";
   1.110 -        }
   1.111 -        return "Attempt to compute " + memory + " " + operation + " " + display + " = " + compute(operation, memory, display);
   1.112 -    }
   1.113 -}