Source Code Cross Referenced for ImageComponent2D.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: ImageComponent2D.java,v $
003:         *
004:         * Copyright 1996-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.BufferedImage;
035:        import java.awt.image.RenderedImage;
036:        import java.util.logging.Level;
037:
038:        /**
039:         * This class defines a 2D image component.  This is used for texture
040:         * images, background images and raster components of Shape3D nodes.
041:         * Prior to Java 3D 1.2, only BufferedImage objects could be used as the
042:         * input to an ImageComponent2D object.  As of Java 3D 1.2, an
043:         * ImageComponent2D accepts any RenderedImage object (BufferedImage is
044:         * an implementation of the RenderedImage interface).  The methods
045:         * that set/get a BufferedImage object are left in for compatibility.
046:         * The new methods that set/get a RenderedImage are a superset of the
047:         * old methods.  In particular, the two set methods in the following
048:         * example are equivalent:
049:         *
050:         * <p>
051:         * <ul>
052:         * <code>
053:         * BufferedImage bi;<br>
054:         * RenderedImage ri = bi;<br>
055:         * ImageComponent2D ic;<br>
056:         * <p>
057:         * // Set the image to the specified BufferedImage<br>
058:         * ic.set(bi);<br>
059:         * <p>
060:         * // Set the image to the specified RenderedImage<br>
061:         * ic.set(ri);<br>
062:         * </code>
063:         * </ul>
064:         *
065:         * <p>
066:         * As of Java 3D 1.5, an ImageComponent2D accepts an NioImageBuffer object
067:         * as an alternative to a RenderedImage.
068:         */
069:
070:        public class ImageComponent2D extends ImageComponent {
071:
072:            // non-public, no parameter constructor
073:            ImageComponent2D() {
074:            }
075:
076:            /**
077:             * Constructs a 2D image component object using the specified
078:             * format, width, and height. Default values are used for
079:             * all other parameters.  The default values are as follows:
080:             * <ul>
081:             * image : null<br>
082:             * imageClass : ImageClass.BUFFERED_IMAGE<br>
083:             * </ul>
084:             *
085:             * @param format the image component format, one of: FORMAT_RGB,
086:             * FORMAT_RGBA, etc.
087:             * @param width the number of columns of pixels in this image component
088:             * object
089:             * @param height the number of rows of pixels in this image component
090:             * object
091:             * @exception IllegalArgumentException if format is invalid, or if
092:             * width or height are not positive.
093:             */
094:            public ImageComponent2D(int format, int width, int height) {
095:
096:                if (MasterControl.isDevLoggable(Level.FINER)) {
097:                    MasterControl.getDevLogger().finer(
098:                            "ImageComponent - using default of byCopy");
099:                }
100:                ((ImageComponent2DRetained) this .retained).processParams(
101:                        format, width, height, 1);
102:            }
103:
104:            /**
105:             * Constructs a 2D image component object using the specified format
106:             * and BufferedImage.  A copy of the BufferedImage is made.
107:             * The image class is set to ImageClass.BUFFERED_IMAGE.
108:             * Default values are used for all other parameters.
109:             *
110:             * @param format the image component format, one of: FORMAT_RGB,
111:             * FORMAT_RGBA, etc.
112:             * @param image the BufferedImage used to create this 2D image component.
113:             * @exception IllegalArgumentException if format is invalid, or if
114:             * the width or height of the image are not positive.
115:             */
116:            public ImageComponent2D(int format, BufferedImage image) {
117:
118:                if (MasterControl.isDevLoggable(Level.FINER)) {
119:                    MasterControl.getDevLogger().finer(
120:                            "ImageComponent - using default of byCopy");
121:                }
122:                ((ImageComponent2DRetained) this .retained).processParams(
123:                        format, image.getWidth(), image.getHeight(), 1);
124:                ((ImageComponent2DRetained) this .retained).set(image);
125:            }
126:
127:            /**
128:             * Constructs a 2D image component object using the specified format
129:             * and RenderedImage.  A copy of the RenderedImage is made.
130:             * The image class is set to ImageClass.BUFFERED_IMAGE.
131:             * Default values are used for all other parameters.
132:             *
133:             * @param format the image component format, one of: FORMAT_RGB,
134:             * FORMAT_RGBA, etc.
135:             * @param image the RenderedImage used to create this 2D image component
136:             * @exception IllegalArgumentException if format is invalid, or if
137:             * the width or height of the image are not positive.
138:             *
139:             * @since Java 3D 1.2
140:             */
141:            public ImageComponent2D(int format, RenderedImage image) {
142:
143:                if (MasterControl.isDevLoggable(Level.FINER)) {
144:                    MasterControl.getDevLogger().finer(
145:                            "ImageComponent - using default of byCopy");
146:                }
147:                ((ImageComponent2DRetained) this .retained).processParams(
148:                        format, image.getWidth(), image.getHeight(), 1);
149:                ((ImageComponent2DRetained) this .retained).set(image);
150:            }
151:
152:            /**
153:             * Constructs a 2D image component object using the specified
154:             * format, width, height, byReference flag, and yUp flag.
155:             * Default values are used for all other parameters.
156:             *
157:             * @param format the image component format, one of: FORMAT_RGB,
158:             * FORMAT_RGBA, etc.
159:             * @param width the number of columns of pixels in this image component
160:             * object
161:             * @param height the number of rows of pixels in this image component
162:             * object
163:             * @param byReference a flag that indicates whether the data is copied
164:             * into this image component object or is accessed by reference.
165:             * @param yUp a flag that indicates the y-orientation of this image
166:             * component.  If yUp is set to true, the origin of the image is
167:             * the lower left; otherwise, the origin of the image is the upper
168:             * left.
169:             * @exception IllegalArgumentException if format is invalid, or if
170:             * width or height are not positive.
171:             *
172:             * @since Java 3D 1.2
173:             */
174:            public ImageComponent2D(int format, int width, int height,
175:                    boolean byReference, boolean yUp) {
176:
177:                if (MasterControl.isDevLoggable(Level.INFO)) {
178:                    if (byReference && !yUp) {
179:                        MasterControl
180:                                .getDevLogger()
181:                                .info(
182:                                        "ImageComponent - yUp should "
183:                                                + "be set when using byReference, "
184:                                                + "otherwise an extra copy of the image will be created");
185:                    }
186:                }
187:
188:                ((ImageComponentRetained) this .retained)
189:                        .setByReference(byReference);
190:                ((ImageComponentRetained) this .retained).setYUp(yUp);
191:                ((ImageComponent2DRetained) this .retained).processParams(
192:                        format, width, height, 1);
193:            }
194:
195:            /**
196:             * Constructs a 2D image component object using the specified format,
197:             * BufferedImage, byReference flag, and yUp flag.
198:             * The image class is set to ImageClass.BUFFERED_IMAGE.
199:             *
200:             * @param format the image component format, one of: FORMAT_RGB,
201:             * FORMAT_RGBA, etc.
202:             * @param image the BufferedImage used to create this 2D image component
203:             * @param byReference a flag that indicates whether the data is copied
204:             * into this image component object or is accessed by reference
205:             * @param yUp a flag that indicates the y-orientation of this image
206:             * component.  If yUp is set to true, the origin of the image is
207:             * the lower left; otherwise, the origin of the image is the upper
208:             * left.
209:             * @exception IllegalArgumentException if format is invalid, or if
210:             * the width or height of the image are not positive.
211:             *
212:             * @since Java 3D 1.2
213:             */
214:            public ImageComponent2D(int format, BufferedImage image,
215:                    boolean byReference, boolean yUp) {
216:
217:                if (MasterControl.isDevLoggable(Level.INFO)) {
218:                    if (byReference && !yUp) {
219:                        MasterControl
220:                                .getDevLogger()
221:                                .info(
222:                                        "ImageComponent - yUp should "
223:                                                + "be set when using byReference, "
224:                                                + "otherwise an extra copy of the image will be created");
225:                    }
226:                }
227:
228:                ((ImageComponentRetained) this .retained)
229:                        .setByReference(byReference);
230:                ((ImageComponentRetained) this .retained).setYUp(yUp);
231:                ((ImageComponent2DRetained) this .retained).processParams(
232:                        format, image.getWidth(), image.getHeight(), 1);
233:                ((ImageComponent2DRetained) this .retained).set(image);
234:            }
235:
236:            /**
237:             * Constructs a 2D image component object using the specified format,
238:             * RenderedImage, byReference flag, and yUp flag.
239:             * The image class is set to ImageClass.RENDERED_IMAGE if the byReferece
240:             * flag is true and the specified RenderedImage is <i>not</i> an instance
241:             * of BufferedImage. In all other cases, the image class is set to
242:             * ImageClass.BUFFERED_IMAGE.
243:             *
244:             * @param format the image component format, one of: FORMAT_RGB,
245:             * FORMAT_RGBA, etc.
246:             * @param image the RenderedImage used to create this 2D image component
247:             * @param byReference a flag that indicates whether the data is copied
248:             * into this image component object or is accessed by reference.
249:             * @param yUp a flag that indicates the y-orientation of this image
250:             * component.  If yUp is set to true, the origin of the image is
251:             * the lower left; otherwise, the origin of the image is the upper
252:             * left.
253:             * @exception IllegalArgumentException if format is invalid, or if
254:             * the width or height of the image are not positive.
255:             *
256:             * @since Java 3D 1.2
257:             */
258:            public ImageComponent2D(int format, RenderedImage image,
259:                    boolean byReference, boolean yUp) {
260:
261:                if (MasterControl.isDevLoggable(Level.INFO)) {
262:                    if (byReference && !yUp)
263:                        MasterControl
264:                                .getDevLogger()
265:                                .info(
266:                                        "ImageComponent - yUp should "
267:                                                + "be set when using byReference, "
268:                                                + "otherwise an extra copy of the image will be created");
269:                }
270:                ((ImageComponentRetained) this .retained)
271:                        .setByReference(byReference);
272:                ((ImageComponentRetained) this .retained).setYUp(yUp);
273:                ((ImageComponent2DRetained) this .retained).processParams(
274:                        format, image.getWidth(), image.getHeight(), 1);
275:                ((ImageComponent2DRetained) this .retained).set(image);
276:            }
277:
278:            /**
279:             * Constructs a 2D image component object using the specified format,
280:             * NioImageBuffer, byReference flag, and yUp flag.
281:             * The image class is set to ImageClass.NIO_IMAGE_BUFFER.
282:             *
283:             * @param format the image component format, one of: FORMAT_RGB,
284:             * FORMAT_RGBA, etc.
285:             * @param image the NioImageBuffer used to create this 2D image component
286:             * @param byReference a flag that indicates whether the data is copied
287:             * into this image component object or is accessed by reference.
288:             * @param yUp a flag that indicates the y-orientation of this image
289:             * component.  If yUp is set to true, the origin of the image is
290:             * the lower left; otherwise, the origin of the image is the upper
291:             * left.
292:             *
293:             * @exception IllegalArgumentException if format is invalid, or if
294:             * the width or height of the image are not positive.
295:             *
296:             * @exception IllegalArgumentException if the byReference flag is false.
297:             *
298:             * @exception IllegalArgumentException if the yUp flag is false.
299:             *
300:             * @exception IllegalArgumentException if the number of components in format 
301:             * does not match the number of components in image.
302:             *
303:             * @since Java 3D 1.5
304:             */
305:            public ImageComponent2D(int format, NioImageBuffer image,
306:                    boolean byReference, boolean yUp) {
307:
308:                ((ImageComponentRetained) this .retained)
309:                        .setByReference(byReference);
310:                ((ImageComponentRetained) this .retained).setYUp(yUp);
311:                ((ImageComponent2DRetained) this .retained).processParams(
312:                        format, image.getWidth(), image.getHeight(), 1);
313:                ((ImageComponent2DRetained) this .retained).set(image);
314:            }
315:
316:            /**
317:             * Sets this image component to the specified BufferedImage
318:             * object.
319:             * If the data access mode is not by-reference, then the
320:             * BufferedImage data is copied into this object.  If
321:             * the data access mode is by-reference, then a reference to the
322:             * BufferedImage is saved, but the data is not necessarily
323:             * copied.
324:             * <p>
325:             * The image class is set to ImageClass.BUFFERED_IMAGE.
326:             *
327:             * @param image BufferedImage object containing the image.
328:             * Its size must be the same as the current size of this
329:             * ImageComponent2D object.
330:             *
331:             * @exception CapabilityNotSetException if appropriate capability is
332:             * not set and this object is part of live or compiled scene graph
333:             *
334:             * @exception IllegalArgumentException if the width and height of the
335:             * specified image is not equal to the width and height of this
336:             * ImageComponent object.
337:             */
338:            public void set(BufferedImage image) {
339:                if (isLiveOrCompiled()) {
340:                    if (!this .getCapability(ALLOW_IMAGE_WRITE))
341:                        throw new CapabilityNotSetException(J3dI18N
342:                                .getString("ImageComponent2D1"));
343:                }
344:
345:                ((ImageComponent2DRetained) this .retained).set(image);
346:            }
347:
348:            /**
349:             * Sets this image component to the specified RenderedImage
350:             * object.  If the data access mode is not by-reference, the
351:             * RenderedImage data is copied into this object.  If
352:             * the data access mode is by-reference, a reference to the
353:             * RenderedImage is saved, but the data is not necessarily
354:             * copied.
355:             * <p>
356:             * The image class is set to ImageClass.RENDERED_IMAGE if the the
357:             * data access mode is by-reference and the specified
358:             * RenderedImage is <i>not</i> an instance of BufferedImage. In all
359:             * other cases, the image class is set to ImageClass.BUFFERED_IMAGE.
360:             *
361:             * @param image RenderedImage object containing the image.
362:             * Its size must be the same as the current size of this
363:             * ImageComponent2D object.
364:             *
365:             * @exception CapabilityNotSetException if appropriate capability is
366:             * not set and this object is part of live or compiled scene graph
367:             *
368:             * @exception IllegalArgumentException if the width and height of the
369:             * specified image is not equal to the width and height of this
370:             * ImageComponent object.
371:             *
372:             * @since Java 3D 1.2
373:             */
374:            public void set(RenderedImage image) {
375:                if (isLiveOrCompiled()) {
376:                    if (!this .getCapability(ALLOW_IMAGE_WRITE))
377:                        throw new CapabilityNotSetException(J3dI18N
378:                                .getString("ImageComponent2D1"));
379:                }
380:
381:                ((ImageComponent2DRetained) this .retained).set(image);
382:            }
383:
384:            /**
385:             * Sets this image component to the specified NioImageBuffer
386:             * object.  If the data access mode is not by-reference, the
387:             * NioImageBuffer data is copied into this object.  If
388:             * the data access mode is by-reference, a reference to the
389:             * NioImageBuffer is saved, but the data is not necessarily
390:             * copied.
391:             * <p>
392:             * The image class is set to ImageClass.NIO_IMAGE_BUFFER.
393:             *
394:             * @param image NioImageBuffer object containing the image.
395:             * Its size must be the same as the current size of this
396:             * ImageComponent2D object.
397:             *
398:             * @exception CapabilityNotSetException if appropriate capability is
399:             * not set and this object is part of live or compiled scene graph
400:             *
401:             * @exception IllegalStateException if this ImageComponent object
402:             * is <i>not</i> yUp.
403:             *
404:             * @exception IllegalArgumentException if the width and height of the
405:             * specified image is not equal to the width and height of this
406:             * ImageComponent object.
407:             *
408:             * @exception IllegalArgumentException if the number of components in format 
409:             * does not match the number of components in image.
410:             *
411:             * @since Java 3D 1.5
412:             */
413:            public void set(NioImageBuffer image) {
414:                if (isLiveOrCompiled()) {
415:                    if (!this .getCapability(ALLOW_IMAGE_WRITE)) {
416:                        throw new CapabilityNotSetException(J3dI18N
417:                                .getString("ImageComponent2D1"));
418:                    }
419:                }
420:
421:                ((ImageComponent2DRetained) this .retained).set(image);
422:            }
423:
424:            /**
425:             * Retrieves the image from this ImageComponent2D object.  If the
426:             * data access mode is not by-reference, a copy of the image
427:             * is made.  If the data access mode is by-reference, the
428:             * reference is returned.
429:             *
430:             * @return either a new BufferedImage object created from the data
431:             * in this image component, or the BufferedImage object referenced
432:             * by this image component.
433:             *
434:             * @exception CapabilityNotSetException if appropriate capability is
435:             * not set and this object is part of live or compiled scene graph
436:             *
437:             * @exception IllegalStateException if the image class is not
438:             * ImageClass.BUFFERED_IMAGE.
439:             */
440:            public BufferedImage getImage() {
441:                if (isLiveOrCompiled()) {
442:                    if (!this .getCapability(ImageComponent.ALLOW_IMAGE_READ))
443:                        throw new CapabilityNotSetException(J3dI18N
444:                                .getString("ImageComponent2D0"));
445:                }
446:
447:                RenderedImage img = ((ImageComponent2DRetained) this .retained)
448:                        .getImage();
449:
450:                if ((img != null) && !(img instanceof  BufferedImage)) {
451:                    throw new IllegalStateException(J3dI18N
452:                            .getString("ImageComponent2D5"));
453:                }
454:                return (BufferedImage) img;
455:
456:            }
457:
458:            /**
459:             * Retrieves the image from this ImageComponent2D object.  If the
460:             * data access mode is not by-reference, a copy of the image
461:             * is made.  If the data access mode is by-reference, the
462:             * reference is returned.
463:             *
464:             * @return either a new RenderedImage object created from the data
465:             * in this image component, or the RenderedImage object referenced
466:             * by this image component.
467:             *
468:             * @exception CapabilityNotSetException if appropriate capability is
469:             * not set and this object is part of live or compiled scene graph
470:             *
471:             * @exception IllegalStateException if the image class is not one of:
472:             * ImageClass.BUFFERED_IMAGE or ImageClass.RENDERED_IMAGE.
473:             *
474:             * @since Java 3D 1.2
475:             */
476:            public RenderedImage getRenderedImage() {
477:
478:                if (isLiveOrCompiled())
479:                    if (!this .getCapability(ImageComponent.ALLOW_IMAGE_READ))
480:                        throw new CapabilityNotSetException(J3dI18N
481:                                .getString("ImageComponent2D0"));
482:                return ((ImageComponent2DRetained) this .retained).getImage();
483:            }
484:
485:            /**
486:             * Retrieves the image from this ImageComponent2D object.  If the
487:             * data access mode is not by-reference, a copy of the image
488:             * is made.  If the data access mode is by-reference, the
489:             * reference is returned.
490:             *
491:             * @return either a new NioImageBuffer object created from the data
492:             * in this image component, or the NioImageBuffer object referenced
493:             * by this image component.
494:             *
495:             * @exception CapabilityNotSetException if appropriate capability is
496:             * not set and this object is part of live or compiled scene graph
497:             *
498:             * @exception IllegalStateException if the image class is not
499:             * ImageClass.NIO_IMAGE_BUFFER.
500:             *
501:             * @since Java 3D 1.5
502:             */
503:            public NioImageBuffer getNioImage() {
504:
505:                if (isLiveOrCompiled()) {
506:                    if (!this .getCapability(ImageComponent.ALLOW_IMAGE_READ)) {
507:                        throw new CapabilityNotSetException(J3dI18N
508:                                .getString("ImageComponent2D0"));
509:                    }
510:                }
511:                return ((ImageComponent2DRetained) this .retained).getNioImage();
512:
513:            }
514:
515:            /**
516:             * Modifies a contiguous subregion of the image component.
517:             * Block of data of dimension (width * height)
518:             * starting at the offset (srcX, srcY) of the specified 
519:             * RenderedImage object will be copied into the image component
520:             * starting at the offset (dstX, dstY) of the ImageComponent2D object.
521:             * The specified RenderedImage object must be of the same format as
522:             * the current RenderedImage object in this image component.
523:             * This method can only be used if the data access mode is
524:             * by-copy. If it is by-reference, see updateData().
525:             *
526:             * @param image RenderedImage object containing the subimage.
527:             * @param width width of the subregion.
528:             * @param height height of the subregion.
529:             * @param srcX starting X offset of the subregion in the 
530:             * specified image.
531:             * @param srcY starting Y offset of the subregion in the 
532:             * specified image.
533:             * @param dstX starting X offset of the subregion in the image 
534:             * component of this object.
535:             * @param dstY starting Y offset of the subregion in the image 
536:             * component of this object.
537:             *
538:             * @exception CapabilityNotSetException if appropriate capability is
539:             * not set and this object is part of live or compiled scene graph
540:             *
541:             * @exception IllegalStateException if the data access mode is
542:             * <code>BY_REFERENCE</code>.
543:             *
544:             * @exception IllegalArgumentException if <code>width</code> or 
545:             * <code>height</code> of
546:             * the subregion exceeds the dimension of the image of this object.
547:             *
548:             * @exception IllegalArgumentException if <code>dstX</code> < 0, or
549:             * (<code>dstX</code> + <code>width</code>) > width of this object, or 
550:             * <code>dstY</code> < 0, or
551:             * (<code>dstY</code> + <code>height</code>) > height of this object.
552:             *
553:             * @exception IllegalArgumentException if <code>srcX</code> < 0, or
554:             * (<code>srcX</code> + <code>width</code>) > width of the RenderedImage
555:             * object containing the subimage, or 
556:             * <code>srcY</code> < 0, or
557:             * (<code>srcY</code> + <code>height</code>) > height of the 
558:             * RenderedImage object containing the subimage.
559:             *
560:             * @exception IllegalArgumentException if the specified RenderedImage
561:             * is not compatible with the existing RenderedImage. 
562:             *
563:             * @exception IllegalStateException if the image class is not one of:
564:             * ImageClass.BUFFERED_IMAGE or ImageClass.RENDERED_IMAGE.
565:             *
566:             * @since Java 3D 1.3
567:             */
568:            public void setSubImage(RenderedImage image, int width, int height,
569:                    int srcX, int srcY, int dstX, int dstY) {
570:                if (isLiveOrCompiled()
571:                        && !this .getCapability(ALLOW_IMAGE_WRITE)) {
572:                    throw new CapabilityNotSetException(J3dI18N
573:                            .getString("ImageComponent2D1"));
574:                }
575:
576:                if (((ImageComponent2DRetained) this .retained).isByReference()) {
577:                    throw new IllegalStateException(J3dI18N
578:                            .getString("ImageComponent2D4"));
579:                }
580:
581:                int w = ((ImageComponent2DRetained) this .retained).getWidth();
582:                int h = ((ImageComponent2DRetained) this .retained).getHeight();
583:
584:                // Fix to issue 492
585:                if ((srcX < 0) || (srcY < 0)
586:                        || ((srcX + width) > image.getWidth())
587:                        || ((srcY + height) > image.getHeight()) || (dstX < 0)
588:                        || (dstY < 0) || ((dstX + width) > w)
589:                        || ((dstY + height) > h)) {
590:                    throw new IllegalArgumentException(J3dI18N
591:                            .getString("ImageComponent2D3"));
592:                }
593:
594:                ((ImageComponent2DRetained) this .retained).setSubImage(image,
595:                        width, height, srcX, srcY, dstX, dstY);
596:            }
597:
598:            /**
599:             * Updates image data that is accessed by reference.
600:             * This method calls the updateData method of the specified
601:             * ImageComponent2D.Updater object to synchronize updates to the
602:             * image data that is referenced by this ImageComponent2D object.
603:             * Applications that wish to modify such data must perform all
604:             * updates via this method.
605:             * <p>
606:             * The data to be modified has to be within the boundary of the
607:             * subregion
608:             * specified by the offset (x, y) and the dimension (width*height).
609:             * It is illegal to modify data outside this boundary.
610:             * If any referenced data is modified outisde the updateData
611:             * method, or any data outside the specified boundary is modified,
612:             * the results are undefined.
613:             * <p>
614:             * @param updater object whose updateData callback method will be
615:             * called to update the data referenced by this ImageComponent2D object.
616:             * @param x starting X offset of the subregion.
617:             * @param y starting Y offset of the subregion.
618:             * @param width width of the subregion.
619:             * @param height height of the subregion.
620:             *
621:             * @exception CapabilityNotSetException if the appropriate capability
622:             * is not set, and this object is part of a live or compiled scene graph
623:             * @exception IllegalStateException if the data access mode is
624:             * <code>BY_COPY</code>.
625:             * @exception IllegalArgumentException if <code>width</code> or
626:             * <code>height</code> of
627:             * the subregion exceeds the dimension of the image of this object.
628:             * @exception IllegalArgumentException if <code>x</code> < 0, or
629:             * (<code>x</code> + <code>width</code>) > width of this object, or
630:             * <code>y</code> < 0, or
631:             * (<code>y</code> + <code>height</code>) > height of this object.
632:             *
633:             * @since Java 3D 1.3
634:             */
635:            public void updateData(Updater updater, int x, int y, int width,
636:                    int height) {
637:
638:                if (isLiveOrCompiled()
639:                        && !this .getCapability(ALLOW_IMAGE_WRITE)) {
640:                    throw new CapabilityNotSetException(J3dI18N
641:                            .getString("ImageComponent2D1"));
642:                }
643:
644:                if (!((ImageComponent2DRetained) this .retained).isByReference()) {
645:                    throw new IllegalStateException(J3dI18N
646:                            .getString("ImageComponent2D2"));
647:                }
648:
649:                int w = ((ImageComponent2DRetained) this .retained).getWidth();
650:                int h = ((ImageComponent2DRetained) this .retained).getHeight();
651:
652:                if ((x < 0) || (y < 0) || ((x + width) > w)
653:                        || ((y + height) > h)) {
654:                    throw new IllegalArgumentException(J3dI18N
655:                            .getString("ImageComponent2D3"));
656:                }
657:
658:                ((ImageComponent2DRetained) this .retained).updateData(updater,
659:                        x, y, width, height);
660:            }
661:
662:            /**
663:             * Creates a retained mode ImageComponent2DRetained object that this
664:             * ImageComponent2D component object will point to.
665:             */
666:            void createRetained() {
667:                this .retained = new ImageComponent2DRetained();
668:                this .retained.setSource(this );
669:            }
670:
671:            /**
672:             * @deprecated replaced with cloneNodeComponent(boolean forceDuplicate)
673:             */
674:            public NodeComponent cloneNodeComponent() {
675:                ImageComponent2DRetained rt = (ImageComponent2DRetained) retained;
676:
677:                ImageComponent2D img = new ImageComponent2D(rt.getFormat(),
678:                        rt.width, rt.height, rt.byReference, rt.yUp);
679:                img.duplicateNodeComponent(this );
680:                return img;
681:            }
682:
683:            /**
684:             * Copies all node information from <code>originalNodeComponent</code> 
685:             * into the current node.  This method is called from the
686:             * <code>duplicateNode</code> method. This routine does
687:             * the actual duplication of all "local data" (any data defined in
688:             * this object). 
689:             *
690:             * @param originalNodeComponent the original node to duplicate
691:             * @param forceDuplicate when set to <code>true</code>, causes the
692:             *  <code>duplicateOnCloneTree</code> flag to be ignored.  When
693:             *  <code>false</code>, the value of each node's
694:             *  <code>duplicateOnCloneTree</code> variable determines whether
695:             *  NodeComponent data is duplicated or copied.
696:             *
697:             * @see Node#cloneTree
698:             * @see NodeComponent#setDuplicateOnCloneTree
699:             */
700:            void duplicateAttributes(NodeComponent originalNodeComponent,
701:                    boolean forceDuplicate) {
702:                super 
703:                        .duplicateAttributes(originalNodeComponent,
704:                                forceDuplicate);
705:
706:                ImageComponent.ImageClass imageClass = ((ImageComponentRetained) originalNodeComponent.retained)
707:                        .getImageClass();
708:                if (imageClass == ImageComponent.ImageClass.NIO_IMAGE_BUFFER) {
709:                    NioImageBuffer nioImg = ((ImageComponent2DRetained) originalNodeComponent.retained)
710:                            .getNioImage();
711:
712:                    if (nioImg != null) {
713:                        ((ImageComponent2DRetained) retained).set(nioImg);
714:                    }
715:                } else {
716:                    RenderedImage img = ((ImageComponent2DRetained) originalNodeComponent.retained)
717:                            .getImage();
718:
719:                    if (img != null) {
720:                        ((ImageComponent2DRetained) retained).set(img);
721:                    }
722:                }
723:            }
724:
725:            /**
726:             * The ImageComponent2D.Updater interface is used in updating image data
727:             * that is accessed by reference from a live or compiled ImageComponent
728:             * object.  Applications that wish to modify such data must define a
729:             * class that implements this interface.  An instance of that class is
730:             * then passed to the <code>updateData</code> method of the
731:             * ImageComponent object to be modified.
732:             *
733:             * @since Java 3D 1.3
734:             */
735:            public static interface Updater {
736:                /**
737:                 * Updates image data that is accessed by reference.
738:                 * This method is called by the updateData method of an
739:                 * ImageComponent object to effect
740:                 * safe updates to image data that
741:                 * is referenced by that object.  Applications that wish to modify
742:                 * such data must implement this method and perform all updates
743:                 * within it.
744:                 * <br>
745:                 * NOTE: Applications should <i>not</i> call this method directly.
746:                 *
747:                 * @param imageComponent the ImageComponent object being updated.
748:                 * @param x starting X offset of the subregion.
749:                 * @param y starting Y offset of the subregion.
750:                 * @param width width of the subregion.
751:                 * @param height height of the subregion.
752:                 *
753:                 * @see ImageComponent2D#updateData
754:                 */
755:                public void updateData(ImageComponent2D imageComponent, int x,
756:                        int y, int width, int height);
757:            }
758:
759:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.