source: branches/libc-0.6/src/gcc/libjava/java/awt/image/renderable/RenderableImageOp.java

Last change on this file was 1389, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.6 KB
Line 
1/* RenderableImageOp.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38
39package java.awt.image.renderable;
40
41import java.awt.RenderingHints;
42import java.awt.geom.AffineTransform;
43import java.awt.image.RenderedImage;
44import java.util.Vector;
45
46public 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 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 // Now copy.sources should be only RenderedImages.
155 return crif.create(context, copy);
156 }
157} // class RenderableImageOp
Note: See TracBrowser for help on using the repository browser.