1 18 package org.apache.batik.gvt; 19 20 import java.awt.Graphics2D ; 21 import java.awt.Paint ; 22 import java.awt.Shape ; 23 import java.awt.geom.Rectangle2D ; 24 import java.awt.geom.Point2D ; 25 26 32 public class FillShapePainter implements ShapePainter { 33 34 37 protected Shape shape; 38 39 42 protected Paint paint; 43 44 51 public FillShapePainter(Shape shape) { 52 if (shape == null) 53 throw new IllegalArgumentException ("Shape can not be null!"); 54 55 this.shape = shape; 56 } 57 58 63 public void setPaint(Paint newPaint) { 64 this.paint = newPaint; 65 } 66 67 72 public void paint(Graphics2D g2d) { 73 if (paint != null) { 74 g2d.setPaint(paint); 75 g2d.fill(shape); 76 } 77 } 78 79 82 public Shape getPaintedArea(){ 83 if (paint == null) 84 return null; 85 return shape; 86 } 87 88 91 public Rectangle2D getPaintedBounds2D(){ 92 if ((paint == null) || (shape == null)) 93 return null; 94 95 return shape.getBounds2D(); 96 } 97 98 101 public boolean inPaintedArea(Point2D pt){ 102 if ((paint == null) || (shape == null)) 103 return false; 104 105 return shape.contains(pt); 106 } 107 108 112 public Shape getSensitiveArea(){ 113 return shape; 114 } 115 116 120 public Rectangle2D getSensitiveBounds2D() { 121 if (shape == null) 122 return null; 123 return shape.getBounds2D(); 124 } 125 126 129 public boolean inSensitiveArea(Point2D pt){ 130 if (shape == null) 131 return false; 132 return shape.contains(pt); 133 } 134 135 141 public void setShape(Shape shape){ 142 if (shape == null) { 143 throw new IllegalArgumentException (); 144 } 145 this.shape = shape; 146 } 147 148 153 public Shape getShape(){ 154 return shape; 155 } 156 } 157 | Popular Tags |