Limited extensibility of Style and it's three allowed subclasses canvas
authorAnton Epple <toni.epple@eppleton.de>
Thu, 23 May 2013 09:47:20 +0200
branchcanvas
changeset 1132368626597f1a
parent 1131 dec5f4e7d031
child 1133 0ae830f00e0c
Limited extensibility of Style and it's three allowed subclasses
javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java
javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsEnvironment.java
javaquery/canvas/src/main/java/net/java/html/canvas/Image.java
javaquery/canvas/src/main/java/net/java/html/canvas/ImageData.java
javaquery/canvas/src/main/java/net/java/html/canvas/LinearGradient.java
javaquery/canvas/src/main/java/net/java/html/canvas/Pattern.java
javaquery/canvas/src/main/java/net/java/html/canvas/RadialGradient.java
javaquery/canvas/src/main/java/net/java/html/canvas/Style.java
     1.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java	Thu May 23 08:15:11 2013 +0200
     1.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java	Thu May 23 09:47:20 2013 +0200
     1.3 @@ -132,15 +132,15 @@
     1.4          graphicsEnvironmentImpl.scale(x, y);
     1.5      }
     1.6  
     1.7 -    public void drawImage(ImageData image, double x, double y){
     1.8 +    public void drawImage(Image image, double x, double y){
     1.9          graphicsEnvironmentImpl.drawImage(image, x, y);
    1.10      }
    1.11  
    1.12 -    public void drawImage(ImageData image, double x, double y, double width, double height){
    1.13 +    public void drawImage(Image image, double x, double y, double width, double height){
    1.14          graphicsEnvironmentImpl.drawImage(image, x, y, width, height);
    1.15      }
    1.16  
    1.17 -    public void drawImage(ImageData image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height){
    1.18 +    public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height){
    1.19          graphicsEnvironmentImpl.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height);
    1.20      }
    1.21  
    1.22 @@ -152,18 +152,10 @@
    1.23          return graphicsEnvironmentImpl.getFillStyle();
    1.24      }
    1.25  
    1.26 -    public void setFillStyle(Pattern style){
    1.27 -        graphicsEnvironmentImpl.setFillStyle(style);
    1.28 -    }
    1.29 -
    1.30      public void setStrokeStyle(String style){
    1.31          graphicsEnvironmentImpl.setStrokeStyle(style);
    1.32      }
    1.33  
    1.34 -    public void setStrokeStyle(Pattern style){
    1.35 -        graphicsEnvironmentImpl.setStrokeStyle(style);
    1.36 -    }
    1.37 -
    1.38      public void setShadowColor(String color){
    1.39          graphicsEnvironmentImpl.setShadowColor(color);
    1.40      }
    1.41 @@ -276,23 +268,23 @@
    1.42          graphicsEnvironmentImpl.strokeText(text, x, y, maxWidth);
    1.43      }
    1.44  
    1.45 -    public ImageData createImageData(double x, double y){
    1.46 +    public Image createImageData(double x, double y){
    1.47          return graphicsEnvironmentImpl.createImageData(x, y);
    1.48      }
    1.49  
    1.50 -    public ImageData createImageData(ImageData imageData){
    1.51 +    public Image createImageData(Image imageData){
    1.52          return graphicsEnvironmentImpl.createImageData(imageData);
    1.53      }
    1.54  
    1.55 -    public ImageData getImageData(double x, double y, double width, double height){
    1.56 +    public Image getImageData(double x, double y, double width, double height){
    1.57          return graphicsEnvironmentImpl.getImageData(x, y, width, height);
    1.58      }
    1.59  
    1.60 -    public void putImageData(ImageData imageData, double x, double y){
    1.61 +    public void putImageData(Image imageData, double x, double y){
    1.62          graphicsEnvironmentImpl.putImageData(imageData, x, y);
    1.63      }
    1.64  
    1.65 -    public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight){
    1.66 +    public void putImageData(Image imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight){
    1.67          graphicsEnvironmentImpl.putImageData(imageData, x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
    1.68      }
    1.69  
    1.70 @@ -316,7 +308,7 @@
    1.71          return new LinearGradient(x0, y0, x1, y1);
    1.72      }
    1.73  
    1.74 -    public Pattern createPattern(ImageData image, String repeat){
    1.75 +    public Pattern createPattern(Image image, String repeat){
    1.76          return new Pattern(image, repeat);
    1.77      }
    1.78  
    1.79 @@ -324,7 +316,7 @@
    1.80          return new RadialGradient(x0, y0, r0, x1, y1, r1);
    1.81      }
    1.82  
    1.83 -    public ImageData getImageDataForPath(String path){
    1.84 +    public Image getImageDataForPath(String path){
    1.85          return graphicsEnvironmentImpl.getImageDataForPath(path);
    1.86      }
    1.87  
     2.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsEnvironment.java	Thu May 23 08:15:11 2013 +0200
     2.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsEnvironment.java	Thu May 23 09:47:20 2013 +0200
     2.3 @@ -80,11 +80,11 @@
     2.4  
     2.5      public void scale(double x, double y);
     2.6  
     2.7 -    public void drawImage(ImageData image, double x, double y);
     2.8 +    public void drawImage(Image image, double x, double y);
     2.9  
    2.10 -    public void drawImage(ImageData image, double x, double y, double width, double height);
    2.11 +    public void drawImage(Image image, double x, double y, double width, double height);
    2.12  
    2.13 -    public void drawImage(ImageData image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height);
    2.14 +    public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height);
    2.15  
    2.16      public void setFillStyle(String style);
    2.17  
    2.18 @@ -152,15 +152,15 @@
    2.19  
    2.20      public void strokeText(String text, double x, double y, double maxWidth);
    2.21  
    2.22 -    public ImageData createImageData(double x, double y);
    2.23 +    public Image createImageData(double x, double y);
    2.24  
    2.25 -    public ImageData createImageData(ImageData imageData);
    2.26 +    public Image createImageData(Image imageData);
    2.27  
    2.28 -    public ImageData getImageData(double x, double y, double width, double height);
    2.29 +    public Image getImageData(double x, double y, double width, double height);
    2.30  
    2.31 -    public void putImageData(ImageData imageData, double x, double y);
    2.32 +    public void putImageData(Image imageData, double x, double y);
    2.33  
    2.34 -    public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
    2.35 +    public void putImageData(Image imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
    2.36  
    2.37      public void setGlobalAlpha(double alpha);
    2.38  
    2.39 @@ -170,9 +170,7 @@
    2.40  
    2.41      public String getGlobalCompositeOperation();
    2.42  
    2.43 -    public void addColorStop(LinearGradient gradient, double position, String color);
    2.44 -
    2.45 -    public ImageData getImageDataForPath(String path);
    2.46 +    public Image getImageDataForPath(String path);
    2.47  
    2.48      public int getHeight();
    2.49  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Image.java	Thu May 23 09:47:20 2013 +0200
     3.3 @@ -0,0 +1,34 @@
     3.4 +/**
     3.5 + * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
     3.6 + * <jaroslav.tulach@apidesign.org>
     3.7 + *
     3.8 + * This program is free software: you can redistribute it and/or modify it under
     3.9 + * the terms of the GNU General Public License as published by the Free Software
    3.10 + * Foundation, version 2 of the License.
    3.11 + *
    3.12 + * This program is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    3.14 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    3.15 + * details.
    3.16 + *
    3.17 + * You should have received a copy of the GNU General Public License along with
    3.18 + * this program. Look for COPYING file in the top folder. If not, see
    3.19 + * http://opensource.org/licenses/GPL-2.0.
    3.20 + */
    3.21 +package net.java.html.canvas;
    3.22 +
    3.23 +/**
    3.24 + *
    3.25 + * @author antonepple
    3.26 + */
    3.27 +public interface Image {
    3.28 +
    3.29 +    public double getHeight();
    3.30 +
    3.31 +    public double getWidth();
    3.32 +    
    3.33 +    public int getValueAt(double x, double y);
    3.34 +    
    3.35 +    public void setValueAt(double x, double y, int value);
    3.36 +    
    3.37 +}
     4.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/ImageData.java	Thu May 23 08:15:11 2013 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,34 +0,0 @@
     4.4 -/**
     4.5 - * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
     4.6 - * <jaroslav.tulach@apidesign.org>
     4.7 - *
     4.8 - * This program is free software: you can redistribute it and/or modify it under
     4.9 - * the terms of the GNU General Public License as published by the Free Software
    4.10 - * Foundation, version 2 of the License.
    4.11 - *
    4.12 - * This program is distributed in the hope that it will be useful, but WITHOUT
    4.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    4.14 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    4.15 - * details.
    4.16 - *
    4.17 - * You should have received a copy of the GNU General Public License along with
    4.18 - * this program. Look for COPYING file in the top folder. If not, see
    4.19 - * http://opensource.org/licenses/GPL-2.0.
    4.20 - */
    4.21 -package net.java.html.canvas;
    4.22 -
    4.23 -/**
    4.24 - *
    4.25 - * @author antonepple
    4.26 - */
    4.27 -public interface ImageData {
    4.28 -
    4.29 -    public double getHeight();
    4.30 -
    4.31 -    public double getWidth();
    4.32 -    
    4.33 -    public int getValueAt(double x, double y);
    4.34 -    
    4.35 -    public void setValueAt(double x, double y, int value);
    4.36 -    
    4.37 -}
     5.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/LinearGradient.java	Thu May 23 08:15:11 2013 +0200
     5.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/LinearGradient.java	Thu May 23 09:47:20 2013 +0200
     5.3 @@ -23,13 +23,13 @@
     5.4   *
     5.5   * @author antonepple
     5.6   */
     5.7 -public class LinearGradient implements Style {
     5.8 +public class LinearGradient extends Style {
     5.9  
    5.10      HashMap<Double,String> stops;
    5.11      
    5.12      double x0, y0, x1, y1;
    5.13  
    5.14 -    public LinearGradient( double x0, double y0, double x1, double y1) {
    5.15 +    LinearGradient( double x0, double y0, double x1, double y1) {
    5.16          this.x0 = x0;
    5.17          this.y0 = y0;
    5.18          this.x1 = x1;
     6.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Pattern.java	Thu May 23 08:15:11 2013 +0200
     6.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Pattern.java	Thu May 23 09:47:20 2013 +0200
     6.3 @@ -21,21 +21,21 @@
     6.4   *
     6.5   * @author antonepple
     6.6   */
     6.7 -public class  Pattern implements Style{
     6.8 + public final class Pattern extends Style{
     6.9      
    6.10 -    ImageData imageData; 
    6.11 +    Image imageData; 
    6.12      String repeat;
    6.13  
    6.14 -    public Pattern(ImageData imageData, String repeat) {
    6.15 +    Pattern(Image imageData, String repeat) {
    6.16          this.imageData = imageData;
    6.17          this.repeat = repeat;
    6.18      }
    6.19      
    6.20 -    public ImageData getImageData() {
    6.21 +    public Image getImageData() {
    6.22          return imageData;
    6.23      }
    6.24  
    6.25 -    public void setImageData(ImageData imageData) {
    6.26 +    public void setImageData(Image imageData) {
    6.27          this.imageData = imageData;
    6.28      }
    6.29  
     7.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/RadialGradient.java	Thu May 23 08:15:11 2013 +0200
     7.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/RadialGradient.java	Thu May 23 09:47:20 2013 +0200
     7.3 @@ -21,10 +21,10 @@
     7.4   *
     7.5   * @author antonepple
     7.6   */
     7.7 -public class RadialGradient extends LinearGradient{
     7.8 +public final class RadialGradient extends LinearGradient{
     7.9      double r0, r1;
    7.10  
    7.11 -    public RadialGradient( double x0, double y0,double r0, double x1, double y1, double r1) {
    7.12 +    RadialGradient( double x0, double y0,double r0, double x1, double y1, double r1) {
    7.13          super(x0, y0, x1, y1);
    7.14          this.r0 = r0;
    7.15          this.r1 = r1;
     8.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java	Thu May 23 08:15:11 2013 +0200
     8.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java	Thu May 23 09:47:20 2013 +0200
     8.3 @@ -21,6 +21,23 @@
     8.4   *
     8.5   * @author antonepple
     8.6   */
     8.7 -public interface Style {
     8.8 +public class Style {
     8.9 +
    8.10 +    Style() {
    8.11 +    }
    8.12 +    
    8.13 +    public static final RadialGradient createRadialGradient( double x0, double y0,double r0, double x1, double y1, double r1){
    8.14 +        return new RadialGradient(x0, y0, r0, x1, y1, r1);
    8.15 +    }
    8.16 +    
    8.17 +    public static final LinearGradient createLinearGradient(double x0, double y0, double x1, double y1){
    8.18 +        return new LinearGradient(x0, y0, x1, y1);
    8.19 +    }
    8.20 +    
    8.21 +    public static final Pattern createPattern(Image imageData, String repeat){
    8.22 +        return new Pattern(imageData, repeat);
    8.23 +    }
    8.24 +    
    8.25 +    
    8.26      
    8.27  }