jaroslav@1941: /** jaroslav@1941: * Back 2 Browser Bytecode Translator jaroslav@1941: * Copyright (C) 2012-2015 Jaroslav Tulach jaroslav@1941: * jaroslav@1941: * This program is free software: you can redistribute it and/or modify jaroslav@1941: * it under the terms of the GNU General Public License as published by jaroslav@1941: * the Free Software Foundation, version 2 of the License. jaroslav@1941: * jaroslav@1941: * This program is distributed in the hope that it will be useful, jaroslav@1941: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@1941: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@1941: * GNU General Public License for more details. jaroslav@1941: * jaroslav@1941: * You should have received a copy of the GNU General Public License jaroslav@1941: * along with this program. Look for COPYING file in the top folder. jaroslav@1941: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@1941: */ jaroslav@1941: package org.apidesign.bck2brwsr.kosample.js; jaroslav@1941: jaroslav@1941: import net.java.html.js.JavaScriptBody; jaroslav@1941: jaroslav@1941: /** Use {@link JavaScriptBody} annotation on methods to jaroslav@1941: * directly interact with JavaScript. See jaroslav@1941: * http://bits.netbeans.org/html+java/1.2/net/java/html/js/package-summary.html jaroslav@1941: * to understand how. jaroslav@1941: */ jaroslav@1941: public final class Dialogs { jaroslav@1941: private Dialogs() { jaroslav@1941: } jaroslav@1941: jaroslav@1941: /** Shows confirmation dialog to the user. jaroslav@1941: * jaroslav@1941: * @param msg the message jaroslav@1941: * @param callback called back when the use accepts (can be null) jaroslav@1941: */ jaroslav@1941: @JavaScriptBody( jaroslav@1941: args = { "msg", "callback" }, jaroslav@1941: javacall = true, jaroslav@1941: body = "if (confirm(msg)) {\n" jaroslav@1941: + " callback.@java.lang.Runnable::run()();\n" jaroslav@1941: + "}\n" jaroslav@1941: ) jaroslav@1941: public static native void confirmByUser(String msg, Runnable callback); jaroslav@1941: jaroslav@1941: @JavaScriptBody( jaroslav@1941: args = {}, body = jaroslav@1941: "var w = window,\n" + jaroslav@1941: " d = document,\n" + jaroslav@1941: " e = d.documentElement,\n" + jaroslav@1941: " g = d.getElementsByTagName('body')[0],\n" + jaroslav@1941: " x = w.innerWidth || e.clientWidth || g.clientWidth,\n" + jaroslav@1941: " y = w.innerHeight|| e.clientHeight|| g.clientHeight;\n" + jaroslav@1941: "\n" + jaroslav@1941: "return 'Screen size is ' + x + ' times ' + y;\n" jaroslav@1941: ) jaroslav@1941: public static native String screenSize(); jaroslav@1947: jaroslav@1947: @JavaScriptBody(args = { "id" }, body = jaroslav@1947: "var e = window.document.getElementById(id);\n " jaroslav@1947: + "var ev = window.document.createEvent('MouseEvents');\n " jaroslav@1947: + "ev.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);\n " jaroslav@1947: + "e.dispatchEvent(ev);\n " jaroslav@1947: ) jaroslav@1947: public static native void triggerClick(String id); jaroslav@1941: }