# HG changeset patch # User Anton Epple # Date 1380230418 25200 # Node ID e67363288df16295fa9569694a47209734291735 # Parent 2960a1d372772b4b850b752bc2b3a8223e5c7902 refactoring for API review diff -r 2960a1d37277 -r e67363288df1 javaquery/canvas/pom.xml --- a/javaquery/canvas/pom.xml Mon Sep 23 07:52:41 2013 -0700 +++ b/javaquery/canvas/pom.xml Thu Sep 26 14:20:18 2013 -0700 @@ -4,12 +4,12 @@ javaquery org.apidesign.bck2brwsr - 0.8-SNAPSHOT + 0.9-SNAPSHOT net.java.html canvas - 0.8-SNAPSHOT + 0.9-SNAPSHOT jar canvas http://maven.apache.org diff -r 2960a1d37277 -r e67363288df1 javaquery/canvas/src/main/java/net/java/html/canvas/Dimension.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Dimension.java Mon Sep 23 07:52:41 2013 -0700 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Dimension.java Thu Sep 26 14:20:18 2013 -0700 @@ -1,3 +1,20 @@ +/** + * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach + * + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. Look for COPYING file in the top folder. If not, see + * http://opensource.org/licenses/GPL-2.0. + */ /* * To change this template, choose Tools | Templates * and open the template in the editor. @@ -5,35 +22,35 @@ package net.java.html.canvas; /** - * Just a simple class to replace the need of java.awt.Dimension, since we only + * Just a simple class to replace the need of java.awt.Dimension, since we only * want to use Java core APIs to keep porting simple. + * * @author antonepple */ -public class Dimension { - double width, height; +public final class Dimension { + + final double width, height; public Dimension(double width, double height) { this.width = width; this.height = height; } - - + /** + * Returns the height of this Dimension in double precision + * + * @return the width of this Dimension. + */ public double getWidth() { return width; } - public void setWidth(double width) { - this.width = width; - } - + /** + * Returns the width of this Dimension in double precision. + * + * @return the height of this Dimension. + */ public double getHeight() { return height; } - - public void setHeight(double height) { - this.height = height; - } - - } diff -r 2960a1d37277 -r e67363288df1 javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java Mon Sep 23 07:52:41 2013 -0700 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java Thu Sep 26 14:20:18 2013 -0700 @@ -22,20 +22,40 @@ import net.java.html.canvas.Style.Pattern; import net.java.html.canvas.Style.RadialGradient; import net.java.html.canvas.spi.GraphicsEnvironment; +import org.apidesign.html.canvas.impl.CnvsAccssr; /** - * A 2D Graphics Context similar to HTML5 or JavaFX GraphicsContext. - * Use this to paint on your Canvas.s + * A 2D Graphics Context similar to HTML5 or JavaFX GraphicsContext. Use this to + * paint on your Canvas.s + * * @author antonepple */ public final class GraphicsContext { GraphicsEnvironment graphicsEnvironmentImpl; - public GraphicsContext(GraphicsEnvironment graphicsEnvironment) { + static { + CnvsAccssr cnvsAccssr = new CnvsAccssr() { + @Override + public GraphicsContext create(GraphicsEnvironment environment) { + return new GraphicsContext(environment); + } + }; + } + + GraphicsContext(GraphicsEnvironment graphicsEnvironment) { this.graphicsEnvironmentImpl = graphicsEnvironment; } + /** + * Adds path elements to the current path to make an arc. + * + * @param centerX the center x position of the arc. + * @param centerY the center y position of the arc. + * @param radius the radius of the arc. + * @param endAngle teh endAngle of the arc + * @param ccw the direction of the arc (counterclockwise) + */ public void arc(double centerX, double centerY, double startAngle, @@ -45,328 +65,594 @@ graphicsEnvironmentImpl.arc(centerX, centerY, startAngle, radius, endAngle, ccw); } + /** + * Adds segments to the current path to make an arc. + * + * @param x1 the X coordinate of the first point of the arc. + * @param y1 the Y coordinate of the first point of the arc. + * @param x2 the X coordinate of the second point of the arc. + * @param y2 the Y coordinate of the second point of the arc. + * @param radius the radius of the arc in the range {0.0-positive infinity}. + */ public void arcTo(double x1, double y1, double x2, double y2, - double r) { - graphicsEnvironmentImpl.arcTo(x1, y1, x2, y2, r); + double radius) { + graphicsEnvironmentImpl.arcTo(x1, y1, x2, y2, radius); } + /** + * Returns true if the the given x,y point is inside the path. + * + * @param x the X coordinate to use for the check. + * @param y the Y coordinate to use for the check. + * @return true if the point given is inside the path, false otherwise. + */ public boolean isPointInPath(double x, double y) { return graphicsEnvironmentImpl.isPointInPath(x, y); } + /** + * Fills the path with the current fill paint. + */ public void fill() { graphicsEnvironmentImpl.fill(); } + /** + * Strokes the path with the current stroke paint. + */ public void stroke() { graphicsEnvironmentImpl.stroke(); } + /** + * Starts a Path + */ public void beginPath() { graphicsEnvironmentImpl.beginPath(); } - public void closePath(){ + /** + * Closes the path. + */ + public void closePath() { graphicsEnvironmentImpl.closePath(); } - public void clip(){ + /** + * Clips using the current path + */ + public void clip() { graphicsEnvironmentImpl.clip(); } - public void moveTo(double x, double y){ + /** + * Issues a move command for the current path to the given x,y coordinate. + * + * @param x0 the X position for the move to command. + * @param y0 the Y position for the move to command. + */ + public void moveTo(double x, double y) { graphicsEnvironmentImpl.moveTo(x, y); } - public void lineTo(double x, double y){ + /** + * Adds segments to the current path to make a line at the given x,y + * coordinate. + * + * @param x1 the X coordinate of the ending point of the line. + * @param y1 the Y coordinate of the ending point of the line. + */ + public void lineTo(double x, double y) { graphicsEnvironmentImpl.lineTo(x, y); } - public void quadraticCurveTo(double cpx, double cpy, double x, double y){ - graphicsEnvironmentImpl.quadraticCurveTo(cpx, cpy, x, y); + /** + * Adds segments to the current path to make a quadratic curve. + * + * @param cpx the X coordinate of the control point + * @param cpy the Y coordinate of the control point + * @param x the X coordinate of the end point + * @param y the Y coordinate of the end point + */ + public void quadraticCurveTo(double cpx, double cpy, double x, double y) { + graphicsEnvironmentImpl.quadraticCurveTo(cpx, cpy, x, y); } - public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y){ + /** + * Adds segments to the current path to make a cubic bezier curve. + * + * @param cp1x the X coordinate of first bezier control point. + * @param cp1y the Y coordinate of the first bezier control point. + * @param cp2x the X coordinate of the second bezier control point. + * @param cp2y the Y coordinate of the second bezier control point. + * @param x the X coordinate of the end point. + * @param y the Y coordinate of the end point. + */ + public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y) { graphicsEnvironmentImpl.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y); } - public void fillRect(double x, double y, double width, double height){ + /** + * Fills a rectangle using the current fill paint. + * + * @param x the X position of the upper left corner of the rectangle. + * @param y the Y position of the upper left corner of the rectangle. + * @param w the width of the rectangle. + * @param h the height of the rectangle. + */ + public void fillRect(double x, double y, double width, double height) { graphicsEnvironmentImpl.fillRect(x, y, width, height); } - public void strokeRect(double x, double y, double width, double height){ - graphicsEnvironmentImpl.strokeRect(x, y, width, height); + /** + * Strokes a rectangle using the current stroke paint. + * + * @param x the X position of the upper left corner of the rectangle. + * @param y the Y position of the upper left corner of the rectangle. + * @param width the width of the rectangle. + * @param height the height of the rectangle. + */ + public void strokeRect(double x, double y, double width, double height) { + graphicsEnvironmentImpl.strokeRect(x, y, width, height); } - public void clearRect(double x, double y, double width, double height){ + /** + * Clears a portion of the canvas with a transparent color value. + * + * @param x X position of the upper left corner of the rectangle. + * @param y Y position of the upper left corner of the rectangle. + * @param width width of the rectangle. + * @param height height of the rectangle. + */ + public void clearRect(double x, double y, double width, double height) { graphicsEnvironmentImpl.clearRect(x, y, width, height); } - public void rect(double x, double y, double width, double height){ + /** + * Clears a portion of the canvas with a transparent color value. + * + * @param x X position of the upper left corner of the rectangle. + * @param y Y position of the upper left corner of the rectangle. + * @param width width of the rectangle. + * @param height height of the rectangle. + */ + public void rect(double x, double y, double width, double height) { graphicsEnvironmentImpl.rect(x, y, width, height); } - public void save(){ + /** + * Saves the following attributes onto a stack. + * + * This method does NOT alter the current state in any way. Also, not that + * the current path is not saved. + */ + public void save() { graphicsEnvironmentImpl.save(); } - public void restore(){ + /** + * Pops the state off of the stack, setting the following attributes to + * their value at the time when that state was pushed onto the stack. If the + * stack is empty then nothing is changed. + * + * + */ + public void restore() { graphicsEnvironmentImpl.restore(); } - public void rotate(double angle){ + /** + * Rotates the current transform in degrees. + * + * @param angle value in degrees to rotate the current transform. + */ + public void rotate(double angle) { graphicsEnvironmentImpl.rotate(angle); } - public void transform(double a, double b, double c, double d, double e, double f){ - graphicsEnvironmentImpl.transform(a, b, c, d, e, f); + /** + * Concatenates the input with the current transform. + * + * @param mxx - the X coordinate scaling element of the 3x4 matrix + * @param myx - the Y coordinate shearing element of the 3x4 matrix + * @param mxy - the X coordinate shearing element of the 3x4 matrix + * @param myy - the Y coordinate scaling element of the 3x4 matrix + * @param mxt - the X coordinate translation element of the 3x4 matrix + * @param myt - the Y coordinate translation element of the 3x4 matrix + */ + public void transform(double mxx, double myx, double mxy, double myy, double mxt, double myt) { + graphicsEnvironmentImpl.transform(mxx, myx, mxy, myy, mxt, myt); } - public void setTransform(double a, double b, double c, double d, double e, double f){ - graphicsEnvironmentImpl.setTransform(a, b, c, d, e, f); + /** + * Concatenates the input with the current transform. + * + * @param mxx - the X coordinate scaling element of the 3x4 matrix + * @param myx - the Y coordinate shearing element of the 3x4 matrix + * @param mxy - the X coordinate shearing element of the 3x4 matrix + * @param myy - the Y coordinate scaling element of the 3x4 matrix + * @param mxt - the X coordinate translation element of the 3x4 matrix + * @param myt - the Y coordinate translation element of the 3x4 matrix + */ + public void setTransform(double mxx, double myx, double mxy, double myy, double mxt, double myt) { + graphicsEnvironmentImpl.setTransform(mxx, myx, mxy, myy, mxt, myt); } - public void translate(double x, double y){ + /** + * Translates the current transform by x, y. + * + * @param x value to translate along the x axis. + * @param y value to translate along the y axis. + */ + public void translate(double x, double y) { graphicsEnvironmentImpl.translate(x, y); } - public void scale(double x, double y){ + /** + * Scales the current transform by x, y. + * + * @param x value to scale in the x axis. + * @param y value to scale in the y axis. + */ + public void scale(double x, double y) { graphicsEnvironmentImpl.scale(x, y); } - public void drawImage(Image image, double x, double y){ + /** + * Draws an image at the given x, y position using the width and height of + * the given image. + * + * @param img the image to be drawn. + * @param x the X coordinate on the destination for the upper left of the + * image. + * @param y the Y coordinate on the destination for the upper left of the + * image. + */ + public void drawImage(Image image, double x, double y) { Object nativeImage = graphicsEnvironmentImpl.drawImage(image, x, y, image.getCached()); image.cache(nativeImage); } - public void drawImage(Image image, double x, double y, double width, double height){ + /** + * Draws an image into the given destination rectangle of the canvas. The + * Image is scaled to fit into the destination rectagnle. + * + * @param img the image to be drawn. + * @param x the X coordinate on the destination for the upper left of the + * image. + * @param y the Y coordinate on the destination for the upper left of the + * image. + * @param width the width of the destination rectangle. + * @param height the height of the destination rectangle. + */ + public void drawImage(Image image, double x, double y, double width, double height) { Object nativeImage = graphicsEnvironmentImpl.drawImage(image, x, y, width, height, image.getCached()); image.cache(nativeImage); } - public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height){ - Object nativeImage = graphicsEnvironmentImpl.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height, image.getCached()); + /** + * Draws the current source rectangle of the given image to the given + * destination rectangle of the Canvas. + * + * @param img the image to be drawn. + * @param sx the source rectangle's X coordinate position. + * @param sy the source rectangle's Y coordinate position. + * @param sw the source rectangle's width. + * @param sh the source rectangle's height. + * @param dx the destination rectangle's X coordinate position. + * @param dy the destination rectangle's Y coordinate position. + * @param dw the destination rectangle's width. + * @param dh the destination rectangle's height. + */ + public void drawImage(Image image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh) { + Object nativeImage = graphicsEnvironmentImpl.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh, image.getCached()); image.cache(nativeImage); } - - public Image merge(Image a, Image b){ - if(a.getCached()==null){ + + /** + * Merges two images drawing one on top of the other and returning the + * result. + * + * @param a the lower Image + * @param b the upper Image + * @return + */ + public Image merge(Image a, Image b) { + if (a.getCached() == null) { drawImage(a, 0, 0); } - if(b.getCached()==null){ + if (b.getCached() == null) { drawImage(b, 0, 0); } - Object nativeImage = graphicsEnvironmentImpl.mergeImages(a,b,a.getCached(),b.getCached()); + Object nativeImage = graphicsEnvironmentImpl.mergeImages(a, b, a.getCached(), b.getCached()); Image merged = Image.create("should add real path here"); merged.cache(nativeImage); return merged; } - public void setShadowColor(String color){ - graphicsEnvironmentImpl.setShadowColor(color); - } - - public void setShadowBlur(double blur){ - graphicsEnvironmentImpl.setShadowBlur(blur); - } - - public void setShadowOffsetX(double x){ - graphicsEnvironmentImpl.setShadowOffsetX(x); - } - - public void setShadowOffsetY(double y){ - graphicsEnvironmentImpl.setShadowOffsetY(y); - } - - public String getShadowColor(){ - return graphicsEnvironmentImpl.getShadowColor(); - } - - public double getShadowBlur(){ - return graphicsEnvironmentImpl.getShadowBlur(); - } - - public double getShadowOffsetX(){ - return graphicsEnvironmentImpl.getShadowOffsetX(); - } - - public double getShadowOffsetY(){ - return graphicsEnvironmentImpl.getShadowOffsetY(); - } - - public String getLineCap(){ +// public void setShadowColor(String color) { +// graphicsEnvironmentImpl.setShadowColor(color); +// } +// +// public void setShadowBlur(double blur) { +// graphicsEnvironmentImpl.setShadowBlur(blur); +// } +// +// public void setShadowOffsetX(double x) { +// graphicsEnvironmentImpl.setShadowOffsetX(x); +// } +// +// public void setShadowOffsetY(double y) { +// graphicsEnvironmentImpl.setShadowOffsetY(y); +// } +// +// public String getShadowColor() { +// return graphicsEnvironmentImpl.getShadowColor(); +// } +// +// public double getShadowBlur() { +// return graphicsEnvironmentImpl.getShadowBlur(); +// } +// +// public double getShadowOffsetX() { +// return graphicsEnvironmentImpl.getShadowOffsetX(); +// } +// +// public double getShadowOffsetY() { +// return graphicsEnvironmentImpl.getShadowOffsetY(); +// } + public String getLineCap() { return graphicsEnvironmentImpl.getLineCap(); } - public void setLineCap(String style){ + public void setLineCap(String style) { graphicsEnvironmentImpl.setLineCap(style); } - public String getLineJoin(){ + public String getLineJoin() { return graphicsEnvironmentImpl.getLineJoin(); } - public void setLineJoin(String style){ + public void setLineJoin(String style) { graphicsEnvironmentImpl.setLineJoin(style); } - public double getLineWidth(){ + public double getLineWidth() { return graphicsEnvironmentImpl.getLineWidth(); } - public void setLineWidth(double width){ + public void setLineWidth(double width) { graphicsEnvironmentImpl.setLineWidth(width); } - public double getMiterLimit(){ + public double getMiterLimit() { return graphicsEnvironmentImpl.getMiterLimit(); } - public void setMiterLimit(double limit){ + public void setMiterLimit(double limit) { graphicsEnvironmentImpl.setMiterLimit(limit); } - - public void setFillStyle(Style style){ + + public void setFillStyle(Style style) { Object nativeFillStyle = graphicsEnvironmentImpl.setFillStyle(style, style.getCached()); style.cache(nativeFillStyle); } - public String getFont(){ + public String getFont() { return graphicsEnvironmentImpl.getFont(); } - public void setFont(String font){ + public void setFont(String font) { graphicsEnvironmentImpl.setFont(font); } - - public void setStrokeStyle(Style style){ + + public void setStrokeStyle(Style style) { Object nativeStrokeStyle = graphicsEnvironmentImpl.setStrokeStyle(style, style.getCached()); style.cache(nativeStrokeStyle); } - public String getTextAlign(){ + public String getTextAlign() { return graphicsEnvironmentImpl.getTextAlign(); } - public void setTextAlign(String textAlign){ + public void setTextAlign(String textAlign) { graphicsEnvironmentImpl.setTextAlign(textAlign); } - public String getTextBaseline(){ + public String getTextBaseline() { return graphicsEnvironmentImpl.getTextBaseline(); } - public void setTextBaseline(String textbaseline){ + public void setTextBaseline(String textbaseline) { graphicsEnvironmentImpl.setTextBaseline(textbaseline); } - public void fillText(String text, double x, double y){ + public void fillText(String text, double x, double y) { graphicsEnvironmentImpl.fillText(text, x, y); } - public void fillText(String text, double x, double y, double maxWidth){ + public void fillText(String text, double x, double y, double maxWidth) { graphicsEnvironmentImpl.fillText(text, x, y, maxWidth); } - public Dimension measureText(String text){ + public Dimension measureText(String text) { return graphicsEnvironmentImpl.measureText(text); } - public void strokeText(String text, double x, double y){ + public void strokeText(String text, double x, double y) { graphicsEnvironmentImpl.strokeText(text, x, y); } - public void strokeText(String text, double x, double y, double maxWidth){ + public void strokeText(String text, double x, double y, double maxWidth) { graphicsEnvironmentImpl.strokeText(text, x, y, maxWidth); } - public ImageData createPixelMap(double x, double y){ - return graphicsEnvironmentImpl.createPixelMap(x, y); - } - - public ImageData createPixelMap(ImageData pixelMap){ - return graphicsEnvironmentImpl.createPixelMap(pixelMap); - } - - public ImageData getSnapshot(double x, double y, double width, double height){ - return graphicsEnvironmentImpl.getPixelMap(x, y, width, height); - } - - public void drawPixelMap(ImageData pixelMap, double x, double y){ - graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y); - } - - public void drawPixelMap(ImageData pixelMap, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight){ - graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y, dirtyx, dirtyy, dirtywidth, dirtyheight); - } - - public void setGlobalAlpha(double alpha){ +// public ImageData createPixelMap(double x, double y) { +// return graphicsEnvironmentImpl.createPixelMap(x, y); +// } +// +// public ImageData createPixelMap(ImageData pixelMap) { +// return graphicsEnvironmentImpl.createPixelMap(pixelMap); +// } +// +// public ImageData getSnapshot(double x, double y, double width, double height) { +// return graphicsEnvironmentImpl.getPixelMap(x, y, width, height); +// } +// +// public void drawPixelMap(ImageData pixelMap, double x, double y) { +// graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y); +// } +// +// public void drawPixelMap(ImageData pixelMap, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) { +// graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y, dirtyx, dirtyy, dirtywidth, dirtyheight); +// } + /** + * Sets the global alpha of the current state. + * + * @param alpha value in the range {@code 0.0-1.0}. The value is clamped if + * it is out of range. + */ + public void setGlobalAlpha(double alpha) { graphicsEnvironmentImpl.setGlobalAlpha(alpha); } - public double getGlobalAlpha(){ + /** + * Gets the current global alpha. + * + * @return the current global alpha. + */ + public double getGlobalAlpha() { return graphicsEnvironmentImpl.getGlobalAlpha(); } - public void setGlobalCompositeOperation(String operation){ + /** + * Sets the global blend mode. + * + * @param op the BlendMode that will be set. + */ + public void setGlobalCompositeOperation(String operation) { graphicsEnvironmentImpl.setGlobalCompositeOperation(operation); } - public String getGlobalCompositeOperation(){ + /** + * Gets the global blend mode. + * + * @return the global BlendMode of the current state. + */ + public String getGlobalCompositeOperation() { return graphicsEnvironmentImpl.getGlobalCompositeOperation(); } - public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1){ + public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) { return new Style.LinearGradient(x0, y0, x1, y1); } - public Pattern createPattern(Image image, String repeat){ + public Pattern createPattern(Image image, String repeat) { return new Pattern(image, repeat); } - public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1){ + public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) { return new RadialGradient(x0, y0, r0, x1, y1, r1); } - - public Color getWebColor(String webColor){ + + public Color getWebColor(String webColor) { return new Style.Color(webColor); } - public int getHeight(){ + /** + * Get the height of this GraphicsContext (which should be the same as the + * enclosing canvas height) + * + * @return the height of this GraphicsContext + */ + public int getHeight() { return graphicsEnvironmentImpl.getHeight(); } - public int getWidth(){ + /** + * Get the width of this GraphicsContext (which should be the same as the + * enclosing canvas height) + * + * @return the width of this GraphicsContext + */ + public int getWidth() { return graphicsEnvironmentImpl.getWidth(); } - public void setHeight(int height){ - graphicsEnvironmentImpl.setHeight(height); +// public void setHeight(int height) { +// graphicsEnvironmentImpl.setHeight(height); +// } +// +// public void setWidth(int width) { +// graphicsEnvironmentImpl.setWidth(width); +// } + /** + * Fill a circle with a center position of centerX, centerY and the + * specified radius. + * + * @param centerX + * @param centerY + * @param radius + */ + public void fillCircle(float centerX, float centerY, float radius) { + graphicsEnvironmentImpl.arc(centerX, centerY, radius, 0, Math.PI * 2, false); } - public void setWidth(int width){ - graphicsEnvironmentImpl.setWidth(width); - } - - public void fillCircle(float centerX, float centerY, float radius) { - graphicsEnvironmentImpl.arc(centerX, centerY, radius, 0, Math.PI*2, false); - } - + /** + * Fills a polygon with the given points using the currently set fill paint. + * + * @param x_coord array containing the x coordinates of the polygon's + * points. + * @param y_coord array containing the y coordinates of the polygon's + * points. + * @param vertexCount the number of points that make the polygon. + */ public void fillPolygon(double[] x_coord, double[] y_coord, int vertexCount) { - if (vertexCount >=1&&x_coord!=null && x_coord.length>=vertexCount && y_coord!=null && y_coord.length>=vertexCount) - graphicsEnvironmentImpl.beginPath(); + if (vertexCount >= 1 && x_coord != null && x_coord.length >= vertexCount && y_coord != null && y_coord.length >= vertexCount) { + graphicsEnvironmentImpl.beginPath(); + } graphicsEnvironmentImpl.moveTo(x_coord[0], y_coord[0]); for (int i = 1; i < vertexCount; i++) { graphicsEnvironmentImpl.lineTo(x_coord[i], y_coord[i]); - + } graphicsEnvironmentImpl.closePath(); graphicsEnvironmentImpl.fill(); graphicsEnvironmentImpl.stroke(); - - } } diff -r 2960a1d37277 -r e67363288df1 javaquery/canvas/src/main/java/net/java/html/canvas/Image.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Image.java Mon Sep 23 07:52:41 2013 -0700 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Image.java Thu Sep 26 14:20:18 2013 -0700 @@ -1,19 +1,19 @@ /** - * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach - * + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, version 2 of the License. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with - * this program. Look for COPYING file in the top folder. If not, see - * http://opensource.org/licenses/GPL-2.0. + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. */ package net.java.html.canvas; diff -r 2960a1d37277 -r e67363288df1 javaquery/canvas/src/main/java/net/java/html/canvas/ImageData.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/ImageData.java Mon Sep 23 07:52:41 2013 -0700 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/ImageData.java Thu Sep 26 14:20:18 2013 -0700 @@ -1,19 +1,19 @@ /** - * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach - * + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, version 2 of the License. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with - * this program. Look for COPYING file in the top folder. If not, see - * http://opensource.org/licenses/GPL-2.0. + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. */ package net.java.html.canvas; diff -r 2960a1d37277 -r e67363288df1 javaquery/canvas/src/main/java/net/java/html/canvas/Style.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java Mon Sep 23 07:52:41 2013 -0700 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java Thu Sep 26 14:20:18 2013 -0700 @@ -1,19 +1,19 @@ /** - * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach - * + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, version 2 of the License. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with - * this program. Look for COPYING file in the top folder. If not, see - * http://opensource.org/licenses/GPL-2.0. + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. */ package net.java.html.canvas; diff -r 2960a1d37277 -r e67363288df1 javaquery/canvas/src/main/java/net/java/html/canvas/spi/GraphicsEnvironment.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/spi/GraphicsEnvironment.java Mon Sep 23 07:52:41 2013 -0700 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/spi/GraphicsEnvironment.java Thu Sep 26 14:20:18 2013 -0700 @@ -19,7 +19,6 @@ import net.java.html.canvas.Dimension; import net.java.html.canvas.Image; -import net.java.html.canvas.ImageData; import net.java.html.canvas.Style; /** @@ -84,19 +83,16 @@ public void scale(double x, double y); - public Object drawImage(Image image, double x, double y, Object nativeImage); + public Object drawImage(Image image, double x, double y, Object nativeImage); public Object drawImage(Image image, double x, double y, double width, double height, Object nativeImage); public Object drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height, Object nativeImage); - public int getWidth(Image image, Object nativeImage); - + public int getHeight(Image image, Object nativeImage); - - - + /** * When implementing you can return an Object of your choice to enable * caching. Returning null means no caching. When caching is enabled, and @@ -123,70 +119,189 @@ */ public Object setStrokeStyle(Style style, Object nativeStyle); - public void setShadowColor(String color); - - public void setShadowBlur(double blur); - - public void setShadowOffsetX(double x); - - public void setShadowOffsetY(double y); - - public String getShadowColor(); - - public double getShadowBlur(); - - public double getShadowOffsetX(); - - public double getShadowOffsetY(); - +// public void setShadowColor(String color); +// +// public void setShadowBlur(double blur); +// +// public void setShadowOffsetX(double x); +// +// public void setShadowOffsetY(double y); +// +// public String getShadowColor(); +// +// public double getShadowBlur(); +// +// public double getShadowOffsetX(); +// +// public double getShadowOffsetY(); + /** + * Gets the current stroke line cap. + * + * @return {@code StrokeLineCap} with a value of Butt, Round, or Square. + */ public String getLineCap(); + /** + * Sets the current stroke line cap. + * + * @param style a value of Butt, Round, or Square. + */ public void setLineCap(String style); + /** + * Gets the current stroke line join. + * + * @return a value of Miter, Bevel, or Round. + */ public String getLineJoin(); + /** + * Sets the current stroke line join. + * + * @param style with a value of Miter, Bevel, or Round. + */ public void setLineJoin(String style); + /** + * Gets the current line width. + * + * @return value between 0 and infinity. + */ public double getLineWidth(); + /** + * Sets the current line width. + * + * @param width value in the range {0-positive infinity}, with any other + * value being ignored and leaving the value unchanged. + */ public void setLineWidth(double width); + /** + * Gets the current miter limit. v + * + * @return the miter limit value in the range {@code 0.0-positive infinity} + */ public double getMiterLimit(); + /** + * Sets the current miter limit. + * + * @param limit miter limit value between 0 and positive infinity with any + * other value being ignored and leaving the value unchanged. + */ public void setMiterLimit(double limit); + /** + * Gets the current Font. + * + * @return the Font + */ public String getFont(); + /** + * Sets the current Font. + * + */ public void setFont(String font); + /** + * Gets the current {@code TextAlignment}. + * + * @return TextAlignment with values of Left, Center, Right, or Justify. + */ public String getTextAlign(); + /** + * Defines horizontal text alignment, relative to the text origin. + * + * @param textAlign with values of Left, Center, Right. + */ public void setTextAlign(String textAlign); + /** + * Sets the current Text Baseline. + * + * @param baseline with values of Top, Center, Baseline, or Bottom + */ public String getTextBaseline(); - public void setTextBaseline(String textbaseline); + /** + * Sets the current Text Baseline. + * + * @param baseline with values of Top, Center, Baseline, or Bottom + */ + public void setTextBaseline(String baseline); + /** + * Fills the given string of text at position x, y (0,0 at top left) with + * the current fill paint attribute. + * + * @param text the string of text. + * @param x position on the x axis. + * @param y position on the y axis. + */ public void fillText(String text, double x, double y); + /** + * Fills text and includes a maximum width of the string. + * + * If the width of the text extends past max width, then it will be sized to + * fit. + * + * @param text the string of text. + * @param x position on the x axis. + * @param y position on the y axis. + * @param maxWidth maximum width the text string can have. + */ public void fillText(String text, double x, double y, double maxWidth); + /** + * The Dimension of this text using the current Font settings + * + * @param text + * @return the Dimension of this text using the current Font settings + */ public Dimension measureText(String text); + /** + * draws the given string of text at position x, y (0,0 at top left) with + * the current stroke paint attribute. + * + * @param text the string of text. + * @param x position on the x axis. + * @param y position on the y axis. + */ public void strokeText(String text, double x, double y); + /** + * Draws text with stroke paint and includes a maximum width of the string. + * + * If the width of the text extends past max width, then it will be sized to + * fit. + * + * @param text the string of text. + * @param x position on the x axis. + * @param y position on the y axis. + * @param maxWidth maximum width the text string can have. + */ public void strokeText(String text, double x, double y, double maxWidth); - public ImageData createPixelMap(double x, double y); - - public ImageData createPixelMap(ImageData imageData); - - public ImageData getPixelMap(double x, double y, double width, double height); - - public void putPixelMap(ImageData imageData, double x, double y); - - public void putPixelMap(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight); - +// public ImageData createPixelMap(double x, double y); +// +// public ImageData createPixelMap(ImageData imageData); +// +// public ImageData getPixelMap(double x, double y, double width, double height); +// +// public void putPixelMap(ImageData imageData, double x, double y); +// +// public void putPixelMap(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight); + /** + * Sets the global alpha of the current state. + * + * @param alpha value in the range {@code 0.0-1.0}. The value is clamped if + * it is out of range. + */ public void setGlobalAlpha(double alpha); public double getGlobalAlpha(); @@ -194,14 +309,14 @@ public void setGlobalCompositeOperation(String operation); public String getGlobalCompositeOperation(); - + public int getHeight(); public int getWidth(); - public void setHeight(int height); - - public void setWidth(int width); +// public void setHeight(int height); +// +// public void setWidth(int width); public Object mergeImages(Image a, Image b, Object cachedA, Object cachedB); } diff -r 2960a1d37277 -r e67363288df1 javaquery/canvas/src/main/java/net/java/html/canvas/spi/GraphicsUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/spi/GraphicsUtils.java Thu Sep 26 14:20:18 2013 -0700 @@ -0,0 +1,24 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package net.java.html.canvas.spi; + +import net.java.html.canvas.GraphicsContext; +import org.apidesign.html.canvas.impl.CnvsAccssr; + +/** + * + * @author antonepple + */ +public class GraphicsUtils { + + private GraphicsUtils() { + } + + public static GraphicsContext create(GraphicsEnvironment environment){ + return CnvsAccssr.getDefault().create(environment); + } + + +} diff -r 2960a1d37277 -r e67363288df1 javaquery/canvas/src/main/java/org/apidesign/html/canvas/impl/CnvsAccssr.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javaquery/canvas/src/main/java/org/apidesign/html/canvas/impl/CnvsAccssr.java Thu Sep 26 14:20:18 2013 -0700 @@ -0,0 +1,28 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.apidesign.html.canvas.impl; + +import net.java.html.canvas.GraphicsContext; +import net.java.html.canvas.spi.GraphicsEnvironment; + +/** + * + * @author antonepple + */ +public abstract class CnvsAccssr { + + static CnvsAccssr DEFAULT; + + public CnvsAccssr() { + if (DEFAULT!=null) throw new IllegalStateException("Already initialized"); + DEFAULT = this; + } + + public static CnvsAccssr getDefault() { + return DEFAULT; + } + + public abstract GraphicsContext create(GraphicsEnvironment environment); +} diff -r 2960a1d37277 -r e67363288df1 javaquery/canvas/src/main/resources/net/java/html/canvas/package.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javaquery/canvas/src/main/resources/net/java/html/canvas/package.html Thu Sep 26 14:20:18 2013 -0700 @@ -0,0 +1,5 @@ + + + Universal, flexible, capable, effective, highly efficient Canvas API for any device on the planet (and beyond). + + diff -r 2960a1d37277 -r e67363288df1 javaquery/canvas/src/main/resources/net/java/html/canvas/spi/package.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javaquery/canvas/src/main/resources/net/java/html/canvas/spi/package.html Thu Sep 26 14:20:18 2013 -0700 @@ -0,0 +1,5 @@ + + + SPI for enabling the Canvas API on different platforms. + +