javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/PageController.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 09 Nov 2012 11:47:00 +0100
changeset 140 590958fcb7d7
parent 124 htmlpage/src/test/java/org/apidesign/bck2brwsr/htmlpage/PageController.java@a5f8cb32549e
child 435 fb4ed6cc0d4b
permissions -rw-r--r--
Moving the htmlpage API into a submodule in preparation of adding in an example of its usage
     1 /**
     2  * Back 2 Browser Bytecode Translator
     3  * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4  *
     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.
     8  *
     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.
    13  *
    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.
    17  */
    18 package org.apidesign.bck2brwsr.htmlpage;
    19 
    20 import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
    21 import org.apidesign.bck2brwsr.htmlpage.api.Page;
    22 
    23 /** Trivial demo for the bck2brwsr project. First of all start
    24  * with <a href="TestPage.html">your XHTML page</a>. Include there
    25  * a script that will <em>boot Java</em> in your browser.
    26  * <p>
    27  * Then use <code>@Page</code> annotation to 
    28  * generate a Java representation of elements with IDs in that page.
    29  * Depending on the type of the elements, they will have different 
    30  * methods (e.g. <code>PG_TITLE</code> has <code>setText</code>, etc.).
    31  * Use <code>@OnClick</code> annotation to associate behavior
    32  * with existing elements. Use the generated elements
    33  * (<code>PG_TITLE</code>, <code>PG_TEXT</code>) to modify the page.
    34  * <p>
    35  * Everything is type-safe. As soon as somebody modifies the page and
    36  * removes the IDs or re-assigns them to wrong elements. Java compiler
    37  * will emit an error.
    38  * <p>
    39  * Welcome to the type-safe HTML5 world!
    40  *
    41  * @author Jaroslav Tulach <jtulach@netbeans.org>
    42  */
    43 @Page(xhtml="TestPage.html")
    44 public class PageController {
    45     @OnClick(id="pg.button")
    46     static void updateTitle() {
    47         TestPage.PG_TITLE.setText("You want this window to be named " + TestPage.PG_TEXT.getValue());
    48     }
    49     
    50     @OnClick(id={ "pg.title", "pg.text" })
    51     static void click(String id) {
    52         if (!id.equals("pg.title")) {
    53             throw new IllegalStateException();
    54         }
    55         TestPage.PG_TITLE.setText(id);
    56     }
    57 }