1 7 8 17 18 package java.awt.image.renderable; 19 import java.awt.geom.AffineTransform ; 20 import java.awt.geom.Rectangle2D ; 21 import java.awt.image.RenderedImage ; 22 import java.awt.RenderingHints ; 23 import java.util.Hashtable ; 24 import java.util.Vector ; 25 26 30 public class RenderableImageOp implements RenderableImage { 31 32 33 ParameterBlock paramBlock; 34 35 36 ContextualRenderedImageFactory myCRIF; 37 38 39 Rectangle2D boundingBox; 40 41 42 54 public RenderableImageOp(ContextualRenderedImageFactory CRIF, 55 ParameterBlock paramBlock) { 56 this.myCRIF = CRIF; 57 this.paramBlock = (ParameterBlock ) paramBlock.clone(); 58 } 59 60 68 public Vector <RenderableImage > getSources() { 69 return getRenderableSources(); 70 } 71 72 private Vector getRenderableSources() { 73 Vector sources = null; 74 75 if (paramBlock.getNumSources() > 0) { 76 sources = new Vector (); 77 int i = 0; 78 while (i < paramBlock.getNumSources()) { 79 Object o = paramBlock.getSource(i); 80 if (o instanceof RenderableImage ) { 81 sources.add((RenderableImage )o); 82 i++; 83 } else { 84 break; 85 } 86 } 87 } 88 return sources; 89 } 90 91 100 public Object getProperty(String name) { 101 return myCRIF.getProperty(paramBlock, name); 102 } 103 104 108 public String [] getPropertyNames() { 109 return myCRIF.getPropertyNames(); 110 } 111 112 122 public boolean isDynamic() { 123 return myCRIF.isDynamic(); 124 } 125 126 133 public float getWidth() { 134 if (boundingBox == null) { 135 boundingBox = myCRIF.getBounds2D(paramBlock); 136 } 137 return (float)boundingBox.getWidth(); 138 } 139 140 146 public float getHeight() { 147 if (boundingBox == null) { 148 boundingBox = myCRIF.getBounds2D(paramBlock); 149 } 150 return (float)boundingBox.getHeight(); 151 } 152 153 156 public float getMinX() { 157 if (boundingBox == null) { 158 boundingBox = myCRIF.getBounds2D(paramBlock); 159 } 160 return (float)boundingBox.getMinX(); 161 } 162 163 166 public float getMinY() { 167 if (boundingBox == null) { 168 boundingBox = myCRIF.getBounds2D(paramBlock); 169 } 170 return (float)boundingBox.getMinY(); 171 } 172 173 183 public ParameterBlock setParameterBlock(ParameterBlock paramBlock) { 184 ParameterBlock oldParamBlock = this.paramBlock; 185 this.paramBlock = (ParameterBlock )paramBlock.clone(); 186 return oldParamBlock; 187 } 188 189 195 public ParameterBlock getParameterBlock() { 196 return paramBlock; 197 } 198 199 224 public RenderedImage createScaledRendering(int w, int h, 225 RenderingHints hints) { 226 double sx = (double)w/getWidth(); 228 double sy = (double)h/getHeight(); 229 if (Math.abs(sx/sy - 1.0) < 0.01) { 230 sx = sy; 231 } 232 AffineTransform usr2dev = AffineTransform.getScaleInstance(sx, sy); 233 RenderContext newRC = new RenderContext (usr2dev, hints); 234 return createRendering(newRC); 235 } 236 237 247 public RenderedImage createDefaultRendering() { 248 AffineTransform usr2dev = new AffineTransform (); RenderContext newRC = new RenderContext (usr2dev); 250 return createRendering(newRC); 251 } 252 253 291 public RenderedImage createRendering(RenderContext renderContext) { 292 RenderedImage image = null; 293 RenderContext rcOut = null; 294 295 ParameterBlock renderedParamBlock = (ParameterBlock )paramBlock.clone(); 299 Vector sources = getRenderableSources(); 300 301 try { 302 305 if (sources != null) { 306 Vector renderedSources = new Vector (); 307 for (int i = 0; i < sources.size(); i++) { 308 rcOut = myCRIF.mapRenderContext(i, renderContext, 309 paramBlock, this); 310 RenderedImage rdrdImage = 311 ((RenderableImage )sources.elementAt(i)).createRendering(rcOut); 312 if (rdrdImage == null) { 313 return null; 314 } 315 316 renderedSources.addElement(rdrdImage); 319 } 320 321 if (renderedSources.size() > 0) { 322 renderedParamBlock.setSources(renderedSources); 323 } 324 } 325 326 return myCRIF.create(renderContext, renderedParamBlock); 327 } catch (ArrayIndexOutOfBoundsException e) { 328 return null; 330 } 331 } 332 } 333 | Popular Tags |