# HG changeset patch # User Anton Epple # Date 1369642723 -7200 # Node ID 42e29ceb837102af1ec068e7e0f09679efb7dbe7 # Parent 78c3cdffe719b247b34f3ef5a3e89cb1c054a1cb Grouped Style subclasses as static inner classes of Style diff -r 78c3cdffe719 -r 42e29ceb8371 javaquery/canvas/src/main/java/net/java/html/canvas/Color.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Color.java Mon May 27 10:04:39 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package net.java.html.canvas; - -/** - * - * @author antonepple - */ -public class Color extends Style{ - - String web; - - /** - * Creates an RGB color specified with an HTML or CSS attribute string. - * @param webColor Colordefined as - */ - Color(String webColor) { - this.web = web; - } - - public String getAsString(){ - return web; - } - -} diff -r 78c3cdffe719 -r 42e29ceb8371 javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java Mon May 27 10:04:39 2013 +0200 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java Mon May 27 10:18:43 2013 +0200 @@ -17,6 +17,10 @@ */ package net.java.html.canvas; +import net.java.html.canvas.Style.Color; +import net.java.html.canvas.Style.LinearGradient; +import net.java.html.canvas.Style.Pattern; +import net.java.html.canvas.Style.RadialGradient; import net.java.html.canvas.spi.GraphicsEnvironment; /** @@ -302,7 +306,7 @@ } public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1){ - return new LinearGradient(x0, y0, x1, y1); + return new Style.LinearGradient(x0, y0, x1, y1); } public Pattern createPattern(Image image, String repeat){ @@ -312,6 +316,10 @@ public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1){ return new RadialGradient(x0, y0, r0, x1, y1, r1); } + + public Color getWebColor(String webColor){ + return new Style.Color(webColor); + } public Image getImageForPath(String path){ return graphicsEnvironmentImpl.getImageForPath(path); diff -r 78c3cdffe719 -r 42e29ceb8371 javaquery/canvas/src/main/java/net/java/html/canvas/LinearGradient.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/LinearGradient.java Mon May 27 10:04:39 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,125 +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; - -import java.util.HashMap; -import java.util.Objects; - -/** - * - * @author antonepple - */ -public class LinearGradient extends Style { - - HashMap stops; - - double x0, y0, x1, y1; - - LinearGradient( double x0, double y0, double x1, double y1) { - this.x0 = x0; - this.y0 = y0; - this.x1 = x1; - this.y1 = y1; - } - - - - void addColorStop(double position, String color){ - if (stops == null) stops = new HashMap<>(); - stops.put(position, color); - } - - public HashMap getStops() { - return stops; - } - - public void setStops(HashMap stops) { - this.stops = stops; - } - - public double getX0() { - return x0; - } - - public void setX0(double x0) { - this.x0 = x0; - } - - public double getY0() { - return y0; - } - - public void setY0(double y0) { - this.y0 = y0; - } - - public double getX1() { - return x1; - } - - public void setX1(double x1) { - this.x1 = x1; - } - - public double getY1() { - return y1; - } - - public void setY1(double y1) { - this.y1 = y1; - } - - @Override - public int hashCode() { - int hash = 7; - hash = 29 * hash + Objects.hashCode(this.stops); - hash = 29 * hash + (int) (Double.doubleToLongBits(this.x0) ^ (Double.doubleToLongBits(this.x0) >>> 32)); - hash = 29 * hash + (int) (Double.doubleToLongBits(this.y0) ^ (Double.doubleToLongBits(this.y0) >>> 32)); - hash = 29 * hash + (int) (Double.doubleToLongBits(this.x1) ^ (Double.doubleToLongBits(this.x1) >>> 32)); - hash = 29 * hash + (int) (Double.doubleToLongBits(this.y1) ^ (Double.doubleToLongBits(this.y1) >>> 32)); - return hash; - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final LinearGradient other = (LinearGradient) obj; - if (!Objects.equals(this.stops, other.stops)) { - return false; - } - if (Double.doubleToLongBits(this.x0) != Double.doubleToLongBits(other.x0)) { - return false; - } - if (Double.doubleToLongBits(this.y0) != Double.doubleToLongBits(other.y0)) { - return false; - } - if (Double.doubleToLongBits(this.x1) != Double.doubleToLongBits(other.x1)) { - return false; - } - if (Double.doubleToLongBits(this.y1) != Double.doubleToLongBits(other.y1)) { - return false; - } - return true; - } - -} diff -r 78c3cdffe719 -r 42e29ceb8371 javaquery/canvas/src/main/java/net/java/html/canvas/Pattern.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Pattern.java Mon May 27 10:04:39 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +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 final class Pattern extends Style{ - - Image imageResource; - String repeat; - - Pattern(Image imageResource, String repeat) { - this.imageResource = imageResource; - this.repeat = repeat; - } - - public Image getImageResource() { - return imageResource; - } - - public void setImageResource(Image imageResource) { - this.imageResource = imageResource; - } - - public String getRepeat() { - return repeat; - } - - public void setRepeat(String repeat) { - this.repeat = repeat; - } - - - -} diff -r 78c3cdffe719 -r 42e29ceb8371 javaquery/canvas/src/main/java/net/java/html/canvas/RadialGradient.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/RadialGradient.java Mon May 27 10:04:39 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +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 final class RadialGradient extends LinearGradient { - - - private double r0, 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; - } - - public double getR0() { - return r0; - } - - public void setR0(double r0) { - this.r0 = r0; - } - - public double getR1() { - return r1; - } - - public void setR1(double r1) { - this.r1 = r1; - } - - @Override - public int hashCode() { - int hash = super.hashCode(); - hash = 17 * hash + (int) (Double.doubleToLongBits(this.r0) ^ (Double.doubleToLongBits(this.r0) >>> 32)); - hash = 17 * hash + (int) (Double.doubleToLongBits(this.r1) ^ (Double.doubleToLongBits(this.r1) >>> 32)); - - return hash; - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - if (!super.equals(obj)) { - return false; - } - final RadialGradient other = (RadialGradient) obj; - if (Double.doubleToLongBits(this.r0) != Double.doubleToLongBits(other.r0)) { - return false; - } - if (Double.doubleToLongBits(this.r1) != Double.doubleToLongBits(other.r1)) { - return false; - } - return true; - } -} diff -r 78c3cdffe719 -r 42e29ceb8371 javaquery/canvas/src/main/java/net/java/html/canvas/Style.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java Mon May 27 10:04:39 2013 +0200 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java Mon May 27 10:18:43 2013 +0200 @@ -17,6 +17,9 @@ */ package net.java.html.canvas; +import java.util.HashMap; +import java.util.Objects; + /** * * @author antonepple @@ -29,19 +32,19 @@ Style() { } - public static final RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) { + 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) { + 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 imageResource, String repeat) { + static final Pattern createPattern(Image imageResource, String repeat) { return new Pattern(imageResource, repeat); } - public static final Color createColor(String webColor) { + static final Color getWebColor(String webColor) { return new Color(webColor); } @@ -57,4 +60,204 @@ Object getCached() { return isCached() ? cached : null; } + + public static final class Pattern extends Style { + + private Image imageResource; + private String repeat; + + Pattern(Image imageResource, String repeat) { + this.imageResource = imageResource; + this.repeat = repeat; + } + + public Image getImageResource() { + return imageResource; + } + + public void setImageResource(Image imageResource) { + this.imageResource = imageResource; + } + + public String getRepeat() { + return repeat; + } + + public void setRepeat(String repeat) { + this.repeat = repeat; + } + } + + public static final class Color extends Style { + + private String web; + + /** + * Creates an RGB color specified with an HTML or CSS attribute string. + * + * @param webColor Colordefined as + */ + Color(String webColor) { + this.web = web; + } + + public String getAsString() { + return web; + } + } + + public static class LinearGradient extends Style { + + private HashMap stops; + private double x0, y0, x1, y1; + + LinearGradient(double x0, double y0, double x1, double y1) { + this.x0 = x0; + this.y0 = y0; + this.x1 = x1; + this.y1 = y1; + } + + void addColorStop(double position, String color) { + if (stops == null) { + stops = new HashMap<>(); + } + stops.put(position, color); + } + + public HashMap getStops() { + return stops; + } + + public void setStops(HashMap stops) { + this.stops = stops; + } + + public double getX0() { + return x0; + } + + public void setX0(double x0) { + this.x0 = x0; + } + + public double getY0() { + return y0; + } + + public void setY0(double y0) { + this.y0 = y0; + } + + public double getX1() { + return x1; + } + + public void setX1(double x1) { + this.x1 = x1; + } + + public double getY1() { + return y1; + } + + public void setY1(double y1) { + this.y1 = y1; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 29 * hash + Objects.hashCode(this.stops); + hash = 29 * hash + (int) (Double.doubleToLongBits(this.x0) ^ (Double.doubleToLongBits(this.x0) >>> 32)); + hash = 29 * hash + (int) (Double.doubleToLongBits(this.y0) ^ (Double.doubleToLongBits(this.y0) >>> 32)); + hash = 29 * hash + (int) (Double.doubleToLongBits(this.x1) ^ (Double.doubleToLongBits(this.x1) >>> 32)); + hash = 29 * hash + (int) (Double.doubleToLongBits(this.y1) ^ (Double.doubleToLongBits(this.y1) >>> 32)); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final LinearGradient other = (LinearGradient) obj; + if (!Objects.equals(this.stops, other.stops)) { + return false; + } + if (Double.doubleToLongBits(this.x0) != Double.doubleToLongBits(other.x0)) { + return false; + } + if (Double.doubleToLongBits(this.y0) != Double.doubleToLongBits(other.y0)) { + return false; + } + if (Double.doubleToLongBits(this.x1) != Double.doubleToLongBits(other.x1)) { + return false; + } + if (Double.doubleToLongBits(this.y1) != Double.doubleToLongBits(other.y1)) { + return false; + } + return true; + } + } + + public static final class RadialGradient extends LinearGradient { + + private double r0, 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; + } + + public double getR0() { + return r0; + } + + public void setR0(double r0) { + this.r0 = r0; + } + + public double getR1() { + return r1; + } + + public void setR1(double r1) { + this.r1 = r1; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 17 * hash + (int) (Double.doubleToLongBits(this.r0) ^ (Double.doubleToLongBits(this.r0) >>> 32)); + hash = 17 * hash + (int) (Double.doubleToLongBits(this.r1) ^ (Double.doubleToLongBits(this.r1) >>> 32)); + + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + if (!super.equals(obj)) { + return false; + } + final RadialGradient other = (RadialGradient) obj; + if (Double.doubleToLongBits(this.r0) != Double.doubleToLongBits(other.r0)) { + return false; + } + if (Double.doubleToLongBits(this.r1) != Double.doubleToLongBits(other.r1)) { + return false; + } + return true; + } + } }