1.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java Thu Sep 26 14:20:18 2013 -0700
1.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java Thu Sep 26 16:33:04 2013 -0700
1.3 @@ -17,6 +17,7 @@
1.4 */
1.5 package net.java.html.canvas;
1.6
1.7 +import java.util.Collection;
1.8 import java.util.HashMap;
1.9 import java.util.Objects;
1.10
1.11 @@ -49,31 +50,42 @@
1.12 return isCached() ? cached : null;
1.13 }
1.14
1.15 + /**
1.16 + * A Fill Pattern using an Image Resource to create a fill style supporting
1.17 + * different repeat styles repeat, repeat-x, repeat-y, or no-repeat.
1.18 + * Default is repeat.
1.19 + */
1.20 public static final class Pattern extends Style {
1.21
1.22 - private Image imageResource;
1.23 - private String repeat;
1.24 + private final Image imageResource;
1.25 + private final String repeat;
1.26
1.27 + /**
1.28 + *
1.29 + * @param imageResource the base image of thsi pattern
1.30 + * @param repeat the repeat pattern, possible values are repeat, repeat-x, repeat-y, or no-repeat.
1.31 + */
1.32 public Pattern(Image imageResource, String repeat) {
1.33 this.imageResource = imageResource;
1.34 this.repeat = repeat;
1.35 }
1.36
1.37 + /**
1.38 + * Get the base image of this pattern
1.39 + * @return the base image of this pattern
1.40 + */
1.41 public Image getImageResource() {
1.42 return imageResource;
1.43 }
1.44
1.45 - public void setImageResource(Image imageResource) {
1.46 - this.imageResource = imageResource;
1.47 - }
1.48 -
1.49 + /**
1.50 + * Get the repeat style for this pattern
1.51 + * @return return the repeat style
1.52 + */
1.53 public String getRepeat() {
1.54 return repeat;
1.55 }
1.56
1.57 - public void setRepeat(String repeat) {
1.58 - this.repeat = repeat;
1.59 - }
1.60 }
1.61
1.62 public static final class Color extends Style {
1.63 @@ -83,22 +95,38 @@
1.64 /**
1.65 * Creates an RGB color specified with an HTML or CSS attribute string.
1.66 *
1.67 - * @param webColor Colordefined as
1.68 + * @param webColor Color defined as web color (e.g. #ff0000)
1.69 */
1.70 public Color(String webColor) {
1.71 this.web = webColor;
1.72 }
1.73
1.74 + /**
1.75 + *
1.76 + *
1.77 + * @return the Color value as a Web Color (e.g. #ff0000)
1.78 + */
1.79 public String getAsString() {
1.80 return web;
1.81 }
1.82 }
1.83
1.84 + /**
1.85 + * A Linear Gradient. The GRadient has a direction defined by two coordinates
1.86 + * and stops defining the Color at a specific position.
1.87 + */
1.88 public static class LinearGradient extends Style {
1.89
1.90 private HashMap<Double, String> stops;
1.91 private double x0, y0, x1, y1;
1.92
1.93 + /**
1.94 + *
1.95 + * @param x0 the x coordinate of the start point for this gradient
1.96 + * @param y0 the y coordinate of the start point for this gradient
1.97 + * @param x1 the x coordinate of the end point for this gradient
1.98 + * @param y1 the y coordinate of the end point for this gradient
1.99 + */
1.100 LinearGradient(double x0, double y0, double x1, double y1) {
1.101 this.x0 = x0;
1.102 this.y0 = y0;
1.103 @@ -106,6 +134,12 @@
1.104 this.y1 = y1;
1.105 }
1.106
1.107 + /**
1.108 + * Add a new Color stop. A color stop defines a fixed color at a position
1.109 + * along the coordinates.
1.110 + * @param position the position of this stop in percent [0.0-1.0]
1.111 + * @param color A Color defined in web format (e.g. #ff0000)
1.112 + */
1.113 void addColorStop(double position, String color) {
1.114 if (stops == null) {
1.115 stops = new HashMap<>();
1.116 @@ -113,14 +147,23 @@
1.117 stops.put(position, color);
1.118 }
1.119
1.120 - public HashMap<Double, String> getStops() {
1.121 - return stops;
1.122 + /**
1.123 + * Get the stops of this gradient.
1.124 + * @return the stops of this gradient
1.125 + */
1.126 + public HashMap<Double, String> getStops(){
1.127 + return new HashMap<>(stops);
1.128 + }
1.129 +
1.130 + /**
1.131 + * Set the stops as Position/Color pairs
1.132 + * @param stops the stops for thsi Gradient
1.133 + */
1.134 + public void setStops(HashMap<Double, String> stops) {
1.135 + this.stops = new HashMap<>(stops);
1.136 }
1.137
1.138 - public void setStops(HashMap<Double, String> stops) {
1.139 - this.stops = stops;
1.140 - }
1.141 -
1.142 +
1.143 public double getX0() {
1.144 return x0;
1.145 }