1.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/HTML5GraphicsEnvironment.java Fri May 24 07:36:58 2013 +0200
1.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/HTML5GraphicsEnvironment.java Fri May 24 07:37:46 2013 +0200
1.3 @@ -17,19 +17,16 @@
1.4 */
1.5 package org.apidesign.bck2brwsr.htmlpage;
1.6
1.7 -import java.awt.Dimension;
1.8 import java.util.HashMap;
1.9 import java.util.Set;
1.10 -import net.java.html.canvas.GraphicsEnvironment;
1.11 -import net.java.html.canvas.ImageData;
1.12 +import net.java.html.canvas.Dimension;
1.13 import net.java.html.canvas.LinearGradient;
1.14 import net.java.html.canvas.Pattern;
1.15 import net.java.html.canvas.RadialGradient;
1.16 import net.java.html.canvas.Style;
1.17 +import net.java.html.canvas.spi.GraphicsEnvironment;
1.18 import org.apidesign.bck2brwsr.core.JavaScriptBody;
1.19 import org.apidesign.bck2brwsr.htmlpage.api.Canvas;
1.20 -import org.apidesign.bck2brwsr.htmlpage.api.Element;
1.21 -import org.apidesign.bck2brwsr.htmlpage.api.Image;
1.22
1.23 /**
1.24 *
1.25 @@ -149,29 +146,29 @@
1.26 @Override
1.27 public native void scale(double x, double y);
1.28
1.29 - @Override
1.30 - public void drawImage(ImageData image, double x, double y) {
1.31 - drawImageImpl(context, Element.getElementById((Image) image), x, y);
1.32 - }
1.33 -
1.34 - @Override
1.35 - public void drawImage(ImageData image, double x, double y, double width, double height) {
1.36 - drawImageImpl(context, Element.getElementById((Image) image), x, y, width, height);
1.37 - }
1.38 -
1.39 - @Override
1.40 - public void drawImage(ImageData image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
1.41 - drawImageImpl(context, Element.getElementById((Image) image), sx, sy, sWidth, sHeight, x, y, width, height);
1.42 - }
1.43 -
1.44 - @JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height);")
1.45 - private native static void drawImageImpl(Object ctx, Object img, double x, double y, double width, double height);
1.46 -
1.47 - @JavaScriptBody(args = {"ctx", "img", "sx", "sy", "swidth", "sheight", "x", "y", "width", "height"}, body = "ctx.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);")
1.48 - private native static void drawImageImpl(Object ctx, Object img, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height);
1.49 -
1.50 - @JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y);")
1.51 - private native static void drawImageImpl(Object ctx, Object img, double x, double y);
1.52 +//// @Override
1.53 +//// public void drawImage(Image image, double x, double y) {
1.54 +//// drawImageImpl(context, Element.getElementById((Image) image), x, y);
1.55 +//// }
1.56 +////
1.57 +//// @Override
1.58 +//// public void drawImage(Image image, double x, double y, double width, double height) {
1.59 +//// drawImageImpl(context, Element.getElementById((Image) image), x, y, width, height);
1.60 +//// }
1.61 +////
1.62 +//// @Override
1.63 +//// public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
1.64 +//// drawImageImpl(context, Element.getElementById((Image) image), sx, sy, sWidth, sHeight, x, y, width, height);
1.65 +//// }
1.66 +//
1.67 +//// @JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height);")
1.68 +//// private native static void drawImageImpl(Object ctx, Object img, double x, double y, double width, double height);
1.69 +////
1.70 +//// @JavaScriptBody(args = {"ctx", "img", "sx", "sy", "swidth", "sheight", "x", "y", "width", "height"}, body = "ctx.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);")
1.71 +//// private native static void drawImageImpl(Object ctx, Object img, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height);
1.72 +////
1.73 +//// @JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y);")
1.74 +//// private native static void drawImageImpl(Object ctx, Object img, double x, double y);
1.75
1.76 @JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style.valueOf();")
1.77 @Override
1.78 @@ -215,8 +212,9 @@
1.79 addColorStopImpl(style, double1, stops.get(double1));
1.80 }
1.81 return gradient;
1.82 - } else if (style instanceof Pattern) {
1.83 - return createPatternWrapper(((Pattern) style).getImageData(), ((Pattern) style).getRepeat());
1.84 + }
1.85 + else if (style instanceof Pattern) {
1.86 +// return createPatternWrapper(((Pattern) style).getImage(), ((Pattern) style).getRepeat());
1.87 }
1.88 return null;
1.89 }
1.90 @@ -334,6 +332,7 @@
1.91 public native void setTextBaseline(String textbaseline);
1.92
1.93 @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().fillText(text,x,y);")
1.94 +// @JavaScriptBody(args = {"text", "x", "y"}, body = "console.log(text);")
1.95 @Override
1.96 public native void fillText(String text, double x, double y);
1.97
1.98 @@ -344,8 +343,8 @@
1.99
1.100 @Override
1.101 public Dimension measureText(String text) {
1.102 - TextMetrics textMetrics = new TextMetrics(measureTextImpl(text));
1.103 - return new Dimension((int) textMetrics.getWidth(), (int) textMetrics.getHeight());
1.104 + measureTextImpl(text);
1.105 + return new Dimension(1,1);
1.106 }
1.107
1.108 @JavaScriptBody(args = {"text"},
1.109 @@ -360,42 +359,42 @@
1.110 @Override
1.111 public native void strokeText(String text, double x, double y, double maxWidth);
1.112
1.113 -// @Override
1.114 -// public ImageData createImageData(double x, double y) {
1.115 -// return new ImageDataWrapper(createImageDataImpl(x, y));
1.116 -// }
1.117 +//// @Override
1.118 +//// public ImageData createImageData(double x, double y) {
1.119 +//// return new ImageDataWrapper(createImageDataImpl(x, y));
1.120 +//// }
1.121 +////
1.122 +//// @JavaScriptBody(args = {"x", "y"},
1.123 +//// body = "return this._context().createImageData(x,y);")
1.124 +//// private native Object createImageDataImpl(double x, double y);
1.125 +////
1.126 +//// @Override
1.127 +//// public ImageData createImageData(ImageData imageData) {
1.128 +//// return new ImageDataWrapper(createImageDataImpl(imageData.getWidth(), imageData.getHeight()));
1.129 +//// }
1.130 +////
1.131 +//// @Override
1.132 +//// public ImageData getImageData(double x, double y, double width, double height) {
1.133 +//// return new ImageDataWrapper(getImageDataImpl(x, y, width, height));
1.134 +//// }
1.135 //
1.136 -// @JavaScriptBody(args = {"x", "y"},
1.137 -// body = "return this._context().createImageData(x,y);")
1.138 -// private native Object createImageDataImpl(double x, double y);
1.139 +// @JavaScriptBody(args = {"x", "y", "width", "height"},
1.140 +// body = "return this._context().getImageData(x,y,width,height);")
1.141 +// private native Object getImageDataImpl(double x, double y, double width, double height);
1.142 //
1.143 -// @Override
1.144 -// public ImageData createImageData(ImageData imageData) {
1.145 -// return new ImageDataWrapper(createImageDataImpl(imageData.getWidth(), imageData.getHeight()));
1.146 -// }
1.147 -//
1.148 -// @Override
1.149 -// public ImageData getImageData(double x, double y, double width, double height) {
1.150 -// return new ImageDataWrapper(getImageDataImpl(x, y, width, height));
1.151 -// }
1.152 -
1.153 - @JavaScriptBody(args = {"x", "y", "width", "height"},
1.154 - body = "return this._context().getImageData(x,y,width,height);")
1.155 - private native Object getImageDataImpl(double x, double y, double width, double height);
1.156 -
1.157 -// @Override
1.158 -// public void putImageData(ImageData imageData, double x, double y) {
1.159 -// putImageDataImpl(((ImageDataWrapper) imageData).object(), x, y);
1.160 -// }
1.161 -//
1.162 -// @JavaScriptBody(args = {"imageData", "x", "y"},
1.163 -// body = "this._context().putImageData(imageData,x,y);")
1.164 -// private native void putImageDataImpl(Object imageData, double x, double y);
1.165 -//
1.166 -// @Override
1.167 -// public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
1.168 -// putImageDataImpl(((ImageDataWrapper) imageData).object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
1.169 -// }
1.170 +//// @Override
1.171 +//// public void putImageData(ImageData imageData, double x, double y) {
1.172 +//// putImageDataImpl(((ImageDataWrapper) imageData).object(), x, y);
1.173 +//// }
1.174 +////
1.175 +//// @JavaScriptBody(args = {"imageData", "x", "y"},
1.176 +//// body = "this._context().putImageData(imageData,x,y);")
1.177 +//// private native void putImageDataImpl(Object imageData, double x, double y);
1.178 +////
1.179 +//// @Override
1.180 +//// public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
1.181 +//// putImageDataImpl(((ImageDataWrapper) imageData).object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
1.182 +//// }
1.183
1.184 @JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
1.185 body = "this._context().putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
1.186 @@ -424,12 +423,12 @@
1.187 @JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
1.188 private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
1.189
1.190 - public PatternWrapper createPatternWrapper(ImageData image, String repeat) {
1.191 - return new PatternWrapper(createPatternImpl(context, image, repeat));
1.192 - }
1.193 -
1.194 - @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
1.195 - private static native Object createPatternImpl(Object context, ImageData image, String repeat);
1.196 +// public PatternWrapper createPatternWrapper(Image image, String repeat) {
1.197 +// return new PatternWrapper(createPatternImpl(context, image, repeat));
1.198 +// }
1.199 +//
1.200 +// @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
1.201 +// private static native Object createPatternImpl(Object context, Image image, String repeat);
1.202
1.203 public RadialGradientWrapper createRadialGradientWrapper(double x0, double y0, double r0, double x1, double y1, double r1) {
1.204 return new RadialGradientWrapper(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
1.205 @@ -438,9 +437,9 @@
1.206 @JavaScriptBody(args = {"context", "x0", "y0", "r0", "x1", "y1", "r1"}, body = "return context.createRadialGradient(x0,y0,r0,x1,y1,r1);")
1.207 private static native Object createRadialGradientImpl(Object context, double x0, double y0, double r0, double x1, double y1, double r1);
1.208
1.209 -//
1.210 -// @JavaScriptBody(args = {"path"}, body = "var b = new Image(); b.src=path; return b;")
1.211 -// public native Image getImageForPath(String path);
1.212 +////
1.213 +//// @JavaScriptBody(args = {"path"}, body = "var b = new Image(); b.src=path; return b;")
1.214 +//// public native Image getImageForPath(String path);
1.215
1.216
1.217
2.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Canvas.java Fri May 24 07:36:58 2013 +0200
2.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Canvas.java Fri May 24 07:37:46 2013 +0200
2.3 @@ -17,9 +17,9 @@
2.4 */
2.5 package org.apidesign.bck2brwsr.htmlpage.api;
2.6
2.7 -import org.apidesign.bck2brwsr.htmlpage.HTML5GraphicsEnvironment;
2.8 import net.java.html.canvas.GraphicsContext;
2.9 import org.apidesign.bck2brwsr.core.JavaScriptBody;
2.10 +import org.apidesign.bck2brwsr.htmlpage.HTML5GraphicsEnvironment;
2.11 import static org.apidesign.bck2brwsr.htmlpage.api.Element.getAttribute;
2.12
2.13 /**
2.14 @@ -30,7 +30,6 @@
2.15
2.16 public Canvas(String id) {
2.17 super(id);
2.18 - System.out.println("created Canvas");
2.19 }
2.20
2.21 public void setHeight(int height) {
2.22 @@ -58,7 +57,7 @@
2.23 private native static Object getContextImpl(Canvas el);
2.24
2.25 public GraphicsContext getContext() {
2.26 - System.err.println("called getContext");
2.27 +// System.err.println("called getContext");
2.28 return new GraphicsContext(new HTML5GraphicsEnvironment(getContextImpl(this), this));
2.29 }
2.30
3.1 --- a/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ProcessPageTest.java Fri May 24 07:36:58 2013 +0200
3.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ProcessPageTest.java Fri May 24 07:37:46 2013 +0200
3.3 @@ -17,11 +17,8 @@
3.4 */
3.5 package org.apidesign.bck2brwsr.htmlpage;
3.6
3.7 -import java.io.File;
3.8 -import java.io.FileReader;
3.9 import java.io.IOException;
3.10 import java.io.InputStream;
3.11 -import java.io.PrintWriter;
3.12 import java.util.Set;
3.13 import javax.script.Invocable;
3.14 import javax.script.ScriptEngine;
3.15 @@ -34,7 +31,7 @@
3.16 public class ProcessPageTest {
3.17
3.18
3.19 - @Test public void findsThreeIds() throws IOException {
3.20 + @Test public void findsFourIds() throws IOException {
3.21 InputStream is = ProcessPageTest.class.getResourceAsStream("TestPage.html");
3.22 assertNotNull(is, "Sample HTML page found");
3.23 ProcessPage res = ProcessPage.readPage(is);
3.24 @@ -88,95 +85,95 @@
3.25 assertEquals(ret, "You want this window to be named something", "We expect that the JavaCode performs all the wiring");
3.26 }
3.27
3.28 -// @Test public void clickWithArgumentCalled() throws Exception {
3.29 -// StringBuilder sb = new StringBuilder();
3.30 -// sb.append(
3.31 -// "var window = new Object();\n"
3.32 -// + "var doc = new Object();\n"
3.33 -// + "doc.button = new Object();\n"
3.34 -// + "doc.title = new Object();\n"
3.35 -// + "doc.title.innerHTML = 'nothing';\n"
3.36 -// + "doc.text = new Object();\n"
3.37 -// + "doc.text.value = 'something';\n"
3.38 -// + "doc.canvas = new Object();\n"
3.39 -// + "doc.getElementById = function(id) {\n"
3.40 -// + " switch(id) {\n"
3.41 -// + " case 'pg.button': return doc.button;\n"
3.42 -// + " case 'pg.title': return doc.title;\n"
3.43 -// + " case 'pg.text': return doc.text;\n"
3.44 -// + " case 'pg.canvas': return doc.canvas;\n"
3.45 -// + " }\n"
3.46 -// + " throw id;\n"
3.47 -// + " }\n"
3.48 -// + "\n"
3.49 -// + "function clickAndCheck() {\n"
3.50 -// + " doc.title.onclick();\n"
3.51 -// + " return doc.title.innerHTML.toString();\n"
3.52 -// + "};\n"
3.53 -// + "\n"
3.54 -// + "window.document = doc;\n"
3.55 -// );
3.56 -// Invocable i = compileClass(sb,
3.57 -// "org/apidesign/bck2brwsr/htmlpage/PageController"
3.58 -// );
3.59 -//
3.60 -// Object ret = null;
3.61 -// try {
3.62 -// ret = i.invokeFunction("clickAndCheck");
3.63 -// } catch (ScriptException ex) {
3.64 -// fail("Execution failed in " + sb, ex);
3.65 -// } catch (NoSuchMethodException ex) {
3.66 -// fail("Cannot find method in " + sb, ex);
3.67 -// }
3.68 -// assertEquals(ret, "pg.title", "Title has been passed to the method argument");
3.69 -// }
3.70 + @Test public void clickWithArgumentCalled() throws Exception {
3.71 + StringBuilder sb = new StringBuilder();
3.72 + sb.append(
3.73 + "var window = new Object();\n"
3.74 + + "var doc = new Object();\n"
3.75 + + "doc.button = new Object();\n"
3.76 + + "doc.title = new Object();\n"
3.77 + + "doc.title.innerHTML = 'nothing';\n"
3.78 + + "doc.text = new Object();\n"
3.79 + + "doc.text.value = 'something';\n"
3.80 + + "doc.canvas = new Object();\n"
3.81 + + "doc.getElementById = function(id) {\n"
3.82 + + " switch(id) {\n"
3.83 + + " case 'pg.button': return doc.button;\n"
3.84 + + " case 'pg.title': return doc.title;\n"
3.85 + + " case 'pg.text': return doc.text;\n"
3.86 + + " case 'pg.canvas': return doc.canvas;\n"
3.87 + + " }\n"
3.88 + + " throw id;\n"
3.89 + + " }\n"
3.90 + + "\n"
3.91 + + "function clickAndCheck() {\n"
3.92 + + " doc.title.onclick();\n"
3.93 + + " return doc.title.innerHTML.toString();\n"
3.94 + + "};\n"
3.95 + + "\n"
3.96 + + "window.document = doc;\n"
3.97 + );
3.98 + Invocable i = compileClass(sb,
3.99 + "org/apidesign/bck2brwsr/htmlpage/PageController"
3.100 + );
3.101
3.102 -// @Test public void clickWithArgumentAndParameterCalled() throws Exception {
3.103 -// StringBuilder sb = new StringBuilder();
3.104 -// sb.append(
3.105 -// "var window = new Object();\n"
3.106 -// + "var doc = new Object();\n"
3.107 -// + "var eventObject = new Object();\n"
3.108 -// + "eventObject.layerX = 100;\n"
3.109 -// + "doc.button = new Object();\n"
3.110 -// + "doc.title = new Object();\n"
3.111 -// + "doc.title.innerHTML = 'nothing';\n"
3.112 -// + "doc.text = new Object();\n"
3.113 -// + "doc.text.value = 'something';\n"
3.114 -// + "doc.canvas = new Object();\n"
3.115 -// + "doc.canvas.width = 200;\n"
3.116 -// + "doc.getElementById = function(id) {\n"
3.117 -// + " switch(id) {\n"
3.118 -// + " case 'pg.button': return doc.button;\n"
3.119 -// + " case 'pg.title': return doc.title;\n"
3.120 -// + " case 'pg.text': return doc.text;\n"
3.121 -// + " case 'pg.canvas': return doc.canvas;\n"
3.122 -// + " }\n"
3.123 -// + " throw id;\n"
3.124 -// + " }\n"
3.125 -// + "\n"
3.126 -// + "function clickAndCheck() {\n"
3.127 -// + " doc.canvas.onclick(eventObject);\n"
3.128 -// + " return doc.canvas.width.toString();\n"
3.129 -// + "};\n"
3.130 -// + "\n"
3.131 -// + "window.document = doc;\n"
3.132 -// );
3.133 -// Invocable i = compileClass(sb,
3.134 -// "org/apidesign/bck2brwsr/htmlpage/PageController"
3.135 -// );
3.136 -//
3.137 -// Object ret = null;
3.138 -// try {
3.139 -// ret = i.invokeFunction("clickAndCheck");
3.140 -// } catch (ScriptException ex) {
3.141 -// fail("Execution failed in " + sb, ex);
3.142 -// } catch (NoSuchMethodException ex) {
3.143 -// fail("Cannot find method in " + sb, ex);
3.144 -// }
3.145 -// assertEquals(ret, "100", "layerX has been passed to the method argument");
3.146 -// }
3.147 -//
3.148 + Object ret = null;
3.149 + try {
3.150 + ret = i.invokeFunction("clickAndCheck");
3.151 + } catch (ScriptException ex) {
3.152 + fail("Execution failed in " + sb, ex);
3.153 + } catch (NoSuchMethodException ex) {
3.154 + fail("Cannot find method in " + sb, ex);
3.155 + }
3.156 + assertEquals(ret, "pg.title", "Title has been passed to the method argument");
3.157 + }
3.158 +
3.159 + @Test public void clickWithArgumentAndParameterCalled() throws Exception {
3.160 + StringBuilder sb = new StringBuilder();
3.161 + sb.append(
3.162 + "var window = new Object();\n"
3.163 + + "var doc = new Object();\n"
3.164 + + "var eventObject = new Object();\n"
3.165 + + "eventObject.layerX = 100;\n"
3.166 + + "doc.button = new Object();\n"
3.167 + + "doc.title = new Object();\n"
3.168 + + "doc.title.innerHTML = 'nothing';\n"
3.169 + + "doc.text = new Object();\n"
3.170 + + "doc.text.value = 'something';\n"
3.171 + + "doc.canvas = new Object();\n"
3.172 + + "doc.canvas.width = 200;\n"
3.173 + + "doc.getElementById = function(id) {\n"
3.174 + + " switch(id) {\n"
3.175 + + " case 'pg.button': return doc.button;\n"
3.176 + + " case 'pg.title': return doc.title;\n"
3.177 + + " case 'pg.text': return doc.text;\n"
3.178 + + " case 'pg.canvas': return doc.canvas;\n"
3.179 + + " }\n"
3.180 + + " throw id;\n"
3.181 + + " }\n"
3.182 + + "\n"
3.183 + + "function clickAndCheck() {\n"
3.184 + + " doc.canvas.onclick(eventObject);\n"
3.185 + + " return doc.canvas.width.toString();\n"
3.186 + + "};\n"
3.187 + + "\n"
3.188 + + "window.document = doc;\n"
3.189 + );
3.190 + Invocable i = compileClass(sb,
3.191 + "org/apidesign/bck2brwsr/htmlpage/PageController"
3.192 + );
3.193 +
3.194 + Object ret = null;
3.195 + try {
3.196 + ret = i.invokeFunction("clickAndCheck");
3.197 + } catch (ScriptException ex) {
3.198 + fail("Execution failed in " + sb, ex);
3.199 + } catch (NoSuchMethodException ex) {
3.200 + fail("Cannot find method in " + sb, ex);
3.201 + }
3.202 + assertEquals(ret, "100", "layerX has been passed to the method argument");
3.203 + }
3.204 +
3.205 static Invocable compileClass(StringBuilder sb, String... names) throws ScriptException, IOException {
3.206
3.207 if (sb == null) {
3.208 @@ -195,11 +192,6 @@
3.209 assertTrue(js instanceof Invocable, "It is invocable object: " + res);
3.210 return (Invocable) js;
3.211 } catch (ScriptException ex) {
3.212 -// System.err.println("ex "+ex+ " col "+ex.getColumnNumber());
3.213 -// PrintWriter out = new PrintWriter("filename.txt");
3.214 -// out.println(sb.toString());
3.215 -// out.flush();
3.216 -// out.close();
3.217 fail("Could not compile:\n" , ex);
3.218 return null;
3.219 }