Alas, need to merge into default branch, but without any changes from the accidental commit on default branch
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
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.
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.
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.
18 package org.apidesign.bck2brwsr.htmlpage.api;
20 import org.apidesign.bck2brwsr.core.JavaScriptBody;
22 /** Represents a generic HTML element.
24 * @author Jaroslav Tulach <jtulach@netbeans.org>
26 public abstract class Element {
27 private final String id;
29 public Element(String id) {
33 /** Id of the element in the document.
34 * @return the id for this element
36 public String getId() {
40 abstract void dontSubclass();
43 args={"el", "property", "value"},
44 body="var e = window.document.getElementById(el._id());\n"
45 + "e[property] = value;\n"
47 static native void setAttribute(Element el, String property, Object value);
50 args={"el", "property"},
51 body="var e = window.document.getElementById(el._id());\n"
52 + "return e[property];\n"
54 static native Object getAttribute(Element el, String property);
58 body="return window.document.getElementById(el._id());"
60 static native Object getElementById(Element el);
62 /** Executes given runnable when user performs a "click" on the given
64 * @param data an array of one element to fill with event parameter (if any)
65 * @param r the runnable to execute, never null
69 body="var e = window.document.getElementById(this._id());\n"
70 + "e[ev._id()] = function(ev) {\n"
71 + " var d = ev ? ev : null;\n"
72 + " r.onEvent__VLjava_lang_Object_2(d);\n"
75 final void on(OnEvent ev, OnHandler r) {
78 /** Shows alert message dialog in a browser.
79 * @param msg the message to show
81 @JavaScriptBody(args = "msg", body = "alert(msg);")
82 public static native void alert(String msg);
84 /** Generic way to query any attribute of this element.
85 * @param property name of the attribute
87 public final Object getAttribute(String property) {
88 return getAttribute(this, property);
91 /** Generic way to change an attribute of this element.
93 * @param property name of the attribute
94 * @param value value to associate with the attribute
96 public final void setAttribute(String property, Object value) {
97 setAttribute(this, property, value);