1.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java Fri Jan 11 11:17:55 2013 +0100
1.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java Sat Jan 12 10:44:37 2013 +0100
1.3 @@ -37,18 +37,14 @@
1.4 body="var e = window.document.getElementById(el.fld_id);\n"
1.5 + "e[property] = value;\n"
1.6 )
1.7 - static void setAttribute(Element el, String property, Object value) {
1.8 - throw new UnsupportedOperationException("Needs JavaScript!");
1.9 - }
1.10 + static native void setAttribute(Element el, String property, Object value);
1.11
1.12 @JavaScriptBody(
1.13 args={"el", "property"},
1.14 body="var e = window.document.getElementById(el.fld_id);\n"
1.15 + "return e[property];\n"
1.16 )
1.17 - static Object getAttribute(Element el, String property) {
1.18 - throw new UnsupportedOperationException("Needs JavaScript!");
1.19 - }
1.20 + static native Object getAttribute(Element el, String property);
1.21
1.22 /** Executes given runnable when user performs a "click" on the given
1.23 * element.
1.24 @@ -59,7 +55,12 @@
1.25 body="var e = window.document.getElementById(el.fld_id);\n"
1.26 + "e.onclick = function() { r.run__V(); };\n"
1.27 )
1.28 - public final void addOnClick(Runnable r) {
1.29 - throw new UnsupportedOperationException("Needs JavaScript!");
1.30 - }
1.31 + public final native void addOnClick(Runnable r);
1.32 +
1.33 + /** Shows alert message dialog in a browser.
1.34 + * @param msg the message to show
1.35 + */
1.36 + @JavaScriptBody(args = "msg", body = "alert(msg);")
1.37 + public static native void alert(String msg);
1.38 +
1.39 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Timer.java Sat Jan 12 10:44:37 2013 +0100
2.3 @@ -0,0 +1,59 @@
2.4 +/**
2.5 + * Back 2 Browser Bytecode Translator
2.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
2.7 + *
2.8 + * This program is free software: you can redistribute it and/or modify
2.9 + * it under the terms of the GNU General Public License as published by
2.10 + * the Free Software Foundation, version 2 of the License.
2.11 + *
2.12 + * This program is distributed in the hope that it will be useful,
2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.15 + * GNU General Public License for more details.
2.16 + *
2.17 + * You should have received a copy of the GNU General Public License
2.18 + * along with this program. Look for COPYING file in the top folder.
2.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
2.20 + */
2.21 +package org.apidesign.bck2brwsr.htmlpage.api;
2.22 +
2.23 +import java.io.Closeable;
2.24 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
2.25 +
2.26 +/**
2.27 + *
2.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
2.29 + */
2.30 +public class Timer implements Closeable {
2.31 + private final Object t;
2.32 +
2.33 + private Timer(Object t) {
2.34 + this.t = t;
2.35 + }
2.36 +
2.37 + /** Creates a timer that invokes provided runnable on a fixed interval
2.38 + *
2.39 + * @param r the runnable to execute
2.40 + * @param time milliseconds to invoke the timer periodically
2.41 + */
2.42 + public static Timer create(Runnable r, int time) {
2.43 + return new Timer(interval(r, time));
2.44 + }
2.45 +
2.46 + @JavaScriptBody(args = { "r", "time" }, body =
2.47 + "return window.setInterval(function() { r.run__V(); }, time);"
2.48 + )
2.49 + private static native Object interval(Runnable r, int time);
2.50 +
2.51 + @JavaScriptBody(args = { "self" }, body =
2.52 + "window.clearInterval(self);"
2.53 + )
2.54 + private static native void close(Object self);
2.55 +
2.56 + /** Cancels this timer.
2.57 + */
2.58 + @Override
2.59 + public void close() {
2.60 + close(t);
2.61 + }
2.62 +}