src/share/classes/java/awt/image/renderable/RenderableImageOp.java

Print this page


   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


  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


  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<RenderableImage> getRenderableSources() {
  91         Vector<RenderableImage> 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<? extends Object> 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<Object> 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);