diff -r 448bed1f6d5a -r 37ad459579bc rt/archetype/src/main/resources/archetype-resources/src/main/java/App.java
--- a/rt/archetype/src/main/resources/archetype-resources/src/main/java/App.java Fri Mar 22 00:02:21 2013 +0100
+++ b/rt/archetype/src/main/resources/archetype-resources/src/main/java/App.java Mon Sep 09 17:34:30 2013 +0200
@@ -1,16 +1,19 @@
package ${package};
+import java.util.List;
import org.apidesign.bck2brwsr.htmlpage.api.*;
import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
import org.apidesign.bck2brwsr.htmlpage.api.Page;
import org.apidesign.bck2brwsr.htmlpage.api.Property;
import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
-/** Edit the index.xhtml file. Use 'id' to name certain HTML elements.
- * Use this class to define behavior of the elements.
+/** This is the controller class for associated index.html page. The Index
+ * is autogenerated by parsing the index.html page. It fields represent individual
+ * elements annotated by "id" in the page.
*/
@Page(xhtml="index.html", className="Index", properties={
- @Property(name="name", type=String.class)
+ @Property(name="name", type=String.class),
+ @Property(name="messages", type=String.class, array=true),
})
public class App {
static {
@@ -19,16 +22,67 @@
model.applyBindings();
}
+ /**
+ * @param m the model of the index page creates in static initializer
+ */
@On(event = CLICK, id="hello")
static void hello(Index m) {
- GraphicsContext g = m.CANVAS.getContext();
+ display(m.getHelloMessage(), m);
+ m.getMessages().add(m.getHelloMessage());
+ }
+
+ /** Reacts when mouse moves over the canvas.
+ *
+ * @param m the model of the page
+ * @param x property "x" extracted from the event generated by the browser
+ * @param y property "y" from the mouse event
+ */
+ @On(event = MOUSE_MOVE, id="canvas")
+ static void clearPoint(Index m, int x, int y) {
+ GraphicsContext g = m.canvas.getContext();
+ boolean even = (x + y) % 2 == 0;
+ if (even) {
+ g.setFillStyle("blue");
+ } else {
+ g.setFillStyle("red");
+ }
g.clearRect(0, 0, 1000, 1000);
g.setFont("italic 40px Calibri");
g.fillText(m.getHelloMessage(), 10, 40);
}
+
+ /** Callback function called by the KnockOut/Java binding on elements
+ * representing href's with individual messages being their data.
+ *
+ * @param data the data associated with the element
+ * @param m the model of the page
+ */
+ @OnFunction
+ static void display(String data, Index m) {
+ GraphicsContext g = m.canvas.getContext();
+ g.clearRect(0, 0, 1000, 1000);
+ g.setFillStyle("black");
+ g.setFont("italic 40px Calibri");
+ g.fillText(data, 10, 40);
+ }
+
+ /** Callback function.
+ *
+ * @param data data associated with the actual element on the page
+ * @param m the model of the page
+ */
+ @OnFunction
+ static void remove(String data, Index m) {
+ m.getMessages().remove(data);
+ }
@ComputedProperty
static String helloMessage(String name) {
return "Hello " + name + "!";
}
+
+ @ComputedProperty
+ static boolean noMessages(List messages) {
+ return messages.isEmpty();
+ }
}