removed factory methods for style. Those are in GraphicsContext now for consistency (GraphicsContext should create all graphics related Objects).
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 void cache(Object toCache) {
36 cacheHash = hashCode();
37 this.cached = toCache;
40 private boolean isCached() {
41 return cacheHash == hashCode();
45 return isCached() ? cached : null;
48 public static final class Pattern extends Style {
50 private Image imageResource;
51 private String repeat;
53 Pattern(Image imageResource, String repeat) {
54 this.imageResource = imageResource;
58 public Image getImageResource() {
62 public void setImageResource(Image imageResource) {
63 this.imageResource = imageResource;
66 public String getRepeat() {
70 public void setRepeat(String repeat) {
75 public static final class Color extends Style {
80 * Creates an RGB color specified with an HTML or CSS attribute string.
82 * @param webColor Colordefined as
84 Color(String webColor) {
88 public String getAsString() {
93 public static class LinearGradient extends Style {
95 private HashMap<Double, String> stops;
96 private double x0, y0, x1, y1;
98 LinearGradient(double x0, double y0, double x1, double y1) {
105 void addColorStop(double position, String color) {
107 stops = new HashMap<>();
109 stops.put(position, color);
112 public HashMap<Double, String> getStops() {
116 public void setStops(HashMap<Double, String> stops) {
120 public double getX0() {
124 public void setX0(double x0) {
128 public double getY0() {
132 public void setY0(double y0) {
136 public double getX1() {
140 public void setX1(double x1) {
144 public double getY1() {
148 public void setY1(double y1) {
153 public int hashCode() {
155 hash = 29 * hash + Objects.hashCode(this.stops);
156 hash = 29 * hash + (int) (Double.doubleToLongBits(this.x0) ^ (Double.doubleToLongBits(this.x0) >>> 32));
157 hash = 29 * hash + (int) (Double.doubleToLongBits(this.y0) ^ (Double.doubleToLongBits(this.y0) >>> 32));
158 hash = 29 * hash + (int) (Double.doubleToLongBits(this.x1) ^ (Double.doubleToLongBits(this.x1) >>> 32));
159 hash = 29 * hash + (int) (Double.doubleToLongBits(this.y1) ^ (Double.doubleToLongBits(this.y1) >>> 32));
164 public boolean equals(Object obj) {
168 if (getClass() != obj.getClass()) {
171 final LinearGradient other = (LinearGradient) obj;
172 if (!Objects.equals(this.stops, other.stops)) {
175 if (Double.doubleToLongBits(this.x0) != Double.doubleToLongBits(other.x0)) {
178 if (Double.doubleToLongBits(this.y0) != Double.doubleToLongBits(other.y0)) {
181 if (Double.doubleToLongBits(this.x1) != Double.doubleToLongBits(other.x1)) {
184 if (Double.doubleToLongBits(this.y1) != Double.doubleToLongBits(other.y1)) {
191 public static final class RadialGradient extends LinearGradient {
193 private double r0, r1;
195 RadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
196 super(x0, y0, x1, y1);
201 public double getR0() {
205 public void setR0(double r0) {
209 public double getR1() {
213 public void setR1(double r1) {
218 public int hashCode() {
219 int hash = super.hashCode();
220 hash = 17 * hash + (int) (Double.doubleToLongBits(this.r0) ^ (Double.doubleToLongBits(this.r0) >>> 32));
221 hash = 17 * hash + (int) (Double.doubleToLongBits(this.r1) ^ (Double.doubleToLongBits(this.r1) >>> 32));
227 public boolean equals(Object obj) {
231 if (getClass() != obj.getClass()) {
234 if (!super.equals(obj)) {
237 final RadialGradient other = (RadialGradient) obj;
238 if (Double.doubleToLongBits(this.r0) != Double.doubleToLongBits(other.r0)) {
241 if (Double.doubleToLongBits(this.r1) != Double.doubleToLongBits(other.r1)) {