1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45:
46: public class RenderableImageOp implements RenderableImage
47: {
48: private final ContextualRenderedImageFactory crif;
49: private ParameterBlock block;
50:
51: public RenderableImageOp(ContextualRenderedImageFactory crif,
52: ParameterBlock block)
53: {
54: this.crif = crif;
55: this.block = (ParameterBlock) block.clone();
56: }
57:
58: public Vector<RenderableImage> getSources()
59: {
60: if (block.sources == null)
61: return null;
62: int size = block.sources.size();
63: Vector v = new Vector();
64: for (int i = 0; i < size; i++)
65: {
66: Object o = block.sources.get(i);
67: if (o instanceof RenderableImage)
68: v.add(o);
69: }
70: return v;
71: }
72:
73: public Object getProperty(String name)
74: {
75: return crif.getProperty(block, name);
76: }
77:
78: public String[] getPropertyNames()
79: {
80: return crif.getPropertyNames();
81: }
82:
83: public boolean isDynamic()
84: {
85: return crif.isDynamic();
86: }
87:
88: public float getWidth()
89: {
90: return (float) crif.getBounds2D(block).getWidth();
91: }
92:
93: public float getHeight()
94: {
95: return (float) crif.getBounds2D(block).getHeight();
96: }
97:
98: public float getMinX()
99: {
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:
155: return crif.create(context, copy);
156: }
157: }