jaroslav@1941
|
1 |
/**
|
jaroslav@1941
|
2 |
* Back 2 Browser Bytecode Translator
|
jaroslav@1941
|
3 |
* Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jaroslav@1941
|
4 |
*
|
jaroslav@1941
|
5 |
* This program is free software: you can redistribute it and/or modify
|
jaroslav@1941
|
6 |
* it under the terms of the GNU General Public License as published by
|
jaroslav@1941
|
7 |
* the Free Software Foundation, version 2 of the License.
|
jaroslav@1941
|
8 |
*
|
jaroslav@1941
|
9 |
* This program is distributed in the hope that it will be useful,
|
jaroslav@1941
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@1941
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@1941
|
12 |
* GNU General Public License for more details.
|
jaroslav@1941
|
13 |
*
|
jaroslav@1941
|
14 |
* You should have received a copy of the GNU General Public License
|
jaroslav@1941
|
15 |
* along with this program. Look for COPYING file in the top folder.
|
jaroslav@1941
|
16 |
* If not, see http://opensource.org/licenses/GPL-2.0.
|
jaroslav@1941
|
17 |
*/
|
jaroslav@1941
|
18 |
package org.apidesign.bck2brwsr.kosample.js;
|
jaroslav@1941
|
19 |
|
jaroslav@1941
|
20 |
import net.java.html.js.JavaScriptBody;
|
jaroslav@1941
|
21 |
|
jaroslav@1941
|
22 |
/** Use {@link JavaScriptBody} annotation on methods to
|
jaroslav@1941
|
23 |
* directly interact with JavaScript. See
|
jaroslav@1941
|
24 |
* http://bits.netbeans.org/html+java/1.2/net/java/html/js/package-summary.html
|
jaroslav@1941
|
25 |
* to understand how.
|
jaroslav@1941
|
26 |
*/
|
jaroslav@1941
|
27 |
public final class Dialogs {
|
jaroslav@1941
|
28 |
private Dialogs() {
|
jaroslav@1941
|
29 |
}
|
jaroslav@1941
|
30 |
|
jaroslav@1941
|
31 |
/** Shows confirmation dialog to the user.
|
jaroslav@1941
|
32 |
*
|
jaroslav@1941
|
33 |
* @param msg the message
|
jaroslav@1941
|
34 |
* @param callback called back when the use accepts (can be null)
|
jaroslav@1941
|
35 |
*/
|
jaroslav@1941
|
36 |
@JavaScriptBody(
|
jaroslav@1941
|
37 |
args = { "msg", "callback" },
|
jaroslav@1941
|
38 |
javacall = true,
|
jaroslav@1941
|
39 |
body = "if (confirm(msg)) {\n"
|
jaroslav@1941
|
40 |
+ " callback.@java.lang.Runnable::run()();\n"
|
jaroslav@1941
|
41 |
+ "}\n"
|
jaroslav@1941
|
42 |
)
|
jaroslav@1941
|
43 |
public static native void confirmByUser(String msg, Runnable callback);
|
jaroslav@1941
|
44 |
|
jaroslav@1941
|
45 |
@JavaScriptBody(
|
jaroslav@1941
|
46 |
args = {}, body =
|
jaroslav@1941
|
47 |
"var w = window,\n" +
|
jaroslav@1941
|
48 |
" d = document,\n" +
|
jaroslav@1941
|
49 |
" e = d.documentElement,\n" +
|
jaroslav@1941
|
50 |
" g = d.getElementsByTagName('body')[0],\n" +
|
jaroslav@1941
|
51 |
" x = w.innerWidth || e.clientWidth || g.clientWidth,\n" +
|
jaroslav@1941
|
52 |
" y = w.innerHeight|| e.clientHeight|| g.clientHeight;\n" +
|
jaroslav@1941
|
53 |
"\n" +
|
jaroslav@1941
|
54 |
"return 'Screen size is ' + x + ' times ' + y;\n"
|
jaroslav@1941
|
55 |
)
|
jaroslav@1941
|
56 |
public static native String screenSize();
|
jaroslav@1947
|
57 |
|
jaroslav@1947
|
58 |
@JavaScriptBody(args = { "id" }, body =
|
jaroslav@1947
|
59 |
"var e = window.document.getElementById(id);\n "
|
jaroslav@1947
|
60 |
+ "var ev = window.document.createEvent('MouseEvents');\n "
|
jaroslav@1947
|
61 |
+ "ev.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);\n "
|
jaroslav@1947
|
62 |
+ "e.dispatchEvent(ev);\n "
|
jaroslav@1947
|
63 |
)
|
jaroslav@1947
|
64 |
public static native void triggerClick(String id);
|
jaroslav@1941
|
65 |
}
|