1.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java Sat Jan 12 18:18:25 2013 +0100
1.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java Sat Jan 12 20:24:30 2013 +0100
1.3 @@ -43,7 +43,7 @@
1.4 import javax.tools.Diagnostic;
1.5 import javax.tools.FileObject;
1.6 import javax.tools.StandardLocation;
1.7 -import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
1.8 +import org.apidesign.bck2brwsr.htmlpage.api.On;
1.9 import org.apidesign.bck2brwsr.htmlpage.api.Page;
1.10 import org.openide.util.lookup.ServiceProvider;
1.11
1.12 @@ -55,7 +55,7 @@
1.13 @ServiceProvider(service=Processor.class)
1.14 @SupportedAnnotationTypes({
1.15 "org.apidesign.bck2brwsr.htmlpage.api.Page",
1.16 - "org.apidesign.bck2brwsr.htmlpage.api.OnClick"
1.17 + "org.apidesign.bck2brwsr.htmlpage.api.On"
1.18 })
1.19 public final class PageProcessor extends AbstractProcessor {
1.20 @Override
1.21 @@ -146,11 +146,11 @@
1.22 }
1.23 TypeElement type = (TypeElement)clazz;
1.24 for (Element method : clazz.getEnclosedElements()) {
1.25 - OnClick oc = method.getAnnotation(OnClick.class);
1.26 + On oc = method.getAnnotation(On.class);
1.27 if (oc != null) {
1.28 for (String id : oc.id()) {
1.29 if (pp.tagNameForId(id) == null) {
1.30 - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "id = " + oc.id() + " does not exist in the HTML page. Found only " + pp.ids(), method);
1.31 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "id = " + id + " does not exist in the HTML page. Found only " + pp.ids(), method);
1.32 return false;
1.33 }
1.34 ExecutableElement ee = (ExecutableElement)method;
1.35 @@ -159,21 +159,21 @@
1.36 hasParam = false;
1.37 } else {
1.38 if (ee.getParameters().size() != 1 || ee.getParameters().get(0).asType() != stringType) {
1.39 - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@OnClick method should either have no arguments or one String argument", ee);
1.40 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@On method should either have no arguments or one String argument", ee);
1.41 return false;
1.42 }
1.43 hasParam = true;
1.44 }
1.45 if (!ee.getModifiers().contains(Modifier.STATIC)) {
1.46 - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@OnClick method has to be static", ee);
1.47 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@On method has to be static", ee);
1.48 return false;
1.49 }
1.50 if (ee.getModifiers().contains(Modifier.PRIVATE)) {
1.51 - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@OnClick method can't be private", ee);
1.52 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@On method can't be private", ee);
1.53 return false;
1.54 }
1.55 - w.append(" ").append(cnstnt(id)).
1.56 - append(".addOnClick(new Runnable() { public void run() {\n");
1.57 + w.append(" OnEvent." + oc.event()).append(".of(").append(cnstnt(id)).
1.58 + append(").perform(new Runnable() { public void run() {\n");
1.59 w.append(" ").append(type.getSimpleName().toString()).
1.60 append('.').append(ee.getSimpleName()).append("(");
1.61 if (hasParam) {
2.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java Sat Jan 12 18:18:25 2013 +0100
2.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java Sat Jan 12 20:24:30 2013 +0100
2.3 @@ -51,11 +51,11 @@
2.4 * @param r the runnable to execute, never null
2.5 */
2.6 @JavaScriptBody(
2.7 - args={"el", "r"},
2.8 - body="var e = window.document.getElementById(el.fld_id);\n"
2.9 - + "e.onclick = function() { r.run__V(); };\n"
2.10 + args={ "self", "ev", "r" },
2.11 + body="var e = window.document.getElementById(self.fld_id);\n"
2.12 + + "e[ev.fld_id] = function() { r.run__V(r); };\n"
2.13 )
2.14 - public final native void addOnClick(Runnable r);
2.15 + final native void on(OnEvent ev, Runnable r);
2.16
2.17 /** Shows alert message dialog in a browser.
2.18 * @param msg the message to show
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/On.java Sat Jan 12 20:24:30 2013 +0100
3.3 @@ -0,0 +1,35 @@
3.4 +/**
3.5 + * Back 2 Browser Bytecode Translator
3.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3.7 + *
3.8 + * This program is free software: you can redistribute it and/or modify
3.9 + * it under the terms of the GNU General Public License as published by
3.10 + * the Free Software Foundation, version 2 of the License.
3.11 + *
3.12 + * This program is distributed in the hope that it will be useful,
3.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3.15 + * GNU General Public License for more details.
3.16 + *
3.17 + * You should have received a copy of the GNU General Public License
3.18 + * along with this program. Look for COPYING file in the top folder.
3.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
3.20 + */
3.21 +package org.apidesign.bck2brwsr.htmlpage.api;
3.22 +
3.23 +import java.lang.annotation.ElementType;
3.24 +import java.lang.annotation.Retention;
3.25 +import java.lang.annotation.RetentionPolicy;
3.26 +import java.lang.annotation.Target;
3.27 +
3.28 +/** Adds an onClick handler to an element identified by given <em>id</em>.
3.29 + * Apply on a <code>public static void</code> method with no arguments.
3.30 + *
3.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
3.32 + */
3.33 +@Retention(RetentionPolicy.SOURCE)
3.34 +@Target(ElementType.METHOD)
3.35 +public @interface On {
3.36 + OnEvent event();
3.37 + String[] id();
3.38 +}
4.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/OnClick.java Sat Jan 12 18:18:25 2013 +0100
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,34 +0,0 @@
4.4 -/**
4.5 - * Back 2 Browser Bytecode Translator
4.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
4.7 - *
4.8 - * This program is free software: you can redistribute it and/or modify
4.9 - * it under the terms of the GNU General Public License as published by
4.10 - * the Free Software Foundation, version 2 of the License.
4.11 - *
4.12 - * This program is distributed in the hope that it will be useful,
4.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.15 - * GNU General Public License for more details.
4.16 - *
4.17 - * You should have received a copy of the GNU General Public License
4.18 - * along with this program. Look for COPYING file in the top folder.
4.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
4.20 - */
4.21 -package org.apidesign.bck2brwsr.htmlpage.api;
4.22 -
4.23 -import java.lang.annotation.ElementType;
4.24 -import java.lang.annotation.Retention;
4.25 -import java.lang.annotation.RetentionPolicy;
4.26 -import java.lang.annotation.Target;
4.27 -
4.28 -/** Adds an onClick handler to an element identified by given <em>id</em>.
4.29 - * Apply on a <code>public static void</code> method with no arguments.
4.30 - *
4.31 - * @author Jaroslav Tulach <jtulach@netbeans.org>
4.32 - */
4.33 -@Retention(RetentionPolicy.SOURCE)
4.34 -@Target(ElementType.METHOD)
4.35 -public @interface OnClick {
4.36 - String[] id();
4.37 -}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/OnController.java Sat Jan 12 20:24:30 2013 +0100
5.3 @@ -0,0 +1,43 @@
5.4 +/**
5.5 + * Back 2 Browser Bytecode Translator
5.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5.7 + *
5.8 + * This program is free software: you can redistribute it and/or modify
5.9 + * it under the terms of the GNU General Public License as published by
5.10 + * the Free Software Foundation, version 2 of the License.
5.11 + *
5.12 + * This program is distributed in the hope that it will be useful,
5.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.15 + * GNU General Public License for more details.
5.16 + *
5.17 + * You should have received a copy of the GNU General Public License
5.18 + * along with this program. Look for COPYING file in the top folder.
5.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
5.20 + */
5.21 +package org.apidesign.bck2brwsr.htmlpage.api;
5.22 +
5.23 +/** Controller created via {@link OnEvent#of(org.apidesign.bck2brwsr.htmlpage.api.Element[])}.
5.24 + *
5.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
5.26 + */
5.27 +public final class OnController {
5.28 + private final Element[] arr;
5.29 + private final OnEvent event;
5.30 +
5.31 + OnController(OnEvent event, Element[] arr) {
5.32 + this.event = event;
5.33 + this.arr = arr;
5.34 + }
5.35 +
5.36 + /** Registers a runnable to be performed on associated {@link OnEvent}
5.37 + * and {@link Element}.
5.38 + *
5.39 + * @see OnEvent#of
5.40 + */
5.41 + public void perform(Runnable r) {
5.42 + for (Element e : arr) {
5.43 + e.on(event, r);
5.44 + }
5.45 + }
5.46 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/OnEvent.java Sat Jan 12 20:24:30 2013 +0100
6.3 @@ -0,0 +1,95 @@
6.4 +/**
6.5 + * Back 2 Browser Bytecode Translator
6.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
6.7 + *
6.8 + * This program is free software: you can redistribute it and/or modify
6.9 + * it under the terms of the GNU General Public License as published by
6.10 + * the Free Software Foundation, version 2 of the License.
6.11 + *
6.12 + * This program is distributed in the hope that it will be useful,
6.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.15 + * GNU General Public License for more details.
6.16 + *
6.17 + * You should have received a copy of the GNU General Public License
6.18 + * along with this program. Look for COPYING file in the top folder.
6.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
6.20 + */
6.21 +package org.apidesign.bck2brwsr.htmlpage.api;
6.22 +
6.23 +/** Type of events to use in connection with {@link On} annotation.
6.24 + *
6.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
6.26 + */
6.27 +public enum OnEvent {
6.28 + ABORT("onabort"),
6.29 + BLUR("onblur"),
6.30 + CAN_PLAY("oncanplay"),
6.31 + CAN_PLAY_THROUGH("oncanplaythrough"),
6.32 + CLICK("onclick"),
6.33 + CONTEXT_MENU("oncontextmenu"),
6.34 + DBL_CLICK("ondblclick"),
6.35 + DRAG("ondrag"),
6.36 + DRAG_END("ondragend"),
6.37 + DRAG_ENTER("ondragenter"),
6.38 + DRAG_LEAVE("ondragleave"),
6.39 + DRAG_OVER("ondragover"),
6.40 + DRAG_START("ondragstart"),
6.41 + DROP("ondrop"),
6.42 + DURATION_CHANGE("ondurationchange"),
6.43 + EMPTIED("onemptied"),
6.44 + ENDED("onended"),
6.45 + ERROR("onerror"),
6.46 + FOCUS("onfocus"),
6.47 + FORM_CHANGE("onformchange"),
6.48 + FORM_INPUT("onforminput"),
6.49 + INPUT("oninput"),
6.50 + INVALID("oninvalid"),
6.51 + KEY_DOWN("onkeydown"),
6.52 + KEY_PRESS("onkeypress"),
6.53 + KEY_UP("onkeyup"),
6.54 + LOAD("onload"),
6.55 + LOADED_DATA("onloadeddata"),
6.56 + LOADED_META_DATA("onloadedmetadata"),
6.57 + LOAD_START("onloadstart"),
6.58 + MOUSE_DOWN("onmousedown"),
6.59 + MOUSE_MOVE("onmousemove"),
6.60 + MOUSE_OUT("onmouseout"),
6.61 + MOUSE_OVER("onmouseover"),
6.62 + MOUSE_UP("onmouseup"),
6.63 + MOUSE_WHEEL("onmousewheel"),
6.64 + PAUSE("onpause"),
6.65 + PLAY("onplay"),
6.66 + PLAYING("onplaying"),
6.67 + PROGRESS("onprogress"),
6.68 + RATE_CHANGE("onratechange"),
6.69 + READY_STATE_CHANGE("onreadystatechange"),
6.70 + SCROLL("onscroll"),
6.71 + SEEKED("onseeked"),
6.72 + SEEKING("onseeking"),
6.73 + SELECT("onselect"),
6.74 + SHOW("onshow"),
6.75 + STALLED("onstalled"),
6.76 + SUBMIT("onsubmit"),
6.77 + SUSPEND("onsuspend"),
6.78 + TIME_UPDATE("ontimeupdate"),
6.79 + VOLUME_CHANGE("onvolumechange"),
6.80 + WAITING("onwaiting");
6.81 +
6.82 + final String id;
6.83 +
6.84 + private OnEvent(String id) {
6.85 + this.id = id;
6.86 + }
6.87 +
6.88 + /** What should happen when this even happen on one
6.89 + * of associated elements. Continue by calling {@link OnController#perform(java.lang.Runnable)}
6.90 + * method.
6.91 + *
6.92 + * @param elmnts one or more elements
6.93 + * @return controller with <code>perform</code> method.
6.94 + */
6.95 + public OnController of(Element... elmnts) {
6.96 + return new OnController(this, elmnts);
6.97 + }
6.98 +}
7.1 --- a/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/PageController.java Sat Jan 12 18:18:25 2013 +0100
7.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/PageController.java Sat Jan 12 20:24:30 2013 +0100
7.3 @@ -17,7 +17,8 @@
7.4 */
7.5 package org.apidesign.bck2brwsr.htmlpage;
7.6
7.7 -import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
7.8 +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
7.9 +import org.apidesign.bck2brwsr.htmlpage.api.On;
7.10 import org.apidesign.bck2brwsr.htmlpage.api.Page;
7.11
7.12 /** Trivial demo for the bck2brwsr project. First of all start
7.13 @@ -42,12 +43,12 @@
7.14 */
7.15 @Page(xhtml="TestPage.html")
7.16 public class PageController {
7.17 - @OnClick(id="pg.button")
7.18 + @On(event = CLICK, id="pg.button")
7.19 static void updateTitle() {
7.20 TestPage.PG_TITLE.setText("You want this window to be named " + TestPage.PG_TEXT.getValue());
7.21 }
7.22
7.23 - @OnClick(id={ "pg.title", "pg.text" })
7.24 + @On(event = CLICK, id={ "pg.title", "pg.text" })
7.25 static void click(String id) {
7.26 if (!id.equals("pg.title")) {
7.27 throw new IllegalStateException();
8.1 --- a/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java Sat Jan 12 18:18:25 2013 +0100
8.2 +++ b/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java Sat Jan 12 20:24:30 2013 +0100
8.3 @@ -17,7 +17,8 @@
8.4 */
8.5 package org.apidesign.bck2brwsr.mavenhtml;
8.6
8.7 -import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
8.8 +import org.apidesign.bck2brwsr.htmlpage.api.On;
8.9 +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
8.10 import org.apidesign.bck2brwsr.htmlpage.api.Page;
8.11
8.12 /** HTML5 & Java demo showing the power of
8.13 @@ -31,21 +32,21 @@
8.14 private static double memory;
8.15 private static String operation;
8.16
8.17 - @OnClick(id="clear")
8.18 + @On(event = CLICK, id="clear")
8.19 static void clear() {
8.20 memory = 0;
8.21 operation = null;
8.22 Calculator.DISPLAY.setValue("0");
8.23 }
8.24
8.25 - @OnClick(id= { "plus", "minus", "mul", "div" })
8.26 + @On(event = CLICK, id= { "plus", "minus", "mul", "div" })
8.27 static void applyOp(String op) {
8.28 memory = getValue();
8.29 operation = op;
8.30 Calculator.DISPLAY.setValue("0");
8.31 }
8.32
8.33 - @OnClick(id="result")
8.34 + @On(event = CLICK, id="result")
8.35 static void computeTheValue() {
8.36 switch (operation) {
8.37 case "plus": setValue(memory + getValue()); break;
8.38 @@ -56,7 +57,7 @@
8.39 }
8.40 }
8.41
8.42 - @OnClick(id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"})
8.43 + @On(event = CLICK, id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"})
8.44 static void addDigit(String digit) {
8.45 digit = digit.substring(1);
8.46 String v = Calculator.DISPLAY.getValue();
9.1 --- a/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java Sat Jan 12 18:18:25 2013 +0100
9.2 +++ b/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java Sat Jan 12 20:24:30 2013 +0100
9.3 @@ -17,7 +17,8 @@
9.4 */
9.5 package org.apidesign.bck2brwsr.mavenhtml;
9.6
9.7 -import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
9.8 +import org.apidesign.bck2brwsr.htmlpage.api.On;
9.9 +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
9.10 import org.apidesign.bck2brwsr.htmlpage.api.Page;
9.11
9.12 /** HTML5 & Java demo showing the power of
9.13 @@ -31,21 +32,21 @@
9.14 private static double memory;
9.15 private static String operation;
9.16
9.17 - @OnClick(id="clear")
9.18 + @On(event = CLICK, id="clear")
9.19 static void clear() {
9.20 memory = 0;
9.21 operation = null;
9.22 Calculator.DISPLAY.setValue("0");
9.23 }
9.24
9.25 - @OnClick(id= { "plus", "minus", "mul", "div" })
9.26 + @On(event = CLICK, id= { "plus", "minus", "mul", "div" })
9.27 static void applyOp(String op) {
9.28 memory = getValue();
9.29 operation = op;
9.30 Calculator.DISPLAY.setValue("0");
9.31 }
9.32
9.33 - @OnClick(id="result")
9.34 + @On(event = CLICK, id="result")
9.35 static void computeTheValue() {
9.36 switch (operation) {
9.37 case "plus": setValue(memory + getValue()); break;
9.38 @@ -56,7 +57,7 @@
9.39 }
9.40 }
9.41
9.42 - @OnClick(id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"})
9.43 + @On(event = CLICK, id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"})
9.44 static void addDigit(String digit) {
9.45 digit = digit.substring(1);
9.46 String v = Calculator.DISPLAY.getValue();
10.1 --- a/mojo/src/main/resources/archetype-resources/src/main/java/App.java Sat Jan 12 18:18:25 2013 +0100
10.2 +++ b/mojo/src/main/resources/archetype-resources/src/main/java/App.java Sat Jan 12 20:24:30 2013 +0100
10.3 @@ -1,6 +1,7 @@
10.4 package ${package};
10.5
10.6 -import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
10.7 +import org.apidesign.bck2brwsr.htmlpage.api.On;
10.8 +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
10.9 import org.apidesign.bck2brwsr.htmlpage.api.Page;
10.10
10.11 /** Edit the index.xhtml file. Use 'id' to name certain HTML elements.
10.12 @@ -8,8 +9,9 @@
10.13 */
10.14 @Page(xhtml="index.xhtml", className="Index")
10.15 public class App {
10.16 - @OnClick(id="hello")
10.17 + @On(event = CLICK, id="hello")
10.18 static void hello() {
10.19 Index.HELLO.setDisabled(true);
10.20 + Element.alert("Hello World!");
10.21 }
10.22 }