Source Code Cross Referenced for ImageComponent2DRetained.java in  » 6.0-JDK-Modules » java-3d » javax » media » j3d » 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 3d » javax.media.j3d 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: ImageComponent2DRetained.java,v $
003:         *
004:         * Copyright 1998-2008 Sun Microsystems, Inc.  All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006:         *
007:         * This code is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU General Public License version 2 only, as
009:         * published by the Free Software Foundation.  Sun designates this
010:         * particular file as subject to the "Classpath" exception as provided
011:         * by Sun in the LICENSE file that accompanied this code.
012:         *
013:         * This code is distributed in the hope that it will be useful, but WITHOUT
014:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
016:         * version 2 for more details (a copy is included in the LICENSE file that
017:         * accompanied this code).
018:         *
019:         * You should have received a copy of the GNU General Public License version
020:         * 2 along with this work; if not, write to the Free Software Foundation,
021:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022:         *
023:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024:         * CA 95054 USA or visit www.sun.com if you need additional information or
025:         * have any questions.
026:         *
027:         * $Revision: 1.10 $
028:         * $Date: 2008/02/28 20:17:23 $
029:         * $State: Exp $
030:         */
031:
032:        package javax.media.j3d;
033:
034:        import java.awt.image.*;
035:        import java.awt.color.ColorSpace;
036:
037:        /**
038:         * This class defines a 2D image component.
039:         * This is used for texture images, background images and raster components
040:         * of Shape3D nodes.
041:         */
042:
043:        class ImageComponent2DRetained extends ImageComponentRetained {
044:
045:            ImageComponent2DRetained() {
046:            }
047:
048:            /**
049:             * This method handles NioImageBuffer
050:             * Refers or copies the specified NioImageBuffer to this 2D image component object.
051:             * @param image NioImageBuffer object containing the image.
052:             * The format and size must be the same as the current format in this
053:             * ImageComponent2D object.
054:             */
055:            void set(NioImageBuffer image) {
056:
057:                int width = image.getWidth();
058:                int height = image.getHeight();
059:
060:                if (!byReference) {
061:                    throw new IllegalArgumentException(J3dI18N
062:                            .getString("ImageComponent2D7"));
063:                }
064:                if (!yUp) {
065:                    throw new IllegalArgumentException(J3dI18N
066:                            .getString("ImageComponent2D8"));
067:                }
068:
069:                if (width != this .width) {
070:                    throw new IllegalArgumentException(J3dI18N
071:                            .getString("ImageComponent2DRetained0"));
072:                }
073:                if (height != this .height) {
074:                    throw new IllegalArgumentException(J3dI18N
075:                            .getString("ImageComponent2DRetained1"));
076:                }
077:
078:                geomLock.getLock();
079:
080:                setImageClass(image);
081:
082:                // This is a byRef image.
083:                setRefImage(image, 0);
084:
085:                // Reset this flag to true, incase it was set to false due to
086:                // the previous image type.
087:                abgrSupported = true;
088:
089:                imageTypeIsSupported = isImageTypeSupported(image);
090:
091:                if (imageTypeIsSupported) {
092:
093:                    /* Use reference when ( format is OK, Yup is true, and byRef is true). */
094:                    // Create image data object with the byRef image. */
095:                    imageData = createNioImageBufferDataObject(image);
096:
097:                } else {
098:                    // Handle abgrSupported is false case.
099:                    imageData = createNioImageBufferDataObject(null);
100:                    copyUnsupportedNioImageToImageData(image, 0, 0, 0, 0,
101:                            width, height, imageData);
102:
103:                }
104:
105:                geomLock.unLock();
106:
107:                if (source.isLive()) {
108:                    // send a IMAGE_CHANGED message in order to
109:                    // notify all the users of the change
110:                    sendMessage(IMAGE_CHANGED, null);
111:                }
112:            }
113:
114:            /**
115:             * This method handles both BufferedImage and RenderedImage
116:             * Copies the specified RenderedImage to this 2D image component object.
117:             * @param image RenderedImage object containing the image.
118:             * The format and size must be the same as the current format in this
119:             * ImageComponent2D object.
120:             */
121:            void set(RenderedImage image) {
122:
123:                int width = image.getWidth();
124:                int height = image.getHeight();
125:
126:                if (width != this .width) {
127:                    throw new IllegalArgumentException(J3dI18N
128:                            .getString("ImageComponent2DRetained0"));
129:                }
130:                if (height != this .height) {
131:                    throw new IllegalArgumentException(J3dI18N
132:                            .getString("ImageComponent2DRetained1"));
133:                }
134:
135:                setImageClass(image);
136:
137:                geomLock.getLock();
138:
139:                if (byReference) {
140:                    setRefImage(image, 0);
141:                }
142:
143:                // Reset this flag to true, incase it was set to false due to 
144:                // the previous image type.
145:                abgrSupported = true;
146:
147:                imageTypeIsSupported = isImageTypeSupported(image);
148:
149:                if (imageTypeIsSupported) {
150:
151:                    if (byReference && yUp) {
152:                        /* Use reference when ( format is OK, Yup is true, and byRef is true). */
153:                        // System.err.println("ImageComponent2DRetained.set() : (imageTypeSupported && byReference && yUp) --- (1)");
154:                        if (image instanceof  BufferedImage) {
155:                            // Create image data object with the byRef image. */                    
156:                            imageData = createRenderedImageDataObject(image);
157:                        } else {
158:                            // System.err.println("byRef and not BufferedImage !!!");
159:                            imageData = null;
160:                        }
161:
162:                    } else {
163:                        // Either not byRef or not yUp or not both
164:                        // System.err.println("ImageComponent2DRetained.set() : (imageTypeSupported && ((!byReference && yUp) || (imageTypeSupported && !yUp)) --- (2)");
165:
166:                        // Create image data object with buffer for image. */
167:                        imageData = createRenderedImageDataObject(null);
168:                        copySupportedImageToImageData(image, 0, imageData);
169:                    }
170:
171:                } else {
172:                    // image type is unsupported, need to create a supported local copy.
173:                    // TODO : borrow code from JAI to convert to right format.
174:                    // System.err.println("ImageComponent2DRetained.set() : (imageTypeSupported == false) --- (4)");
175:                    /* Will use the code segment in copy() method */
176:
177:                    // Create image data object with buffer for image. */
178:                    imageData = createRenderedImageDataObject(null);
179:                    copyUnsupportedImageToImageData(image, 0, imageData);
180:
181:                }
182:
183:                geomLock.unLock();
184:
185:                if (source.isLive()) {
186:                    // send a IMAGE_CHANGED message in order to
187:                    // notify all the users of the change
188:                    sendMessage(IMAGE_CHANGED, null);
189:                }
190:            }
191:
192:            void setSubImage(RenderedImage image, int width, int height,
193:                    int srcX, int srcY, int dstX, int dstY) {
194:
195:                if (!isSubImageTypeEqual(image)) {
196:                    throw new IllegalStateException(J3dI18N
197:                            .getString("ImageComponent2D6"));
198:                }
199:
200:                // Can't be byReference
201:                assert (!byReference);
202:                assert (imageData != null);
203:
204:                geomLock.getLock();
205:
206:                if (imageTypeIsSupported) {
207:                    // Either not byRef or not yUp or not both
208:                    // System.err.println("ImageComponent2DRetained.setSubImage() : (imageTypeSupported ) --- (1)");
209:                    if (image instanceof  BufferedImage) {
210:                        copyImageLineByLine((BufferedImage) image, srcX, srcY,
211:                                dstX, dstY, 0, width, height, imageData);
212:                    } else {
213:                        copySupportedImageToImageData(image, srcX, srcY, dstX,
214:                                dstY, 0, width, height, imageData);
215:                    }
216:                } else {
217:                    // image type is unsupported, need to create a supported local copy.
218:                    // TODO : Should look into borrow code from JAI to convert to right format.
219:                    // System.err.println("ImageComponent2DRetained.setSubImage() : (imageTypeSupported == false) --- (2)");
220:                    if (image instanceof  BufferedImage) {
221:                        copyUnsupportedImageToImageData((BufferedImage) image,
222:                                srcX, srcY, dstX, dstY, 0, width, height,
223:                                imageData);
224:                    } else {
225:                        copyUnsupportedImageToImageData(image, srcX, srcY,
226:                                dstX, dstY, 0, width, height, imageData);
227:                    }
228:                }
229:                geomLock.unLock();
230:
231:                if (source.isLive()) {
232:
233:                    // send a SUBIMAGE_CHANGED message in order to
234:                    // notify all the users of the change
235:
236:                    ImageComponentUpdateInfo info;
237:
238:                    info = new ImageComponentUpdateInfo();
239:                    info.x = dstX;
240:                    info.y = dstY;
241:                    info.z = 0;
242:                    info.width = width;
243:                    info.height = height;
244:
245:                    sendMessage(SUBIMAGE_CHANGED, info);
246:                }
247:            }
248:
249:            /**
250:             * Retrieves a copy of the image in this ImageComponent2D object.
251:             * @return a new RenderedImage object created from the image in this
252:             * ImageComponent2D object
253:             */
254:            RenderedImage getImage() {
255:
256:                if (isByReference()) {
257:                    return (RenderedImage) getRefImage(0);
258:                }
259:
260:                if (imageData != null) {
261:                    return imageData.createBufferedImage(0);
262:                }
263:
264:                return null;
265:            }
266:
267:            /**
268:             * Retrieves the reference of the nio image in this ImageComponent2D object.
269:             */
270:            NioImageBuffer getNioImage() {
271:
272:                if (getImageClass() != ImageComponent.ImageClass.NIO_IMAGE_BUFFER) {
273:                    throw new IllegalStateException(J3dI18N
274:                            .getString("ImageComponent2D9"));
275:                }
276:
277:                assert (byReference == true);
278:
279:                return (NioImageBuffer) getRefImage(0);
280:            }
281:
282:            /**
283:             * Update data.
284:             * x and y specifies the x & y offset of the image data in
285:             * ImageComponent.  It assumes that the origin is (0, 0).
286:             */
287:            void updateData(ImageComponent2D.Updater updater, int x, int y,
288:                    int width, int height) {
289:
290:                geomLock.getLock();
291:                // call the user supplied updateData method to update the data
292:                updater.updateData((ImageComponent2D) source, x, y, width,
293:                        height);
294:
295:                Object refImage = getRefImage(0);
296:                assert (refImage != null);
297:                assert (imageData != null);
298:
299:                // Check is data copied internally.
300:                if (!imageData.isDataByRef()) {
301:                    // update the internal copy of the image data if a copy has been
302:                    // made            
303:                    if (imageTypeIsSupported) {
304:                        assert !(refImage instanceof  NioImageBuffer);
305:
306:                        if (refImage instanceof  BufferedImage) {
307:                            copyImageLineByLine((BufferedImage) refImage, x, y,
308:                                    x, y, 0, width, height, imageData);
309:                        } else {
310:                            RenderedImage ri = (RenderedImage) refImage;
311:                            copySupportedImageToImageData(ri,
312:                                    (x + ri.getMinX()), (y + ri.getMinY()), x,
313:                                    y, 0, width, height, imageData);
314:                        }
315:                    } else {
316:                        // image type is unsupported, need to create a supported local copy.
317:                        // TODO : Should look into borrow code from JAI to convert to right format.
318:                        if (refImage instanceof  BufferedImage) {
319:                            copyUnsupportedImageToImageData(
320:                                    (BufferedImage) refImage, x, y, x, y, 0,
321:                                    width, height, imageData);
322:                        } else if (refImage instanceof  RenderedImage) {
323:                            RenderedImage ri = (RenderedImage) refImage;
324:                            copyUnsupportedImageToImageData(ri, (x + ri
325:                                    .getMinX()), (y + ri.getMinY()), x, y, 0,
326:                                    width, height, imageData);
327:                        } else if (refImage instanceof  NioImageBuffer) {
328:                            copyUnsupportedNioImageToImageData(
329:                                    (NioImageBuffer) refImage, x, y, x, y,
330:                                    width, height, imageData);
331:                        } else {
332:                            assert false;
333:                        }
334:                    }
335:                }
336:                geomLock.unLock();
337:
338:                if (source.isLive()) {
339:
340:                    // send a SUBIMAGE_CHANGED message in order to 
341:                    // notify all the users of the change
342:
343:                    ImageComponentUpdateInfo info;
344:
345:                    info = new ImageComponentUpdateInfo();
346:                    info.x = x;
347:                    info.y = y;
348:                    info.z = 0;
349:                    info.width = width;
350:                    info.height = height;
351:
352:                    sendMessage(SUBIMAGE_CHANGED, info);
353:                }
354:            }
355:
356:            void clearLive(int refCount) {
357:                super.clearLive(refCount);
358:            }
359:
360:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.