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