# HG changeset patch # User Jaroslav Tulach # Date 1384678005 -3600 # Node ID c2293ae622dfa718ce65da2d74af0e7e70d4e035 # Parent 386d1f27e2e6b0af05f035e30bf723c48c6bb087 Adding histogram demo diff -r 386d1f27e2e6 -r c2293ae622df histogram/nbactions-bck2brwsr.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/histogram/nbactions-bck2brwsr.xml Sun Nov 17 09:46:45 2013 +0100 @@ -0,0 +1,39 @@ + + + + + run + + package + bck2brwsr:brwsr + + + true + NONE + + + diff -r 386d1f27e2e6 -r c2293ae622df histogram/nbactions-fxbrwsr.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/histogram/nbactions-fxbrwsr.xml Sun Nov 17 09:46:45 2013 +0100 @@ -0,0 +1,45 @@ + + + + + run + + process-classes + exec:java + + + + debug + + process-classes + exec:java + + + maven + + + diff -r 386d1f27e2e6 -r c2293ae622df histogram/nbactions.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/histogram/nbactions.xml Sun Nov 17 09:46:45 2013 +0100 @@ -0,0 +1,45 @@ + + + + + run + + process-classes + exec:java + + + + debug + + process-classes + exec:java + + + maven + + + diff -r 386d1f27e2e6 -r c2293ae622df histogram/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/histogram/pom.xml Sun Nov 17 09:46:45 2013 +0100 @@ -0,0 +1,201 @@ + + + 4.0.0 + + dew.demo + histogram + 1.0-SNAPSHOT + jar + + histogram + + + UTF-8 + 0.6 + 0.8 + pages/index.html + dew.demo.histogram.Main + none + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + ${project.mainclass} + true + lib/ + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + + browser.rootdir + ${basedir}/src/main/webapp/ + + + ${project.mainclass} + + + + + + + org.apidesign.html + net.java.html.json + ${net.java.html.version} + + + org.apidesign.html + net.java.html.boot + ${net.java.html.version} + + + org.testng + testng + 6.7 + test + + + + + fxbrwsr + + true + + + + + maven-assembly-plugin + 2.4 + + + distro-assembly + package + + single + + + + src/main/assembly/html.java.net.xml + + + + + + + + + + org.apidesign.html + ko-fx + ${net.java.html.version} + runtime + + + org.apidesign.html + boot-fx + ${net.java.html.version} + runtime + + + + + bck2brwsr + + + brwsr + bck2brwsr + + + + + + org.apidesign.bck2brwsr + bck2brwsr-maven-plugin + ${bck2brwsr.version} + + + + brwsr + + + + + ${basedir}/src/main/webapp/ + ${brwsr.startpage} + + + + org.apache.maven.plugins + maven-compiler-plugin + + + netbeans.ignore.jdk.bootclasspath + + + + + maven-assembly-plugin + 2.4 + + + distro-assembly + package + + single + + + + src/main/assembly/bck2brwsr.xml + + + + + + + + + + org.apidesign.bck2brwsr + emul + ${bck2brwsr.version} + rt + + + org.apidesign.bck2brwsr + ko-bck2brwsr + ${bck2brwsr.version} + runtime + + + org.apidesign.bck2brwsr + vm4brwsr + js + zip + ${bck2brwsr.version} + provided + + + + + diff -r 386d1f27e2e6 -r c2293ae622df histogram/src/main/assembly/bck2brwsr.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/histogram/src/main/assembly/bck2brwsr.xml Sun Nov 17 09:46:45 2013 +0100 @@ -0,0 +1,68 @@ + + + + + bck2brwsr + + zip + + public_html + + + false + runtime + lib + + *:jar + *:rt + + + + false + provided + + *:js + + true + / + + + + + src/main/webapp/pages + / + true + + + + + ${project.build.directory}/${project.build.finalName}.jar + / + + + diff -r 386d1f27e2e6 -r c2293ae622df histogram/src/main/assembly/html.java.net.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/histogram/src/main/assembly/html.java.net.xml Sun Nov 17 09:46:45 2013 +0100 @@ -0,0 +1,57 @@ + + + + + html.java.net + + zip + + ${project.build.finalName}-app + + + false + runtime + lib + + + + + ${project.build.directory}/${project.build.finalName}.jar + / + + + + + src/main/webapp/ + / + + pages/** + + + + diff -r 386d1f27e2e6 -r c2293ae622df histogram/src/main/java/dew/demo/histogram/DataModel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/histogram/src/main/java/dew/demo/histogram/DataModel.java Sun Nov 17 09:46:45 2013 +0100 @@ -0,0 +1,80 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package dew.demo.histogram; + +import java.util.ArrayList; +import java.util.List; +import net.java.html.json.ComputedProperty; +import net.java.html.json.Model; +import net.java.html.json.Property; + +/** Model annotation generates class Data with + * one property for list of of numbers and read-only property + * for ten of bars. + */ +@Model(className = "Data", properties = { + @Property(name = "numbers", type = String.class) +}) +final class DataModel { + @ComputedProperty static java.util.List bars(String numbers) { + List arr = new ArrayList(10); + for (int i = 0; i < 10; i++) { + arr.add(new Bar(i, 0)); + } + String[] words = numbers == null ? new String[0] : numbers.split(" "); + for (String word : words) { + try { + double n = Double.parseDouble(word); + if (n > 99) { + n = 99; + } else if (n <= 0) { + n = 0; + } + Bar b = arr.get((int) (n / 10)); + b.setValue(b.getValue() + 1); + }catch (NumberFormatException ex) { + // ignore + } + } + return arr; + } + + @Model(className = "Bar", properties = { + @Property(name = "index", type = int.class), + @Property(name = "value", type = int.class) + }) + static class BarModel { + @ComputedProperty static String left(int index) { + return (index * 50 + 20) + "px"; + } + + @ComputedProperty static String top(int value) { + return (199 - value * 20) + "px"; + } + + @ComputedProperty static String height(int value) { + return 20 * value + "px"; + } + } +} diff -r 386d1f27e2e6 -r c2293ae622df histogram/src/main/java/dew/demo/histogram/Main.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/histogram/src/main/java/dew/demo/histogram/Main.java Sun Nov 17 09:46:45 2013 +0100 @@ -0,0 +1,50 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package dew.demo.histogram; + +import net.java.html.boot.BrowserBuilder; + + +/** Bootstrap and initialization. */ +public final class Main { + private Main() { + } + + /** Launches the browser */ + public static void main(String... args) throws Exception { + BrowserBuilder.newBrowser(). + loadPage("pages/index.html"). + loadClass(Main.class). + invoke("onPageLoad", args). + showAndWait(); + System.exit(0); + } + + /** Called when page is ready */ + public static void onPageLoad(String... args) throws Exception { + Data d = new Data(); + d.setNumbers("15 35 55 75 95"); + d.applyBindings(); + } +} diff -r 386d1f27e2e6 -r c2293ae622df histogram/src/main/java/dew/demo/histogram/MainBrwsr.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/histogram/src/main/java/dew/demo/histogram/MainBrwsr.java Sun Nov 17 09:46:45 2013 +0100 @@ -0,0 +1,34 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package dew.demo.histogram; + +public class MainBrwsr { + static { + try { + Main.onPageLoad(); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + } +} diff -r 386d1f27e2e6 -r c2293ae622df histogram/src/main/webapp/pages/index.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/histogram/src/main/webapp/pages/index.html Sun Nov 17 09:46:45 2013 +0100 @@ -0,0 +1,83 @@ + + + + + + + + + + + +

Histogram Demo

+ + +
+
    +
  • + +
  • +
+
+ + + + + + diff -r 386d1f27e2e6 -r c2293ae622df histogram/src/test/java/dew/demo/histogram/DataModelTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/histogram/src/test/java/dew/demo/histogram/DataModelTest.java Sun Nov 17 09:46:45 2013 +0100 @@ -0,0 +1,39 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package dew.demo.histogram; + +import static org.testng.Assert.*; +import org.testng.annotations.Test; + +public class DataModelTest { + @Test public void areHelloWorldTwoWords() { + Data model = new Data(); + model.setNumbers("-1 103"); + + java.util.List arr = model.getBars(); + assertEquals(arr.size(), 10, "Ten bars"); + assertEquals(arr.get(0).getValue(), 1, "One at lower segment"); + assertEquals(arr.get(9).getValue(), 1, "One at highest segment"); + } +} diff -r 386d1f27e2e6 -r c2293ae622df pom.xml --- a/pom.xml Wed Sep 25 04:27:55 2013 +0200 +++ b/pom.xml Sun Nov 17 09:46:45 2013 +0100 @@ -20,6 +20,7 @@ twitter chat chess + histogram spinningcube words