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