toni@521: /** toni@521: * Back 2 Browser Bytecode Translator toni@521: * Copyright (C) 2012 Jaroslav Tulach toni@521: * toni@521: * This program is free software: you can redistribute it and/or modify toni@521: * it under the terms of the GNU General Public License as published by toni@521: * the Free Software Foundation, version 2 of the License. toni@521: * toni@521: * This program is distributed in the hope that it will be useful, toni@521: * but WITHOUT ANY WARRANTY; without even the implied warranty of toni@521: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the toni@521: * GNU General Public License for more details. toni@521: * toni@521: * You should have received a copy of the GNU General Public License toni@521: * along with this program. Look for COPYING file in the top folder. toni@521: * If not, see http://opensource.org/licenses/GPL-2.0. toni@521: */ toni@521: package org.apidesign.bck2brwsr.htmlpage.api; toni@521: toni@1134: import net.java.html.canvas.GraphicsContext; jaroslav@1307: import net.java.html.canvas.spi.GraphicsUtils; toni@521: import org.apidesign.bck2brwsr.core.JavaScriptBody; toni@1138: import org.apidesign.bck2brwsr.htmlpage.HTML5GraphicsEnvironment; toni@809: import static org.apidesign.bck2brwsr.htmlpage.api.Element.getAttribute; toni@521: toni@521: /** toni@521: * toni@521: * @author Anton Epple toni@521: */ toni@1134: public class Canvas extends Element { toni@521: toni@1125: public Canvas(String id) { toni@521: super(id); toni@521: } toni@521: toni@521: public void setHeight(int height) { toni@521: setAttribute(this, "height", height); toni@521: } toni@521: toni@521: public int getHeight() { toni@809: Object ret = getAttribute(this, "height"); toni@809: return (ret instanceof Number) ? ((Number)ret).intValue(): Integer.MIN_VALUE; toni@521: } toni@521: toni@521: public void setWidth(int width) { toni@521: setAttribute(this, "width", width); toni@521: } toni@521: toni@811: public int getWidth() { toni@809: Object ret = getAttribute(this, "width"); toni@809: return (ret instanceof Number) ? ((Number)ret).intValue(): Integer.MIN_VALUE; toni@521: } toni@521: toni@521: @JavaScriptBody( toni@521: args = {"el"}, jaroslav@592: body = "var e = window.document.getElementById(el._id());\n" toni@521: + "return e.getContext('2d');\n") toni@1125: private native static Object getContextImpl(Canvas el); toni@521: toni@1134: public GraphicsContext getContext() { jaroslav@1307: final HTML5GraphicsEnvironment env = new HTML5GraphicsEnvironment(getContextImpl(this), this); toni@1138: // System.err.println("called getContext"); jaroslav@1307: return GraphicsUtils.create(env); toni@521: } toni@521: toni@521: @Override toni@521: void dontSubclass() { toni@521: } toni@521: }