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
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@100
    20
import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
jaroslav@100
    21
import org.apidesign.bck2brwsr.htmlpage.api.Page;
jaroslav@100
    22
jaroslav@100
    23
/** Trivial demo for the bck2brwsr project. First of all start
jaroslav@100
    24
 * with <a href="TestPage.html">your XHTML page</a>. Include there
jaroslav@100
    25
 * a script that will <em>boot Java</em> in your browser.
jaroslav@100
    26
 * <p>
jaroslav@100
    27
 * Then use <code>@Page</code> annotation to 
jaroslav@100
    28
 * generate a Java representation of elements with IDs in that page.
jaroslav@100
    29
 * Depending on the type of the elements, they will have different 
jaroslav@100
    30
 * methods (e.g. <code>PG_TITLE</code> has <code>setText</code>, etc.).
jaroslav@100
    31
 * Use <code>@OnClick</code> annotation to associate behavior
jaroslav@100
    32
 * with existing elements. Use the generated elements
jaroslav@100
    33
 * (<code>PG_TITLE</code>, <code>PG_TEXT</code>) to modify the page.
jaroslav@100
    34
 * <p>
jaroslav@100
    35
 * Everything is type-safe. As soon as somebody modifies the page and
jaroslav@100
    36
 * removes the IDs or re-assigns them to wrong elements. Java compiler
jaroslav@100
    37
 * will emit an error.
jaroslav@100
    38
 * <p>
jaroslav@100
    39
 * Welcome to the type-safe HTML5 world!
jaroslav@100
    40
 *
jaroslav@100
    41
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@100
    42
 */
jaroslav@108
    43
@Page(xhtml="TestPage.html")
jaroslav@100
    44
public class PageController {
jaroslav@100
    45
    @OnClick(id="pg.button")
jaroslav@100
    46
    static void updateTitle() {
jaroslav@104
    47
        TestPage.PG_TITLE.setText("You want this window to be named " + TestPage.PG_TEXT.getValue());
jaroslav@100
    48
    }
jaroslav@124
    49
    
jaroslav@124
    50
    @OnClick(id={ "pg.title", "pg.text" })
jaroslav@124
    51
    static void click(String id) {
jaroslav@124
    52
        if (!id.equals("pg.title")) {
jaroslav@124
    53
            throw new IllegalStateException();
jaroslav@124
    54
        }
jaroslav@124
    55
        TestPage.PG_TITLE.setText(id);
jaroslav@124
    56
    }
jaroslav@100
    57
}