Source Code Cross Referenced for ApplyToCollectionRCIF.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » ca » forklabs » media » jai » opimage » 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.opimage 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#) $Header: /cvs/jai-operators/src/main/ca/forklabs/media/jai/opimage/ApplyToCollectionRCIF.java,v 1.4 2007/07/17 16:39:33 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.opimage;
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 javax.media.jai.CollectionImage;
028:        import javax.media.jai.CollectionImageFactory;
029:        import javax.media.jai.CollectionOp;
030:        import javax.media.jai.JAI;
031:        import javax.media.jai.RenderableCollectionImageFactory;
032:        import ca.forklabs.media.jai.SimpleCollectionImage;
033:        import ca.forklabs.media.jai.operator.ApplyToCollectionDescriptor;
034:
035:        /**
036:         * Class {@code ApplyToToCollectionRCIF} is a {@link CollectionImageFactory} and
037:         * {@link RenderableCollectionImageFactory} supporting the
038:         * <em>applytocollection</em> operation.
039:         *
040:         * @author   <a href="mailto:forklabs at dev.java.net?subject=ca.forklabs.media.jai.opimage.ApplyToCollectionRCIF">Daniel Léonard</a>
041:         * @version $Revision: 1.4 $
042:         */
043:        public class ApplyToCollectionRCIF implements  CollectionImageFactory,
044:                RenderableCollectionImageFactory {
045:
046:            //---------------------------
047:            // Constructor
048:            //---------------------------
049:
050:            /**
051:             * Constructor.
052:             */
053:            public ApplyToCollectionRCIF() {
054:                // nothing
055:            }
056:
057:            //---------------------------
058:            // Instance methods
059:            //---------------------------
060:
061:            /**
062:             * Gets the name of the operation parameter within the parameter block.
063:             * @param   pb   the parameter block.
064:             * @return   the name of the operation.
065:             */
066:            protected String getOperation(ParameterBlock pb) {
067:                int index = ApplyToCollectionDescriptor.OPERATION_PARAMETER_INDEX;
068:                String operation = (String) pb.getObjectParameter(index);
069:                return operation;
070:            }
071:
072:            /**
073:             * Gets the parameter block parameter within the parameter block.
074:             * @param   pb   the parameter block.
075:             * @return   the parameter block parameter.
076:             */
077:            protected ParameterBlock getParameters(ParameterBlock pb) {
078:                int index = ApplyToCollectionDescriptor.PARAMETERS_PARAMETER_INDEX;
079:                ParameterBlock parameters = (ParameterBlock) pb
080:                        .getObjectParameter(index);
081:                return parameters;
082:            }
083:
084:            /**
085:             * Creates a {@code CollectionImage} that represents the result of applying
086:             * the requested operation once to each image in the collection.
087:             * @param   pb   the parameter block.
088:             * @param   hints   the rendering hints.
089:             * @return   the collection image containing the results.
090:             */
091:            @SuppressWarnings("unchecked")
092:            protected CollectionImage apply(ParameterBlock pb,
093:                    RenderingHints hints) {
094:                CollectionImage sources = (CollectionImage) pb.getSource(0);
095:
096:                CollectionImage sinks = new SimpleCollectionImage();
097:
098:                String operation = this .getOperation(pb);
099:                ParameterBlock parameters = this .getParameters(pb);
100:
101:                for (Object source : sources) {
102:                    parameters.removeSources();
103:                    parameters.addSource(source);
104:
105:                    Object sink;
106:                    if (source instanceof  RenderedImage) {
107:                        sink = JAI.create(operation, parameters, hints);
108:                    } else if (source instanceof  RenderableImage) {
109:                        sink = JAI.createRenderable(operation, parameters,
110:                                hints);
111:                    }
112:                    // TODO : remove this, only support rendered and renderable image
113:                    else if (source instanceof  CollectionImage) {
114:                        sink = JAI.createCollection(operation, parameters,
115:                                hints);
116:                    } else {
117:                        Class<?> clazz = source.getClass();
118:                        String message = this 
119:                                .getNeitherRenderedNorRenderableErrorMessage(clazz);
120:                        throw new IllegalStateException(message);
121:                    }
122:                    sinks.add(sink);
123:                }
124:
125:                return sinks;
126:            }
127:
128:            /**
129:             * Gets the error message saying that a source image is neither a rendered
130:             * nor a renderable image.
131:             * @param   clazz   the class of the offending image.
132:             * @return   the error message.
133:             */
134:            protected String getNeitherRenderedNorRenderableErrorMessage(
135:                    Class<?> clazz) {
136:                String key = Resources.NEITHER_RENDERED_NOR_RENDERABLE;
137:                String message = Resources.getLocalizedString(key, clazz);
138:                return message;
139:            }
140:
141:            //---------------------------
142:            // Implemented methods from javax.media.jai.CollectionImageFactory
143:            //---------------------------
144:
145:            /**
146:             * Calls {@link #apply(ParameterBlock, RenderingHints)}.
147:             * @param   pb   the parameter block.
148:             * @param   hints   the rendering hints.
149:             * @return   the collection image containing the results.
150:             */
151:            public CollectionImage create(ParameterBlock pb,
152:                    RenderingHints hints) {
153:                CollectionImage image = this .apply(pb, hints);
154:                return image;
155:            }
156:
157:            /**
158:             * It is impratical to perform the update.
159:             * @param old_pb   ignored
160:             * @param old_hints   ignored
161:             * @param new_pb   ignored
162:             * @param new_hints   ignored
163:             * @param old_image   ignored
164:             * @param op   ignored
165:             * @return always {@code null}.
166:             */
167:            public CollectionImage update(ParameterBlock old_pb,
168:                    RenderingHints old_hints, ParameterBlock new_pb,
169:                    RenderingHints new_hints, CollectionImage old_image,
170:                    CollectionOp op) {
171:                // it is impracticable to perform the update
172:                CollectionImage new_image = null;
173:                return new_image;
174:            }
175:
176:            //---------------------------
177:            // Implemented methods from javax.media.jai.RenderableCollectionImageFactory
178:            //---------------------------
179:
180:            /**
181:             * Calls {@link #apply(ParameterBlock, RenderingHints)}.
182:             * @param   pb   the parameter block.
183:             * @return   the collection image containing the results.
184:             */
185:            @Override
186:            public CollectionImage create(ParameterBlock pb) {
187:                RenderingHints hints = null;
188:                CollectionImage image = this .apply(pb, hints);
189:                return image;
190:            }
191:
192:        }
193:
194:        /*
195:         * $Log: ApplyToCollectionRCIF.java,v $
196:         * Revision 1.4  2007/07/17 16:39:33  forklabs
197:         * clean up.
198:         *
199:         * Revision 1.3  2007/07/05 18:23:21  forklabs
200:         * Now uses CollectionImage instead of lists.
201:         *
202:         * Revision 1.2  2007/06/13 18:57:21  forklabs
203:         * Changed parent to use CollectionDescriptor.
204:         *
205:         * Revision 1.1  2007/06/05 21:26:59  forklabs
206:         * applytocollection now supports mode renderablecollection.
207:         *
208:         * Revision 1.1  2007/05/25 21:20:08  forklabs
209:         * Operator "applytocollection"
210:         *
211:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.