2 * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
3 * <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * You should have received a copy of the GNU General Public License along with
15 * this program. Look for COPYING file in the top folder. If not, see
16 * http://opensource.org/licenses/GPL-2.0.
18 package net.java.html.canvas;
20 import java.util.HashMap;
21 import java.util.Objects;
29 private Object cached;
30 private int cacheHash;
35 static final RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
36 return new RadialGradient(x0, y0, r0, x1, y1, r1);
39 static final LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
40 return new LinearGradient(x0, y0, x1, y1);
43 static final Pattern createPattern(Image imageResource, String repeat) {
44 return new Pattern(imageResource, repeat);
47 static final Color getWebColor(String webColor) {
48 return new Color(webColor);
51 void cache(Object toCache) {
52 cacheHash = hashCode();
53 this.cached = toCache;
56 private boolean isCached() {
57 return cacheHash == hashCode();
61 return isCached() ? cached : null;
64 public static final class Pattern extends Style {
66 private Image imageResource;
67 private String repeat;
69 Pattern(Image imageResource, String repeat) {
70 this.imageResource = imageResource;
74 public Image getImageResource() {
78 public void setImageResource(Image imageResource) {
79 this.imageResource = imageResource;
82 public String getRepeat() {
86 public void setRepeat(String repeat) {
91 public static final class Color extends Style {
96 * Creates an RGB color specified with an HTML or CSS attribute string.
98 * @param webColor Colordefined as
100 Color(String webColor) {
104 public String getAsString() {
109 public static class LinearGradient extends Style {
111 private HashMap<Double, String> stops;
112 private double x0, y0, x1, y1;
114 LinearGradient(double x0, double y0, double x1, double y1) {
121 void addColorStop(double position, String color) {
123 stops = new HashMap<>();
125 stops.put(position, color);
128 public HashMap<Double, String> getStops() {
132 public void setStops(HashMap<Double, String> stops) {
136 public double getX0() {
140 public void setX0(double x0) {
144 public double getY0() {
148 public void setY0(double y0) {
152 public double getX1() {
156 public void setX1(double x1) {
160 public double getY1() {
164 public void setY1(double y1) {
169 public int hashCode() {
171 hash = 29 * hash + Objects.hashCode(this.stops);
172 hash = 29 * hash + (int) (Double.doubleToLongBits(this.x0) ^ (Double.doubleToLongBits(this.x0) >>> 32));
173 hash = 29 * hash + (int) (Double.doubleToLongBits(this.y0) ^ (Double.doubleToLongBits(this.y0) >>> 32));
174 hash = 29 * hash + (int) (Double.doubleToLongBits(this.x1) ^ (Double.doubleToLongBits(this.x1) >>> 32));
175 hash = 29 * hash + (int) (Double.doubleToLongBits(this.y1) ^ (Double.doubleToLongBits(this.y1) >>> 32));
180 public boolean equals(Object obj) {
184 if (getClass() != obj.getClass()) {
187 final LinearGradient other = (LinearGradient) obj;
188 if (!Objects.equals(this.stops, other.stops)) {
191 if (Double.doubleToLongBits(this.x0) != Double.doubleToLongBits(other.x0)) {
194 if (Double.doubleToLongBits(this.y0) != Double.doubleToLongBits(other.y0)) {
197 if (Double.doubleToLongBits(this.x1) != Double.doubleToLongBits(other.x1)) {
200 if (Double.doubleToLongBits(this.y1) != Double.doubleToLongBits(other.y1)) {
207 public static final class RadialGradient extends LinearGradient {
209 private double r0, r1;
211 RadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
212 super(x0, y0, x1, y1);
217 public double getR0() {
221 public void setR0(double r0) {
225 public double getR1() {
229 public void setR1(double r1) {
234 public int hashCode() {
235 int hash = super.hashCode();
236 hash = 17 * hash + (int) (Double.doubleToLongBits(this.r0) ^ (Double.doubleToLongBits(this.r0) >>> 32));
237 hash = 17 * hash + (int) (Double.doubleToLongBits(this.r1) ^ (Double.doubleToLongBits(this.r1) >>> 32));
243 public boolean equals(Object obj) {
247 if (getClass() != obj.getClass()) {
250 if (!super.equals(obj)) {
253 final RadialGradient other = (RadialGradient) obj;
254 if (Double.doubleToLongBits(this.r0) != Double.doubleToLongBits(other.r0)) {
257 if (Double.doubleToLongBits(this.r1) != Double.doubleToLongBits(other.r1)) {