001: /*
002: * $RCSfile: NullDescriptor.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:41 $
010: * $State: Exp $
011: */
012: package javax.media.jai.operator;
013:
014: import java.awt.Rectangle;
015: import java.awt.RenderingHints;
016: import java.awt.image.RenderedImage;
017: import java.awt.image.renderable.ParameterBlock;
018: import java.awt.image.renderable.RenderableImage;
019: import java.util.Vector;
020: import javax.media.jai.JAI;
021: import javax.media.jai.OperationDescriptorImpl;
022: import javax.media.jai.OperationNode;
023: import javax.media.jai.ParameterBlockJAI;
024: import javax.media.jai.RenderableOp;
025: import javax.media.jai.RenderedOp;
026: import javax.media.jai.registry.RenderableRegistryMode;
027: import javax.media.jai.registry.RenderedRegistryMode;
028:
029: /**
030: * An <code>OperationDescriptor</code> describing the "Null" operation.
031: *
032: * <p> The "Null" operation performs no processing. It merely propagates its
033: * first source along the operation chain unmodified. There may be an
034: * arbitrary number of sources but only the first one is passed along
035: * so it must have the appropriate class type for the operation mode.
036: *
037: * <p> This operation may be useful as a placeholder in operation chains
038: * and in creating nodes to which <code>PropertyGenerator</code>s may be
039: * attached. This would enable non-image data nodes to be present in chains
040: * without requiring that specific <code>OperationDescriptor</code>s be
041: * implemented for these operations. The <code>PropertyGenerator</code>s
042: * required would in this case be added locally to the nodes using the
043: * <code>addPropertyGenerator()</code> method of the node.
044: *
045: * <p><table border=1>
046: * <caption>Resource List</caption>
047: * <tr><th>Name</th> <th>Value</th></tr>
048: * <tr><td>GlobalName</td> <td>Null</td></tr>
049: * <tr><td>LocalName</td> <td>Null</td></tr>
050: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
051: * <tr><td>Description</td> <td>An operation which does no processing.</td></tr>
052: * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/NullDescriptor.html</td></tr>
053: * <tr><td>Version</td> <td>1.0</td></tr>
054: * </table></p>
055: *
056: * <p> No parameters are needed for this operation.
057: *
058: * @see javax.media.jai.OperationDescriptor
059: *
060: * @since JAI 1.1
061: */
062: public class NullDescriptor extends OperationDescriptorImpl {
063:
064: /**
065: * The resource strings that provide the general documentation
066: * and specify the parameter list for this operation.
067: */
068: private static final String[][] resources = {
069: { "GlobalName", "Null" },
070: { "LocalName", "Null" },
071: { "Vendor", "com.sun.media.jai" },
072: { "Description", JaiI18N.getString("NullDescriptor0") },
073: {
074: "DocURL",
075: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/NullDescriptor.html" },
076: { "Version", JaiI18N.getString("DescriptorVersion") }, };
077:
078: private static final String[] supportedModes = { "rendered",
079: "renderable" };
080:
081: /** Constructor. */
082: public NullDescriptor() {
083: super (resources, supportedModes, 1, null, null, null, null);
084: }
085:
086: /**
087: * If the PB has more than one source, replace it with a new PB which
088: * has only one source equal to the first source of the input.
089: * We want to support an arbitrary number of sources but only care that
090: * there is at least one of the appropriate class.
091: */
092: private static ParameterBlock foolSourceValidation(
093: ParameterBlock args) {
094: if (args.getNumSources() > 1) {
095: Vector singleSource = new Vector();
096: singleSource.add(args.getSource(0));
097: args = new ParameterBlock(singleSource, args
098: .getParameters());
099: }
100: return args;
101: }
102:
103: /**
104: * Returns <code>true</code> if there is at least one source
105: * and the first source is a <code>RenderedImage</code> or
106: * <code>RenderableImage</code>.
107: *
108: * @throws IllegalArgumentException if <code>args</code> is <code>null</code>.
109: * @throws IllegalArgumentException if <code>msg</code> is <code>null</code>
110: * and the validation fails.
111: */
112: protected boolean validateSources(String modeName,
113: ParameterBlock args, StringBuffer msg) {
114:
115: if (args == null || msg == null) {
116: throw new IllegalArgumentException(JaiI18N
117: .getString("Generic0"));
118: }
119:
120: return super .validateSources(modeName,
121: foolSourceValidation(args), msg);
122: }
123:
124: /**
125: * Calculates the region over which two distinct renderings
126: * of the "Null" operation may be expected to differ.
127: *
128: * <p> The operation returns an empty <code>Shape</code> if the first
129: * source in each of the two <code>ParameterBlock</code>s are equal
130: * according to the <code>equals()</code> method of the old source or
131: * <code>null</code> for all other cases.
132: *
133: * @param modeName The name of the mode.
134: * @param oldParamBlock The previous sources and parameters.
135: * @param oldHints The previous hints.
136: * @param newParamBlock The current sources and parameters.
137: * @param newHints The current hints.
138: * @param node The affected node in the processing chain (ignored).
139: *
140: * @return The region over which the data of two renderings of this
141: * operation may be expected to be invalid or <code>null</code>
142: * if there is no common region of validity.
143: * A non-<code>null</code> empty region indicates that the
144: * operation would produce identical data over the bounds of the
145: * old rendering although perhaps not over the area occupied by
146: * the <i>tiles</i> of the old rendering.
147: *
148: * @throws IllegalArgumentException if <code>modeName</code>
149: * is <code>null</code> or if either <code>oldParamBlock</code>
150: * or <code>newParamBlock</code> is <code>null</code>.
151: * @throws IllegalArgumentException if <code>oldParamBlock</code> or
152: * <code>newParamBlock</code> does not contain at least one source.
153: */
154: public Object getInvalidRegion(String modeName,
155: ParameterBlock oldParamBlock, RenderingHints oldHints,
156: ParameterBlock newParamBlock, RenderingHints newHints,
157: OperationNode node) {
158: if (modeName == null || oldParamBlock == null
159: || newParamBlock == null) {
160: throw new IllegalArgumentException(JaiI18N
161: .getString("NullDescriptor1"));
162: }
163:
164: if (oldParamBlock.getNumSources() < 1
165: || newParamBlock.getNumSources() < 1) {
166:
167: throw new IllegalArgumentException(JaiI18N
168: .getString("NullDescriptor2"));
169: }
170:
171: return oldParamBlock.getSource(0).equals(
172: newParamBlock.getSource(0)) ? new Rectangle() : null;
173: }
174:
175: /**
176: * An operation which does no processing.
177: *
178: * <p>Creates a <code>ParameterBlockJAI</code> from all
179: * supplied arguments except <code>hints</code> and invokes
180: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
181: *
182: * @see JAI
183: * @see ParameterBlockJAI
184: * @see RenderedOp
185: *
186: * @param source0 <code>RenderedImage</code> source 0.
187: * @param hints The <code>RenderingHints</code> to use.
188: * May be <code>null</code>.
189: * @return The <code>RenderedOp</code> destination.
190: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
191: */
192: public static RenderedOp create(RenderedImage source0,
193: RenderingHints hints) {
194: ParameterBlockJAI pb = new ParameterBlockJAI("Null",
195: RenderedRegistryMode.MODE_NAME);
196:
197: pb.setSource("source0", source0);
198:
199: return JAI.create("Null", pb, hints);
200: }
201:
202: /**
203: * An operation which does no processing.
204: *
205: * <p>Creates a <code>ParameterBlockJAI</code> from all
206: * supplied arguments except <code>hints</code> and invokes
207: * {@link JAI#createRenderable(String,ParameterBlock,RenderingHints)}.
208: *
209: * @see JAI
210: * @see ParameterBlockJAI
211: * @see RenderableOp
212: *
213: * @param source0 <code>RenderableImage</code> source 0.
214: * @param hints The <code>RenderingHints</code> to use.
215: * May be <code>null</code>.
216: * @return The <code>RenderableOp</code> destination.
217: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
218: */
219: public static RenderableOp createRenderable(
220: RenderableImage source0, RenderingHints hints) {
221: ParameterBlockJAI pb = new ParameterBlockJAI("Null",
222: RenderableRegistryMode.MODE_NAME);
223:
224: pb.setSource("source0", source0);
225:
226: return JAI.createRenderable("Null", pb, hints);
227: }
228: }
|