1 /*
2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
66 *
67 * @param CRIF a ContextualRenderedImageFactory object
68 * @param paramBlock a ParameterBlock containing this operation's source
69 * images and other parameters necessary for the operation
70 * to run.
71 */
72 public RenderableImageOp(ContextualRenderedImageFactory CRIF,
73 ParameterBlock paramBlock) {
74 this.myCRIF = CRIF;
75 this.paramBlock = (ParameterBlock) paramBlock.clone();
76 }
77
78 /**
79 * Returns a vector of RenderableImages that are the sources of
80 * image data for this RenderableImage. Note that this method may
81 * return an empty vector, to indicate that the image has no sources,
82 * or null, to indicate that no information is available.
83 *
84 * @return a (possibly empty) Vector of RenderableImages, or null.
85 */
86 public Vector<RenderableImage> getSources() {
87 return getRenderableSources();
88 }
89
90 private Vector getRenderableSources() {
91 Vector sources = null;
92
93 if (paramBlock.getNumSources() > 0) {
94 sources = new Vector();
95 int i = 0;
96 while (i < paramBlock.getNumSources()) {
97 Object o = paramBlock.getSource(i);
98 if (o instanceof RenderableImage) {
99 sources.add((RenderableImage)o);
100 i++;
101 } else {
102 break;
103 }
104 }
105 }
106 return sources;
107 }
108
109 /**
110 * Gets a property from the property set of this image.
111 * If the property name is not recognized, java.awt.Image.UndefinedProperty
112 * will be returned.
113 *
114 * @param name the name of the property to get, as a String.
297 * This provides a basis case for the recursion.
298 *
299 * <p> The created RenderedImage may have a property identified
300 * by the String HINTS_OBSERVED to indicate which RenderingHints
301 * (from the RenderContext) were used to create the image.
302 * In addition any RenderedImages
303 * that are obtained via the getSources() method on the created
304 * RenderedImage may have such a property.
305 *
306 * @param renderContext The RenderContext to use to perform the rendering.
307 * @return a RenderedImage containing the desired output image.
308 */
309 public RenderedImage createRendering(RenderContext renderContext) {
310 RenderedImage image = null;
311 RenderContext rcOut = null;
312
313 // Clone the original ParameterBlock; if the ParameterBlock
314 // contains RenderableImage sources, they will be replaced by
315 // RenderedImages.
316 ParameterBlock renderedParamBlock = (ParameterBlock)paramBlock.clone();
317 Vector sources = getRenderableSources();
318
319 try {
320 // This assumes that if there is no renderable source, that there
321 // is a rendered source in paramBlock
322
323 if (sources != null) {
324 Vector renderedSources = new Vector();
325 for (int i = 0; i < sources.size(); i++) {
326 rcOut = myCRIF.mapRenderContext(i, renderContext,
327 paramBlock, this);
328 RenderedImage rdrdImage =
329 ((RenderableImage)sources.elementAt(i)).createRendering(rcOut);
330 if (rdrdImage == null) {
331 return null;
332 }
333
334 // Add this rendered image to the ParameterBlock's
335 // list of RenderedImages.
336 renderedSources.addElement(rdrdImage);
337 }
338
339 if (renderedSources.size() > 0) {
340 renderedParamBlock.setSources(renderedSources);
341 }
342 }
343
344 return myCRIF.create(renderContext, renderedParamBlock);
|
1 /*
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
66 *
67 * @param CRIF a ContextualRenderedImageFactory object
68 * @param paramBlock a ParameterBlock containing this operation's source
69 * images and other parameters necessary for the operation
70 * to run.
71 */
72 public RenderableImageOp(ContextualRenderedImageFactory CRIF,
73 ParameterBlock paramBlock) {
74 this.myCRIF = CRIF;
75 this.paramBlock = (ParameterBlock) paramBlock.clone();
76 }
77
78 /**
79 * Returns a vector of RenderableImages that are the sources of
80 * image data for this RenderableImage. Note that this method may
81 * return an empty vector, to indicate that the image has no sources,
82 * or null, to indicate that no information is available.
83 *
84 * @return a (possibly empty) Vector of RenderableImages, or null.
85 */
86 @SuppressWarnings("unchecked")
87 public Vector<RenderableImage> getSources() {
88 return (Vector<RenderableImage>)(Vector)getRenderableSources();
89 }
90
91 private Vector<Object> getRenderableSources() {
92 Vector<Object> sources = null;
93
94 if (paramBlock.getNumSources() > 0) {
95 sources = new Vector<>();
96 int i = 0;
97 while (i < paramBlock.getNumSources()) {
98 Object o = paramBlock.getSource(i);
99 if (o instanceof RenderableImage) {
100 sources.add((RenderableImage)o);
101 i++;
102 } else {
103 break;
104 }
105 }
106 }
107 return sources;
108 }
109
110 /**
111 * Gets a property from the property set of this image.
112 * If the property name is not recognized, java.awt.Image.UndefinedProperty
113 * will be returned.
114 *
115 * @param name the name of the property to get, as a String.
298 * This provides a basis case for the recursion.
299 *
300 * <p> The created RenderedImage may have a property identified
301 * by the String HINTS_OBSERVED to indicate which RenderingHints
302 * (from the RenderContext) were used to create the image.
303 * In addition any RenderedImages
304 * that are obtained via the getSources() method on the created
305 * RenderedImage may have such a property.
306 *
307 * @param renderContext The RenderContext to use to perform the rendering.
308 * @return a RenderedImage containing the desired output image.
309 */
310 public RenderedImage createRendering(RenderContext renderContext) {
311 RenderedImage image = null;
312 RenderContext rcOut = null;
313
314 // Clone the original ParameterBlock; if the ParameterBlock
315 // contains RenderableImage sources, they will be replaced by
316 // RenderedImages.
317 ParameterBlock renderedParamBlock = (ParameterBlock)paramBlock.clone();
318 Vector<Object> sources = getRenderableSources();
319
320 try {
321 // This assumes that if there is no renderable source, that there
322 // is a rendered source in paramBlock
323
324 if (sources != null) {
325 Vector<Object> renderedSources = new Vector<>();
326 for (int i = 0; i < sources.size(); i++) {
327 rcOut = myCRIF.mapRenderContext(i, renderContext,
328 paramBlock, this);
329 RenderedImage rdrdImage =
330 ((RenderableImage)sources.elementAt(i)).createRendering(rcOut);
331 if (rdrdImage == null) {
332 return null;
333 }
334
335 // Add this rendered image to the ParameterBlock's
336 // list of RenderedImages.
337 renderedSources.addElement(rdrdImage);
338 }
339
340 if (renderedSources.size() > 0) {
341 renderedParamBlock.setSources(renderedSources);
342 }
343 }
344
345 return myCRIF.create(renderContext, renderedParamBlock);
|