1 18 package org.apache.batik.ext.awt.image.renderable; 19 20 import java.awt.Color ; 21 import java.awt.Paint ; 22 import java.awt.Rectangle ; 23 import java.awt.Shape ; 24 import java.awt.geom.AffineTransform ; 25 import java.awt.geom.Rectangle2D ; 26 import java.awt.image.RenderedImage ; 27 import java.awt.image.renderable.RenderContext ; 28 29 import org.apache.batik.ext.awt.image.PadMode; 30 import org.apache.batik.ext.awt.image.rendered.CachableRed; 31 import org.apache.batik.ext.awt.image.rendered.FloodRed; 32 import org.apache.batik.ext.awt.image.rendered.PadRed; 33 34 41 42 public class FloodRable8Bit extends AbstractRable 43 implements FloodRable { 44 45 48 Paint floodPaint; 49 50 53 Rectangle2D floodRegion; 54 55 59 public FloodRable8Bit(Rectangle2D floodRegion, 60 Paint floodPaint) { 61 setFloodPaint(floodPaint); 62 setFloodRegion(floodRegion); 63 } 64 65 69 public void setFloodPaint(Paint paint) { 70 touch(); 71 if (paint == null) { 72 floodPaint = new Color (0, 0, 0, 0); 74 } else { 75 floodPaint = paint; 76 } 77 } 78 79 83 public Paint getFloodPaint() { 84 return floodPaint; 86 } 87 88 public Rectangle2D getBounds2D() { 89 90 return (Rectangle2D )floodRegion.clone(); 91 } 92 93 96 public Rectangle2D getFloodRegion(){ 97 return (Rectangle2D )floodRegion.clone(); 98 } 99 100 103 public void setFloodRegion(Rectangle2D floodRegion){ 104 if(floodRegion == null){ 105 throw new IllegalArgumentException (); 106 } 107 108 touch(); 109 this.floodRegion = floodRegion; 110 } 111 112 118 119 public RenderedImage createRendering(RenderContext rc) { 120 AffineTransform usr2dev = rc.getTransform(); 122 if (usr2dev == null) { 123 usr2dev = new AffineTransform (); 124 } 125 126 Rectangle2D imageRect = getBounds2D(); 127 128 Rectangle2D userAOI; 131 Shape aoi = rc.getAreaOfInterest(); 132 if (aoi == null) { 133 aoi = imageRect; 134 userAOI = imageRect; 135 } else { 136 userAOI = aoi.getBounds2D(); 137 138 if (imageRect.intersects(userAOI) == false) 140 return null; 141 142 Rectangle2D.intersect(imageRect, userAOI, userAOI); 144 } 145 146 final Rectangle renderedArea 149 = usr2dev.createTransformedShape(userAOI).getBounds(); 150 151 if ((renderedArea.width <= 0) || (renderedArea.height <= 0)) { 152 return null; 154 } 155 156 CachableRed cr; 157 cr = new FloodRed(renderedArea, getFloodPaint()); 158 cr = new PadRed(cr, renderedArea, PadMode.ZERO_PAD, null); 162 163 return cr; 164 } 165 } 166 | Popular Tags |