001/* RenderableImageOp.java -- 002 Copyright (C) 2002 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038 039package java.awt.image.renderable; 040 041import java.awt.RenderingHints; 042import java.awt.geom.AffineTransform; 043import java.awt.image.RenderedImage; 044import java.util.Vector; 045 046public class RenderableImageOp implements RenderableImage 047{ 048 private final ContextualRenderedImageFactory crif; 049 private ParameterBlock block; 050 051 public RenderableImageOp(ContextualRenderedImageFactory crif, 052 ParameterBlock block) 053 { 054 this.crif = crif; 055 this.block = (ParameterBlock) block.clone(); 056 } 057 058 public Vector<RenderableImage> getSources() 059 { 060 if (block.sources == null) 061 return null; 062 int size = block.sources.size(); 063 Vector v = new Vector(); 064 for (int i = 0; i < size; i++) 065 { 066 Object o = block.sources.get(i); 067 if (o instanceof RenderableImage) 068 v.add(o); 069 } 070 return v; 071 } 072 073 public Object getProperty(String name) 074 { 075 return crif.getProperty(block, name); 076 } 077 078 public String[] getPropertyNames() 079 { 080 return crif.getPropertyNames(); 081 } 082 083 public boolean isDynamic() 084 { 085 return crif.isDynamic(); 086 } 087 088 public float getWidth() 089 { 090 return (float) crif.getBounds2D(block).getWidth(); 091 } 092 093 public float getHeight() 094 { 095 return (float) crif.getBounds2D(block).getHeight(); 096 } 097 098 public float getMinX() 099 { 100 return (float) crif.getBounds2D(block).getX(); 101 } 102 103 public float getMinY() 104 { 105 return (float) crif.getBounds2D(block).getY(); 106 } 107 108 public ParameterBlock setParameterBlock(ParameterBlock block) 109 { 110 ParameterBlock result = this.block; 111 this.block = (ParameterBlock) block.clone(); 112 return result; 113 } 114 115 public ParameterBlock getParameterBlock() 116 { 117 return block; 118 } 119 120 public RenderedImage createScaledRendering(int w, int h, 121 RenderingHints hints) 122 { 123 if (w == 0) 124 if (h == 0) 125 throw new IllegalArgumentException(); 126 else 127 w = Math.round(h * getWidth() / getHeight()); 128 if (h == 0) 129 h = Math.round(w * getHeight() / getWidth()); 130 AffineTransform xform = AffineTransform.getScaleInstance(w * getWidth(), 131 h * getHeight()); 132 return createRendering(new RenderContext(xform, hints)); 133 } 134 135 public RenderedImage createDefaultRendering() 136 { 137 return createRendering(new RenderContext(new AffineTransform())); 138 } 139 140 public RenderedImage createRendering(RenderContext context) 141 { 142 ParameterBlock copy = (ParameterBlock) block.clone(); 143 int i = block.sources.size(); 144 while (--i >= 0) 145 { 146 Object o = block.sources.get(i); 147 if (o instanceof RenderableImage) 148 { 149 RenderableImage ri = (RenderableImage) o; 150 RenderContext rc = crif.mapRenderContext(i, context, block, ri); 151 copy.sources.set(i, ri.createRendering(rc)); 152 } 153 } 154 // Now copy.sources should be only RenderedImages. 155 return crif.create(context, copy); 156 } 157} // class RenderableImageOp