001: /*
002: * $RCSfile: CRIFRegistry.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:47 $
010: * $State: Exp $
011: */
012: package javax.media.jai.registry;
013:
014: import java.awt.image.RenderedImage;
015: import java.awt.image.renderable.ContextualRenderedImageFactory;
016: import java.awt.image.renderable.ParameterBlock;
017: import java.awt.image.renderable.RenderContext;
018: import java.util.Vector;
019: import javax.media.jai.JAI;
020: import javax.media.jai.OperationNode;
021: import javax.media.jai.OperationRegistry;
022: import javax.media.jai.PropertySource;
023: import javax.media.jai.RenderableOp;
024:
025: /**
026: * Utility class to provide type-safe interaction
027: * with the <code>OperationRegistry</code> for
028: * <code>ContextualRenderedImageFactory</code> objects.
029: *
030: * If the <code>OperationRegistry</code> is <code>null</code>, then
031: * <code>JAI.getDefaultInstance().getOperationRegistry()</code> will be used.
032: *
033: * @since JAI 1.1
034: */
035: public final class CRIFRegistry {
036:
037: private static final String MODE_NAME = RenderableRegistryMode.MODE_NAME;
038:
039: /**
040: * Register a CRIF with a particular operation against
041: * a specified mode. This is JAI 1.0.x equivalent of
042: * <code>registry.registerCRIF(...)</code>
043: *
044: * @param registry the <code>OperationRegistry</code> to register with.
045: * if this is <code>null</code>, then <code>
046: * JAI.getDefaultInstance().getOperationRegistry()</code>
047: * will be used.
048: * @param operationName the operation name as a <code>String</code>
049: * @param crif the <code>ContextualRenderedImageFactory</code> to be registered
050: *
051: * @throws IllegalArgumentException if operationName or crif is
052: * <code>null</code>
053: * @throws IllegalArgumentException if there is no <code>
054: * OperationDescriptor</code> registered against
055: * the <code>operationName</code>
056: */
057: public static void register(OperationRegistry registry,
058: String operationName, ContextualRenderedImageFactory crif) {
059:
060: registry = (registry != null) ? registry : JAI
061: .getDefaultInstance().getOperationRegistry();
062:
063: registry.registerFactory(MODE_NAME, operationName, null, crif);
064: }
065:
066: /**
067: * Unregister a CRIF previously registered with an operation
068: * against the specified mode.
069: *
070: * @param registry the <code>OperationRegistry</code> to unregister from.
071: * if this is <code>null</code>, then <code>
072: * JAI.getDefaultInstance().getOperationRegistry()</code>
073: * will be used.
074: * @param operationName the operation name as a <code>String</code>
075: * @param crif the <code>ContextualRenderedImageFactory</code> to be unregistered
076: *
077: * @throws IllegalArgumentException if operationName or crif is
078: * <code>null</code>
079: * @throws IllegalArgumentException if there is no <code>
080: * OperationDescriptor</code> registered against
081: * the <code>operationName</code>
082: * @throws IllegalArgumentException if the crif was not previously
083: * registered against operationName
084: */
085: public static void unregister(OperationRegistry registry,
086: String operationName, ContextualRenderedImageFactory crif) {
087:
088: registry = (registry != null) ? registry : JAI
089: .getDefaultInstance().getOperationRegistry();
090:
091: registry
092: .unregisterFactory(MODE_NAME, operationName, null, crif);
093: }
094:
095: /**
096: * Returns the <code>ContextualRenderedImageFactory</code> object
097: * registered against the operation name.
098: *
099: * @param registry the <code>OperationRegistry</code> to use.
100: * if this is <code>null</code>, then <code>
101: * JAI.getDefaultInstance().getOperationRegistry()</code>
102: * will be used.
103: * @param operationName the operation name as a <code>String</code>
104: *
105: * @return a registered <code>ContextualRenderedImageFactory</code> object
106: *
107: * @throws IllegalArgumentException if operationName is <code>null</code>
108: * @throws IllegalArgumentException if there is no <code>
109: * OperationDescriptor</code> registered against
110: * the <code>operationName</code>
111: */
112: public static ContextualRenderedImageFactory get(
113: OperationRegistry registry, String operationName) {
114:
115: registry = (registry != null) ? registry : JAI
116: .getDefaultInstance().getOperationRegistry();
117:
118: return (ContextualRenderedImageFactory) registry.getFactory(
119: MODE_NAME, operationName);
120: }
121:
122: /**
123: * Creates a rendering, given a RenderContext and a ParameterBlock
124: * containing the operation's sources and parameters. The registry
125: * is used to determine the CRIF to be used to instantiate the
126: * operation.
127: *
128: * @param registry the <code>OperationRegistry</code> to use.
129: * if this is <code>null</code>, then <code>
130: * JAI.getDefaultInstance().getOperationRegistry()</code>
131: * will be used.
132: * @param operationName the operation name as a <code>String</code>
133: * @param context a <code>RenderContext</code> object containing
134: * the rendering context.
135: * @param paramBlock the operation's ParameterBlock.
136: *
137: * @throws IllegalArgumentException if operationName is <code>null</code>
138: * @throws IllegalArgumentException if there is no <code>
139: * OperationDescriptor</code> registered against
140: * the <code>operationName</code>
141: */
142: public static RenderedImage create(OperationRegistry registry,
143: String operationName, RenderContext context,
144: ParameterBlock paramBlock) {
145:
146: registry = (registry != null) ? registry : JAI
147: .getDefaultInstance().getOperationRegistry();
148:
149: Object args[] = { context, paramBlock };
150:
151: return (RenderedImage) registry.invokeFactory(MODE_NAME,
152: operationName, args);
153: }
154:
155: /**
156: * Constructs and returns a <code>PropertySource</code> suitable for
157: * use by a given <code>RenderableOp</code>. The
158: * <code>PropertySource</code> includes properties copied from prior
159: * nodes as well as those generated at the node itself. Additionally,
160: * property suppression is taken into account. The actual implementation
161: * of <code>getPropertySource()</code> may make use of deferred
162: * execution and caching.
163: *
164: * @param op the <code>RenderableOp</code> requesting its
165: * <code>PropertySource</code>.
166: *
167: * @throws IllegalArgumentException if <code>op</code> is <code>null</code>
168: */
169: public static PropertySource getPropertySource(RenderableOp op) {
170:
171: if (op == null)
172: throw new IllegalArgumentException("op - "
173: + JaiI18N.getString("Generic0"));
174:
175: return op.getRegistry().getPropertySource((OperationNode) op);
176: }
177: }
|