javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java
author Anton Epple <toni.epple@eppleton.de>
Mon, 27 May 2013 08:30:18 +0200
branchcanvas
changeset 1144 5bf850c5b7f1
parent 1141 69c81bdaf193
child 1150 42e29ceb8371
permissions -rw-r--r--
Readded Image and ImageData to have the complete API again. No need to use Data in API anymore. Added caching to Image. Image are not required to be added to the page anymore, but are created in javaScript instead.
     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.spi.GraphicsEnvironment;
    21 
    22 /**
    23  *
    24  * @author antonepple
    25  */
    26 public final class GraphicsContext {
    27 
    28     GraphicsEnvironment graphicsEnvironmentImpl;
    29 
    30     public GraphicsContext(GraphicsEnvironment graphicsEnvironment) {
    31         this.graphicsEnvironmentImpl = graphicsEnvironment;
    32     }
    33 
    34     public void arc(double centerX,
    35             double centerY,
    36             double startAngle,
    37             double radius,
    38             double endAngle,
    39             boolean ccw) {
    40         graphicsEnvironmentImpl.arc(centerX, centerY, startAngle, radius, endAngle, ccw);
    41     }
    42 
    43     public void arcTo(double x1,
    44             double y1,
    45             double x2,
    46             double y2,
    47             double r) {
    48         graphicsEnvironmentImpl.arcTo(x1, y1, x2, y2, r);
    49     }
    50 
    51     public boolean isPointInPath(double x, double y) {
    52         return graphicsEnvironmentImpl.isPointInPath(x, y);
    53     }
    54 
    55     public void fill() {
    56         graphicsEnvironmentImpl.fill();
    57     }
    58 
    59     public void stroke() {
    60         graphicsEnvironmentImpl.stroke();
    61     }
    62 
    63     public void beginPath() {
    64         graphicsEnvironmentImpl.beginPath();
    65     }
    66 
    67     public void closePath(){
    68         graphicsEnvironmentImpl.closePath();
    69     }
    70 
    71     public void clip(){
    72         graphicsEnvironmentImpl.clip();
    73     }
    74 
    75     public void moveTo(double x, double y){
    76         graphicsEnvironmentImpl.moveTo(x, y);
    77     }
    78 
    79     public void lineTo(double x, double y){
    80         graphicsEnvironmentImpl.lineTo(x, y);
    81     }
    82 
    83     public void quadraticCurveTo(double cpx, double cpy, double x, double y){
    84     graphicsEnvironmentImpl.quadraticCurveTo(cpx, cpy, x, y);
    85     }
    86 
    87     public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y){
    88         graphicsEnvironmentImpl.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
    89     }
    90 
    91     public void fillRect(double x, double y, double width, double height){
    92         graphicsEnvironmentImpl.fillRect(x, y, width, height);
    93     }
    94 
    95     public void strokeRect(double x, double y, double width, double height){
    96     graphicsEnvironmentImpl.strokeRect(x, y, width, height);
    97     }
    98 
    99     public void clearRect(double x, double y, double width, double height){
   100         graphicsEnvironmentImpl.clearRect(x, y, width, height);
   101     }
   102 
   103     public void rect(double x, double y, double width, double height){
   104         graphicsEnvironmentImpl.rect(x, y, width, height);
   105     }
   106 
   107     public void save(){
   108         graphicsEnvironmentImpl.save();
   109     }
   110 
   111     public void restore(){
   112         graphicsEnvironmentImpl.restore();
   113     }
   114 
   115     public void rotate(double angle){
   116         graphicsEnvironmentImpl.rotate(angle);
   117     }
   118 
   119     public void transform(double a, double b, double c, double d, double e, double f){
   120         graphicsEnvironmentImpl.transform(a, b, c, d, e, f);
   121     }
   122 
   123     public void setTransform(double a, double b, double c, double d, double e, double f){
   124         graphicsEnvironmentImpl.setTransform(a, b, c, d, e, f);
   125     }
   126 
   127     public void translate(double x, double y){
   128         graphicsEnvironmentImpl.translate(x, y);
   129     }
   130 
   131     public void scale(double x, double y){
   132         graphicsEnvironmentImpl.scale(x, y);
   133     }
   134 
   135     public void paintImage(Image image, double x, double y){
   136         Object nativeImage = graphicsEnvironmentImpl.drawImage(image, x, y, image.getCached());
   137         image.cache(nativeImage);
   138     }
   139 
   140     public void paintImage(Image image, double x, double y, double width, double height){
   141         Object nativeImage = graphicsEnvironmentImpl.drawImage(image, x, y, width, height, image.getCached());
   142         image.cache(nativeImage);
   143     }
   144 
   145     public void paintImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height){
   146         Object nativeImage = graphicsEnvironmentImpl.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height, image.getCached());
   147         image.cache(nativeImage);
   148     }
   149 
   150     public void setShadowColor(String color){
   151         graphicsEnvironmentImpl.setShadowColor(color);
   152     }
   153 
   154     public void setShadowBlur(double blur){
   155         graphicsEnvironmentImpl.setShadowBlur(blur);
   156     }
   157 
   158     public void setShadowOffsetX(double x){
   159         graphicsEnvironmentImpl.setShadowOffsetX(x);
   160     }
   161 
   162     public void setShadowOffsetY(double y){
   163         graphicsEnvironmentImpl.setShadowOffsetY(y);
   164     }
   165 
   166     public String getShadowColor(){
   167         return graphicsEnvironmentImpl.getShadowColor();
   168     }
   169 
   170     public double getShadowBlur(){
   171         return graphicsEnvironmentImpl.getShadowBlur();
   172         }
   173 
   174     public double getShadowOffsetX(){
   175         return graphicsEnvironmentImpl.getShadowOffsetX();
   176     }
   177 
   178     public double getShadowOffsetY(){
   179         return graphicsEnvironmentImpl.getShadowOffsetY();
   180     }
   181 
   182     public String getLineCap(){
   183         return graphicsEnvironmentImpl.getLineCap();
   184     }
   185 
   186     public void setLineCap(String style){
   187         graphicsEnvironmentImpl.setLineCap(style);
   188     }
   189 
   190     public String getLineJoin(){
   191         return graphicsEnvironmentImpl.getLineJoin();
   192     }
   193 
   194     public void setLineJoin(String style){
   195         graphicsEnvironmentImpl.setLineJoin(style);
   196     }
   197 
   198     public double getLineWidth(){
   199         return graphicsEnvironmentImpl.getLineWidth();
   200     }
   201 
   202     public void setLineWidth(double width){
   203         graphicsEnvironmentImpl.setLineWidth(width);
   204     }
   205 
   206     public double getMiterLimit(){
   207         return graphicsEnvironmentImpl.getMiterLimit();
   208     }
   209 
   210     public void setMiterLimit(double limit){
   211         graphicsEnvironmentImpl.setMiterLimit(limit);
   212     }
   213     
   214     public void setFillStyle(Style style){
   215         Object nativeFillStyle = graphicsEnvironmentImpl.setFillStyle(style, style.getCached());
   216         style.cache(nativeFillStyle);
   217     }
   218 
   219     public String getFont(){
   220         return graphicsEnvironmentImpl.getFont();
   221     }
   222 
   223     public void setFont(String font){
   224         graphicsEnvironmentImpl.setFont(font);
   225     }
   226     
   227     public void setStrokeStyle(Style style){
   228         Object nativeStrokeStyle = graphicsEnvironmentImpl.setStrokeStyle(style, style.getCached());
   229         style.cache(nativeStrokeStyle);
   230     }
   231 
   232     public String getTextAlign(){
   233         return graphicsEnvironmentImpl.getTextAlign();
   234     }
   235 
   236     public void setTextAlign(String textAlign){
   237         graphicsEnvironmentImpl.setTextAlign(textAlign);
   238     }
   239 
   240     public String getTextBaseline(){
   241         return graphicsEnvironmentImpl.getTextBaseline();
   242     }
   243 
   244     public void setTextBaseline(String textbaseline){
   245         graphicsEnvironmentImpl.setTextBaseline(textbaseline);
   246     }
   247 
   248     public void fillText(String text, double x, double y){
   249         graphicsEnvironmentImpl.fillText(text, x, y);
   250     }
   251 
   252     public void fillText(String text, double x, double y, double maxWidth){
   253         graphicsEnvironmentImpl.fillText(text, x, y, maxWidth);
   254     }
   255 
   256     public Dimension measureText(String text){
   257         return graphicsEnvironmentImpl.measureText(text);
   258     }
   259 
   260     public void strokeText(String text, double x, double y){
   261         graphicsEnvironmentImpl.strokeText(text, x, y);
   262     }
   263 
   264     public void strokeText(String text, double x, double y, double maxWidth){
   265         graphicsEnvironmentImpl.strokeText(text, x, y, maxWidth);
   266     }
   267 
   268     public ImageData createPixelMap(double x, double y){
   269         return graphicsEnvironmentImpl.createPixelMap(x, y);
   270     }
   271 
   272     public ImageData createPixelMap(ImageData pixelMap){
   273         return graphicsEnvironmentImpl.createPixelMap(pixelMap);
   274     }
   275 
   276     public ImageData getSnapshot(double x, double y, double width, double height){
   277         return graphicsEnvironmentImpl.getPixelMap(x, y, width, height);
   278     }
   279 
   280     public void paintPixelMap(ImageData pixelMap, double x, double y){
   281         graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y);
   282     }
   283 
   284     public void paintPixelMap(ImageData pixelMap, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight){
   285         graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
   286     }
   287 
   288     public void setGlobalAlpha(double alpha){
   289         graphicsEnvironmentImpl.setGlobalAlpha(alpha);
   290     }
   291 
   292     public double getGlobalAlpha(){
   293         return graphicsEnvironmentImpl.getGlobalAlpha();
   294     }
   295 
   296     public void setGlobalCompositeOperation(String operation){
   297         graphicsEnvironmentImpl.setGlobalCompositeOperation(operation);
   298     }
   299 
   300     public String getGlobalCompositeOperation(){
   301         return graphicsEnvironmentImpl.getGlobalCompositeOperation();
   302     }
   303 
   304     public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1){
   305         return new LinearGradient(x0, y0, x1, y1);
   306     }
   307 
   308     public Pattern createPattern(Image image, String repeat){
   309         return new Pattern(image, repeat);
   310     }
   311 
   312     public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1){
   313         return new RadialGradient(x0, y0, r0, x1, y1, r1);
   314     }
   315 
   316     public Image getImageForPath(String path){
   317         return graphicsEnvironmentImpl.getImageForPath(path);
   318     }
   319 
   320     public int getHeight(){
   321         return graphicsEnvironmentImpl.getHeight();
   322     }
   323 
   324     public int getWidth(){
   325         return graphicsEnvironmentImpl.getWidth();
   326     }
   327 
   328     public void setHeight(int height){
   329         graphicsEnvironmentImpl.setHeight(height);
   330     }
   331 
   332     public void setWidth(int width){
   333         graphicsEnvironmentImpl.setWidth(width);
   334     }
   335 }