1 18 package org.apache.batik.ext.awt; 19 20 import java.awt.Color ; 21 import java.awt.PaintContext ; 22 import java.awt.Rectangle ; 23 import java.awt.RenderingHints ; 24 import java.awt.geom.AffineTransform ; 25 import java.awt.geom.NoninvertibleTransformException ; 26 import java.awt.geom.Point2D ; 27 import java.awt.geom.Rectangle2D ; 28 import java.awt.image.ColorModel ; 29 30 88 public final class LinearGradientPaint extends MultipleGradientPaint { 89 90 91 private Point2D start, end; 92 93 120 public LinearGradientPaint(float startX, float startY, 121 float endX, float endY, 122 float[] fractions, Color [] colors) { 123 124 this(new Point2D.Float (startX, startY), 125 new Point2D.Float (endX, endY), 126 fractions, 127 colors, 128 NO_CYCLE, 129 SRGB); 130 } 131 132 160 public LinearGradientPaint(float startX, float startY, 161 float endX, float endY, 162 float[] fractions, Color [] colors, 163 CycleMethodEnum cycleMethod) { 164 this(new Point2D.Float (startX, startY), 165 new Point2D.Float (endX, endY), 166 fractions, 167 colors, 168 cycleMethod, 169 SRGB); 170 } 171 172 192 public LinearGradientPaint(Point2D start, Point2D end, float[] fractions, 193 Color [] colors) { 194 195 this(start, end, fractions, colors, NO_CYCLE, SRGB); 196 } 197 198 222 public LinearGradientPaint(Point2D start, Point2D end, float[] fractions, 223 Color [] colors, 224 CycleMethodEnum cycleMethod, 225 ColorSpaceEnum colorSpace) { 226 227 this(start, end, fractions, colors, cycleMethod, colorSpace, 228 new AffineTransform ()); 229 230 } 231 232 259 public LinearGradientPaint(Point2D start, Point2D end, float[] fractions, 260 Color [] colors, 261 CycleMethodEnum cycleMethod, 262 ColorSpaceEnum colorSpace, 263 AffineTransform gradientTransform) { 264 super(fractions, colors, cycleMethod, colorSpace, gradientTransform); 265 266 if (start == null || end == null) { 270 throw new NullPointerException ("Start and end points must be" + 271 "non-null"); 272 } 273 274 if (start.equals(end)) { 275 throw new IllegalArgumentException ("Start point cannot equal" + 276 "endpoint"); 277 } 278 279 this.start = (Point2D )start.clone(); 281 282 this.end = (Point2D )end.clone(); 283 284 } 285 286 309 public PaintContext createContext(ColorModel cm, 310 Rectangle deviceBounds, 311 Rectangle2D userBounds, 312 AffineTransform transform, 313 RenderingHints hints) { 314 315 transform = new AffineTransform (transform); 317 transform.concatenate(gradientTransform); 319 320 try { 321 return new LinearGradientPaintContext(cm, 322 deviceBounds, 323 userBounds, 324 transform, 325 hints, 326 start, 327 end, 328 fractions, 329 this.getColors(), 330 cycleMethod, 331 colorSpace); 332 } 333 334 catch(NoninvertibleTransformException e) { 335 e.printStackTrace(); 336 throw new IllegalArgumentException ("transform should be" + 337 "invertible"); 338 } 339 } 340 341 347 public Point2D getStartPoint() { 348 return new Point2D.Double (start.getX(), start.getY()); 349 } 350 351 356 public Point2D getEndPoint() { 357 return new Point2D.Double (end.getX(), end.getY()); 358 } 359 360 } 361 362 363 | Popular Tags |