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.Stroke ; 24 import java.awt.geom.Rectangle2D ; 25 import java.awt.geom.Point2D ; 26 27 33 public class StrokeShapePainter implements ShapePainter { 34 35 38 protected Shape shape; 39 40 43 protected Shape strokedShape; 44 45 48 protected Stroke stroke; 49 50 53 protected Paint paint; 54 55 62 public StrokeShapePainter(Shape shape) { 63 if (shape == null) { 64 throw new IllegalArgumentException (); 65 } 66 this.shape = shape; 67 } 68 69 74 public void setStroke(Stroke newStroke) { 75 this.stroke = newStroke; 76 this.strokedShape = null; 77 } 78 79 84 public void setPaint(Paint newPaint) { 85 this.paint = newPaint; 86 } 87 88 94 public void paint(Graphics2D g2d) { 95 if (stroke != null && paint != null) { 96 g2d.setPaint(paint); 97 g2d.setStroke(stroke); 98 g2d.draw(shape); 99 } 100 } 101 102 105 public Shape getPaintedArea(){ 106 if ((paint == null) || (stroke == null)) 107 return null; 108 109 if (strokedShape == null) 110 strokedShape = stroke.createStrokedShape(shape); 111 112 return strokedShape; 113 } 114 115 118 public Rectangle2D getPaintedBounds2D() { 119 Shape painted = getPaintedArea(); 120 if (painted == null) 121 return null; 122 123 return painted.getBounds2D(); 124 } 125 126 129 public boolean inPaintedArea(Point2D pt){ 130 Shape painted = getPaintedArea(); 131 if (painted == null) 132 return false; 133 return painted.contains(pt); 134 } 135 136 139 public Shape getSensitiveArea(){ 140 if (stroke == null) 141 return null; 142 143 if (strokedShape == null) 144 strokedShape = stroke.createStrokedShape(shape); 145 146 return strokedShape; 147 } 148 149 153 public Rectangle2D getSensitiveBounds2D() { 154 Shape sensitive = getSensitiveArea(); 155 if (sensitive == null) 156 return null; 157 158 return sensitive.getBounds2D(); 159 } 160 161 165 public boolean inSensitiveArea(Point2D pt){ 166 Shape sensitive = getSensitiveArea(); 167 if (sensitive == null) 168 return false; 169 return sensitive.contains(pt); 170 } 171 172 178 public void setShape(Shape shape){ 179 if (shape == null) { 180 throw new IllegalArgumentException (); 181 } 182 this.shape = shape; 183 this.strokedShape = null; 184 } 185 186 191 public Shape getShape(){ 192 return shape; 193 } 194 } 195 | Popular Tags |