1.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java Wed Feb 12 13:12:44 2014 +0100
1.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java Wed Feb 12 14:19:10 2014 +0100
1.3 @@ -17,6 +17,7 @@
1.4 */
1.5 package net.java.html.canvas;
1.6
1.7 +import java.util.Map;
1.8 import net.java.html.canvas.Style.Color;
1.9 import net.java.html.canvas.Style.LinearGradient;
1.10 import net.java.html.canvas.Style.Pattern;
1.11 @@ -32,7 +33,7 @@
1.12 */
1.13 public final class GraphicsContext {
1.14
1.15 - public static void getAccssr() {
1.16 + public static void init() {
1.17 // do nothing we need this in order to have the class loaded and static
1.18 // block executed for CnvsAccssr.
1.19 }
1.20 @@ -736,8 +737,8 @@
1.21 * @param y1 y coordinate of end point
1.22 * @return the gradient
1.23 */
1.24 - public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
1.25 - return new Style.LinearGradient(x0, y0, x1, y1);
1.26 + public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1, Map<Double, String> stops) {
1.27 + return Style.LinearGradient.create(x0, y0, x1, y1, stops);
1.28 }
1.29
1.30 /**
1.31 @@ -763,8 +764,8 @@
1.32 * @param r1 radius of ending circle
1.33 * @return the Gradient
1.34 */
1.35 - public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
1.36 - return new RadialGradient(x0, y0, r0, x1, y1, r1);
1.37 + public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1, Map<Double, String> stops) {
1.38 + return RadialGradient.create(x0, y0, r0, x1, y1, r1, stops);
1.39 }
1.40
1.41 /**
2.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java Wed Feb 12 13:12:44 2014 +0100
2.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java Wed Feb 12 14:19:10 2014 +0100
2.3 @@ -117,14 +117,10 @@
2.4 }
2.5 }
2.6
2.7 - /**
2.8 - * A Linear Gradient. The Gradient has a direction defined by two
2.9 - * coordinates and stops defining the Color at a specific position.
2.10 - */
2.11 - public static class LinearGradient extends Style {
2.12 + private static class Gradient extends Style {
2.13
2.14 - private Map<Double, String> stops;
2.15 - private double x0, y0, x1, y1;
2.16 + protected final Map<Double, String> stops;
2.17 + protected final double x0, y0, x1, y1;
2.18
2.19 /**
2.20 *
2.21 @@ -132,43 +128,13 @@
2.22 * @param y0 the y coordinate of the start point for this gradient
2.23 * @param x1 the x coordinate of the end point for this gradient
2.24 * @param y1 the y coordinate of the end point for this gradient
2.25 + * @param stops the stops of this gradient
2.26 */
2.27 - LinearGradient(double x0, double y0, double x1, double y1) {
2.28 + private Gradient(double x0, double y0, double x1, double y1,Map<Double, String> stops) {
2.29 this.x0 = x0;
2.30 this.y0 = y0;
2.31 this.x1 = x1;
2.32 this.y1 = y1;
2.33 - }
2.34 -
2.35 - /**
2.36 - * Add a new Color stop. A color stop defines a fixed color at a
2.37 - * position along the coordinates.
2.38 - *
2.39 - * @param position the position of this stop in percent [0.0-1.0]
2.40 - * @param color A Color defined in web format (e.g. #ff0000)
2.41 - */
2.42 - void addColorStop(double position, String color) {
2.43 - if (stops == null) {
2.44 - stops = new HashMap<>();
2.45 - }
2.46 - stops.put(position, color);
2.47 - }
2.48 -
2.49 - /**
2.50 - * Get the stops of this gradient.
2.51 - *
2.52 - * @return the stops of this gradient
2.53 - */
2.54 - public Map<Double, String> getStops() {
2.55 - return new HashMap<>(stops);
2.56 - }
2.57 -
2.58 - /**
2.59 - * Set the stops as Position/Color pairs
2.60 - *
2.61 - * @param stops the stops for thsi Gradient
2.62 - */
2.63 - public void setStops(Map<Double, String> stops) {
2.64 this.stops = new HashMap<>(stops);
2.65 }
2.66
2.67 @@ -184,12 +150,8 @@
2.68 /**
2.69 * Set the X coordinate of the Gradients start point
2.70 *
2.71 - * @param x0 x coordinate
2.72 + * @param x0 x coordinate public void setX0(double x0) { this.x0 = x0; }
2.73 */
2.74 - public void setX0(double x0) {
2.75 - this.x0 = x0;
2.76 - }
2.77 -
2.78 /**
2.79 * Get the Y coordinate of the Gradients start point
2.80 *
2.81 @@ -202,12 +164,8 @@
2.82 /**
2.83 * Set the Y coordinate of the Gradients start point
2.84 *
2.85 - * @param y0 y coordinate
2.86 + * @param y0 y coordinate public void setY0(double y0) { this.y0 = y0; }
2.87 */
2.88 - public void setY0(double y0) {
2.89 - this.y0 = y0;
2.90 - }
2.91 -
2.92 /**
2.93 * Set the X coordinate of the Gradients end point
2.94 *
2.95 @@ -220,12 +178,8 @@
2.96 /**
2.97 * Set the X coordinate of the Gradients end point
2.98 *
2.99 - * @param X coordinate
2.100 + * @param X coordinate public void setX1(double x1) { this.x1 = x1; }
2.101 */
2.102 - public void setX1(double x1) {
2.103 - this.x1 = x1;
2.104 - }
2.105 -
2.106 /**
2.107 * Get the Y coordinate of the Gradients end point
2.108 *
2.109 @@ -235,13 +189,14 @@
2.110 return y1;
2.111 }
2.112
2.113 +
2.114 /**
2.115 - * Set the Y coordinate of the Gradients end point
2.116 + * Get the stops of this gradient.
2.117 *
2.118 - * @param y1 coordinate
2.119 + * @return the stops of this gradient
2.120 */
2.121 - public void setY1(double y1) {
2.122 - this.y1 = y1;
2.123 + public Map<Double, String> getStops() {
2.124 + return new HashMap<>(stops);
2.125 }
2.126
2.127 @Override
2.128 @@ -284,15 +239,47 @@
2.129 }
2.130
2.131 /**
2.132 + * A Linear Gradient. The Gradient has a direction defined by two
2.133 + * coordinates and stops defining the Color at a specific position.
2.134 + */
2.135 + public static class LinearGradient extends Gradient {
2.136 +
2.137 + private LinearGradient(double x0, double y0, double x1, double y1,Map<Double, String> stops) {
2.138 + super(x0, y0, x1, y1, stops);
2.139 + }
2.140 +
2.141 + /**
2.142 + *
2.143 + * @param x0 the x coordinate of the start point for this gradient
2.144 + * @param y0 the y coordinate of the start point for this gradient
2.145 + * @param x1 the x coordinate of the end point for this gradient
2.146 + * @param y1 the y coordinate of the end point for this gradient
2.147 + * @param stops the stops of this gradient
2.148 + * @return linearGradient the gradient
2.149 + */
2.150 + public static LinearGradient create(double x0, double y0, double x1, double y1,Map<Double, String> stops) {
2.151 + return new LinearGradient(x0, y0, x1, y1, stops);
2.152 + }
2.153 +
2.154 + }
2.155 +
2.156 + /**
2.157 * A Radial Gradient. Radial gradients are defined with two imaginary
2.158 * circles, a starting circle and an ending circle. The gradient starts with
2.159 * the start circle and moves towards the end circle.
2.160 */
2.161 - public static final class RadialGradient extends LinearGradient {
2.162 + public static final class RadialGradient extends Gradient {
2.163
2.164 - private double r0, r1;
2.165 + final private double r0, r1;
2.166
2.167 - /**
2.168 +
2.169 + private RadialGradient(double x0, double y0, double r0, double x1, double y1, double r1, Map<Double, String> stops) {
2.170 + super(x0, y0, x1, y1,stops);
2.171 + this.r0 = r0;
2.172 + this.r1 = r1;
2.173 + }
2.174 +
2.175 + /**
2.176 * Create a new RadialGradient
2.177 *
2.178 * @param x0 x Coordinate of starting circle
2.179 @@ -301,15 +288,16 @@
2.180 * @param x1 x coordinate of ending circle
2.181 * @param y1 y coordinate of ending circle
2.182 * @param r1 radius of ending circle
2.183 + * @param stops the stops of this gradient
2.184 + * @return radialGradient the gradient
2.185 */
2.186 - RadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
2.187 - super(x0, y0, x1, y1);
2.188 - this.r0 = r0;
2.189 - this.r1 = r1;
2.190 + public static RadialGradient create(double x0, double y0, double r0, double x1, double y1, double r1, Map<Double, String> stops){
2.191 + return new RadialGradient(x0, y0, r0, x1, y1, r1, stops);
2.192 }
2.193 -
2.194 +
2.195 /**
2.196 * get the radius of the start circle.
2.197 + *
2.198 * @return the radius
2.199 */
2.200 public double getR0() {
2.201 @@ -318,14 +306,14 @@
2.202
2.203 /**
2.204 * set the radius of the start circle.
2.205 + *
2.206 * @param r0 the radius
2.207 + *
2.208 + * public void setR0(double r0) { this.r0 = r0; }
2.209 */
2.210 - public void setR0(double r0) {
2.211 - this.r0 = r0;
2.212 - }
2.213 -
2.214 /**
2.215 * get the radius of the end circle
2.216 + *
2.217 * @return the radius
2.218 */
2.219 public double getR1() {
2.220 @@ -334,12 +322,11 @@
2.221
2.222 /**
2.223 * set the radius of the end circle.
2.224 + *
2.225 * @param r1 the radius.
2.226 + *
2.227 + * public void setR1(double r1) { this.r1 = r1; }
2.228 */
2.229 - public void setR1(double r1) {
2.230 - this.r1 = r1;
2.231 - }
2.232 -
2.233 @Override
2.234 public int hashCode() {
2.235 int hash = super.hashCode();
2.236 @@ -373,4 +360,5 @@
2.237 return true;
2.238 }
2.239 }
2.240 +
2.241 }
3.1 --- a/javaquery/canvas/src/main/java/org/apidesign/html/canvas/impl/CnvsAccssr.java Wed Feb 12 13:12:44 2014 +0100
3.2 +++ b/javaquery/canvas/src/main/java/org/apidesign/html/canvas/impl/CnvsAccssr.java Wed Feb 12 14:19:10 2014 +0100
3.3 @@ -38,7 +38,7 @@
3.4 }
3.5
3.6 public static CnvsAccssr getDefault() {
3.7 - if (DEFAULT== null) GraphicsContext.getAccssr();
3.8 + if (DEFAULT== null) GraphicsContext.init();
3.9 return DEFAULT;
3.10 }
3.11