javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 12 Jan 2013 20:24:30 +0100
changeset 435 fb4ed6cc0d4b
parent 428 2d52faa0c40a
child 436 42f0ad9e4152
permissions -rw-r--r--
Allowing access to all onsmthng events of page elements
jaroslav@26
     1
/**
jaroslav@106
     2
 * Back 2 Browser Bytecode Translator
jaroslav@106
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@26
     4
 *
jaroslav@26
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@26
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@26
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@26
     8
 *
jaroslav@26
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@26
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@26
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@26
    12
 * GNU General Public License for more details.
jaroslav@26
    13
 *
jaroslav@26
    14
 * You should have received a copy of the GNU General Public License
jaroslav@26
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@26
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@26
    17
 */
jaroslav@26
    18
package org.apidesign.bck2brwsr.htmlpage.api;
jaroslav@26
    19
jaroslav@100
    20
import org.apidesign.bck2brwsr.core.JavaScriptBody;
jaroslav@100
    21
jaroslav@26
    22
/** Represents a generic HTML element.
jaroslav@26
    23
 *
jaroslav@26
    24
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@26
    25
 */
jaroslav@26
    26
public abstract class Element {
jaroslav@26
    27
    private final String id;
jaroslav@26
    28
    
jaroslav@26
    29
    public Element(String id) {
jaroslav@26
    30
        this.id = id;
jaroslav@26
    31
    }
jaroslav@26
    32
    
jaroslav@26
    33
    abstract void dontSubclass();
jaroslav@27
    34
    
jaroslav@100
    35
    @JavaScriptBody(
jaroslav@100
    36
        args={"el", "property", "value"},
jaroslav@139
    37
        body="var e = window.document.getElementById(el.fld_id);\n"
jaroslav@100
    38
           + "e[property] = value;\n"
jaroslav@100
    39
    )
jaroslav@428
    40
    static native void setAttribute(Element el, String property, Object value);
jaroslav@100
    41
jaroslav@100
    42
    @JavaScriptBody(
jaroslav@100
    43
        args={"el", "property"},
jaroslav@139
    44
        body="var e = window.document.getElementById(el.fld_id);\n"
jaroslav@100
    45
           + "return e[property];\n"
jaroslav@100
    46
    )
jaroslav@428
    47
    static native Object getAttribute(Element el, String property);
jaroslav@28
    48
    
jaroslav@28
    49
    /** Executes given runnable when user performs a "click" on the given
jaroslav@28
    50
     * element.
jaroslav@28
    51
     * @param r the runnable to execute, never null
jaroslav@28
    52
     */
jaroslav@100
    53
    @JavaScriptBody(
jaroslav@435
    54
        args={ "self", "ev", "r" },
jaroslav@435
    55
        body="var e = window.document.getElementById(self.fld_id);\n"
jaroslav@435
    56
           + "e[ev.fld_id] = function() { r.run__V(r); };\n"
jaroslav@100
    57
    )
jaroslav@435
    58
    final native void on(OnEvent ev, Runnable r);
jaroslav@428
    59
jaroslav@428
    60
    /** Shows alert message dialog in a browser.
jaroslav@428
    61
     * @param msg the message to show
jaroslav@428
    62
     */
jaroslav@428
    63
    @JavaScriptBody(args = "msg", body = "alert(msg);")
jaroslav@428
    64
    public static native void alert(String msg);
jaroslav@428
    65
    
jaroslav@26
    66
}