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