Source Code Cross Referenced for ApplyToCollectionDescriptor.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » ca » forklabs » media » jai » operator » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » Java Advanced Imaging » ca.forklabs.media.jai.operator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#) $Header: /cvs/jai-operators/src/main/ca/forklabs/media/jai/operator/ApplyToCollectionDescriptor.java,v 1.6 2007/07/04 20:02:23 forklabs Exp $
003:         *
004:         * Copyright (C) 2007  Forklabs Daniel Léonard
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         */
020:
021:        package ca.forklabs.media.jai.operator;
022:
023:        import java.awt.RenderingHints;
024:        import java.awt.image.RenderedImage;
025:        import java.awt.image.renderable.ParameterBlock;
026:        import java.awt.image.renderable.RenderableImage;
027:        import java.util.Collection;
028:        import javax.media.jai.JAI;
029:        import javax.media.jai.OperationDescriptor;
030:        import javax.media.jai.ParameterBlockJAI;
031:        import javax.media.jai.ParameterListDescriptor;
032:        import javax.media.jai.registry.CollectionRegistryMode;
033:        import javax.media.jai.registry.RenderableCollectionRegistryMode;
034:        import ca.forklabs.media.jai.CollectionDescriptor;
035:
036:        /**
037:         * Class {@code ApplyToCollectionDescriptor} is an {@link OperationDescriptor}
038:         * describing the <em>applytocollection</em> operation. This operation applies
039:         * the same operation to all the image of a collection.
040:         * <p>
041:         * The <em>applytocollection</em> operation takes two parameters: the name of
042:         * the operation to apply and the parameter of the operation. No source need
043:         * to be added to the parameter, it will be done internally.
044:         *
045:         * <table border=1>
046:         * <caption>Resource List</caption>
047:         * <tr><th>Name</th>        <th>Value</th></tr>
048:         * <tr><td>GlobalName</td>  <td>ApplyToCollection</td></tr>
049:         * <tr><td>LocalName</td>   <td>ApplyToCollection</td></tr>
050:         * <tr><td>Vendor</td>      <td>ca.forklabs.media.jai.opimage</td></tr>
051:         * <tr><td>Description</td> <td>Applies the same operator to a collection of images</td></tr>
052:         * <tr><td>DocURL</td>      <td>n/a</td></tr>
053:         * <tr><td>Version</td>     <td>$Version$</td></tr>
054:         * <tr><td>Arg0Desct</td>   <td>The operation name</td></tr>
055:         * <tr><td>Arg1Desct</td>   <td>The parameter block</td></tr>
056:         * </table>
057:         *
058:         * <table border=1>
059:         * <caption>Parameter List</caption>
060:         * <tr><th>Name</th>         <th>Class Type</th>               <th>Default Value</th></tr>
061:         * <tr><td>operation</td>    <td>{@link String}</td>           <td>{@code "null"}</td>
062:         * <tr><td>parameters</td>   <td>{@link ParameterBlock}</td>   <td>{@code new ParameterBlock()}</td>
063:         * </table>
064:         *
065:         * @author   <a href="mailto:forklabs at dev.java.net?subject=ca.forklabs.media.jai.operator.ApplyToCollectionDescriptor">Daniel Léonard</a>
066:         * @version $Revision: 1.6 $
067:         */
068:        public class ApplyToCollectionDescriptor extends CollectionDescriptor {
069:
070:            //---------------------------
071:            // Class variables
072:            //---------------------------
073:
074:            /** <em>serialVersionUID</em>. */
075:            private static final long serialVersionUID = -131508813948168907L;
076:
077:            /** The name of this operator. */
078:            @SuppressWarnings("nls")
079:            public static final String NAME = "ApplyToCollection";
080:
081:            /** The name of the operation parameter. */
082:            @SuppressWarnings("nls")
083:            public static final String OPERATION_PARAMETER_NAME = "operation";
084:            /** The name of the parameter block parameter. */
085:            @SuppressWarnings("nls")
086:            public static final String PARAMETERS_PARAMETER_NAME = "parameters";
087:
088:            /** The index in the parameter block of the operation parameter. */
089:            public static final int OPERATION_PARAMETER_INDEX = 0;
090:            /** The index in the parameter block of the parameter block parameter. */
091:            public static final int PARAMETERS_PARAMETER_INDEX = 1;
092:
093:            /**
094:             * The resource strings that provide the general documentation and specify
095:             * the parameter list for this operation.
096:             */
097:            @SuppressWarnings("nls")
098:            private static final String[][] RESOURCES = {
099:                    { "GlobalName", ApplyToCollectionDescriptor.NAME, },
100:                    { "LocalName", ApplyToCollectionDescriptor.NAME, },
101:                    { "Vendor", "ca.forklabs.media.jai.opimage", },
102:                    { "Description",
103:                            ApplyToCollectionDescriptor.getDescription(), },
104:                    { "DocURL", "n/a", },
105:                    { "Version", "$Version$", },
106:                    { "arg0Desc",
107:                            ApplyToCollectionDescriptor.getArg0Description(), },
108:                    { "arg1Desc",
109:                            ApplyToCollectionDescriptor.getArg1Description(), }, };
110:
111:            /** The supported modes. */
112:            private static final String[] SUPPORTED_MODES = {
113:                    CollectionRegistryMode.MODE_NAME,
114:                    RenderableCollectionRegistryMode.MODE_NAME, };
115:
116:            /** The name of the source, use default. */
117:            private static final String[] SOURCE_NAMES = null;
118:
119:            /** The type of source for each mode. */
120:            private static final Class<?>[][] SOURCE_CLASSES = new Class<?>[][] {
121:                    { Collection.class, }, { Collection.class, }, };
122:
123:            /** The parameter list descriptor for all modes. */
124:            private static final ParameterListDescriptor PARAMETER_LIST_DESCRIPTOR = new CollectionDescriptor.EmptyParameterListDescriptor() {
125:
126:                @Override
127:                public int getNumParameters() {
128:                    int num_parameters = 2;
129:                    return num_parameters;
130:                }
131:
132:                @Override
133:                public Class<?>[] getParamClasses() {
134:                    Class<?>[] clazzes = new Class<?>[] { String.class,
135:                            ParameterBlock.class, };
136:                    return clazzes;
137:                }
138:
139:                @Override
140:                @SuppressWarnings({"synthetic-access","static-access"})
141:                public Object getParamDefaultValue(String name) {
142:                    int index = -1;
143:                    if (ApplyToCollectionDescriptor.OPERATION_PARAMETER_NAME
144:                            .equals(name)) {
145:                        index = ApplyToCollectionDescriptor.OPERATION_PARAMETER_INDEX;
146:                    } else if (ApplyToCollectionDescriptor.PARAMETERS_PARAMETER_NAME
147:                            .equals(name)) {
148:                        index = ApplyToCollectionDescriptor.PARAMETERS_PARAMETER_INDEX;
149:                    } else {
150:                        // this call will throw an exception
151:                        super .getParamDefaultValue(name);
152:                    }
153:
154:                    Object[] values = this .getParamDefaults();
155:                    Object value = values[index];
156:                    return value;
157:                }
158:
159:                @Override
160:                @SuppressWarnings("nls")
161:                public Object[] getParamDefaults() {
162:                    // defaults would be the null operator
163:                    // with its parameter block
164:                    Object[] defaults = new Object[] { "null",
165:                            new ParameterBlock(), };
166:                    return defaults;
167:                }
168:
169:                @Override
170:                public String[] getParamNames() {
171:                    String[] names = new String[] {
172:                            ApplyToCollectionDescriptor.OPERATION_PARAMETER_NAME,
173:                            ApplyToCollectionDescriptor.PARAMETERS_PARAMETER_NAME, };
174:                    return names;
175:                }
176:
177:                @Override
178:                public boolean isParameterValueValid(String name, Object value) {
179:                    // there is not much to do but check
180:                    // that the value is not null
181:                    boolean is_valid = (null != value);
182:                    return is_valid;
183:                }
184:
185:            };
186:
187:            /** Description of the parameters. */
188:            private static final ParameterListDescriptor[] PARAMETER_LIST_DESCRIPTORS = new ParameterListDescriptor[] {
189:                    ApplyToCollectionDescriptor.PARAMETER_LIST_DESCRIPTOR,
190:                    ApplyToCollectionDescriptor.PARAMETER_LIST_DESCRIPTOR, };
191:
192:            //---------------------------
193:            // Constructors
194:            //---------------------------
195:
196:            /**
197:             * Constructor.
198:             */
199:            public ApplyToCollectionDescriptor() {
200:                super (RESOURCES, SUPPORTED_MODES, SOURCE_NAMES, SOURCE_CLASSES,
201:                        PARAMETER_LIST_DESCRIPTORS);
202:            }
203:
204:            //---------------------------
205:            // Class methods
206:            //---------------------------
207:
208:            /**
209:             * Creates and fills a new parameter block.
210:             * @param   mode   the rendering mode.
211:             * @param   source   the source image.
212:             * @param   operation   the name of the operation.
213:             * @param   parameters   the parameter block for the operation.
214:             * @return   a new parameter block.
215:             */
216:            protected static ParameterBlockJAI createParameterBlock(
217:                    String mode, Object source, String operation,
218:                    ParameterBlock parameters) {
219:                String name = ApplyToCollectionDescriptor.NAME;
220:                ParameterBlockJAI pb = new ParameterBlockJAI(name, mode);
221:                if (null != source) {
222:                    pb.addSource(source);
223:                }
224:                pb.setParameter(
225:                        ApplyToCollectionDescriptor.OPERATION_PARAMETER_NAME,
226:                        operation);
227:                pb.setParameter(
228:                        ApplyToCollectionDescriptor.PARAMETERS_PARAMETER_NAME,
229:                        parameters);
230:                return pb;
231:            }
232:
233:            /**
234:             * Performs the operation on a collection of rendered images.
235:             * @param   sources   the source images.
236:             * @param   operation   the name of the operation.
237:             * @param   parameters   the parameter block for the operation.
238:             * @param   hints    the rendering hints, may be {@code null}.
239:             * @return   the rendered result image.
240:             */
241:            @SuppressWarnings("unchecked")
242:            public static Collection<RenderedImage> createCollection(
243:                    Collection<RenderedImage> sources, String operation,
244:                    ParameterBlock parameters, RenderingHints hints) {
245:                String name = ApplyToCollectionDescriptor.NAME;
246:                String mode = CollectionRegistryMode.MODE_NAME;
247:                ParameterBlockJAI parameter_block = ApplyToCollectionDescriptor
248:                        .createParameterBlock(mode, sources, operation,
249:                                parameters);
250:                Collection<RenderedImage> sinks = JAI.createCollection(name,
251:                        parameter_block, hints);
252:                return sinks;
253:            }
254:
255:            /**
256:             * Performs the operation on a collection of renderable images.
257:             * @param   sources   the source images.
258:             * @param   operation   the name of the operation.
259:             * @param   parameters   the parameter block for the operation.
260:             * @param   hints    the rendering hints, may be {@code null}.
261:             * @return   the rendered result image.
262:             */
263:            @SuppressWarnings("unchecked")
264:            public static Collection<RenderableImage> createRenderableCollection(
265:                    Collection<RenderableImage> sources, String operation,
266:                    ParameterBlock parameters, RenderingHints hints) {
267:                String name = ApplyToCollectionDescriptor.NAME;
268:                String mode = RenderableCollectionRegistryMode.MODE_NAME;
269:                ParameterBlockJAI parameter_block = ApplyToCollectionDescriptor
270:                        .createParameterBlock(mode, sources, operation,
271:                                parameters);
272:                Collection<RenderableImage> sinks = JAI
273:                        .createRenderableCollection(name, parameter_block,
274:                                hints);
275:                return sinks;
276:            }
277:
278:            //---------------------------
279:            // External resources methods
280:            //---------------------------
281:
282:            /**
283:             * Gets the description of this operation.
284:             * @return   the description message.
285:             */
286:            protected static String getDescription() {
287:                String key = Resources.APPLY_TO_COLLECTION_DESCRIPTION;
288:                String message = Resources.getLocalizedString(key);
289:                return message;
290:            }
291:
292:            /**
293:             * Gets the description for the first argument, the operation name.
294:             * @return   the description message.
295:             */
296:            protected static String getArg0Description() {
297:                String key = Resources.APPLY_TO_COLLECTION_ARG0_DESCRIPTION;
298:                String message = Resources.getLocalizedString(key);
299:                return message;
300:            }
301:
302:            /**
303:             * Gets the description for the second argument, the parameter block.
304:             * @return   the description message.
305:             */
306:            protected static String getArg1Description() {
307:                String key = Resources.APPLY_TO_COLLECTION_ARG1_DESCRIPTION;
308:                String message = Resources.getLocalizedString(key);
309:                return message;
310:            }
311:
312:        }
313:
314:        /*
315:         * $Log: ApplyToCollectionDescriptor.java,v $
316:         * Revision 1.6  2007/07/04 20:02:23  forklabs
317:         * Updated documentation.
318:         *
319:         * Revision 1.5  2007/06/13 18:57:22  forklabs
320:         * Changed parent to use CollectionDescriptor.
321:         *
322:         * Revision 1.3  2007/06/05 21:26:14  forklabs
323:         * applytocollection now supports mode renderablecollection.
324:         *
325:         * Revision 1.2  2007/06/05 00:39:31  forklabs
326:         * Changed the serialVersionUID.
327:         *
328:         * Revision 1.1  2007/05/25 21:20:23  forklabs
329:         * Operator "applytocollection"
330:         *
331:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.