# HG changeset patch # User Anton Epple # Date 1392211150 -3600 # Node ID 6be5961e27ee1f5bab766c5a7186562b6dddba23 # Parent ff7ac82effa3d43f14bd83c51ba29c4f31515614 changed LinearGradient and RadialGradient inheritance (Y08) removed setters from Style subclasses (Y06) renamed method getAccssr to what it does: init (Y02) created factory method for Gradients (Y07) diff -r ff7ac82effa3 -r 6be5961e27ee javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java Wed Feb 12 13:12:44 2014 +0100 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java Wed Feb 12 14:19:10 2014 +0100 @@ -17,6 +17,7 @@ */ package net.java.html.canvas; +import java.util.Map; import net.java.html.canvas.Style.Color; import net.java.html.canvas.Style.LinearGradient; import net.java.html.canvas.Style.Pattern; @@ -32,7 +33,7 @@ */ public final class GraphicsContext { - public static void getAccssr() { + public static void init() { // do nothing we need this in order to have the class loaded and static // block executed for CnvsAccssr. } @@ -736,8 +737,8 @@ * @param y1 y coordinate of end point * @return the gradient */ - public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) { - return new Style.LinearGradient(x0, y0, x1, y1); + public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1, Map stops) { + return Style.LinearGradient.create(x0, y0, x1, y1, stops); } /** @@ -763,8 +764,8 @@ * @param r1 radius of ending circle * @return the Gradient */ - 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 RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1, Map stops) { + return RadialGradient.create(x0, y0, r0, x1, y1, r1, stops); } /** diff -r ff7ac82effa3 -r 6be5961e27ee javaquery/canvas/src/main/java/net/java/html/canvas/Style.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java Wed Feb 12 13:12:44 2014 +0100 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java Wed Feb 12 14:19:10 2014 +0100 @@ -117,14 +117,10 @@ } } - /** - * A Linear Gradient. The Gradient has a direction defined by two - * coordinates and stops defining the Color at a specific position. - */ - public static class LinearGradient extends Style { + private static class Gradient extends Style { - private Map stops; - private double x0, y0, x1, y1; + protected final Map stops; + protected final double x0, y0, x1, y1; /** * @@ -132,43 +128,13 @@ * @param y0 the y coordinate of the start point for this gradient * @param x1 the x coordinate of the end point for this gradient * @param y1 the y coordinate of the end point for this gradient + * @param stops the stops of this gradient */ - LinearGradient(double x0, double y0, double x1, double y1) { + private Gradient(double x0, double y0, double x1, double y1,Map stops) { this.x0 = x0; this.y0 = y0; this.x1 = x1; this.y1 = y1; - } - - /** - * Add a new Color stop. A color stop defines a fixed color at a - * position along the coordinates. - * - * @param position the position of this stop in percent [0.0-1.0] - * @param color A Color defined in web format (e.g. #ff0000) - */ - void addColorStop(double position, String color) { - if (stops == null) { - stops = new HashMap<>(); - } - stops.put(position, color); - } - - /** - * Get the stops of this gradient. - * - * @return the stops of this gradient - */ - public Map getStops() { - return new HashMap<>(stops); - } - - /** - * Set the stops as Position/Color pairs - * - * @param stops the stops for thsi Gradient - */ - public void setStops(Map stops) { this.stops = new HashMap<>(stops); } @@ -184,12 +150,8 @@ /** * Set the X coordinate of the Gradients start point * - * @param x0 x coordinate + * @param x0 x coordinate public void setX0(double x0) { this.x0 = x0; } */ - public void setX0(double x0) { - this.x0 = x0; - } - /** * Get the Y coordinate of the Gradients start point * @@ -202,12 +164,8 @@ /** * Set the Y coordinate of the Gradients start point * - * @param y0 y coordinate + * @param y0 y coordinate public void setY0(double y0) { this.y0 = y0; } */ - public void setY0(double y0) { - this.y0 = y0; - } - /** * Set the X coordinate of the Gradients end point * @@ -220,12 +178,8 @@ /** * Set the X coordinate of the Gradients end point * - * @param X coordinate + * @param X coordinate public void setX1(double x1) { this.x1 = x1; } */ - public void setX1(double x1) { - this.x1 = x1; - } - /** * Get the Y coordinate of the Gradients end point * @@ -235,13 +189,14 @@ return y1; } + /** - * Set the Y coordinate of the Gradients end point + * Get the stops of this gradient. * - * @param y1 coordinate + * @return the stops of this gradient */ - public void setY1(double y1) { - this.y1 = y1; + public Map getStops() { + return new HashMap<>(stops); } @Override @@ -284,15 +239,47 @@ } /** + * A Linear Gradient. The Gradient has a direction defined by two + * coordinates and stops defining the Color at a specific position. + */ + public static class LinearGradient extends Gradient { + + private LinearGradient(double x0, double y0, double x1, double y1,Map stops) { + super(x0, y0, x1, y1, stops); + } + + /** + * + * @param x0 the x coordinate of the start point for this gradient + * @param y0 the y coordinate of the start point for this gradient + * @param x1 the x coordinate of the end point for this gradient + * @param y1 the y coordinate of the end point for this gradient + * @param stops the stops of this gradient + * @return linearGradient the gradient + */ + public static LinearGradient create(double x0, double y0, double x1, double y1,Map stops) { + return new LinearGradient(x0, y0, x1, y1, stops); + } + + } + + /** * A Radial Gradient. Radial gradients are defined with two imaginary * circles, a starting circle and an ending circle. The gradient starts with * the start circle and moves towards the end circle. */ - public static final class RadialGradient extends LinearGradient { + public static final class RadialGradient extends Gradient { - private double r0, r1; + final private double r0, r1; - /** + + private RadialGradient(double x0, double y0, double r0, double x1, double y1, double r1, Map stops) { + super(x0, y0, x1, y1,stops); + this.r0 = r0; + this.r1 = r1; + } + + /** * Create a new RadialGradient * * @param x0 x Coordinate of starting circle @@ -301,15 +288,16 @@ * @param x1 x coordinate of ending circle * @param y1 y coordinate of ending circle * @param r1 radius of ending circle + * @param stops the stops of this gradient + * @return radialGradient the gradient */ - 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 static RadialGradient create(double x0, double y0, double r0, double x1, double y1, double r1, Map stops){ + return new RadialGradient(x0, y0, r0, x1, y1, r1, stops); } - + /** * get the radius of the start circle. + * * @return the radius */ public double getR0() { @@ -318,14 +306,14 @@ /** * set the radius of the start circle. + * * @param r0 the radius + * + * public void setR0(double r0) { this.r0 = r0; } */ - public void setR0(double r0) { - this.r0 = r0; - } - /** * get the radius of the end circle + * * @return the radius */ public double getR1() { @@ -334,12 +322,11 @@ /** * set the radius of the end circle. + * * @param r1 the radius. + * + * public void setR1(double r1) { this.r1 = r1; } */ - public void setR1(double r1) { - this.r1 = r1; - } - @Override public int hashCode() { int hash = super.hashCode(); @@ -373,4 +360,5 @@ return true; } } + } diff -r ff7ac82effa3 -r 6be5961e27ee javaquery/canvas/src/main/java/org/apidesign/html/canvas/impl/CnvsAccssr.java --- a/javaquery/canvas/src/main/java/org/apidesign/html/canvas/impl/CnvsAccssr.java Wed Feb 12 13:12:44 2014 +0100 +++ b/javaquery/canvas/src/main/java/org/apidesign/html/canvas/impl/CnvsAccssr.java Wed Feb 12 14:19:10 2014 +0100 @@ -38,7 +38,7 @@ } public static CnvsAccssr getDefault() { - if (DEFAULT== null) GraphicsContext.getAccssr(); + if (DEFAULT== null) GraphicsContext.init(); return DEFAULT; }