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