jan@866: /** jan@866: * Back 2 Browser Bytecode Translator jan@866: * Copyright (C) 2012 Jaroslav Tulach jan@866: * jan@866: * This program is free software: you can redistribute it and/or modify jan@866: * it under the terms of the GNU General Public License as published by jan@866: * the Free Software Foundation, version 2 of the License. jan@866: * jan@866: * This program is distributed in the hope that it will be useful, jan@866: * but WITHOUT ANY WARRANTY; without even the implied warranty of jan@866: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jan@866: * GNU General Public License for more details. jan@866: * jan@866: * You should have received a copy of the GNU General Public License jan@866: * along with this program. Look for COPYING file in the top folder. jan@866: * If not, see http://opensource.org/licenses/GPL-2.0. jan@866: */ jan@866: package org.apidesign.bck2brwsr.htmlpage; jan@866: jan@866: import java.io.IOException; jan@866: import java.io.Writer; jan@866: import java.util.HashMap; jan@866: import java.util.Map; jan@866: jan@866: /** jan@866: * jan@866: * @author Jan Horvath jan@866: */ jan@866: public class PredefinedFields { jan@866: jan@866: private static final Map IMPORTS = new HashMap() { jan@866: { jan@866: put("canvas", "import org.apidesign.bck2brwsr.core.JavaScriptBody;"); jan@866: } jan@866: }; jan@866: jan@866: private static final Map FIELDS = new HashMap() { jan@866: { jan@866: put("canvas", jan@866: " @JavaScriptBody(\n" + jan@866: " args = {\"el\"},\n" + jan@866: " body = \"var e = window.document.getElementById(el._id());\\n\"\n" + jan@866: " + \"return e.getContext('2d');\\n\")\n" + jan@866: " private native static Object getContextImpl(Canvas el);\n" + jan@866: " \n" + jan@866: " public GraphicsContext getContext() {\n" + jan@866: " return new GraphicsContext(getContextImpl(this));\n" + jan@866: " }"); jan@866: } jan@866: }; jan@866: jan@866: static void appendImports(Writer w, String tag) throws IOException { jan@866: String text = IMPORTS.get(tag.toLowerCase()); jan@866: if (text != null) { jan@866: w.append(text).append("\n"); jan@866: } jan@866: } jan@866: jan@866: static void appendFields(Writer w, String tag) throws IOException { jan@866: String text = FIELDS.get(tag.toLowerCase()); jan@866: if (text != null) { jan@866: w.append(text).append("\n"); jan@866: } jan@866: } jan@866: }