1.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java Wed Feb 12 13:12:44 2014 +0100
1.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java Wed Feb 12 14:19:10 2014 +0100
1.3 @@ -117,14 +117,10 @@
1.4 }
1.5 }
1.6
1.7 - /**
1.8 - * A Linear Gradient. The Gradient has a direction defined by two
1.9 - * coordinates and stops defining the Color at a specific position.
1.10 - */
1.11 - public static class LinearGradient extends Style {
1.12 + private static class Gradient extends Style {
1.13
1.14 - private Map<Double, String> stops;
1.15 - private double x0, y0, x1, y1;
1.16 + protected final Map<Double, String> stops;
1.17 + protected final double x0, y0, x1, y1;
1.18
1.19 /**
1.20 *
1.21 @@ -132,43 +128,13 @@
1.22 * @param y0 the y coordinate of the start point for this gradient
1.23 * @param x1 the x coordinate of the end point for this gradient
1.24 * @param y1 the y coordinate of the end point for this gradient
1.25 + * @param stops the stops of this gradient
1.26 */
1.27 - LinearGradient(double x0, double y0, double x1, double y1) {
1.28 + private Gradient(double x0, double y0, double x1, double y1,Map<Double, String> stops) {
1.29 this.x0 = x0;
1.30 this.y0 = y0;
1.31 this.x1 = x1;
1.32 this.y1 = y1;
1.33 - }
1.34 -
1.35 - /**
1.36 - * Add a new Color stop. A color stop defines a fixed color at a
1.37 - * position along the coordinates.
1.38 - *
1.39 - * @param position the position of this stop in percent [0.0-1.0]
1.40 - * @param color A Color defined in web format (e.g. #ff0000)
1.41 - */
1.42 - void addColorStop(double position, String color) {
1.43 - if (stops == null) {
1.44 - stops = new HashMap<>();
1.45 - }
1.46 - stops.put(position, color);
1.47 - }
1.48 -
1.49 - /**
1.50 - * Get the stops of this gradient.
1.51 - *
1.52 - * @return the stops of this gradient
1.53 - */
1.54 - public Map<Double, String> getStops() {
1.55 - return new HashMap<>(stops);
1.56 - }
1.57 -
1.58 - /**
1.59 - * Set the stops as Position/Color pairs
1.60 - *
1.61 - * @param stops the stops for thsi Gradient
1.62 - */
1.63 - public void setStops(Map<Double, String> stops) {
1.64 this.stops = new HashMap<>(stops);
1.65 }
1.66
1.67 @@ -184,12 +150,8 @@
1.68 /**
1.69 * Set the X coordinate of the Gradients start point
1.70 *
1.71 - * @param x0 x coordinate
1.72 + * @param x0 x coordinate public void setX0(double x0) { this.x0 = x0; }
1.73 */
1.74 - public void setX0(double x0) {
1.75 - this.x0 = x0;
1.76 - }
1.77 -
1.78 /**
1.79 * Get the Y coordinate of the Gradients start point
1.80 *
1.81 @@ -202,12 +164,8 @@
1.82 /**
1.83 * Set the Y coordinate of the Gradients start point
1.84 *
1.85 - * @param y0 y coordinate
1.86 + * @param y0 y coordinate public void setY0(double y0) { this.y0 = y0; }
1.87 */
1.88 - public void setY0(double y0) {
1.89 - this.y0 = y0;
1.90 - }
1.91 -
1.92 /**
1.93 * Set the X coordinate of the Gradients end point
1.94 *
1.95 @@ -220,12 +178,8 @@
1.96 /**
1.97 * Set the X coordinate of the Gradients end point
1.98 *
1.99 - * @param X coordinate
1.100 + * @param X coordinate public void setX1(double x1) { this.x1 = x1; }
1.101 */
1.102 - public void setX1(double x1) {
1.103 - this.x1 = x1;
1.104 - }
1.105 -
1.106 /**
1.107 * Get the Y coordinate of the Gradients end point
1.108 *
1.109 @@ -235,13 +189,14 @@
1.110 return y1;
1.111 }
1.112
1.113 +
1.114 /**
1.115 - * Set the Y coordinate of the Gradients end point
1.116 + * Get the stops of this gradient.
1.117 *
1.118 - * @param y1 coordinate
1.119 + * @return the stops of this gradient
1.120 */
1.121 - public void setY1(double y1) {
1.122 - this.y1 = y1;
1.123 + public Map<Double, String> getStops() {
1.124 + return new HashMap<>(stops);
1.125 }
1.126
1.127 @Override
1.128 @@ -284,15 +239,47 @@
1.129 }
1.130
1.131 /**
1.132 + * A Linear Gradient. The Gradient has a direction defined by two
1.133 + * coordinates and stops defining the Color at a specific position.
1.134 + */
1.135 + public static class LinearGradient extends Gradient {
1.136 +
1.137 + private LinearGradient(double x0, double y0, double x1, double y1,Map<Double, String> stops) {
1.138 + super(x0, y0, x1, y1, stops);
1.139 + }
1.140 +
1.141 + /**
1.142 + *
1.143 + * @param x0 the x coordinate of the start point for this gradient
1.144 + * @param y0 the y coordinate of the start point for this gradient
1.145 + * @param x1 the x coordinate of the end point for this gradient
1.146 + * @param y1 the y coordinate of the end point for this gradient
1.147 + * @param stops the stops of this gradient
1.148 + * @return linearGradient the gradient
1.149 + */
1.150 + public static LinearGradient create(double x0, double y0, double x1, double y1,Map<Double, String> stops) {
1.151 + return new LinearGradient(x0, y0, x1, y1, stops);
1.152 + }
1.153 +
1.154 + }
1.155 +
1.156 + /**
1.157 * A Radial Gradient. Radial gradients are defined with two imaginary
1.158 * circles, a starting circle and an ending circle. The gradient starts with
1.159 * the start circle and moves towards the end circle.
1.160 */
1.161 - public static final class RadialGradient extends LinearGradient {
1.162 + public static final class RadialGradient extends Gradient {
1.163
1.164 - private double r0, r1;
1.165 + final private double r0, r1;
1.166
1.167 - /**
1.168 +
1.169 + private RadialGradient(double x0, double y0, double r0, double x1, double y1, double r1, Map<Double, String> stops) {
1.170 + super(x0, y0, x1, y1,stops);
1.171 + this.r0 = r0;
1.172 + this.r1 = r1;
1.173 + }
1.174 +
1.175 + /**
1.176 * Create a new RadialGradient
1.177 *
1.178 * @param x0 x Coordinate of starting circle
1.179 @@ -301,15 +288,16 @@
1.180 * @param x1 x coordinate of ending circle
1.181 * @param y1 y coordinate of ending circle
1.182 * @param r1 radius of ending circle
1.183 + * @param stops the stops of this gradient
1.184 + * @return radialGradient the gradient
1.185 */
1.186 - RadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
1.187 - super(x0, y0, x1, y1);
1.188 - this.r0 = r0;
1.189 - this.r1 = r1;
1.190 + public static RadialGradient create(double x0, double y0, double r0, double x1, double y1, double r1, Map<Double, String> stops){
1.191 + return new RadialGradient(x0, y0, r0, x1, y1, r1, stops);
1.192 }
1.193 -
1.194 +
1.195 /**
1.196 * get the radius of the start circle.
1.197 + *
1.198 * @return the radius
1.199 */
1.200 public double getR0() {
1.201 @@ -318,14 +306,14 @@
1.202
1.203 /**
1.204 * set the radius of the start circle.
1.205 + *
1.206 * @param r0 the radius
1.207 + *
1.208 + * public void setR0(double r0) { this.r0 = r0; }
1.209 */
1.210 - public void setR0(double r0) {
1.211 - this.r0 = r0;
1.212 - }
1.213 -
1.214 /**
1.215 * get the radius of the end circle
1.216 + *
1.217 * @return the radius
1.218 */
1.219 public double getR1() {
1.220 @@ -334,12 +322,11 @@
1.221
1.222 /**
1.223 * set the radius of the end circle.
1.224 + *
1.225 * @param r1 the radius.
1.226 + *
1.227 + * public void setR1(double r1) { this.r1 = r1; }
1.228 */
1.229 - public void setR1(double r1) {
1.230 - this.r1 = r1;
1.231 - }
1.232 -
1.233 @Override
1.234 public int hashCode() {
1.235 int hash = super.hashCode();
1.236 @@ -373,4 +360,5 @@
1.237 return true;
1.238 }
1.239 }
1.240 +
1.241 }