Support for event parameters for methods annotated by @On(event). Basic idea by me, tests provided by Toni. Thanks a lot.
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.htmlpage;
20 import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
21 import org.apidesign.bck2brwsr.htmlpage.api.On;
22 import org.apidesign.bck2brwsr.htmlpage.api.Page;
24 /** Trivial demo for the bck2brwsr project. First of all start
25 * with <a href="TestPage.html">your XHTML page</a>. Include there
26 * a script that will <em>boot Java</em> in your browser.
28 * Then use <code>@Page</code> annotation to
29 * generate a Java representation of elements with IDs in that page.
30 * Depending on the type of the elements, they will have different
31 * methods (e.g. <code>PG_TITLE</code> has <code>setText</code>, etc.).
32 * Use <code>@OnClick</code> annotation to associate behavior
33 * with existing elements. Use the generated elements
34 * (<code>PG_TITLE</code>, <code>PG_TEXT</code>) to modify the page.
36 * Everything is type-safe. As soon as somebody modifies the page and
37 * removes the IDs or re-assigns them to wrong elements. Java compiler
40 * Welcome to the type-safe HTML5 world!
42 * @author Jaroslav Tulach <jtulach@netbeans.org>
44 @Page(xhtml="TestPage.html")
45 public class PageController {
46 private static final TestPage PAGE = new TestPage();
48 @On(event = CLICK, id="pg.button")
49 static void updateTitle(TestPage ref) {
51 throw new IllegalStateException("Both references should be the same. " + ref + " != " + PAGE);
53 ref.PG_TITLE.setText("You want this window to be named " + ref.PG_TEXT.getValue());
56 @On(event = CLICK, id={ "pg.title", "pg.text" })
57 static void click(String id) {
58 if (!id.equals("pg.title")) {
59 throw new IllegalStateException();
61 PAGE.PG_TITLE.setText(id);
64 @On(event = CLICK, id={ "pg.canvas" })
65 static void clickCanvas(String id, double layerX) {
66 PAGE.PG_CANVAS.setWidth((int) layerX);