author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Sun, 20 Jan 2013 18:20:18 +0100 | |
branch | model |
changeset 492 | 854286e49061 |
parent 140 | 590958fcb7d7 |
child 505 | 4198be34b516 |
permissions | -rw-r--r-- |
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@435 | 46 |
@On(event = CLICK, id="pg.button") |
jaroslav@100 | 47 |
static void updateTitle() { |
jaroslav@104 | 48 |
TestPage.PG_TITLE.setText("You want this window to be named " + TestPage.PG_TEXT.getValue()); |
jaroslav@100 | 49 |
} |
jaroslav@124 | 50 |
|
jaroslav@435 | 51 |
@On(event = CLICK, id={ "pg.title", "pg.text" }) |
jaroslav@124 | 52 |
static void click(String id) { |
jaroslav@124 | 53 |
if (!id.equals("pg.title")) { |
jaroslav@124 | 54 |
throw new IllegalStateException(); |
jaroslav@124 | 55 |
} |
jaroslav@124 | 56 |
TestPage.PG_TITLE.setText(id); |
jaroslav@124 | 57 |
} |
jaroslav@100 | 58 |
} |