Source Code Cross Referenced for ImageComponentByReferenceTest.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3d » examples » geometry_by_ref » 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 » org.jdesktop.j3d.examples.geometry_by_ref 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: ImageComponentByReferenceTest.java,v $
003:         *
004:         * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         * - Redistribution of source code must retain the above copyright
011:         *   notice, this list of conditions and the following disclaimer.
012:         *
013:         * - Redistribution in binary form must reproduce the above copyright
014:         *   notice, this list of conditions and the following disclaimer in
015:         *   the documentation and/or other materials provided with the
016:         *   distribution.
017:         *
018:         * Neither the name of Sun Microsystems, Inc. or the names of
019:         * contributors may be used to endorse or promote products derived
020:         * from this software without specific prior written permission.
021:         *
022:         * This software is provided "AS IS," without a warranty of any
023:         * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
024:         * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
025:         * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
026:         * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
027:         * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
028:         * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
029:         * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
030:         * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
031:         * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
032:         * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
033:         * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
034:         * POSSIBILITY OF SUCH DAMAGES.
035:         *
036:         * You acknowledge that this software is not designed, licensed or
037:         * intended for use in the design, construction, operation or
038:         * maintenance of any nuclear facility.
039:         *
040:         * $Revision: 1.3 $
041:         * $Date: 2007/02/09 17:21:39 $
042:         * $State: Exp $
043:         */
044:
045:        package org.jdesktop.j3d.examples.geometry_by_ref;
046:
047:        import java.awt.*;
048:        import java.awt.event.*;
049:        import com.sun.j3d.utils.applet.MainFrame;
050:        import com.sun.j3d.utils.universe.*;
051:        import javax.media.j3d.*;
052:        import javax.vecmath.*;
053:        import javax.swing.*;
054:        import com.sun.j3d.utils.image.TextureLoader;
055:        import com.sun.j3d.utils.geometry.Box;
056:        import java.awt.image.*;
057:        import org.jdesktop.j3d.examples.Resources;
058:
059:        public class ImageComponentByReferenceTest extends JApplet implements 
060:                ActionListener {
061:
062:            Shape3D s1, s2;
063:            TextureLoader t0, t1, t2;
064:            int count = 0;
065:
066:            Appearance app = new Appearance();
067:            BranchGroup objRoot = new BranchGroup();
068:            TransformGroup objTrans = new TransformGroup();
069:            BufferedImage bImage1;
070:            TiledImage checkBoard;
071:            boolean yUp = false;
072:            boolean byRef = true;
073:            JComboBox rasterType, texType;
074:            ImageComponent2D[] image = new ImageComponent2D[8];
075:            Appearance dummyApp = new Appearance();
076:            Texture2D texOne, texCheckBoard;
077:            javax.media.j3d.Raster raster;
078:            Box textureCube;
079:            Shape3D boxShape;
080:            int w1 = 64, h1 = 32, checkw = 16, checkh = 16;
081:
082:            private java.net.URL texImage = null;
083:
084:            private SimpleUniverse u = null;
085:
086:            public BranchGroup createSceneGraph() {
087:                objRoot = new BranchGroup();
088:
089:                objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
090:                objTrans.setCapability(Group.ALLOW_CHILDREN_WRITE);
091:
092:                objRoot.addChild(objTrans);
093:
094:                BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,
095:                        0.0, 0.0), 100.0);
096:
097:                app.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
098:
099:                textureCube = new Box(0.4f, 0.4f, 0.4f,
100:                        Box.GENERATE_TEXTURE_COORDS | Box.GENERATE_NORMALS, app);
101:                boxShape = textureCube.getShape(Box.FRONT);
102:                boxShape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
103:                objTrans.addChild(textureCube);
104:
105:                checkBoard = new TiledImage();
106:                TextureLoader texLoader = new TextureLoader(texImage, this );
107:                ImageComponent2D oneImage = texLoader.getImage();
108:                bImage1 = oneImage.getImage();
109:
110:                int index = 0;
111:                image[index++] = new ImageComponent2D(oneImage.getFormat(),
112:                        (RenderedImage) bImage1, false, true);
113:
114:                image[index++] = new ImageComponent2D(oneImage.getFormat(),
115:                        (RenderedImage) bImage1, true, true);
116:
117:                image[index++] = new ImageComponent2D(oneImage.getFormat(),
118:                        (RenderedImage) bImage1, false, false);
119:
120:                image[index++] = new ImageComponent2D(oneImage.getFormat(),
121:                        (RenderedImage) bImage1, true, false);
122:
123:                createRaster(objRoot);
124:
125:                image[index++] = new ImageComponent2D(
126:                        ImageComponent.FORMAT_RGBA, checkBoard, false, true);
127:
128:                image[index++] = new ImageComponent2D(
129:                        ImageComponent.FORMAT_RGBA, checkBoard, true, true);
130:
131:                image[index++] = new ImageComponent2D(
132:                        ImageComponent.FORMAT_RGBA, checkBoard, false, false);
133:
134:                image[index++] = new ImageComponent2D(
135:                        ImageComponent.FORMAT_RGBA, checkBoard, true, false);
136:
137:                texOne = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA,
138:                        image[2].getWidth(), image[2].getHeight());
139:
140:                texOne.setCapability(Texture.ALLOW_IMAGE_WRITE);
141:                texOne.setImage(0, image[2]);
142:
143:                app.setTexture(texOne);
144:
145:                texCheckBoard = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA,
146:                        image[4].getWidth(), image[4].getHeight());
147:
148:                texCheckBoard.setCapability(Texture.ALLOW_IMAGE_WRITE);
149:                objRoot.compile();
150:                return objRoot;
151:            }
152:
153:            public void actionPerformed(ActionEvent e) {
154:                Object target = e.getSource();
155:
156:                if (target == rasterType) {
157:                    if (rasterType.getSelectedIndex() < 4) {
158:                        raster.setSize(w1, h1);
159:                    } else {
160:                        raster.setSize(checkw, checkh);
161:                    }
162:                    raster.setImage(image[rasterType.getSelectedIndex()]);
163:                } else if (target == texType) {
164:                    boxShape.setAppearance(dummyApp);
165:                    if (texType.getSelectedIndex() < 4) {
166:                        texOne.setImage(0, image[texType.getSelectedIndex()]);
167:                        app.setTexture(texOne);
168:                    } else {
169:                        texCheckBoard.setImage(0, image[texType
170:                                .getSelectedIndex()]);
171:                        app.setTexture(texCheckBoard);
172:                    }
173:
174:                    boxShape.setAppearance(app);
175:                }
176:
177:            }
178:
179:            JPanel createImagePanel() {
180:                JPanel panel = new JPanel();
181:                String texVals[] = { "One_Yup_ByCopy", "One_Yup_ByReference",
182:                        "One_Ydown_ByCopy", "One_Ydown_ByReference",
183:                        "Checkered_Yup_ByCopy", "Checkered_Yup_ByReference",
184:                        "Checkered_Ydown_ByCopy", "Checkered_Ydown_ByReference" };
185:
186:                rasterType = new JComboBox(texVals);
187:                rasterType.setLightWeightPopupEnabled(false);
188:                rasterType.addActionListener(this );
189:                rasterType.setSelectedIndex(2);
190:                panel.add(new JLabel("Raster Image"));
191:                panel.add(rasterType);
192:
193:                texType = new JComboBox(texVals);
194:                texType.setLightWeightPopupEnabled(false);
195:                texType.addActionListener(this );
196:                texType.setSelectedIndex(2);
197:                panel.add(new JLabel("Texture Image"));
198:                panel.add(texType);
199:                return panel;
200:
201:            }
202:
203:            public ImageComponentByReferenceTest() {
204:            }
205:
206:            public ImageComponentByReferenceTest(java.net.URL url) {
207:                texImage = url;
208:            }
209:
210:            public void init() {
211:
212:                texImage = Resources.getResource("resources/images/one.jpg");
213:                if (texImage == null) {
214:                    System.err.println("resources/images/one.jpg not found");
215:                    System.exit(1);
216:                }
217:
218:                Canvas3D c = new Canvas3D(SimpleUniverse
219:                        .getPreferredConfiguration());
220:                BranchGroup scene = createSceneGraph();
221:                u = new SimpleUniverse(c);
222:                u.getViewingPlatform().setNominalViewingTransform();
223:                u.addBranchGraph(scene);
224:                Container contentPane = getContentPane();
225:                JPanel p = new JPanel();
226:                BoxLayout boxlayout = new BoxLayout(p, BoxLayout.Y_AXIS);
227:                p.setLayout(boxlayout);
228:                contentPane.add("Center", c);
229:
230:                contentPane.add("South", p);
231:
232:                p.add(createImagePanel());
233:
234:            }
235:
236:            public void destroy() {
237:                u.cleanup();
238:            }
239:
240:            public static void main(String[] args) {
241:                java.net.URL url = null;
242:                // the path to the image file for an application
243:                url = Resources.getResource("resources/images/one.jpg");
244:                if (url == null) {
245:                    System.err.println("resources/images/one.jpg not found");
246:                    System.exit(1);
247:                }
248:
249:                new MainFrame(new ImageComponentByReferenceTest(url), 800, 700);
250:            }
251:
252:            void createRaster(BranchGroup scene) {
253:                // Create raster geometries and shapes
254:                Vector3f trans = new Vector3f();
255:                Transform3D tr = new Transform3D();
256:                TransformGroup tg;
257:
258:                // Left
259:                raster = new javax.media.j3d.Raster();
260:                raster.setCapability(javax.media.j3d.Raster.ALLOW_IMAGE_WRITE);
261:                raster.setCapability(javax.media.j3d.Raster.ALLOW_SIZE_WRITE);
262:                raster.setPosition(new Point3f(-0.9f, 0.75f, 0.0f));
263:                raster.setType(javax.media.j3d.Raster.RASTER_COLOR);
264:                raster.setOffset(0, 0);
265:
266:                raster.setSize(image[2].getWidth(), image[2].getHeight());
267:                raster.setImage(image[2]);
268:                Shape3D sh = new Shape3D(raster, new Appearance());
269:                scene.addChild(sh);
270:            }
271:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.