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 102 103 public final class RadialGradientPaint extends MultipleGradientPaint { 104 105 106 private Point2D focus; 107 108 109 private Point2D center; 110 111 112 private float radius; 113 114 145 public RadialGradientPaint(float cx, float cy, float radius, 146 float[] fractions, Color [] colors) { 147 this(cx, cy, 148 radius, 149 cx, cy, 150 fractions, 151 colors); 152 } 153 154 181 public RadialGradientPaint(Point2D center, float radius, 182 float[] fractions, Color [] colors) { 183 this(center, 184 radius, 185 center, 186 fractions, 187 colors); 188 } 189 190 225 public RadialGradientPaint(float cx, float cy, float radius, 226 float fx, float fy, 227 float[] fractions, Color [] colors) { 228 this(new Point2D.Float (cx, cy), 229 radius, 230 new Point2D.Float (fx, fy), 231 fractions, 232 colors, 233 NO_CYCLE, 234 SRGB); 235 } 236 237 266 public RadialGradientPaint(Point2D center, float radius, 267 Point2D focus, 268 float[] fractions, Color [] colors) { 269 this(center, 270 radius, 271 focus, 272 fractions, 273 colors, 274 NO_CYCLE, 275 SRGB); 276 } 277 278 311 public RadialGradientPaint(Point2D center, float radius, 312 Point2D focus, 313 float[] fractions, Color [] colors, 314 CycleMethodEnum cycleMethod, 315 ColorSpaceEnum colorSpace) { 316 this(center, 317 radius, 318 focus, 319 fractions, 320 colors, 321 cycleMethod, 322 colorSpace, 323 new AffineTransform ()); 324 } 325 326 362 public RadialGradientPaint(Point2D center, 363 float radius, 364 Point2D focus, 365 float[] fractions, Color [] colors, 366 CycleMethodEnum cycleMethod, 367 ColorSpaceEnum colorSpace, 368 AffineTransform gradientTransform){ 369 super(fractions, colors, cycleMethod, colorSpace, gradientTransform); 370 371 if (center == null) { 373 throw new NullPointerException ("Center point should not be null."); 374 } 375 376 if (focus == null) { 377 throw new NullPointerException ("Focus point should not be null."); 378 } 379 380 if (radius <= 0) { 381 throw new IllegalArgumentException ("radius should be greater than zero"); 382 } 383 384 this.center = (Point2D )center.clone(); 386 this.focus = (Point2D )focus.clone(); 387 this.radius = radius; 388 } 389 390 413 public RadialGradientPaint(Rectangle2D gradientBounds, 414 float[] fractions, Color [] colors) { 415 416 this((float)gradientBounds.getX() + 418 ( (float)gradientBounds.getWidth() / 2), 419 420 (float)gradientBounds.getY() + 421 ( (float)gradientBounds.getWidth() / 2), 422 423 (float)gradientBounds.getWidth() / 2, 424 fractions, colors); 425 } 426 427 428 453 public PaintContext createContext(ColorModel cm, 454 Rectangle deviceBounds, 455 Rectangle2D userBounds, 456 AffineTransform transform, 457 RenderingHints hints) { 458 transform = new AffineTransform (transform); 460 transform.concatenate(gradientTransform); 462 463 try{ 464 return new RadialGradientPaintContext 465 (cm, deviceBounds, userBounds, transform, hints, 466 (float)center.getX(), (float)center.getY(), radius, 467 (float)focus.getX(), (float)focus.getY(), 468 fractions, colors, cycleMethod, colorSpace); 469 } 470 471 catch(NoninvertibleTransformException e){ 472 throw new IllegalArgumentException ("transform should be " + 473 "invertible"); 474 } 475 } 476 477 481 public Point2D getCenterPoint() { 482 return new Point2D.Double (center.getX(), center.getY()); 483 } 484 485 488 public Point2D getFocusPoint() { 489 return new Point2D.Double (focus.getX(), focus.getY()); 490 } 491 492 495 public float getRadius() { 496 return radius; 497 } 498 499 } 500 501 | Popular Tags |