javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PredefinedFields.java
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;
20 import java.io.IOException;
21 import java.io.Writer;
22 import java.util.HashMap;
27 * @author Jan Horvath <jhorvath@netbeans.org>
29 public class PredefinedFields {
31 private static final Map<String, String> IMPORTS = new HashMap<String, String>() {
33 put("canvas", "import org.apidesign.bck2brwsr.core.JavaScriptBody;");
37 private static final Map<String, String> FIELDS = new HashMap<String, String>() {
40 " @JavaScriptBody(\n" +
41 " args = {\"el\"},\n" +
42 " body = \"var e = window.document.getElementById(el._id());\\n\"\n" +
43 " + \"return e.getContext('2d');\\n\")\n" +
44 " private native static Object getContextImpl(Canvas el);\n" +
46 " public GraphicsContext getContext() {\n" +
47 " return new GraphicsContext(getContextImpl(this));\n" +
52 static void appendImports(Writer w, String tag) throws IOException {
53 String text = IMPORTS.get(tag.toLowerCase());
55 w.append(text).append("\n");
59 static void appendFields(Writer w, String tag) throws IOException {
60 String text = FIELDS.get(tag.toLowerCase());
62 w.append(text).append("\n");