javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 04 Dec 2012 09:16:53 +0100
changeset 248 0bfcb6585290
parent 140 590958fcb7d7
child 428 2d52faa0c40a
permissions -rw-r--r--
Using the same mangling scheme as JNI
     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.api;
    19 
    20 import org.apidesign.bck2brwsr.core.JavaScriptBody;
    21 
    22 /** Represents a generic HTML element.
    23  *
    24  * @author Jaroslav Tulach <jtulach@netbeans.org>
    25  */
    26 public abstract class Element {
    27     private final String id;
    28     
    29     public Element(String id) {
    30         this.id = id;
    31     }
    32     
    33     abstract void dontSubclass();
    34     
    35     @JavaScriptBody(
    36         args={"el", "property", "value"},
    37         body="var e = window.document.getElementById(el.fld_id);\n"
    38            + "e[property] = value;\n"
    39     )
    40     static void setAttribute(Element el, String property, Object value) {
    41         throw new UnsupportedOperationException("Needs JavaScript!");
    42     }
    43 
    44     @JavaScriptBody(
    45         args={"el", "property"},
    46         body="var e = window.document.getElementById(el.fld_id);\n"
    47            + "return e[property];\n"
    48     )
    49     static Object getAttribute(Element el, String property) {
    50         throw new UnsupportedOperationException("Needs JavaScript!");
    51     }
    52     
    53     /** Executes given runnable when user performs a "click" on the given
    54      * element.
    55      * @param r the runnable to execute, never null
    56      */
    57     @JavaScriptBody(
    58         args={"el", "r"},
    59         body="var e = window.document.getElementById(el.fld_id);\n"
    60            + "e.onclick = function() { r.run__V(); };\n"
    61     )
    62     public final void addOnClick(Runnable r) {
    63         throw new UnsupportedOperationException("Needs JavaScript!");
    64     }
    65 }