javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java
branchcanvas
changeset 1302 e67363288df1
parent 1263 088331d4cb76
child 1303 3d62ad46d744
     1.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java	Sat Sep 07 18:25:09 2013 +0200
     1.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java	Thu Sep 26 14:20:18 2013 -0700
     1.3 @@ -22,20 +22,40 @@
     1.4  import net.java.html.canvas.Style.Pattern;
     1.5  import net.java.html.canvas.Style.RadialGradient;
     1.6  import net.java.html.canvas.spi.GraphicsEnvironment;
     1.7 +import org.apidesign.html.canvas.impl.CnvsAccssr;
     1.8  
     1.9  /**
    1.10 - * A 2D Graphics Context similar to HTML5 or JavaFX GraphicsContext. 
    1.11 - * Use this to paint on your Canvas.s
    1.12 + * A 2D Graphics Context similar to HTML5 or JavaFX GraphicsContext. Use this to
    1.13 + * paint on your Canvas.s
    1.14 + *
    1.15   * @author antonepple
    1.16   */
    1.17  public final class GraphicsContext {
    1.18  
    1.19      GraphicsEnvironment graphicsEnvironmentImpl;
    1.20  
    1.21 -    public GraphicsContext(GraphicsEnvironment graphicsEnvironment) {
    1.22 +    static {
    1.23 +        CnvsAccssr cnvsAccssr = new CnvsAccssr() {
    1.24 +            @Override
    1.25 +            public GraphicsContext create(GraphicsEnvironment environment) {
    1.26 +                return new GraphicsContext(environment);
    1.27 +            }
    1.28 +        };
    1.29 +    }
    1.30 +
    1.31 +    GraphicsContext(GraphicsEnvironment graphicsEnvironment) {
    1.32          this.graphicsEnvironmentImpl = graphicsEnvironment;
    1.33      }
    1.34  
    1.35 +    /**
    1.36 +     * Adds path elements to the current path to make an arc.
    1.37 +     *
    1.38 +     * @param centerX the center x position of the arc.
    1.39 +     * @param centerY the center y position of the arc.
    1.40 +     * @param radius the radius of the arc.
    1.41 +     * @param endAngle teh endAngle of the arc
    1.42 +     * @param ccw the direction of the arc (counterclockwise)
    1.43 +     */
    1.44      public void arc(double centerX,
    1.45              double centerY,
    1.46              double startAngle,
    1.47 @@ -45,328 +65,594 @@
    1.48          graphicsEnvironmentImpl.arc(centerX, centerY, startAngle, radius, endAngle, ccw);
    1.49      }
    1.50  
    1.51 +    /**
    1.52 +     * Adds segments to the current path to make an arc.
    1.53 +     *
    1.54 +     * @param x1 the X coordinate of the first point of the arc.
    1.55 +     * @param y1 the Y coordinate of the first point of the arc.
    1.56 +     * @param x2 the X coordinate of the second point of the arc.
    1.57 +     * @param y2 the Y coordinate of the second point of the arc.
    1.58 +     * @param radius the radius of the arc in the range {0.0-positive infinity}.
    1.59 +     */
    1.60      public void arcTo(double x1,
    1.61              double y1,
    1.62              double x2,
    1.63              double y2,
    1.64 -            double r) {
    1.65 -        graphicsEnvironmentImpl.arcTo(x1, y1, x2, y2, r);
    1.66 +            double radius) {
    1.67 +        graphicsEnvironmentImpl.arcTo(x1, y1, x2, y2, radius);
    1.68      }
    1.69  
    1.70 +    /**
    1.71 +     * Returns true if the the given x,y point is inside the path.
    1.72 +     *
    1.73 +     * @param x the X coordinate to use for the check.
    1.74 +     * @param y the Y coordinate to use for the check.
    1.75 +     * @return true if the point given is inside the path, false otherwise.
    1.76 +     */
    1.77      public boolean isPointInPath(double x, double y) {
    1.78          return graphicsEnvironmentImpl.isPointInPath(x, y);
    1.79      }
    1.80  
    1.81 +    /**
    1.82 +     * Fills the path with the current fill paint.
    1.83 +     */
    1.84      public void fill() {
    1.85          graphicsEnvironmentImpl.fill();
    1.86      }
    1.87  
    1.88 +    /**
    1.89 +     * Strokes the path with the current stroke paint.
    1.90 +     */
    1.91      public void stroke() {
    1.92          graphicsEnvironmentImpl.stroke();
    1.93      }
    1.94  
    1.95 +    /**
    1.96 +     * Starts a Path
    1.97 +     */
    1.98      public void beginPath() {
    1.99          graphicsEnvironmentImpl.beginPath();
   1.100      }
   1.101  
   1.102 -    public void closePath(){
   1.103 +    /**
   1.104 +     * Closes the path.
   1.105 +     */
   1.106 +    public void closePath() {
   1.107          graphicsEnvironmentImpl.closePath();
   1.108      }
   1.109  
   1.110 -    public void clip(){
   1.111 +    /**
   1.112 +     * Clips using the current path
   1.113 +     */
   1.114 +    public void clip() {
   1.115          graphicsEnvironmentImpl.clip();
   1.116      }
   1.117  
   1.118 -    public void moveTo(double x, double y){
   1.119 +    /**
   1.120 +     * Issues a move command for the current path to the given x,y coordinate.
   1.121 +     *
   1.122 +     * @param x0 the X position for the move to command.
   1.123 +     * @param y0 the Y position for the move to command.
   1.124 +     */
   1.125 +    public void moveTo(double x, double y) {
   1.126          graphicsEnvironmentImpl.moveTo(x, y);
   1.127      }
   1.128  
   1.129 -    public void lineTo(double x, double y){
   1.130 +    /**
   1.131 +     * Adds segments to the current path to make a line at the given x,y
   1.132 +     * coordinate.
   1.133 +     *
   1.134 +     * @param x1 the X coordinate of the ending point of the line.
   1.135 +     * @param y1 the Y coordinate of the ending point of the line.
   1.136 +     */
   1.137 +    public void lineTo(double x, double y) {
   1.138          graphicsEnvironmentImpl.lineTo(x, y);
   1.139      }
   1.140  
   1.141 -    public void quadraticCurveTo(double cpx, double cpy, double x, double y){
   1.142 -    graphicsEnvironmentImpl.quadraticCurveTo(cpx, cpy, x, y);
   1.143 +    /**
   1.144 +     * Adds segments to the current path to make a quadratic curve.
   1.145 +     *
   1.146 +     * @param cpx the X coordinate of the control point
   1.147 +     * @param cpy the Y coordinate of the control point
   1.148 +     * @param x the X coordinate of the end point
   1.149 +     * @param y the Y coordinate of the end point
   1.150 +     */
   1.151 +    public void quadraticCurveTo(double cpx, double cpy, double x, double y) {
   1.152 +        graphicsEnvironmentImpl.quadraticCurveTo(cpx, cpy, x, y);
   1.153      }
   1.154  
   1.155 -    public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y){
   1.156 +    /**
   1.157 +     * Adds segments to the current path to make a cubic bezier curve.
   1.158 +     *
   1.159 +     * @param cp1x the X coordinate of first bezier control point.
   1.160 +     * @param cp1y the Y coordinate of the first bezier control point.
   1.161 +     * @param cp2x the X coordinate of the second bezier control point.
   1.162 +     * @param cp2y the Y coordinate of the second bezier control point.
   1.163 +     * @param x the X coordinate of the end point.
   1.164 +     * @param y the Y coordinate of the end point.
   1.165 +     */
   1.166 +    public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y) {
   1.167          graphicsEnvironmentImpl.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
   1.168      }
   1.169  
   1.170 -    public void fillRect(double x, double y, double width, double height){
   1.171 +    /**
   1.172 +     * Fills a rectangle using the current fill paint.
   1.173 +     *
   1.174 +     * @param x the X position of the upper left corner of the rectangle.
   1.175 +     * @param y the Y position of the upper left corner of the rectangle.
   1.176 +     * @param w the width of the rectangle.
   1.177 +     * @param h the height of the rectangle.
   1.178 +     */
   1.179 +    public void fillRect(double x, double y, double width, double height) {
   1.180          graphicsEnvironmentImpl.fillRect(x, y, width, height);
   1.181      }
   1.182  
   1.183 -    public void strokeRect(double x, double y, double width, double height){
   1.184 -    graphicsEnvironmentImpl.strokeRect(x, y, width, height);
   1.185 +    /**
   1.186 +     * Strokes a rectangle using the current stroke paint.
   1.187 +     *
   1.188 +     * @param x the X position of the upper left corner of the rectangle.
   1.189 +     * @param y the Y position of the upper left corner of the rectangle.
   1.190 +     * @param width the width of the rectangle.
   1.191 +     * @param height the height of the rectangle.
   1.192 +     */
   1.193 +    public void strokeRect(double x, double y, double width, double height) {
   1.194 +        graphicsEnvironmentImpl.strokeRect(x, y, width, height);
   1.195      }
   1.196  
   1.197 -    public void clearRect(double x, double y, double width, double height){
   1.198 +    /**
   1.199 +     * Clears a portion of the canvas with a transparent color value.
   1.200 +     *
   1.201 +     * @param x X position of the upper left corner of the rectangle.
   1.202 +     * @param y Y position of the upper left corner of the rectangle.
   1.203 +     * @param width width of the rectangle.
   1.204 +     * @param height height of the rectangle.
   1.205 +     */
   1.206 +    public void clearRect(double x, double y, double width, double height) {
   1.207          graphicsEnvironmentImpl.clearRect(x, y, width, height);
   1.208      }
   1.209  
   1.210 -    public void rect(double x, double y, double width, double height){
   1.211 +    /**
   1.212 +     * Clears a portion of the canvas with a transparent color value.
   1.213 +     *
   1.214 +     * @param x X position of the upper left corner of the rectangle.
   1.215 +     * @param y Y position of the upper left corner of the rectangle.
   1.216 +     * @param width width of the rectangle.
   1.217 +     * @param height height of the rectangle.
   1.218 +     */
   1.219 +    public void rect(double x, double y, double width, double height) {
   1.220          graphicsEnvironmentImpl.rect(x, y, width, height);
   1.221      }
   1.222  
   1.223 -    public void save(){
   1.224 +    /**
   1.225 +     * Saves the following attributes onto a stack.
   1.226 +     * <ul>
   1.227 +     * <li>Global Alpha</li>
   1.228 +     * <li>Global Blend Operation</li>
   1.229 +     * <li>Transform</li>
   1.230 +     * <li>Fill Paint</li>
   1.231 +     * <li>Stroke Paint</li>
   1.232 +     * <li>Line Width</li>
   1.233 +     * <li>Line Cap</li>
   1.234 +     * <li>Line Join</li>
   1.235 +     * <li>Miter Limit</li>
   1.236 +     * <li>Number of Clip Paths</li>
   1.237 +     * <li>Font</li>
   1.238 +     * <li>Text Align</li>
   1.239 +     * <li>Text Baseline</li>
   1.240 +     * <li>Effect</li>
   1.241 +     * <li>Fill Rule</li>
   1.242 +     * </ul>
   1.243 +     * This method does NOT alter the current state in any way. Also, not that
   1.244 +     * the current path is not saved.
   1.245 +     */
   1.246 +    public void save() {
   1.247          graphicsEnvironmentImpl.save();
   1.248      }
   1.249  
   1.250 -    public void restore(){
   1.251 +    /**
   1.252 +     * Pops the state off of the stack, setting the following attributes to
   1.253 +     * their value at the time when that state was pushed onto the stack. If the
   1.254 +     * stack is empty then nothing is changed.
   1.255 +     *
   1.256 +     * <ul>
   1.257 +     * <li>Global Alpha</li>
   1.258 +     * <li>Global Blend Operation</li>
   1.259 +     * <li>Transform</li>
   1.260 +     * <li>Fill Paint</li>
   1.261 +     * <li>Stroke Paint</li>
   1.262 +     * <li>Line Width</li>
   1.263 +     * <li>Line Cap</li>
   1.264 +     * <li>Line Join</li>
   1.265 +     * <li>Miter Limit</li>
   1.266 +     * <li>Number of Clip Paths</li>
   1.267 +     * <li>Font</li>
   1.268 +     * <li>Text Align</li>
   1.269 +     * <li>Text Baseline</li>
   1.270 +     * <li>Effect</li>
   1.271 +     * <li>Fill Rule</li>
   1.272 +     * </ul>
   1.273 +     */
   1.274 +    public void restore() {
   1.275          graphicsEnvironmentImpl.restore();
   1.276      }
   1.277  
   1.278 -    public void rotate(double angle){
   1.279 +    /**
   1.280 +     * Rotates the current transform in degrees.
   1.281 +     *
   1.282 +     * @param angle value in degrees to rotate the current transform.
   1.283 +     */
   1.284 +    public void rotate(double angle) {
   1.285          graphicsEnvironmentImpl.rotate(angle);
   1.286      }
   1.287  
   1.288 -    public void transform(double a, double b, double c, double d, double e, double f){
   1.289 -        graphicsEnvironmentImpl.transform(a, b, c, d, e, f);
   1.290 +    /**
   1.291 +     * Concatenates the input with the current transform.
   1.292 +     *
   1.293 +     * @param mxx - the X coordinate scaling element of the 3x4 matrix
   1.294 +     * @param myx - the Y coordinate shearing element of the 3x4 matrix
   1.295 +     * @param mxy - the X coordinate shearing element of the 3x4 matrix
   1.296 +     * @param myy - the Y coordinate scaling element of the 3x4 matrix
   1.297 +     * @param mxt - the X coordinate translation element of the 3x4 matrix
   1.298 +     * @param myt - the Y coordinate translation element of the 3x4 matrix
   1.299 +     */
   1.300 +    public void transform(double mxx, double myx, double mxy, double myy, double mxt, double myt) {
   1.301 +        graphicsEnvironmentImpl.transform(mxx, myx, mxy, myy, mxt, myt);
   1.302      }
   1.303  
   1.304 -    public void setTransform(double a, double b, double c, double d, double e, double f){
   1.305 -        graphicsEnvironmentImpl.setTransform(a, b, c, d, e, f);
   1.306 +    /**
   1.307 +     * Concatenates the input with the current transform.
   1.308 +     *
   1.309 +     * @param mxx - the X coordinate scaling element of the 3x4 matrix
   1.310 +     * @param myx - the Y coordinate shearing element of the 3x4 matrix
   1.311 +     * @param mxy - the X coordinate shearing element of the 3x4 matrix
   1.312 +     * @param myy - the Y coordinate scaling element of the 3x4 matrix
   1.313 +     * @param mxt - the X coordinate translation element of the 3x4 matrix
   1.314 +     * @param myt - the Y coordinate translation element of the 3x4 matrix
   1.315 +     */
   1.316 +    public void setTransform(double mxx, double myx, double mxy, double myy, double mxt, double myt) {
   1.317 +        graphicsEnvironmentImpl.setTransform(mxx, myx, mxy, myy, mxt, myt);
   1.318      }
   1.319  
   1.320 -    public void translate(double x, double y){
   1.321 +    /**
   1.322 +     * Translates the current transform by x, y.
   1.323 +     *
   1.324 +     * @param x value to translate along the x axis.
   1.325 +     * @param y value to translate along the y axis.
   1.326 +     */
   1.327 +    public void translate(double x, double y) {
   1.328          graphicsEnvironmentImpl.translate(x, y);
   1.329      }
   1.330  
   1.331 -    public void scale(double x, double y){
   1.332 +    /**
   1.333 +     * Scales the current transform by x, y.
   1.334 +     *
   1.335 +     * @param x value to scale in the x axis.
   1.336 +     * @param y value to scale in the y axis.
   1.337 +     */
   1.338 +    public void scale(double x, double y) {
   1.339          graphicsEnvironmentImpl.scale(x, y);
   1.340      }
   1.341  
   1.342 -    public void drawImage(Image image, double x, double y){
   1.343 +    /**
   1.344 +     * Draws an image at the given x, y position using the width and height of
   1.345 +     * the given image.
   1.346 +     *
   1.347 +     * @param img the image to be drawn.
   1.348 +     * @param x the X coordinate on the destination for the upper left of the
   1.349 +     * image.
   1.350 +     * @param y the Y coordinate on the destination for the upper left of the
   1.351 +     * image.
   1.352 +     */
   1.353 +    public void drawImage(Image image, double x, double y) {
   1.354          Object nativeImage = graphicsEnvironmentImpl.drawImage(image, x, y, image.getCached());
   1.355          image.cache(nativeImage);
   1.356      }
   1.357  
   1.358 -    public void drawImage(Image image, double x, double y, double width, double height){
   1.359 +    /**
   1.360 +     * Draws an image into the given destination rectangle of the canvas. The
   1.361 +     * Image is scaled to fit into the destination rectagnle.
   1.362 +     *
   1.363 +     * @param img the image to be drawn.
   1.364 +     * @param x the X coordinate on the destination for the upper left of the
   1.365 +     * image.
   1.366 +     * @param y the Y coordinate on the destination for the upper left of the
   1.367 +     * image.
   1.368 +     * @param width the width of the destination rectangle.
   1.369 +     * @param height the height of the destination rectangle.
   1.370 +     */
   1.371 +    public void drawImage(Image image, double x, double y, double width, double height) {
   1.372          Object nativeImage = graphicsEnvironmentImpl.drawImage(image, x, y, width, height, image.getCached());
   1.373          image.cache(nativeImage);
   1.374      }
   1.375  
   1.376 -    public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height){
   1.377 -        Object nativeImage = graphicsEnvironmentImpl.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height, image.getCached());
   1.378 +    /**
   1.379 +     * Draws the current source rectangle of the given image to the given
   1.380 +     * destination rectangle of the Canvas.
   1.381 +     *
   1.382 +     * @param img the image to be drawn.
   1.383 +     * @param sx the source rectangle's X coordinate position.
   1.384 +     * @param sy the source rectangle's Y coordinate position.
   1.385 +     * @param sw the source rectangle's width.
   1.386 +     * @param sh the source rectangle's height.
   1.387 +     * @param dx the destination rectangle's X coordinate position.
   1.388 +     * @param dy the destination rectangle's Y coordinate position.
   1.389 +     * @param dw the destination rectangle's width.
   1.390 +     * @param dh the destination rectangle's height.
   1.391 +     */
   1.392 +    public void drawImage(Image image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh) {
   1.393 +        Object nativeImage = graphicsEnvironmentImpl.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh, image.getCached());
   1.394          image.cache(nativeImage);
   1.395      }
   1.396 -    
   1.397 -    public Image merge(Image a, Image b){
   1.398 -        if(a.getCached()==null){
   1.399 +
   1.400 +    /**
   1.401 +     * Merges two images drawing one on top of the other and returning the
   1.402 +     * result.
   1.403 +     *
   1.404 +     * @param a the lower Image
   1.405 +     * @param b the upper Image
   1.406 +     * @return
   1.407 +     */
   1.408 +    public Image merge(Image a, Image b) {
   1.409 +        if (a.getCached() == null) {
   1.410              drawImage(a, 0, 0);
   1.411          }
   1.412 -        if(b.getCached()==null){
   1.413 +        if (b.getCached() == null) {
   1.414              drawImage(b, 0, 0);
   1.415          }
   1.416 -        Object nativeImage = graphicsEnvironmentImpl.mergeImages(a,b,a.getCached(),b.getCached());
   1.417 +        Object nativeImage = graphicsEnvironmentImpl.mergeImages(a, b, a.getCached(), b.getCached());
   1.418          Image merged = Image.create("should add real path here");
   1.419          merged.cache(nativeImage);
   1.420          return merged;
   1.421      }
   1.422  
   1.423 -    public void setShadowColor(String color){
   1.424 -        graphicsEnvironmentImpl.setShadowColor(color);
   1.425 -    }
   1.426 -
   1.427 -    public void setShadowBlur(double blur){
   1.428 -        graphicsEnvironmentImpl.setShadowBlur(blur);
   1.429 -    }
   1.430 -
   1.431 -    public void setShadowOffsetX(double x){
   1.432 -        graphicsEnvironmentImpl.setShadowOffsetX(x);
   1.433 -    }
   1.434 -
   1.435 -    public void setShadowOffsetY(double y){
   1.436 -        graphicsEnvironmentImpl.setShadowOffsetY(y);
   1.437 -    }
   1.438 -
   1.439 -    public String getShadowColor(){
   1.440 -        return graphicsEnvironmentImpl.getShadowColor();
   1.441 -    }
   1.442 -
   1.443 -    public double getShadowBlur(){
   1.444 -        return graphicsEnvironmentImpl.getShadowBlur();
   1.445 -        }
   1.446 -
   1.447 -    public double getShadowOffsetX(){
   1.448 -        return graphicsEnvironmentImpl.getShadowOffsetX();
   1.449 -    }
   1.450 -
   1.451 -    public double getShadowOffsetY(){
   1.452 -        return graphicsEnvironmentImpl.getShadowOffsetY();
   1.453 -    }
   1.454 -
   1.455 -    public String getLineCap(){
   1.456 +//    public void setShadowColor(String color) {
   1.457 +//        graphicsEnvironmentImpl.setShadowColor(color);
   1.458 +//    }
   1.459 +//
   1.460 +//    public void setShadowBlur(double blur) {
   1.461 +//        graphicsEnvironmentImpl.setShadowBlur(blur);
   1.462 +//    }
   1.463 +//
   1.464 +//    public void setShadowOffsetX(double x) {
   1.465 +//        graphicsEnvironmentImpl.setShadowOffsetX(x);
   1.466 +//    }
   1.467 +//
   1.468 +//    public void setShadowOffsetY(double y) {
   1.469 +//        graphicsEnvironmentImpl.setShadowOffsetY(y);
   1.470 +//    }
   1.471 +//
   1.472 +//    public String getShadowColor() {
   1.473 +//        return graphicsEnvironmentImpl.getShadowColor();
   1.474 +//    }
   1.475 +//
   1.476 +//    public double getShadowBlur() {
   1.477 +//        return graphicsEnvironmentImpl.getShadowBlur();
   1.478 +//    }
   1.479 +//
   1.480 +//    public double getShadowOffsetX() {
   1.481 +//        return graphicsEnvironmentImpl.getShadowOffsetX();
   1.482 +//    }
   1.483 +//
   1.484 +//    public double getShadowOffsetY() {
   1.485 +//        return graphicsEnvironmentImpl.getShadowOffsetY();
   1.486 +//    }
   1.487 +    public String getLineCap() {
   1.488          return graphicsEnvironmentImpl.getLineCap();
   1.489      }
   1.490  
   1.491 -    public void setLineCap(String style){
   1.492 +    public void setLineCap(String style) {
   1.493          graphicsEnvironmentImpl.setLineCap(style);
   1.494      }
   1.495  
   1.496 -    public String getLineJoin(){
   1.497 +    public String getLineJoin() {
   1.498          return graphicsEnvironmentImpl.getLineJoin();
   1.499      }
   1.500  
   1.501 -    public void setLineJoin(String style){
   1.502 +    public void setLineJoin(String style) {
   1.503          graphicsEnvironmentImpl.setLineJoin(style);
   1.504      }
   1.505  
   1.506 -    public double getLineWidth(){
   1.507 +    public double getLineWidth() {
   1.508          return graphicsEnvironmentImpl.getLineWidth();
   1.509      }
   1.510  
   1.511 -    public void setLineWidth(double width){
   1.512 +    public void setLineWidth(double width) {
   1.513          graphicsEnvironmentImpl.setLineWidth(width);
   1.514      }
   1.515  
   1.516 -    public double getMiterLimit(){
   1.517 +    public double getMiterLimit() {
   1.518          return graphicsEnvironmentImpl.getMiterLimit();
   1.519      }
   1.520  
   1.521 -    public void setMiterLimit(double limit){
   1.522 +    public void setMiterLimit(double limit) {
   1.523          graphicsEnvironmentImpl.setMiterLimit(limit);
   1.524      }
   1.525 -    
   1.526 -    public void setFillStyle(Style style){
   1.527 +
   1.528 +    public void setFillStyle(Style style) {
   1.529          Object nativeFillStyle = graphicsEnvironmentImpl.setFillStyle(style, style.getCached());
   1.530          style.cache(nativeFillStyle);
   1.531      }
   1.532  
   1.533 -    public String getFont(){
   1.534 +    public String getFont() {
   1.535          return graphicsEnvironmentImpl.getFont();
   1.536      }
   1.537  
   1.538 -    public void setFont(String font){
   1.539 +    public void setFont(String font) {
   1.540          graphicsEnvironmentImpl.setFont(font);
   1.541      }
   1.542 -    
   1.543 -    public void setStrokeStyle(Style style){
   1.544 +
   1.545 +    public void setStrokeStyle(Style style) {
   1.546          Object nativeStrokeStyle = graphicsEnvironmentImpl.setStrokeStyle(style, style.getCached());
   1.547          style.cache(nativeStrokeStyle);
   1.548      }
   1.549  
   1.550 -    public String getTextAlign(){
   1.551 +    public String getTextAlign() {
   1.552          return graphicsEnvironmentImpl.getTextAlign();
   1.553      }
   1.554  
   1.555 -    public void setTextAlign(String textAlign){
   1.556 +    public void setTextAlign(String textAlign) {
   1.557          graphicsEnvironmentImpl.setTextAlign(textAlign);
   1.558      }
   1.559  
   1.560 -    public String getTextBaseline(){
   1.561 +    public String getTextBaseline() {
   1.562          return graphicsEnvironmentImpl.getTextBaseline();
   1.563      }
   1.564  
   1.565 -    public void setTextBaseline(String textbaseline){
   1.566 +    public void setTextBaseline(String textbaseline) {
   1.567          graphicsEnvironmentImpl.setTextBaseline(textbaseline);
   1.568      }
   1.569  
   1.570 -    public void fillText(String text, double x, double y){
   1.571 +    public void fillText(String text, double x, double y) {
   1.572          graphicsEnvironmentImpl.fillText(text, x, y);
   1.573      }
   1.574  
   1.575 -    public void fillText(String text, double x, double y, double maxWidth){
   1.576 +    public void fillText(String text, double x, double y, double maxWidth) {
   1.577          graphicsEnvironmentImpl.fillText(text, x, y, maxWidth);
   1.578      }
   1.579  
   1.580 -    public Dimension measureText(String text){
   1.581 +    public Dimension measureText(String text) {
   1.582          return graphicsEnvironmentImpl.measureText(text);
   1.583      }
   1.584  
   1.585 -    public void strokeText(String text, double x, double y){
   1.586 +    public void strokeText(String text, double x, double y) {
   1.587          graphicsEnvironmentImpl.strokeText(text, x, y);
   1.588      }
   1.589  
   1.590 -    public void strokeText(String text, double x, double y, double maxWidth){
   1.591 +    public void strokeText(String text, double x, double y, double maxWidth) {
   1.592          graphicsEnvironmentImpl.strokeText(text, x, y, maxWidth);
   1.593      }
   1.594  
   1.595 -    public ImageData createPixelMap(double x, double y){
   1.596 -        return graphicsEnvironmentImpl.createPixelMap(x, y);
   1.597 -    }
   1.598 -
   1.599 -    public ImageData createPixelMap(ImageData pixelMap){
   1.600 -        return graphicsEnvironmentImpl.createPixelMap(pixelMap);
   1.601 -    }
   1.602 -
   1.603 -    public ImageData getSnapshot(double x, double y, double width, double height){
   1.604 -        return graphicsEnvironmentImpl.getPixelMap(x, y, width, height);
   1.605 -    }
   1.606 -
   1.607 -    public void drawPixelMap(ImageData pixelMap, double x, double y){
   1.608 -        graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y);
   1.609 -    }
   1.610 -
   1.611 -    public void drawPixelMap(ImageData pixelMap, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight){
   1.612 -        graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
   1.613 -    }
   1.614 -
   1.615 -    public void setGlobalAlpha(double alpha){
   1.616 +//    public ImageData createPixelMap(double x, double y) {
   1.617 +//        return graphicsEnvironmentImpl.createPixelMap(x, y);
   1.618 +//    }
   1.619 +//
   1.620 +//    public ImageData createPixelMap(ImageData pixelMap) {
   1.621 +//        return graphicsEnvironmentImpl.createPixelMap(pixelMap);
   1.622 +//    }
   1.623 +//
   1.624 +//    public ImageData getSnapshot(double x, double y, double width, double height) {
   1.625 +//        return graphicsEnvironmentImpl.getPixelMap(x, y, width, height);
   1.626 +//    }
   1.627 +//
   1.628 +//    public void drawPixelMap(ImageData pixelMap, double x, double y) {
   1.629 +//        graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y);
   1.630 +//    }
   1.631 +//
   1.632 +//    public void drawPixelMap(ImageData pixelMap, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
   1.633 +//        graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
   1.634 +//    }
   1.635 +    /**
   1.636 +     * Sets the global alpha of the current state.
   1.637 +     *
   1.638 +     * @param alpha value in the range {@code 0.0-1.0}. The value is clamped if
   1.639 +     * it is out of range.
   1.640 +     */
   1.641 +    public void setGlobalAlpha(double alpha) {
   1.642          graphicsEnvironmentImpl.setGlobalAlpha(alpha);
   1.643      }
   1.644  
   1.645 -    public double getGlobalAlpha(){
   1.646 +    /**
   1.647 +     * Gets the current global alpha.
   1.648 +     *
   1.649 +     * @return the current global alpha.
   1.650 +     */
   1.651 +    public double getGlobalAlpha() {
   1.652          return graphicsEnvironmentImpl.getGlobalAlpha();
   1.653      }
   1.654  
   1.655 -    public void setGlobalCompositeOperation(String operation){
   1.656 +    /**
   1.657 +     * Sets the global blend mode.
   1.658 +     *
   1.659 +     * @param op the BlendMode that will be set.
   1.660 +     */
   1.661 +    public void setGlobalCompositeOperation(String operation) {
   1.662          graphicsEnvironmentImpl.setGlobalCompositeOperation(operation);
   1.663      }
   1.664  
   1.665 -    public String getGlobalCompositeOperation(){
   1.666 +    /**
   1.667 +     * Gets the global blend mode.
   1.668 +     *
   1.669 +     * @return the global BlendMode of the current state.
   1.670 +     */
   1.671 +    public String getGlobalCompositeOperation() {
   1.672          return graphicsEnvironmentImpl.getGlobalCompositeOperation();
   1.673      }
   1.674  
   1.675 -    public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1){
   1.676 +    public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
   1.677          return new Style.LinearGradient(x0, y0, x1, y1);
   1.678      }
   1.679  
   1.680 -    public Pattern createPattern(Image image, String repeat){
   1.681 +    public Pattern createPattern(Image image, String repeat) {
   1.682          return new Pattern(image, repeat);
   1.683      }
   1.684  
   1.685 -    public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1){
   1.686 +    public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
   1.687          return new RadialGradient(x0, y0, r0, x1, y1, r1);
   1.688      }
   1.689 -    
   1.690 -    public Color getWebColor(String webColor){
   1.691 +
   1.692 +    public Color getWebColor(String webColor) {
   1.693          return new Style.Color(webColor);
   1.694      }
   1.695  
   1.696 -    public int getHeight(){
   1.697 +    /**
   1.698 +     * Get the height of this GraphicsContext (which should be the same as the
   1.699 +     * enclosing canvas height)
   1.700 +     *
   1.701 +     * @return the height of this GraphicsContext
   1.702 +     */
   1.703 +    public int getHeight() {
   1.704          return graphicsEnvironmentImpl.getHeight();
   1.705      }
   1.706  
   1.707 -    public int getWidth(){
   1.708 +    /**
   1.709 +     * Get the width of this GraphicsContext (which should be the same as the
   1.710 +     * enclosing canvas height)
   1.711 +     *
   1.712 +     * @return the width of this GraphicsContext
   1.713 +     */
   1.714 +    public int getWidth() {
   1.715          return graphicsEnvironmentImpl.getWidth();
   1.716      }
   1.717  
   1.718 -    public void setHeight(int height){
   1.719 -        graphicsEnvironmentImpl.setHeight(height);
   1.720 +//    public void setHeight(int height) {
   1.721 +//        graphicsEnvironmentImpl.setHeight(height);
   1.722 +//    }
   1.723 +//
   1.724 +//    public void setWidth(int width) {
   1.725 +//        graphicsEnvironmentImpl.setWidth(width);
   1.726 +//    }
   1.727 +    /**
   1.728 +     * Fill a circle with a center position of centerX, centerY and the
   1.729 +     * specified radius.
   1.730 +     *
   1.731 +     * @param centerX
   1.732 +     * @param centerY
   1.733 +     * @param radius
   1.734 +     */
   1.735 +    public void fillCircle(float centerX, float centerY, float radius) {
   1.736 +        graphicsEnvironmentImpl.arc(centerX, centerY, radius, 0, Math.PI * 2, false);
   1.737      }
   1.738  
   1.739 -    public void setWidth(int width){
   1.740 -        graphicsEnvironmentImpl.setWidth(width);
   1.741 -    }
   1.742 -
   1.743 -    public void fillCircle(float centerX, float centerY, float radius) {
   1.744 -        graphicsEnvironmentImpl.arc(centerX, centerY, radius, 0, Math.PI*2, false);
   1.745 -    }
   1.746 -
   1.747 +    /**
   1.748 +     * Fills a polygon with the given points using the currently set fill paint.
   1.749 +     *
   1.750 +     * @param x_coord array containing the x coordinates of the polygon's
   1.751 +     * points.
   1.752 +     * @param y_coord array containing the y coordinates of the polygon's
   1.753 +     * points.
   1.754 +     * @param vertexCount the number of points that make the polygon.
   1.755 +     */
   1.756      public void fillPolygon(double[] x_coord, double[] y_coord, int vertexCount) {
   1.757 -        if (vertexCount >=1&&x_coord!=null && x_coord.length>=vertexCount && y_coord!=null && y_coord.length>=vertexCount)
   1.758 -        graphicsEnvironmentImpl.beginPath();
   1.759 +        if (vertexCount >= 1 && x_coord != null && x_coord.length >= vertexCount && y_coord != null && y_coord.length >= vertexCount) {
   1.760 +            graphicsEnvironmentImpl.beginPath();
   1.761 +        }
   1.762          graphicsEnvironmentImpl.moveTo(x_coord[0], y_coord[0]);
   1.763          for (int i = 1; i < vertexCount; i++) {
   1.764              graphicsEnvironmentImpl.lineTo(x_coord[i], y_coord[i]);
   1.765 -            
   1.766 +
   1.767          }
   1.768          graphicsEnvironmentImpl.closePath();
   1.769          graphicsEnvironmentImpl.fill();
   1.770          graphicsEnvironmentImpl.stroke();
   1.771 -        
   1.772 -        
   1.773      }
   1.774  }