001: /*
002: * $RCSfile: NullCRIF.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:57:12 $
010: * $State: Exp $
011: */
012: package javax.media.jai;
013:
014: import java.awt.RenderingHints;
015: import java.awt.geom.Rectangle2D;
016: import java.awt.geom.Rectangle2D.Float;
017: import java.awt.image.RenderedImage;
018: import java.awt.image.renderable.ContextualRenderedImageFactory;
019: import java.awt.image.renderable.ParameterBlock;
020: import java.awt.image.renderable.RenderableImage;
021: import java.awt.image.renderable.RenderContext;
022: import javax.media.jai.ImageLayout;
023: import javax.media.jai.JAI;
024: import javax.media.jai.RenderedOp;
025:
026: /**
027: * A <code>ContextualRenderedImageFactory</code> representing an operation
028: * which performs no processing of its image source(s) per se, i.e., a no-op.
029: *
030: * <p> The primary use of this image factory is as a utility class in
031: * implementing operations which generate only non-image data via the
032: * use of <code>PropertyGenerator</code>s. A <code>PropertyGenerator</code>
033: * is defined as always contributing to the property environment of a given
034: * operation when it is returned by the <code>getPropertyGenerators()</code>
035: * method of the <code>OperationDescriptor</code> corresponding to the
036: * operation.
037: *
038: * <p> The procedure to be followed to register an operation which generates
039: * only non-image data as JAI image properties is as follows:
040: *
041: * <ul>
042: * <li> Create a <code>PropertyGenerator</code> which calculates the
043: * non-image data given the operation node;
044: * <li> Create an <code>OperationDescriptor</code> the
045: * <code>getPropertyGenerators()</code> method of which returns the
046: * <code>PropertyGenerator</code> defined in the previous step;
047: * <li> Register the <code>OperationDescriptor</code> with the
048: * <code>OperationRegistry</code> as usual by passing it to
049: * <code>registerOperationDescriptor()</code> along with the operation name;
050: * <li> Register a <code>NullCRIF</code> as the image factory corresponding to
051: * this operation.
052: * </ul>
053: *
054: * The properties emitted by the associated <code>PropertyGenerator</code>(s)
055: * will then be available by invoking <code>getProperty()</code> on the node
056: * returned by <code>JAI.create()</code> using the registered operation name.
057: *
058: * @see CRIFImpl
059: * @see java.awt.image.renderable.ContextualRenderedImageFactory
060: *
061: * @since JAI 1.1
062: */
063: public class NullCRIF extends CRIFImpl {
064:
065: /**
066: * Image returned by <code>RenderedImageFactory.create()</code>
067: * when there are ono sources.
068: */
069: private static RenderedImage sourcelessImage = null;
070:
071: /**
072: * Constructs a <code>NullCRIF</code>. The <code>operationName</code>
073: * in the superclass is set to <code>null</code>.
074: */
075: public NullCRIF() {
076: super ();
077: }
078:
079: /**
080: * Sets the value of the <code>RenderedImage</code> to be returned by
081: * the <code>RenderedImageFactory.create()</code> method when there are
082: * no sources in the <code>ParameterBlock</code>.
083: *
084: * @param a <code>RenderedImage</code> or <code>null</code>.
085: */
086: public static final synchronized void setSourcelessImage(
087: RenderedImage im) {
088: sourcelessImage = im;
089: }
090:
091: /**
092: * Gets the value of the RenderedImage to be returned by the RIF.create()
093: * method when there are no sources in the <code>ParameterBlock</code>.
094: *
095: * @return a <code>RenderedImage</code> or <code>null</code>.
096: */
097: public static final synchronized RenderedImage getSourcelessImage() {
098: return sourcelessImage;
099: }
100:
101: /**
102: * Returns the first source in the source list in the
103: * <code>ParameterBlock</code> or the value returned by
104: * <code>getSourcelessImage()</code> if there are no soures.
105: *
106: * @throws ClassCastException if there are sources and the source
107: * at index zero is not a <code>RenderedImage</code>.
108: */
109: public RenderedImage create(ParameterBlock args,
110: RenderingHints renderHints) {
111: return args.getNumSources() == 0 ? getSourcelessImage() : args
112: .getRenderedSource(0);
113: }
114: }
|