1.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java Mon May 27 10:00:12 2013 +0200
1.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java Mon May 27 10:18:43 2013 +0200
1.3 @@ -17,6 +17,9 @@
1.4 */
1.5 package net.java.html.canvas;
1.6
1.7 +import java.util.HashMap;
1.8 +import java.util.Objects;
1.9 +
1.10 /**
1.11 *
1.12 * @author antonepple
1.13 @@ -29,19 +32,19 @@
1.14 Style() {
1.15 }
1.16
1.17 - public static final RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
1.18 + static final RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
1.19 return new RadialGradient(x0, y0, r0, x1, y1, r1);
1.20 }
1.21
1.22 - public static final LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
1.23 + static final LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
1.24 return new LinearGradient(x0, y0, x1, y1);
1.25 }
1.26
1.27 - public static final Pattern createPattern(Image imageResource, String repeat) {
1.28 + static final Pattern createPattern(Image imageResource, String repeat) {
1.29 return new Pattern(imageResource, repeat);
1.30 }
1.31
1.32 - public static final Color createColor(String webColor) {
1.33 + static final Color getWebColor(String webColor) {
1.34 return new Color(webColor);
1.35 }
1.36
1.37 @@ -57,4 +60,204 @@
1.38 Object getCached() {
1.39 return isCached() ? cached : null;
1.40 }
1.41 +
1.42 + public static final class Pattern extends Style {
1.43 +
1.44 + private Image imageResource;
1.45 + private String repeat;
1.46 +
1.47 + Pattern(Image imageResource, String repeat) {
1.48 + this.imageResource = imageResource;
1.49 + this.repeat = repeat;
1.50 + }
1.51 +
1.52 + public Image getImageResource() {
1.53 + return imageResource;
1.54 + }
1.55 +
1.56 + public void setImageResource(Image imageResource) {
1.57 + this.imageResource = imageResource;
1.58 + }
1.59 +
1.60 + public String getRepeat() {
1.61 + return repeat;
1.62 + }
1.63 +
1.64 + public void setRepeat(String repeat) {
1.65 + this.repeat = repeat;
1.66 + }
1.67 + }
1.68 +
1.69 + public static final class Color extends Style {
1.70 +
1.71 + private String web;
1.72 +
1.73 + /**
1.74 + * Creates an RGB color specified with an HTML or CSS attribute string.
1.75 + *
1.76 + * @param webColor Colordefined as
1.77 + */
1.78 + Color(String webColor) {
1.79 + this.web = web;
1.80 + }
1.81 +
1.82 + public String getAsString() {
1.83 + return web;
1.84 + }
1.85 + }
1.86 +
1.87 + public static class LinearGradient extends Style {
1.88 +
1.89 + private HashMap<Double, String> stops;
1.90 + private double x0, y0, x1, y1;
1.91 +
1.92 + LinearGradient(double x0, double y0, double x1, double y1) {
1.93 + this.x0 = x0;
1.94 + this.y0 = y0;
1.95 + this.x1 = x1;
1.96 + this.y1 = y1;
1.97 + }
1.98 +
1.99 + void addColorStop(double position, String color) {
1.100 + if (stops == null) {
1.101 + stops = new HashMap<>();
1.102 + }
1.103 + stops.put(position, color);
1.104 + }
1.105 +
1.106 + public HashMap<Double, String> getStops() {
1.107 + return stops;
1.108 + }
1.109 +
1.110 + public void setStops(HashMap<Double, String> stops) {
1.111 + this.stops = stops;
1.112 + }
1.113 +
1.114 + public double getX0() {
1.115 + return x0;
1.116 + }
1.117 +
1.118 + public void setX0(double x0) {
1.119 + this.x0 = x0;
1.120 + }
1.121 +
1.122 + public double getY0() {
1.123 + return y0;
1.124 + }
1.125 +
1.126 + public void setY0(double y0) {
1.127 + this.y0 = y0;
1.128 + }
1.129 +
1.130 + public double getX1() {
1.131 + return x1;
1.132 + }
1.133 +
1.134 + public void setX1(double x1) {
1.135 + this.x1 = x1;
1.136 + }
1.137 +
1.138 + public double getY1() {
1.139 + return y1;
1.140 + }
1.141 +
1.142 + public void setY1(double y1) {
1.143 + this.y1 = y1;
1.144 + }
1.145 +
1.146 + @Override
1.147 + public int hashCode() {
1.148 + int hash = 7;
1.149 + hash = 29 * hash + Objects.hashCode(this.stops);
1.150 + hash = 29 * hash + (int) (Double.doubleToLongBits(this.x0) ^ (Double.doubleToLongBits(this.x0) >>> 32));
1.151 + hash = 29 * hash + (int) (Double.doubleToLongBits(this.y0) ^ (Double.doubleToLongBits(this.y0) >>> 32));
1.152 + hash = 29 * hash + (int) (Double.doubleToLongBits(this.x1) ^ (Double.doubleToLongBits(this.x1) >>> 32));
1.153 + hash = 29 * hash + (int) (Double.doubleToLongBits(this.y1) ^ (Double.doubleToLongBits(this.y1) >>> 32));
1.154 + return hash;
1.155 + }
1.156 +
1.157 + @Override
1.158 + public boolean equals(Object obj) {
1.159 + if (obj == null) {
1.160 + return false;
1.161 + }
1.162 + if (getClass() != obj.getClass()) {
1.163 + return false;
1.164 + }
1.165 + final LinearGradient other = (LinearGradient) obj;
1.166 + if (!Objects.equals(this.stops, other.stops)) {
1.167 + return false;
1.168 + }
1.169 + if (Double.doubleToLongBits(this.x0) != Double.doubleToLongBits(other.x0)) {
1.170 + return false;
1.171 + }
1.172 + if (Double.doubleToLongBits(this.y0) != Double.doubleToLongBits(other.y0)) {
1.173 + return false;
1.174 + }
1.175 + if (Double.doubleToLongBits(this.x1) != Double.doubleToLongBits(other.x1)) {
1.176 + return false;
1.177 + }
1.178 + if (Double.doubleToLongBits(this.y1) != Double.doubleToLongBits(other.y1)) {
1.179 + return false;
1.180 + }
1.181 + return true;
1.182 + }
1.183 + }
1.184 +
1.185 + public static final class RadialGradient extends LinearGradient {
1.186 +
1.187 + private double r0, r1;
1.188 +
1.189 + RadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
1.190 + super(x0, y0, x1, y1);
1.191 + this.r0 = r0;
1.192 + this.r1 = r1;
1.193 + }
1.194 +
1.195 + public double getR0() {
1.196 + return r0;
1.197 + }
1.198 +
1.199 + public void setR0(double r0) {
1.200 + this.r0 = r0;
1.201 + }
1.202 +
1.203 + public double getR1() {
1.204 + return r1;
1.205 + }
1.206 +
1.207 + public void setR1(double r1) {
1.208 + this.r1 = r1;
1.209 + }
1.210 +
1.211 + @Override
1.212 + public int hashCode() {
1.213 + int hash = super.hashCode();
1.214 + hash = 17 * hash + (int) (Double.doubleToLongBits(this.r0) ^ (Double.doubleToLongBits(this.r0) >>> 32));
1.215 + hash = 17 * hash + (int) (Double.doubleToLongBits(this.r1) ^ (Double.doubleToLongBits(this.r1) >>> 32));
1.216 +
1.217 + return hash;
1.218 + }
1.219 +
1.220 + @Override
1.221 + public boolean equals(Object obj) {
1.222 + if (obj == null) {
1.223 + return false;
1.224 + }
1.225 + if (getClass() != obj.getClass()) {
1.226 + return false;
1.227 + }
1.228 + if (!super.equals(obj)) {
1.229 + return false;
1.230 + }
1.231 + final RadialGradient other = (RadialGradient) obj;
1.232 + if (Double.doubleToLongBits(this.r0) != Double.doubleToLongBits(other.r0)) {
1.233 + return false;
1.234 + }
1.235 + if (Double.doubleToLongBits(this.r1) != Double.doubleToLongBits(other.r1)) {
1.236 + return false;
1.237 + }
1.238 + return true;
1.239 + }
1.240 + }
1.241 }