1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/javaquery/demo-calculator/nbactions.xml Fri Nov 09 12:06:45 2012 +0100
1.3 @@ -0,0 +1,10 @@
1.4 +<?xml version="1.0" encoding="UTF-8"?>
1.5 +<actions>
1.6 + <action>
1.7 + <actionName>run</actionName>
1.8 + <goals>
1.9 + <goal>process-classes</goal>
1.10 + <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
1.11 + </goals>
1.12 + </action>
1.13 + </actions>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/javaquery/demo-calculator/pom.xml Fri Nov 09 12:06:45 2012 +0100
2.3 @@ -0,0 +1,63 @@
2.4 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2.5 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2.6 + <modelVersion>4.0.0</modelVersion>
2.7 +
2.8 + <groupId>org.apidesign.bck2brwsr</groupId>
2.9 + <artifactId>demo.calculator</artifactId>
2.10 + <version>1.0-SNAPSHOT</version>
2.11 + <packaging>jar</packaging>
2.12 +
2.13 + <name>JavaQuery Demo - Calculator</name>
2.14 + <url>http://maven.apache.org</url>
2.15 +
2.16 + <properties>
2.17 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2.18 + </properties>
2.19 + <build>
2.20 + <plugins>
2.21 + <plugin>
2.22 + <groupId>org.apidesign.bck2brwsr</groupId>
2.23 + <artifactId>mojo</artifactId>
2.24 + <version>1.0-SNAPSHOT</version>
2.25 + <executions>
2.26 + <execution>
2.27 + <goals>
2.28 + <goal>j2js</goal>
2.29 + </goals>
2.30 + </execution>
2.31 + </executions>
2.32 + </plugin>
2.33 + <plugin>
2.34 + <groupId>org.codehaus.mojo</groupId>
2.35 + <artifactId>exec-maven-plugin</artifactId>
2.36 + <version>1.2.1</version>
2.37 + <executions>
2.38 + <execution>
2.39 + <goals>
2.40 + <goal>exec</goal>
2.41 + </goals>
2.42 + </execution>
2.43 + </executions>
2.44 + <configuration>
2.45 + <executable>xdg-open</executable>
2.46 + <arguments>
2.47 + <argument>${project.build.directory}/classes/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml</argument>
2.48 + </arguments>
2.49 + </configuration>
2.50 + </plugin>
2.51 + </plugins>
2.52 + </build>
2.53 +
2.54 + <dependencies>
2.55 + <dependency>
2.56 + <groupId>org.apidesign.bck2brwsr</groupId>
2.57 + <artifactId>emul</artifactId>
2.58 + <version>1.0-SNAPSHOT</version>
2.59 + </dependency>
2.60 + <dependency>
2.61 + <groupId>org.apidesign.bck2brwsr</groupId>
2.62 + <artifactId>htmlpage</artifactId>
2.63 + <version>1.0-SNAPSHOT</version>
2.64 + </dependency>
2.65 + </dependencies>
2.66 +</project>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java Fri Nov 09 12:06:45 2012 +0100
3.3 @@ -0,0 +1,74 @@
3.4 +package org.apidesign.bck2brwsr.mavenhtml;
3.5 +
3.6 +import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
3.7 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
3.8 +
3.9 +@Page(xhtml="Calculator.xhtml")
3.10 +public class App {
3.11 + private static final int OP_PLUS = 1;
3.12 + private static final int OP_MINUS = 2;
3.13 + private static final int OP_MUL = 3;
3.14 + private static final int OP_DIV = 4;
3.15 +
3.16 + static double memory = 0;
3.17 + static int operation = 0;
3.18 +
3.19 +
3.20 +
3.21 + @OnClick(id="clear")
3.22 + static void clear() {
3.23 + setValue(0.0);
3.24 + }
3.25 +
3.26 + private static void setValue(double v) {
3.27 + StringBuilder sb = new StringBuilder();
3.28 + sb.append(v);
3.29 + Calculator.DISPLAY.setValue(sb.toString());
3.30 + }
3.31 +
3.32 + private static double getValue() {
3.33 + return Double.parseDouble(Calculator.DISPLAY.getValue());
3.34 + }
3.35 +
3.36 + @OnClick(id="plus")
3.37 + static void plus() {
3.38 + memory = getValue();
3.39 + operation = OP_PLUS;
3.40 + setValue(0.0);
3.41 + }
3.42 +
3.43 + @OnClick(id="minus")
3.44 + static void minus() {
3.45 + memory = getValue();
3.46 + operation = OP_MINUS;
3.47 + setValue(0.0);
3.48 + }
3.49 +
3.50 + @OnClick(id="mul")
3.51 + static void mul() {
3.52 + memory = getValue();
3.53 + operation = OP_MUL;
3.54 + setValue(0.0);
3.55 + }
3.56 +
3.57 + @OnClick(id="result")
3.58 + static void computeTheValue() {
3.59 + switch (operation) {
3.60 + case 0: break;
3.61 + case OP_PLUS: setValue(memory + getValue()); break;
3.62 + case OP_MINUS: setValue(memory - getValue()); break;
3.63 + case OP_MUL: setValue(memory * getValue()); break;
3.64 + }
3.65 + }
3.66 +
3.67 + @OnClick(id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"})
3.68 + static void addDigit(String digit) {
3.69 + digit = digit.substring(1);
3.70 + String v = Calculator.DISPLAY.getValue();
3.71 + if ("0".equals(v) || v == null) {
3.72 + Calculator.DISPLAY.setValue(digit);
3.73 + } else {
3.74 + Calculator.DISPLAY.setValue(v + digit);
3.75 + }
3.76 + }
3.77 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/javaquery/demo-calculator/src/main/resources/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml Fri Nov 09 12:06:45 2012 +0100
4.3 @@ -0,0 +1,46 @@
4.4 +<?xml version="1.0" encoding="UTF-8"?>
4.5 +<!--
4.6 +To change this template, choose Tools | Templates
4.7 +and open the template in the editor.
4.8 +-->
4.9 +<!DOCTYPE html>
4.10 +<html xmlns="http://www.w3.org/1999/xhtml">
4.11 + <head>
4.12 + <title>Simple Calculator in HTML5 and Java</title>
4.13 + </head>
4.14 + <body>
4.15 + <table border="0" cellspacing="2">
4.16 + <tbody>
4.17 + <tr>
4.18 + <td colspan="4"><input id="display" value="0"/></td>
4.19 + </tr>
4.20 + <tr>
4.21 + <td><button id="n1">1</button></td>
4.22 + <td><button id="n2">2</button></td>
4.23 + <td><button id="n3">3</button></td>
4.24 + <td><button id="plus">+</button></td>
4.25 + </tr>
4.26 + <tr>
4.27 + <td><button id="n4">4</button></td>
4.28 + <td><button id="n5">5</button></td>
4.29 + <td><button id="n6">6</button></td>
4.30 + <td><button id="minus">-</button></td>
4.31 + </tr>
4.32 + <tr>
4.33 + <td><button id="n7">7</button></td>
4.34 + <td><button id="n8">8</button></td>
4.35 + <td><button id="n9">9</button></td>
4.36 + <td><button id="mul">*</button></td>
4.37 + </tr>
4.38 + <tr>
4.39 + <td><button id="clear">C</button></td>
4.40 + <td><button id="n0">0</button></td>
4.41 + <td><button id="result">=</button></td>
4.42 + <td><button id="div">/</button></td>
4.43 + </tr>
4.44 + </tbody>
4.45 + </table>
4.46 +
4.47 + <script src="bootjava.js"/>
4.48 + </body>
4.49 +</html>
5.1 --- a/javaquery/pom.xml Fri Nov 09 11:47:00 2012 +0100
5.2 +++ b/javaquery/pom.xml Fri Nov 09 12:06:45 2012 +0100
5.3 @@ -13,5 +13,6 @@
5.4 <name>JavaQuery API and Demo</name>
5.5 <modules>
5.6 <module>api</module>
5.7 + <module>demo-calculator</module>
5.8 </modules>
5.9 </project>