javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java
author Anton Epple <toni.epple@eppleton.de>
Wed, 12 Feb 2014 09:14:20 +0100
branchcanvas
changeset 1447 3e3fb431d2b7
parent 1444 8cb57e6c7012
child 1449 6be5961e27ee
permissions -rw-r--r--
More JavaDoc improvements.
     1 /**
     2  * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
     3  * <jaroslav.tulach@apidesign.org>
     4  *
     5  * This program is free software: you can redistribute it and/or modify it under
     6  * the terms of the GNU General Public License as published by the Free Software
     7  * Foundation, version 2 of the License.
     8  *
     9  * This program is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    12  * details.
    13  *
    14  * You should have received a copy of the GNU General Public License along with
    15  * this program. Look for COPYING file in the top folder. If not, see
    16  * http://opensource.org/licenses/GPL-2.0.
    17  */
    18 package net.java.html.canvas;
    19 
    20 import net.java.html.canvas.Style.Color;
    21 import net.java.html.canvas.Style.LinearGradient;
    22 import net.java.html.canvas.Style.Pattern;
    23 import net.java.html.canvas.Style.RadialGradient;
    24 import net.java.html.canvas.spi.GraphicsEnvironment;
    25 import org.apidesign.html.canvas.impl.CnvsAccssr;
    26 
    27 /**
    28  * A 2D Graphics Context similar to HTML5 or JavaFX GraphicsContext. Use this to
    29  * paint on your Canvas
    30  *
    31  * @author antonepple
    32  */
    33 public final class GraphicsContext {
    34 
    35     public static void getAccssr() {
    36         // do nothing we need this in order to have the class loaded and static 
    37         // block executed for CnvsAccssr.
    38     }
    39 
    40     GraphicsEnvironment graphicsEnvironmentImpl;
    41 
    42     static {
    43         CnvsAccssr cnvsAccssr = new CnvsAccssr() {
    44             @Override
    45             public GraphicsContext create(GraphicsEnvironment environment) {
    46                 return new GraphicsContext(environment);
    47             }
    48         };
    49     }
    50 
    51     GraphicsContext(GraphicsEnvironment graphicsEnvironment) {
    52         this.graphicsEnvironmentImpl = graphicsEnvironment;
    53     }
    54 
    55     /**
    56      * Adds path elements to the current path to make an arc.
    57      *
    58      * @param centerX the center x position of the arc.
    59      * @param centerY the center y position of the arc.
    60      * @param startAngle the startAngle of the arc
    61      * @param radius the radius of the arc.
    62      * @param endAngle the endAngle of the arc
    63      * @param ccw the direction of the arc (counterclockwise)
    64      */
    65     public void arc(double centerX,
    66             double centerY,
    67             double startAngle,
    68             double radius,
    69             double endAngle,
    70             boolean ccw) {
    71         graphicsEnvironmentImpl.arc(centerX, centerY, startAngle, radius, endAngle, ccw);
    72     }
    73 
    74     /**
    75      * Adds segments to the current path to make an arc.
    76      *
    77      * @param x1 the X coordinate of the first point of the arc.
    78      * @param y1 the Y coordinate of the first point of the arc.
    79      * @param x2 the X coordinate of the second point of the arc.
    80      * @param y2 the Y coordinate of the second point of the arc.
    81      * @param radius the radius of the arc in the range {0.0-positive infinity}.
    82      */
    83     public void arcTo(double x1,
    84             double y1,
    85             double x2,
    86             double y2,
    87             double radius) {
    88         graphicsEnvironmentImpl.arcTo(x1, y1, x2, y2, radius);
    89     }
    90 
    91     /**
    92      * Returns true if the the given x,y point is inside the path.
    93      *
    94      * @param x the X coordinate to use for the check.
    95      * @param y the Y coordinate to use for the check.
    96      * @return true if the point given is inside the path, false otherwise.
    97      */
    98     public boolean isPointInPath(double x, double y) {
    99         return graphicsEnvironmentImpl.isPointInPath(x, y);
   100     }
   101 
   102     /**
   103      * Fills the path with the current fill paint.
   104      */
   105     public void fill() {
   106         graphicsEnvironmentImpl.fill();
   107     }
   108 
   109     /**
   110      * Strokes the path with the current stroke paint.
   111      */
   112     public void stroke() {
   113         graphicsEnvironmentImpl.stroke();
   114     }
   115 
   116     /**
   117      * Starts a Path
   118      */
   119     public void beginPath() {
   120         graphicsEnvironmentImpl.beginPath();
   121     }
   122 
   123     /**
   124      * Closes the path.
   125      */
   126     public void closePath() {
   127         graphicsEnvironmentImpl.closePath();
   128     }
   129 
   130     /**
   131      * Clips using the current path
   132      */
   133     public void clip() {
   134         graphicsEnvironmentImpl.clip();
   135     }
   136 
   137     /**
   138      * Issues a move command for the current path to the given x,y coordinate.
   139      *
   140      * @param x0 the X position for the move to command.
   141      * @param y0 the Y position for the move to command.
   142      */
   143     public void moveTo(double x, double y) {
   144         graphicsEnvironmentImpl.moveTo(x, y);
   145     }
   146 
   147     /**
   148      * Adds segments to the current path to make a line at the given x,y
   149      * coordinate.
   150      *
   151      * @param x1 the X coordinate of the ending point of the line.
   152      * @param y1 the Y coordinate of the ending point of the line.
   153      */
   154     public void lineTo(double x, double y) {
   155         graphicsEnvironmentImpl.lineTo(x, y);
   156     }
   157 
   158     /**
   159      * Adds segments to the current path to make a quadratic curve.
   160      *
   161      * @param cpx the X coordinate of the control point
   162      * @param cpy the Y coordinate of the control point
   163      * @param x the X coordinate of the end point
   164      * @param y the Y coordinate of the end point
   165      */
   166     public void quadraticCurveTo(double cpx, double cpy, double x, double y) {
   167         graphicsEnvironmentImpl.quadraticCurveTo(cpx, cpy, x, y);
   168     }
   169 
   170     /**
   171      * Adds segments to the current path to make a cubic bezier curve.
   172      *
   173      * @param cp1x the X coordinate of first bezier control point.
   174      * @param cp1y the Y coordinate of the first bezier control point.
   175      * @param cp2x the X coordinate of the second bezier control point.
   176      * @param cp2y the Y coordinate of the second bezier control point.
   177      * @param x the X coordinate of the end point.
   178      * @param y the Y coordinate of the end point.
   179      */
   180     public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y) {
   181         graphicsEnvironmentImpl.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
   182     }
   183 
   184     /**
   185      * Fills a rectangle using the current fill paint.
   186      *
   187      * @param x the X position of the upper left corner of the rectangle.
   188      * @param y the Y position of the upper left corner of the rectangle.
   189      * @param width the width of the rectangle.
   190      * @param height  the height of the rectangle.
   191      */
   192     public void fillRect(double x, double y, double width, double height) {
   193         graphicsEnvironmentImpl.fillRect(x, y, width, height);
   194     }
   195 
   196     /**
   197      * Strokes a rectangle using the current stroke paint.
   198      *
   199      * @param x the X position of the upper left corner of the rectangle.
   200      * @param y the Y position of the upper left corner of the rectangle.
   201      * @param width the width of the rectangle.
   202      * @param height the height of the rectangle.
   203      */
   204     public void strokeRect(double x, double y, double width, double height) {
   205         graphicsEnvironmentImpl.strokeRect(x, y, width, height);
   206     }
   207 
   208     /**
   209      * Clears a portion of the canvas with a transparent color value.
   210      *
   211      * @param x X position of the upper left corner of the rectangle.
   212      * @param y Y position of the upper left corner of the rectangle.
   213      * @param width width of the rectangle.
   214      * @param height height of the rectangle.
   215      */
   216     public void clearRect(double x, double y, double width, double height) {
   217         graphicsEnvironmentImpl.clearRect(x, y, width, height);
   218     }
   219 
   220     /**
   221      * Clears a portion of the canvas with a transparent color value.
   222      *
   223      * @param x X position of the upper left corner of the rectangle.
   224      * @param y Y position of the upper left corner of the rectangle.
   225      * @param width width of the rectangle.
   226      * @param height height of the rectangle.
   227      */
   228     public void rect(double x, double y, double width, double height) {
   229         graphicsEnvironmentImpl.rect(x, y, width, height);
   230     }
   231 
   232     /**
   233      * Saves the following attributes onto a stack.
   234      * <ul>
   235      * <li>Global Alpha</li>
   236      * <li>Global Blend Operation</li>
   237      * <li>Transform</li>
   238      * <li>Fill Paint</li>
   239      * <li>Stroke Paint</li>
   240      * <li>Line Width</li>
   241      * <li>Line Cap</li>
   242      * <li>Line Join</li>
   243      * <li>Miter Limit</li>
   244      * <li>Number of Clip Paths</li>
   245      * <li>Font</li>
   246      * <li>Text Align</li>
   247      * <li>Text Baseline</li>
   248      * <li>Effect</li>
   249      * <li>Fill Rule</li>
   250      * </ul>
   251      * This method does NOT alter the current state in any way. Also, not that
   252      * the current path is not saved.
   253      */
   254     public void save() {
   255         graphicsEnvironmentImpl.save();
   256     }
   257 
   258     /**
   259      * Pops the state off of the stack, setting the following attributes to
   260      * their value at the time when that state was pushed onto the stack. If the
   261      * stack is empty then nothing is changed.
   262      *
   263      * <ul>
   264      * <li>Global Alpha</li>
   265      * <li>Global Blend Operation</li>
   266      * <li>Transform</li>
   267      * <li>Fill Paint</li>
   268      * <li>Stroke Paint</li>
   269      * <li>Line Width</li>
   270      * <li>Line Cap</li>
   271      * <li>Line Join</li>
   272      * <li>Miter Limit</li>
   273      * <li>Number of Clip Paths</li>
   274      * <li>Font</li>
   275      * <li>Text Align</li>
   276      * <li>Text Baseline</li>
   277      * <li>Effect</li>
   278      * <li>Fill Rule</li>
   279      * </ul>
   280      */
   281     public void restore() {
   282         graphicsEnvironmentImpl.restore();
   283     }
   284 
   285     /**
   286      * Rotates the current transform in degrees.
   287      *
   288      * @param angle value in degrees to rotate the current transform.
   289      */
   290     public void rotate(double angle) {
   291         graphicsEnvironmentImpl.rotate(angle);
   292     }
   293 
   294     /**
   295      * Concatenates the input with the current transform.
   296      *
   297      * @param mxx - the X coordinate scaling element of the 3x4 matrix
   298      * @param myx - the Y coordinate shearing element of the 3x4 matrix
   299      * @param mxy - the X coordinate shearing element of the 3x4 matrix
   300      * @param myy - the Y coordinate scaling element of the 3x4 matrix
   301      * @param mxt - the X coordinate translation element of the 3x4 matrix
   302      * @param myt - the Y coordinate translation element of the 3x4 matrix
   303      */
   304     public void transform(double mxx, double myx, double mxy, double myy, double mxt, double myt) {
   305         graphicsEnvironmentImpl.transform(mxx, myx, mxy, myy, mxt, myt);
   306     }
   307 
   308     /**
   309      * Concatenates the input with the current transform.
   310      *
   311      * @param mxx - the X coordinate scaling element of the 3x4 matrix
   312      * @param myx - the Y coordinate shearing element of the 3x4 matrix
   313      * @param mxy - the X coordinate shearing element of the 3x4 matrix
   314      * @param myy - the Y coordinate scaling element of the 3x4 matrix
   315      * @param mxt - the X coordinate translation element of the 3x4 matrix
   316      * @param myt - the Y coordinate translation element of the 3x4 matrix
   317      */
   318     public void setTransform(double mxx, double myx, double mxy, double myy, double mxt, double myt) {
   319         graphicsEnvironmentImpl.setTransform(mxx, myx, mxy, myy, mxt, myt);
   320     }
   321 
   322     /**
   323      * Translates the current transform by x, y.
   324      *
   325      * @param x value to translate along the x axis.
   326      * @param y value to translate along the y axis.
   327      */
   328     public void translate(double x, double y) {
   329         graphicsEnvironmentImpl.translate(x, y);
   330     }
   331 
   332     /**
   333      * Scales the current transform by x, y.
   334      *
   335      * @param x value to scale in the x axis.
   336      * @param y value to scale in the y axis.
   337      */
   338     public void scale(double x, double y) {
   339         graphicsEnvironmentImpl.scale(x, y);
   340     }
   341 
   342     /**
   343      * Draws an image at the given x, y position using the width and height of
   344      * the given image.
   345      *
   346      * @param image  the image to be drawn.
   347      * @param x the X coordinate on the destination for the upper left of the
   348      * image.
   349      * @param y the Y coordinate on the destination for the upper left of the
   350      * image.
   351      */
   352     public void drawImage(Image image, double x, double y) {
   353         Object nativeImage = graphicsEnvironmentImpl.drawImage(image, x, y, image.getCached());
   354         image.cache(nativeImage);
   355     }
   356 
   357     /**
   358      * Draws an image into the given destination rectangle of the canvas. The
   359      * Image is scaled to fit into the destination rectagnle.
   360      *
   361      * @param image  the image to be drawn.
   362      * @param x the X coordinate on the destination for the upper left of the
   363      * image.
   364      * @param y the Y coordinate on the destination for the upper left of the
   365      * image.
   366      * @param width the width of the destination rectangle.
   367      * @param height the height of the destination rectangle.
   368      */
   369     public void drawImage(Image image, double x, double y, double width, double height) {
   370         Object nativeImage = graphicsEnvironmentImpl.drawImage(image, x, y, width, height, image.getCached());
   371         image.cache(nativeImage);
   372     }
   373 
   374     /**
   375      * Draws the current source rectangle of the given image to the given
   376      * destination rectangle of the Canvas.
   377      *
   378      * @param image  the image to be drawn.
   379      * @param sx the source rectangle's X coordinate position.
   380      * @param sy the source rectangle's Y coordinate position.
   381      * @param sw the source rectangle's width.
   382      * @param sh the source rectangle's height.
   383      * @param dx the destination rectangle's X coordinate position.
   384      * @param dy the destination rectangle's Y coordinate position.
   385      * @param dw the destination rectangle's width.
   386      * @param dh the destination rectangle's height.
   387      */
   388     public void drawImage(Image image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh) {
   389         Object nativeImage = graphicsEnvironmentImpl.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh, image.getCached());
   390         image.cache(nativeImage);
   391     }
   392 
   393     /**
   394      * Merges two images drawing one on top of the other and returning the
   395      * result.
   396      *
   397      * @param a the lower Image
   398      * @param b the upper Image
   399      * @return
   400      */
   401     public Image merge(Image a, Image b) {
   402         if (a.getCached() == null) {
   403             drawImage(a, 0, 0);
   404         }
   405         if (b.getCached() == null) {
   406             drawImage(b, 0, 0);
   407         }
   408         Object nativeImage = graphicsEnvironmentImpl.mergeImages(a, b, a.getCached(), b.getCached());
   409         Image merged = Image.create("should add real path here");
   410         merged.cache(nativeImage);
   411         return merged;
   412     }
   413 
   414 //    public void setShadowColor(String color) {
   415 //        graphicsEnvironmentImpl.setShadowColor(color);
   416 //    }
   417 //
   418 //    public void setShadowBlur(double blur) {
   419 //        graphicsEnvironmentImpl.setShadowBlur(blur);
   420 //    }
   421 //
   422 //    public void setShadowOffsetX(double x) {
   423 //        graphicsEnvironmentImpl.setShadowOffsetX(x);
   424 //    }
   425 //
   426 //    public void setShadowOffsetY(double y) {
   427 //        graphicsEnvironmentImpl.setShadowOffsetY(y);
   428 //    }
   429 //
   430 //    public String getShadowColor() {
   431 //        return graphicsEnvironmentImpl.getShadowColor();
   432 //    }
   433 //
   434 //    public double getShadowBlur() {
   435 //        return graphicsEnvironmentImpl.getShadowBlur();
   436 //    }
   437 //
   438 //    public double getShadowOffsetX() {
   439 //        return graphicsEnvironmentImpl.getShadowOffsetX();
   440 //    }
   441 //
   442 //    public double getShadowOffsetY() {
   443 //        return graphicsEnvironmentImpl.getShadowOffsetY();
   444 //    }
   445     
   446     /**
   447      * Gets the current stroke line cap attribute. 
   448      * 
   449      * @return  a value of butt, round, or square.
   450      */    
   451     public String getLineCap() {
   452         return graphicsEnvironmentImpl.getLineCap();
   453     }
   454     
   455     /**
   456      * Sets the current stroke line cap attribute.
   457      * 
   458      * @param style  a value of miter, bevel, or round.
   459      */
   460     public void setLineCap(String style) {
   461         graphicsEnvironmentImpl.setLineCap(style);
   462     }
   463 
   464     /**
   465      * Gets the current stroke line join attribute.
   466      *
   467      * @return  a value of miter, bevel, or round.
   468      */
   469     public String getLineJoin() {
   470         return graphicsEnvironmentImpl.getLineJoin();
   471     }
   472 
   473     /**
   474      * Sets the current stroke line join attribute.
   475      *
   476      * @param style  a value of miter, bevel, or
   477      * round.
   478      */
   479     public void setLineJoin(String style) {
   480         graphicsEnvironmentImpl.setLineJoin(style);
   481     }
   482 
   483     /**
   484      * Gets the current line width attribute.
   485      *
   486      * @return value between 0 and infinity, with any other value being ignored
   487      * and leaving the value unchanged.
   488      *
   489      */
   490     public double getLineWidth() {
   491         return graphicsEnvironmentImpl.getLineWidth();
   492     }
   493 
   494     /**
   495      * Sets the current line width attribute.
   496      *
   497      * @param lw value between 0 and infinity, with any other value being
   498      * ignored and leaving the value unchanged.
   499      *
   500      */
   501     public void setLineWidth(double width) {
   502         graphicsEnvironmentImpl.setLineWidth(width);
   503     }
   504 
   505     /**
   506      * Gets the current miter limit attribute.
   507      *
   508      * @return limit value between 0 and positive infinity with any other value
   509      * being ignored and leaving the value unchanged.
   510      */
   511     public double getMiterLimit() {
   512         return graphicsEnvironmentImpl.getMiterLimit();
   513     }
   514 
   515     /**
   516      * Sets the current miter limit attribute.
   517      *
   518      * @param ml miter limit value between 0 and positive infinity with any
   519      * other value being ignored and leaving the value unchanged.
   520      */
   521     public void setMiterLimit(double limit) {
   522         graphicsEnvironmentImpl.setMiterLimit(limit);
   523     }
   524 
   525     /**
   526      * Sets the fill style. Will be used when rendering something, e.g. calling
   527      * one of the fillText Methods.
   528      *
   529      * @param style
   530      */
   531     public void setFillStyle(Style style) {
   532         Object nativeFillStyle = graphicsEnvironmentImpl.setFillStyle(style, style.getCached());
   533         style.cache(nativeFillStyle);
   534     }
   535 
   536     /**
   537      * get the current font
   538      *
   539      * @return current Font. of the fillText Methods.
   540      */
   541     public String getFont() {
   542         return graphicsEnvironmentImpl.getFont();
   543     }
   544 
   545     /**
   546      * Set the Font. Will be used when rendering Text, e.g. by calling one of
   547      * the fillText Methods.
   548      *
   549      * @param font
   550      */
   551     public void setFont(String font) {
   552         graphicsEnvironmentImpl.setFont(font);
   553     }
   554 
   555     /**
   556      * sets the Style of the Stroke.
   557      *
   558      * @param style
   559      */
   560     public void setStrokeStyle(Style style) {
   561         Object nativeStrokeStyle = graphicsEnvironmentImpl.setStrokeStyle(style, style.getCached());
   562         style.cache(nativeStrokeStyle);
   563     }
   564 
   565     /**
   566      * Gets the current TextAlignment attribute
   567      *
   568      * @return TextAlignment with values of left, center, right, or justify.
   569      */
   570     public String getTextAlign() {
   571         return graphicsEnvironmentImpl.getTextAlign();
   572     }
   573 
   574     /**
   575      * Defines horizontal text alignment, relative to the text {@code x} origin.
   576      * <p>
   577      * Let horizontal bounds represent the logical width of a single line of
   578      * text. Where each line of text has a separate horizontal bounds.
   579      * <p>
   580      * Then TextAlignment is specified as:
   581      * <ul>
   582      * <li>left: the left edge of the horizontal bounds will be at {@code x}.
   583      * <li>center: the center, halfway between left and right edge, of the
   584      * horizontal bounds will be at {@code x}.
   585      * <li>right: the right edge of the horizontal bounds will be at {@code x}.
   586      * </ul>
   587      * <p>
   588      *
   589      * Note: Canvas does not support line wrapping, therefore the text alignment
   590      * Justify is identical to left aligned text.
   591      * <p>
   592      *
   593      * @param textAlign with values of left, center, right.
   594      */
   595     public void setTextAlign(String textAlign) {
   596         graphicsEnvironmentImpl.setTextAlign(textAlign);
   597     }
   598 
   599     /**
   600      * Gets the current Text Baseline attribute.
   601      *
   602      * @return baseline with values of top, center, baseline, or bottom
   603      */
   604     public String getTextBaseline() {
   605         return graphicsEnvironmentImpl.getTextBaseline();
   606     }
   607 
   608     /**
   609      * Sets the current Text Baseline attribute.
   610      *
   611      * @param baseline with values of top, center, baseline, or bottom
   612      */
   613     public void setTextBaseline(String textbaseline) {
   614         graphicsEnvironmentImpl.setTextBaseline(textbaseline);
   615     }
   616 
   617     /**
   618      * Renders the indicated String with current fill. default is black.
   619      *
   620      * @param text the text to stroke
   621      * @param x x coordinate of start position
   622      * @param y y coordinate of start position
   623      */
   624     public void fillText(String text, double x, double y) {
   625         graphicsEnvironmentImpl.fillText(text, x, y);
   626     }
   627 
   628     /**
   629      * Renders the indicated String with current fill. default is black.
   630      *
   631      * @param text the text to stroke
   632      * @param x x coordinate of start position
   633      * @param y y coordinate of start position
   634      * @param maxWidth maximum width of text
   635      */
   636     public void fillText(String text, double x, double y, double maxWidth) {
   637         graphicsEnvironmentImpl.fillText(text, x, y, maxWidth);
   638     }
   639 
   640     /**
   641      * Check the length of a text before writing it to the Canvas. Takes into
   642      * account the current Font.
   643      *
   644      * @param text the text to measure
   645      * @return the length in pixels
   646      */
   647     public Dimension measureText(String text) {
   648         return graphicsEnvironmentImpl.measureText(text);
   649     }
   650 
   651     /**
   652      * Renders the indicated String (with no fill)
   653      *
   654      * @param text the text to stroke
   655      * @param x x coordinate of start position
   656      * @param y y coordinate of start position
   657      */
   658     public void strokeText(String text, double x, double y) {
   659         graphicsEnvironmentImpl.strokeText(text, x, y);
   660     }
   661 
   662     /**
   663      * Renders the indicated String (with no fill)
   664      *
   665      * @param text the text to stroke
   666      * @param x x coordinate of start position
   667      * @param y y coordinate of start position
   668      * @param maxWidth maximum width of text
   669      */
   670     public void strokeText(String text, double x, double y, double maxWidth) {
   671         graphicsEnvironmentImpl.strokeText(text, x, y, maxWidth);
   672     }
   673 
   674 //    public ImageData createPixelMap(double x, double y) {
   675 //        return graphicsEnvironmentImpl.createPixelMap(x, y);
   676 //    }
   677 //
   678 //    public ImageData createPixelMap(ImageData pixelMap) {
   679 //        return graphicsEnvironmentImpl.createPixelMap(pixelMap);
   680 //    }
   681 //
   682 //    public ImageData getSnapshot(double x, double y, double width, double height) {
   683 //        return graphicsEnvironmentImpl.getPixelMap(x, y, width, height);
   684 //    }
   685 //
   686 //    public void drawPixelMap(ImageData pixelMap, double x, double y) {
   687 //        graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y);
   688 //    }
   689 //
   690 //    public void drawPixelMap(ImageData pixelMap, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
   691 //        graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
   692 //    }
   693     /**
   694      * Sets the global alpha of the current state.
   695      *
   696      * @param alpha value in the range {@code 0.0-1.0}. The value is clamped if
   697      * it is out of range.
   698      */
   699     public void setGlobalAlpha(double alpha) {
   700         graphicsEnvironmentImpl.setGlobalAlpha(alpha);
   701     }
   702 
   703     /**
   704      * Gets the current global alpha.
   705      *
   706      * @return the current global alpha.
   707      */
   708     public double getGlobalAlpha() {
   709         return graphicsEnvironmentImpl.getGlobalAlpha();
   710     }
   711 
   712     /**
   713      * Sets the global blend mode.
   714      *
   715      * @param op the BlendMode that will be set.
   716      */
   717     public void setGlobalCompositeOperation(String operation) {
   718         graphicsEnvironmentImpl.setGlobalCompositeOperation(operation);
   719     }
   720 
   721     /**
   722      * Gets the global blend mode.
   723      *
   724      * @return the global BlendMode of the current state.
   725      */
   726     public String getGlobalCompositeOperation() {
   727         return graphicsEnvironmentImpl.getGlobalCompositeOperation();
   728     }
   729 
   730     /**
   731      * Create a LinearGradient to use in Canvas.
   732      *
   733      * @param x0 x coordinate of start point
   734      * @param y0 y coordinate of start point
   735      * @param x1 x coordinate of end point
   736      * @param y1 y coordinate of end point
   737      * @return the gradient
   738      */
   739     public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
   740         return new Style.LinearGradient(x0, y0, x1, y1);
   741     }
   742 
   743     /**
   744      * Create an Image Pattern from a source Image and a repeat style. Possible
   745      * Styles are repeat, repeat-x, repeat-y, or no-repeat. defaults to repeat
   746      *
   747      * @param image the Image
   748      * @param repeat the repeat style
   749      * @return the Pattern
   750      */
   751     public Pattern createPattern(Image image, String repeat) {
   752         return new Pattern(image, repeat);
   753     }
   754 
   755     /**
   756      * Create a RadialGradient
   757      *
   758      * @param x0 x Coordinate of starting circle
   759      * @param y0 y Coordinate of starting circle
   760      * @param r0 radius of starting circle
   761      * @param x1 x coordinate of ending circle
   762      * @param y1 y coordinate of ending circle
   763      * @param r1 radius of ending circle
   764      * @return the Gradient
   765      */
   766     public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
   767         return new RadialGradient(x0, y0, r0, x1, y1, r1);
   768     }
   769 
   770     /**
   771      * Convert this String Representation of a Color to a Color Object.
   772      *
   773      * @param webColor
   774      * @return The Color represented by the input
   775      */
   776     public Color getWebColor(String webColor) {
   777         return new Style.Color(webColor);
   778     }
   779 
   780     /**
   781      * Get the height of this GraphicsContext (which should be the same as the
   782      * enclosing canvas height)
   783      *
   784      * @return the height of this GraphicsContext
   785      */
   786     public int getHeight() {
   787         return graphicsEnvironmentImpl.getHeight();
   788     }
   789 
   790     /**
   791      * Get the width of this GraphicsContext (which should be the same as the
   792      * enclosing canvas height)
   793      *
   794      * @return the width of this GraphicsContext
   795      */
   796     public int getWidth() {
   797         return graphicsEnvironmentImpl.getWidth();
   798     }
   799 
   800 //    public void setHeight(int height) {
   801 //        graphicsEnvironmentImpl.setHeight(height);
   802 //    }
   803 //
   804 //    public void setWidth(int width) {
   805 //        graphicsEnvironmentImpl.setWidth(width);
   806 //    }
   807     /**
   808      * Fill a circle with a center position of centerX, centerY and the
   809      * specified radius.
   810      *
   811      * @param centerX
   812      * @param centerY
   813      * @param radius
   814      */
   815     public void fillCircle(float centerX, float centerY, float radius) {
   816         graphicsEnvironmentImpl.arc(centerX, centerY, radius, 0, Math.PI * 2, false);
   817     }
   818 
   819     /**
   820      * Fills a polygon with the given points using the currently set fill paint.
   821      *
   822      * @param x_coord array containing the x coordinates of the polygon's
   823      * points.
   824      * @param y_coord array containing the y coordinates of the polygon's
   825      * points.
   826      * @param vertexCount the number of points that make the polygon.
   827      */
   828     public void fillPolygon(double[] x_coord, double[] y_coord, int vertexCount) {
   829         if (vertexCount >= 1 && x_coord != null && x_coord.length >= vertexCount && y_coord != null && y_coord.length >= vertexCount) {
   830             graphicsEnvironmentImpl.beginPath();
   831         }
   832         graphicsEnvironmentImpl.moveTo(x_coord[0], y_coord[0]);
   833         for (int i = 1; i < vertexCount; i++) {
   834             graphicsEnvironmentImpl.lineTo(x_coord[i], y_coord[i]);
   835 
   836         }
   837         graphicsEnvironmentImpl.closePath();
   838         graphicsEnvironmentImpl.fill();
   839         graphicsEnvironmentImpl.stroke();
   840     }
   841 }