001: /*
002: * $RCSfile: PatternDescriptor.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:42 $
010: * $State: Exp $
011: */
012: package javax.media.jai.operator;
013:
014: import java.awt.RenderingHints;
015: import java.awt.image.Raster;
016: import java.awt.image.RenderedImage;
017: import java.awt.image.renderable.ParameterBlock;
018: import javax.media.jai.JAI;
019: import javax.media.jai.OperationDescriptorImpl;
020: import javax.media.jai.ParameterBlockJAI;
021: import javax.media.jai.RenderedOp;
022: import javax.media.jai.registry.RenderedRegistryMode;
023:
024: /**
025: * An <code>OperationDescriptor</code> describing the "Pattern" operation.
026: *
027: * <p> The "Pattern" operation defines a tiled image consisting of a
028: * repeated pattern. The width and height of the destination image
029: * must be specified. The tileWidth and tileHeight are equal to pattern's
030: * width and height. Each tile of the destination image will be defined
031: * by a reference to a shared instance of the pattern.
032: *
033: * <p><table border=1>
034: * <caption>Resource List</caption>
035: * <tr><th>Name</th> <th>Value</th></tr>
036: * <tr><td>GlobalName</td> <td>pattern</td></tr>
037: * <tr><td>LocalName</td> <td>pattern</td></tr>
038: * <tr><td>Vendor</td> <td>com.sun.media.jai</td></tr>
039: * <tr><td>Description</td> <td>Defines an image with a repeated
040: * pattern.</td></tr>
041: * <tr><td>DocURL</td> <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/PatternDescriptor.html</td></tr>
042: * <tr><td>Version</td> <td>1.0</td></tr>
043: * <tr><td>arg0Desc</td> <td>The width of the image in pixels.</td></tr>
044: * <tr><td>arg1Desc</td> <td>The height of the image in pixels.</td></tr>
045: * </table></p>
046: *
047: * <p><table border=1>
048: * <caption>Parameter List</caption>
049: * <tr><th>Name</th> <th>Class Type</th>
050: * <th>Default Value</th></tr>
051: * <tr><td>width</td> <td>java.lang.Integer</td>
052: * <td>NO_PARAMETER_DEFAULT</td>
053: * <tr><td>height</td> <td>java.lang.Integer</td>
054: * <td>NO_PARAMETER_DEFAULT</td>
055: * </table></p>
056: *
057: * @see javax.media.jai.OperationDescriptor
058: */
059: public class PatternDescriptor extends OperationDescriptorImpl {
060:
061: /**
062: * The resource strings that provide the general documentation
063: * for the "Pattern" operation.
064: */
065: private static final String[][] resources = {
066: { "GlobalName", "Pattern" },
067: { "LocalName", "Pattern" },
068: { "Vendor", "com.sun.media.jai" },
069: { "Description", JaiI18N.getString("PatternDescriptor0") },
070: {
071: "DocURL",
072: "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/PatternDescriptor.html" },
073: { "Version", JaiI18N.getString("DescriptorVersion") },
074: { "arg0Desc", JaiI18N.getString("PatternDescriptor1") },
075: { "arg1Desc", JaiI18N.getString("PatternDescriptor2") } };
076:
077: /** The parameter class list for this operation. */
078: private static final Class[] paramClasses = {
079: java.lang.Integer.class, java.lang.Integer.class, };
080:
081: /** The parameter name list for this operation. */
082: private static final String[] paramNames = { "width", "height" };
083:
084: /** The parameter default value list for this operation. */
085: private static final Object[] paramDefaults = {
086: NO_PARAMETER_DEFAULT, NO_PARAMETER_DEFAULT };
087:
088: /** Constructor. */
089: public PatternDescriptor() {
090: super (resources, 1, paramClasses, paramNames, paramDefaults);
091: }
092:
093: public Number getParamMinValue(int index) {
094: if (index == 0 || index == 1) {
095: return new Integer(1);
096: } else {
097: throw new ArrayIndexOutOfBoundsException();
098: }
099: }
100:
101: /**
102: * Defines an image with a repeated pattern.
103: *
104: * <p>Creates a <code>ParameterBlockJAI</code> from all
105: * supplied arguments except <code>hints</code> and invokes
106: * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
107: *
108: * @see JAI
109: * @see ParameterBlockJAI
110: * @see RenderedOp
111: *
112: * @param source0 <code>RenderedImage</code> source 0.
113: * @param width The width of the image in pixels.
114: * @param height The height of the image in pixels.
115: * @param hints The <code>RenderingHints</code> to use.
116: * May be <code>null</code>.
117: * @return The <code>RenderedOp</code> destination.
118: * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
119: * @throws IllegalArgumentException if <code>width</code> is <code>null</code>.
120: * @throws IllegalArgumentException if <code>height</code> is <code>null</code>.
121: */
122: public static RenderedOp create(RenderedImage source0,
123: Integer width, Integer height, RenderingHints hints) {
124: ParameterBlockJAI pb = new ParameterBlockJAI("Pattern",
125: RenderedRegistryMode.MODE_NAME);
126:
127: pb.setSource("source0", source0);
128:
129: pb.setParameter("width", width);
130: pb.setParameter("height", height);
131:
132: return JAI.create("Pattern", pb, hints);
133: }
134: }
|