# HG changeset patch # User Jaroslav Tulach # Date 1356332685 -3600 # Node ID 5751fe604e6b3e726cc594fb11bcf0e055f1bdff # Parent e5b4bd29f26827365f54f2a7f528edcfd347c0f2 Keeping old name for static demo-calculator, as its build products are referenced by Hudson jobs diff -r e5b4bd29f268 -r 5751fe604e6b javaquery/demo-calculator-dynamic/nbactions.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javaquery/demo-calculator-dynamic/nbactions.xml Mon Dec 24 08:04:45 2012 +0100 @@ -0,0 +1,29 @@ + + + + + run + + process-classes + org.apidesign.bck2brwsr:mojo:0.3-SNAPSHOT:brwsr + + + diff -r e5b4bd29f268 -r 5751fe604e6b javaquery/demo-calculator-dynamic/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javaquery/demo-calculator-dynamic/pom.xml Mon Dec 24 08:04:45 2012 +0100 @@ -0,0 +1,58 @@ + + + 4.0.0 + + org.apidesign.bck2brwsr + demo.calculator + 0.3-SNAPSHOT + jar + + JavaQuery Demo - Calculator + http://maven.apache.org + + + UTF-8 + + + + + org.apidesign.bck2brwsr + mojo + 0.3-SNAPSHOT + + + + brwsr + + + + + org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + + + + + org.apidesign.bck2brwsr + emul + 0.3-SNAPSHOT + + + org.apidesign.bck2brwsr + javaquery.api + 0.3-SNAPSHOT + + + diff -r e5b4bd29f268 -r 5751fe604e6b javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java Mon Dec 24 08:04:45 2012 +0100 @@ -0,0 +1,88 @@ +/** + * 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.OnClick; +import org.apidesign.bck2brwsr.htmlpage.api.Page; + +/** HTML5 & Java demo showing the power of + * annotation processors + * as well as other goodies. + * + * @author Jaroslav Tulach + */ +@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); + if (sb.toString().endsWith(".0")) { + final int l = sb.length(); + sb.delete(l - 2, l); + } + 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 e5b4bd29f268 -r 5751fe604e6b javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml Mon Dec 24 08:04:45 2012 +0100 @@ -0,0 +1,158 @@ + + + + + + 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 e5b4bd29f268 -r 5751fe604e6b javaquery/demo-calculator/nbactions.xml --- a/javaquery/demo-calculator/nbactions.xml Mon Dec 24 07:57:33 2012 +0100 +++ b/javaquery/demo-calculator/nbactions.xml Mon Dec 24 08:04:45 2012 +0100 @@ -23,7 +23,7 @@ run process-classes - org.apidesign.bck2brwsr:mojo:0.3-SNAPSHOT:brwsr + org.codehaus.mojo:exec-maven-plugin:1.2.1:exec diff -r e5b4bd29f268 -r 5751fe604e6b javaquery/demo-calculator/pom.xml --- a/javaquery/demo-calculator/pom.xml Mon Dec 24 07:57:33 2012 +0100 +++ b/javaquery/demo-calculator/pom.xml Mon Dec 24 08:04:45 2012 +0100 @@ -4,11 +4,11 @@ 4.0.0 org.apidesign.bck2brwsr - demo.calculator + demo.static.calculator 0.3-SNAPSHOT jar - JavaQuery Demo - Calculator + JavaQuery Demo - Calculator - Static Compilation http://maven.apache.org @@ -16,19 +16,34 @@ + + org.apidesign.bck2brwsr + mojo + 0.3-SNAPSHOT + + + + j2js + + + + - org.apidesign.bck2brwsr - mojo - 0.3-SNAPSHOT + org.codehaus.mojo + exec-maven-plugin + 1.2.1 - brwsr + exec - org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml + xdg-open + + ${project.build.directory}/classes/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml + diff -r e5b4bd29f268 -r 5751fe604e6b javaquery/demo-calculator/src/main/resources/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml --- a/javaquery/demo-calculator/src/main/resources/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml Mon Dec 24 07:57:33 2012 +0100 +++ b/javaquery/demo-calculator/src/main/resources/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml Mon Dec 24 08:04:45 2012 +0100 @@ -77,11 +77,7 @@ - - - +