1 /* RenderableImageOp.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java
.awt
.image
.renderable
;
41 import java
.awt
.RenderingHints
;
42 import java
.awt
.geom
.AffineTransform
;
43 import java
.awt
.image
.RenderedImage
;
44 import java
.util
.Vector
;
46 public class RenderableImageOp
implements RenderableImage
48 private final ContextualRenderedImageFactory crif
;
49 private ParameterBlock block
;
51 public RenderableImageOp(ContextualRenderedImageFactory crif
,
55 this.block
= (ParameterBlock
) block
.clone();
58 public Vector
getSources()
60 if (block
.sources
== null)
62 int size
= block
.sources
.size();
63 Vector v
= new Vector();
64 for (int i
= 0; i
< size
; i
++)
66 Object o
= block
.sources
.get(i
);
67 if (o
instanceof RenderableImage
)
73 public Object
getProperty(String name
)
75 return crif
.getProperty(block
, name
);
78 public String
[] getPropertyNames()
80 return crif
.getPropertyNames();
83 public boolean isDynamic()
85 return crif
.isDynamic();
88 public float getWidth()
90 return (float) crif
.getBounds2D(block
).getWidth();
93 public float getHeight()
95 return (float) crif
.getBounds2D(block
).getHeight();
98 public float getMinX()
100 return (float) crif
.getBounds2D(block
).getX();
103 public float getMinY()
105 return (float) crif
.getBounds2D(block
).getY();
108 public ParameterBlock
setParameterBlock(ParameterBlock block
)
110 ParameterBlock result
= this.block
;
111 this.block
= (ParameterBlock
) block
.clone();
115 public ParameterBlock
getParameterBlock()
120 public RenderedImage
createScaledRendering(int w
, int h
,
121 RenderingHints hints
)
125 throw new IllegalArgumentException();
127 w
= Math
.round(h
* getWidth() / getHeight());
129 h
= Math
.round(w
* getHeight() / getWidth());
130 AffineTransform xform
= AffineTransform
.getScaleInstance(w
* getWidth(),
132 return createRendering(new RenderContext(xform
, hints
));
135 public RenderedImage
createDefaultRendering()
137 return createRendering(new RenderContext(new AffineTransform()));
140 public RenderedImage
createRendering(RenderContext context
)
142 ParameterBlock copy
= (ParameterBlock
) block
.clone();
143 int i
= block
.sources
.size();
146 Object o
= block
.sources
.get(i
);
147 if (o
instanceof RenderableImage
)
149 RenderableImage ri
= (RenderableImage
) o
;
150 RenderContext rc
= crif
.mapRenderContext(i
, context
, block
, ri
);
151 copy
.sources
.set(i
, ri
.createRendering(rc
));
154 // Now copy.sources should be only RenderedImages.
155 return crif
.create(context
, copy
);
157 } // class RenderableImageOp