More JavaDoc improvements.
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;
24 * Style for Stroke and Fill of GraphicsContext. Styles are created using
25 * GraphicsContexts factory methods. If the Implementation supports it, native
26 * Styles will be cached for performance reasons. This happens the first time
27 * the Style is actually used.
34 private int cacheHash;
39 void cache(Object toCache) {
40 cacheHash = hashCode();
41 this.cached = toCache;
44 private boolean isCached() {
45 return cacheHash == hashCode();
49 return isCached() ? cached : null;
53 * A Fill Pattern using an Image Resource to create a fill style supporting
54 * different repeat styles repeat, repeat-x, repeat-y, or no-repeat. Default
57 public static final class Pattern extends Style {
59 private final Image imageResource;
60 private final String repeat;
64 * @param imageResource the base image of thsi pattern
65 * @param repeat the repeat pattern, possible values are repeat,
66 * repeat-x, repeat-y, or no-repeat.
68 public Pattern(Image imageResource, String repeat) {
69 this.imageResource = imageResource;
74 * Get the base image of this pattern
76 * @return the base image of this pattern
78 public Image getImageResource() {
83 * Get the repeat style for this pattern
85 * @return return the repeat style
87 public String getRepeat() {
96 public static final class Color extends Style {
101 * Creates an RGB color specified with an HTML or CSS attribute string.
103 * @param webColor Color defined as web color (e.g. #ff0000)
105 public Color(String webColor) {
112 * @return the Color value as a Web Color (e.g. #ff0000)
114 public String getAsString() {
120 * A Linear Gradient. The Gradient has a direction defined by two
121 * coordinates and stops defining the Color at a specific position.
123 public static class LinearGradient extends Style {
125 private HashMap<Double, String> stops;
126 private double x0, y0, x1, y1;
130 * @param x0 the x coordinate of the start point for this gradient
131 * @param y0 the y coordinate of the start point for this gradient
132 * @param x1 the x coordinate of the end point for this gradient
133 * @param y1 the y coordinate of the end point for this gradient
135 LinearGradient(double x0, double y0, double x1, double y1) {
143 * Add a new Color stop. A color stop defines a fixed color at a
144 * position along the coordinates.
146 * @param position the position of this stop in percent [0.0-1.0]
147 * @param color A Color defined in web format (e.g. #ff0000)
149 void addColorStop(double position, String color) {
151 stops = new HashMap<>();
153 stops.put(position, color);
157 * Get the stops of this gradient.
159 * @return the stops of this gradient
161 public HashMap<Double, String> getStops() {
162 return new HashMap<>(stops);
166 * Set the stops as Position/Color pairs
168 * @param stops the stops for thsi Gradient
170 public void setStops(HashMap<Double, String> stops) {
171 this.stops = new HashMap<>(stops);
175 * Get the X coordinate of the Gradients start point
177 * @return x coordinate
179 public double getX0() {
184 * Set the X coordinate of the Gradients start point
186 * @param x0 x coordinate
188 public void setX0(double x0) {
193 * Get the Y coordinate of the Gradients start point
195 * @return y coordinate
197 public double getY0() {
202 * Set the Y coordinate of the Gradients start point
204 * @param y0 y coordinate
206 public void setY0(double y0) {
211 * Set the X coordinate of the Gradients end point
213 * @return x coordinate
215 public double getX1() {
220 * Set the X coordinate of the Gradients end point
222 * @param X coordinate
224 public void setX1(double x1) {
229 * Get the Y coordinate of the Gradients end point
231 * @return y coordinate
233 public double getY1() {
238 * Set the Y coordinate of the Gradients end point
240 * @param y1 coordinate
242 public void setY1(double y1) {
247 public int hashCode() {
249 hash = 29 * hash + Objects.hashCode(this.stops);
250 hash = 29 * hash + (int) (Double.doubleToLongBits(this.x0) ^ (Double.doubleToLongBits(this.x0) >>> 32));
251 hash = 29 * hash + (int) (Double.doubleToLongBits(this.y0) ^ (Double.doubleToLongBits(this.y0) >>> 32));
252 hash = 29 * hash + (int) (Double.doubleToLongBits(this.x1) ^ (Double.doubleToLongBits(this.x1) >>> 32));
253 hash = 29 * hash + (int) (Double.doubleToLongBits(this.y1) ^ (Double.doubleToLongBits(this.y1) >>> 32));
258 public boolean equals(Object obj) {
262 if (getClass() != obj.getClass()) {
265 final LinearGradient other = (LinearGradient) obj;
266 if (!Objects.equals(this.stops, other.stops)) {
269 if (Double.doubleToLongBits(this.x0) != Double.doubleToLongBits(other.x0)) {
272 if (Double.doubleToLongBits(this.y0) != Double.doubleToLongBits(other.y0)) {
275 if (Double.doubleToLongBits(this.x1) != Double.doubleToLongBits(other.x1)) {
278 if (Double.doubleToLongBits(this.y1) != Double.doubleToLongBits(other.y1)) {
286 * A Radial Gradient. Radial gradients are defined with two imaginary
287 * circles, a starting circle and an ending circle. The gradient starts with
288 * the start circle and moves towards the end circle.
290 public static final class RadialGradient extends LinearGradient {
292 private double r0, r1;
295 * Create a new RadialGradient
297 * @param x0 x Coordinate of starting circle
298 * @param y0 y Coordinate of starting circle
299 * @param r0 radius of starting circle
300 * @param x1 x coordinate of ending circle
301 * @param y1 y coordinate of ending circle
302 * @param r1 radius of ending circle
304 RadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
305 super(x0, y0, x1, y1);
311 * get the radius of the start circle.
314 public double getR0() {
319 * set the radius of the start circle.
320 * @param r0 the radius
322 public void setR0(double r0) {
327 * get the radius of the end circle
330 public double getR1() {
335 * set the radius of the end circle.
336 * @param r1 the radius.
338 public void setR1(double r1) {
343 public int hashCode() {
344 int hash = super.hashCode();
345 hash = 17 * hash + (int) (Double.doubleToLongBits(this.r0) ^ (Double.doubleToLongBits(this.r0) >>> 32));
346 hash = 17 * hash + (int) (Double.doubleToLongBits(this.r1) ^ (Double.doubleToLongBits(this.r1) >>> 32));
352 public boolean equals(Object obj) {
356 if (getClass() != obj.getClass()) {
359 if (!super.equals(obj)) {
362 final RadialGradient other = (RadialGradient) obj;
363 if (Double.doubleToLongBits(this.r0) != Double.doubleToLongBits(other.r0)) {
366 if (Double.doubleToLongBits(this.r1) != Double.doubleToLongBits(other.r1)) {
369 if ((this.getCached() == null) != (other.getCached() == null)) {