# HG changeset patch # User Anton Epple # Date 1369295240 -7200 # Node ID 368626597f1a0ff87d3a0c55bcd1c6eb6f6e4d2e # Parent dec5f4e7d031d831f0ef0abebf46e6d2df088019 Limited extensibility of Style and it's three allowed subclasses diff -r dec5f4e7d031 -r 368626597f1a javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java Thu May 23 08:15:11 2013 +0200 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java Thu May 23 09:47:20 2013 +0200 @@ -132,15 +132,15 @@ graphicsEnvironmentImpl.scale(x, y); } - public void drawImage(ImageData image, double x, double y){ + public void drawImage(Image image, double x, double y){ graphicsEnvironmentImpl.drawImage(image, x, y); } - public void drawImage(ImageData image, double x, double y, double width, double height){ + public void drawImage(Image image, double x, double y, double width, double height){ graphicsEnvironmentImpl.drawImage(image, x, y, width, height); } - public void drawImage(ImageData image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height){ + public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height){ graphicsEnvironmentImpl.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height); } @@ -152,18 +152,10 @@ return graphicsEnvironmentImpl.getFillStyle(); } - public void setFillStyle(Pattern style){ - graphicsEnvironmentImpl.setFillStyle(style); - } - public void setStrokeStyle(String style){ graphicsEnvironmentImpl.setStrokeStyle(style); } - public void setStrokeStyle(Pattern style){ - graphicsEnvironmentImpl.setStrokeStyle(style); - } - public void setShadowColor(String color){ graphicsEnvironmentImpl.setShadowColor(color); } @@ -276,23 +268,23 @@ graphicsEnvironmentImpl.strokeText(text, x, y, maxWidth); } - public ImageData createImageData(double x, double y){ + public Image createImageData(double x, double y){ return graphicsEnvironmentImpl.createImageData(x, y); } - public ImageData createImageData(ImageData imageData){ + public Image createImageData(Image imageData){ return graphicsEnvironmentImpl.createImageData(imageData); } - public ImageData getImageData(double x, double y, double width, double height){ + public Image getImageData(double x, double y, double width, double height){ return graphicsEnvironmentImpl.getImageData(x, y, width, height); } - public void putImageData(ImageData imageData, double x, double y){ + public void putImageData(Image imageData, double x, double y){ graphicsEnvironmentImpl.putImageData(imageData, x, y); } - public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight){ + public void putImageData(Image imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight){ graphicsEnvironmentImpl.putImageData(imageData, x, y, dirtyx, dirtyy, dirtywidth, dirtyheight); } @@ -316,7 +308,7 @@ return new LinearGradient(x0, y0, x1, y1); } - public Pattern createPattern(ImageData image, String repeat){ + public Pattern createPattern(Image image, String repeat){ return new Pattern(image, repeat); } @@ -324,7 +316,7 @@ return new RadialGradient(x0, y0, r0, x1, y1, r1); } - public ImageData getImageDataForPath(String path){ + public Image getImageDataForPath(String path){ return graphicsEnvironmentImpl.getImageDataForPath(path); } diff -r dec5f4e7d031 -r 368626597f1a javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsEnvironment.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsEnvironment.java Thu May 23 08:15:11 2013 +0200 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsEnvironment.java Thu May 23 09:47:20 2013 +0200 @@ -80,11 +80,11 @@ public void scale(double x, double y); - public void drawImage(ImageData image, double x, double y); + public void drawImage(Image image, double x, double y); - public void drawImage(ImageData image, double x, double y, double width, double height); + public void drawImage(Image image, double x, double y, double width, double height); - public void drawImage(ImageData image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height); + public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height); public void setFillStyle(String style); @@ -152,15 +152,15 @@ public void strokeText(String text, double x, double y, double maxWidth); - public ImageData createImageData(double x, double y); + public Image createImageData(double x, double y); - public ImageData createImageData(ImageData imageData); + public Image createImageData(Image imageData); - public ImageData getImageData(double x, double y, double width, double height); + public Image getImageData(double x, double y, double width, double height); - public void putImageData(ImageData imageData, double x, double y); + public void putImageData(Image imageData, double x, double y); - public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight); + public void putImageData(Image imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight); public void setGlobalAlpha(double alpha); @@ -170,9 +170,7 @@ public String getGlobalCompositeOperation(); - public void addColorStop(LinearGradient gradient, double position, String color); - - public ImageData getImageDataForPath(String path); + public Image getImageDataForPath(String path); public int getHeight(); diff -r dec5f4e7d031 -r 368626597f1a javaquery/canvas/src/main/java/net/java/html/canvas/Image.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Image.java Thu May 23 09:47:20 2013 +0200 @@ -0,0 +1,34 @@ +/** + * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach + * + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. Look for COPYING file in the top folder. If not, see + * http://opensource.org/licenses/GPL-2.0. + */ +package net.java.html.canvas; + +/** + * + * @author antonepple + */ +public interface Image { + + public double getHeight(); + + public double getWidth(); + + public int getValueAt(double x, double y); + + public void setValueAt(double x, double y, int value); + +} diff -r dec5f4e7d031 -r 368626597f1a javaquery/canvas/src/main/java/net/java/html/canvas/ImageData.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/ImageData.java Thu May 23 08:15:11 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -/** - * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach - * - * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. Look for COPYING file in the top folder. If not, see - * http://opensource.org/licenses/GPL-2.0. - */ -package net.java.html.canvas; - -/** - * - * @author antonepple - */ -public interface ImageData { - - public double getHeight(); - - public double getWidth(); - - public int getValueAt(double x, double y); - - public void setValueAt(double x, double y, int value); - -} diff -r dec5f4e7d031 -r 368626597f1a javaquery/canvas/src/main/java/net/java/html/canvas/LinearGradient.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/LinearGradient.java Thu May 23 08:15:11 2013 +0200 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/LinearGradient.java Thu May 23 09:47:20 2013 +0200 @@ -23,13 +23,13 @@ * * @author antonepple */ -public class LinearGradient implements Style { +public class LinearGradient extends Style { HashMap stops; double x0, y0, x1, y1; - public LinearGradient( double x0, double y0, double x1, double y1) { + LinearGradient( double x0, double y0, double x1, double y1) { this.x0 = x0; this.y0 = y0; this.x1 = x1; diff -r dec5f4e7d031 -r 368626597f1a javaquery/canvas/src/main/java/net/java/html/canvas/Pattern.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Pattern.java Thu May 23 08:15:11 2013 +0200 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Pattern.java Thu May 23 09:47:20 2013 +0200 @@ -21,21 +21,21 @@ * * @author antonepple */ -public class Pattern implements Style{ + public final class Pattern extends Style{ - ImageData imageData; + Image imageData; String repeat; - public Pattern(ImageData imageData, String repeat) { + Pattern(Image imageData, String repeat) { this.imageData = imageData; this.repeat = repeat; } - public ImageData getImageData() { + public Image getImageData() { return imageData; } - public void setImageData(ImageData imageData) { + public void setImageData(Image imageData) { this.imageData = imageData; } diff -r dec5f4e7d031 -r 368626597f1a javaquery/canvas/src/main/java/net/java/html/canvas/RadialGradient.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/RadialGradient.java Thu May 23 08:15:11 2013 +0200 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/RadialGradient.java Thu May 23 09:47:20 2013 +0200 @@ -21,10 +21,10 @@ * * @author antonepple */ -public class RadialGradient extends LinearGradient{ +public final class RadialGradient extends LinearGradient{ double r0, r1; - public RadialGradient( double x0, double y0,double r0, double x1, double y1, double r1) { + RadialGradient( double x0, double y0,double r0, double x1, double y1, double r1) { super(x0, y0, x1, y1); this.r0 = r0; this.r1 = r1; diff -r dec5f4e7d031 -r 368626597f1a javaquery/canvas/src/main/java/net/java/html/canvas/Style.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java Thu May 23 08:15:11 2013 +0200 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java Thu May 23 09:47:20 2013 +0200 @@ -21,6 +21,23 @@ * * @author antonepple */ -public interface Style { +public class Style { + + Style() { + } + + public static final RadialGradient createRadialGradient( double x0, double y0,double r0, double x1, double y1, double r1){ + return new RadialGradient(x0, y0, r0, x1, y1, r1); + } + + public static final LinearGradient createLinearGradient(double x0, double y0, double x1, double y1){ + return new LinearGradient(x0, y0, x1, y1); + } + + public static final Pattern createPattern(Image imageData, String repeat){ + return new Pattern(imageData, repeat); + } + + }