Source Code Cross Referenced for J3fLoader.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3dfly » utils » loaderwrappers » 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.j3dfly.utils.loaderwrappers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/utils/loaderwrappers/J3fLoader.java,v 1.1 2005/04/20 21:05:11 paulby Exp $
003:         *
004:         *                         Sun Public License Notice
005:         *
006:         *  The contents of this file are subject to the Sun Public License Version
007:         *  1.0 (the "License"). You may not use this file except in compliance with
008:         *  the License. A copy of the License is available at http://www.sun.com/
009:         *  
010:         *  The Original Code is Java 3D(tm) Fly Through.
011:         *  The Initial Developer of the Original Code is Paul Byrne.
012:         *  Portions created by Paul Byrne are Copyright (C) 2002.
013:         *  All Rights Reserved.
014:         *  
015:         *  Contributor(s): Paul Byrne.
016:         *  
017:         **/
018:        package org.jdesktop.j3dfly.utils.loaderwrappers;
019:
020:        import com.sun.j3d.loaders.Scene;
021:        import com.sun.j3d.loaders.SceneBase;
022:
023:        import javax.media.j3d.BranchGroup;
024:
025:        import com.sun.j3d.utils.scenegraph.io.SceneGraphFileReader;
026:
027:        /**
028:         * Provides a Loader which can load Java3D scene graphs saved using the
029:         * SceneGraphFileWriter.
030:         *
031:         * The Java3D LoaderInterface implemented by this class does not provide access
032:         * to all the features that can be stored in a .j3f file.
033:         * Most importantly the file may contain a universe which will be ignored
034:         * by this loader.
035:         *
036:         * @author Paul Byrne
037:         * @version	1.8, 01/18/02
038:         */
039:        public class J3fLoader extends com.sun.j3d.loaders.LoaderBase {
040:
041:            private SceneGraphFileReader reader = null;
042:            //private com.sun.j3d.demos.utils.scenegraph.io.SceneGraphFileReader oldReader=null;
043:            private static J3fLoaderListener loaderListener = null;
044:            private BranchGroup[] graphs = null;
045:            private static ClassLoader classLoader = null;
046:
047:            /**
048:             * Setup a listener to get notified when this loader is used
049:             */
050:            public static void setJ3fLoaderListener(J3fLoaderListener listener) {
051:                loaderListener = listener;
052:            }
053:
054:            /**
055:             * Set the ClassLoader which will be used by the SceneGraphIO system
056:             * when loading the scene graph.
057:             *
058:             * The default null in which case the system will use system class loader
059:             */
060:            public static void setClassLoader(ClassLoader cLoader) {
061:                classLoader = cLoader;
062:            }
063:
064:            /**
065:             * Get the ClassLoader set by setClassLoader
066:             *
067:             * If setClassLoader has not been called the default null will be returned.
068:             * This indicates that systemClassLoader will be used.
069:             */
070:            public static ClassLoader getClassLoader() {
071:                return classLoader;
072:            }
073:
074:            /**
075:             * Load all the BranchGraphs from the file called filename and return
076:             * a Scene containing all the BranchGraphs
077:             */
078:            public Scene load(String filename)
079:                    throws java.io.FileNotFoundException,
080:                    com.sun.j3d.loaders.IncorrectFormatException,
081:                    com.sun.j3d.loaders.ParsingErrorException {
082:
083:                SceneBase scenebase = null;
084:                Scene scene = null;
085:                try {
086:                    reader = new SceneGraphFileReader(
087:                            new java.io.File(filename));
088:                    if (classLoader != null)
089:                        reader.setClassLoader(classLoader);
090:                    int size = reader.getBranchGraphCount();
091:                    scenebase = new SceneBase();
092:
093:                    BranchGroup bg = new BranchGroup();
094:                    graphs = new BranchGroup[size];
095:
096:                    if (size > 1) {
097:                        for (int i = 0; i < size; i++) {
098:                            graphs[i] = reader.readBranchGraph(i)[0];
099:                            bg.addChild(graphs[i]);
100:                        }
101:                    } else {
102:                        bg = reader.readBranchGraph(0)[0];
103:                        graphs[0] = bg;
104:                    }
105:
106:                    scenebase.setSceneGroup(bg);
107:
108:                    String[] objectNames = reader.getNames();
109:                    for (int i = 0; i < objectNames.length; i++)
110:                        try {
111:                            scenebase.addNamedObject(objectNames[i], reader
112:                                    .getNamedObject(objectNames[i]));
113:                        } catch (com.sun.j3d.utils.scenegraph.io.ObjectNotLoadedException e) {
114:                        } catch (com.sun.j3d.utils.scenegraph.io.NamedObjectException e) {
115:                        }
116:
117:                    if (loaderListener != null)
118:                        loaderListener.loadingJ3f(this );
119:                    reader.close();
120:
121:                } catch (java.io.InvalidClassException ex) {
122:                    throw new com.sun.j3d.loaders.IncorrectFormatException(ex
123:                            .getMessage());
124:                } catch (java.io.FileNotFoundException e) {
125:                    throw new java.io.FileNotFoundException(filename);
126:                } catch (java.io.IOException exc) {
127:                    //            if (exc.getMessage().startsWith("Use Java 3D Fly"))
128:                    //                return oldLoad( filename );
129:                    //            else
130:                    throw new java.io.FileNotFoundException(exc.getMessage());
131:                }
132:
133:                if (scenebase == null)
134:                    return scene;
135:                else
136:                    return scenebase;
137:            }
138:
139:            /**
140:             * Load all the BranchGraphs from the file called filename and return
141:             * a Scene containing all the BranchGraphs
142:             *
143:             * This method uses the OLD io package which was included with J3dFly 1.0
144:             */
145:            //    private Scene oldLoad( String filename ) throws java.io.FileNotFoundException,
146:            //                                                com.sun.j3d.loaders.IncorrectFormatException,
147:            //                                                com.sun.j3d.loaders.ParsingErrorException {
148:            //
149:            //        SceneBase scenebase = null;
150:            //        Scene scene=null;
151:            //        try {      
152:            //            oldReader = new com.sun.j3d.demos.utils.scenegraph.io.SceneGraphFileReader( new java.io.File( filename ));
153:            //            int size = oldReader.getBranchGraphCount();
154:            //            scenebase = new SceneBase();
155:            //
156:            //            BranchGroup bg = new BranchGroup();
157:            //            graphs = new BranchGroup[ size ];
158:            //            
159:            //            if (size>1) {            
160:            //                for(int i=0; i<size; i++) {
161:            //                    graphs[i] = oldReader.readBranchGraph( i )[0];
162:            //                    bg.addChild( graphs[i] );
163:            //                }
164:            //            } else {
165:            //                bg = oldReader.readBranchGraph(0)[0];
166:            //                graphs[0] = bg;
167:            //            }
168:            //            
169:            //            scenebase.setSceneGroup( bg );
170:            //            
171:            //            String[] objectNames = oldReader.getNames();
172:            //            for(int i=0; i<objectNames.length; i++)
173:            //                try {
174:            //                    scenebase.addNamedObject( objectNames[i], oldReader.getNamedObject( objectNames[i] ) );
175:            //                } catch( com.sun.j3d.demos.utils.scenegraph.io.ObjectNotLoadedException e ) {}
176:            //                  catch( com.sun.j3d.demos.utils.scenegraph.io.NamedObjectException e ) {}
177:            //
178:            //            if (loaderListener!=null)
179:            //                loaderListener.loadingJ3f( this );
180:            //            oldReader.close();
181:            //            
182:            //        } catch( java.io.InvalidClassException ex ) {
183:            //            throw new com.sun.j3d.loaders.IncorrectFormatException( ex.getMessage() );
184:            //        } catch( java.io.FileNotFoundException e ) {
185:            //            throw new java.io.FileNotFoundException( filename );
186:            //        } catch( java.io.IOException exc ) {
187:            //            throw new java.io.FileNotFoundException( exc.getMessage() );
188:            //        }
189:            //        
190:            //        
191:            //        if (scenebase==null)
192:            //        return scene;
193:            //        else return scenebase;
194:            //    }
195:            /**
196:             * Scene only supports a single sceneBase.
197:             *
198:             * For any J3f files containing multiple BranchGraphs all the graphs
199:             * will be added as children of SceneBase.
200:             *
201:             * This call will return the actual set of BranchGraphs (this will
202:             * still be children of the sceneBase ). If their is only a single
203:             * branchgraph getBranchGrapgs()[0] == sceneBase
204:             */
205:            public BranchGroup[] getBranchGraphs() {
206:                return graphs;
207:            }
208:
209:            /**
210:             * Get the user object for the file, should be called from within a J3fLoaderListener only
211:             */
212:            public Object getFileUserData() throws java.io.IOException {
213:                //        if (oldReader!=null)
214:                //            return oldReader.readUserData();
215:
216:                return reader.readUserData();
217:            }
218:
219:            /** Not Implemented
220:             */
221:            public Scene load(java.net.URL url)
222:                    throws java.io.FileNotFoundException,
223:                    com.sun.j3d.loaders.IncorrectFormatException,
224:                    com.sun.j3d.loaders.ParsingErrorException {
225:                throw new RuntimeException("NOT IMPLEMENTED");
226:            }
227:
228:            /** Not Implemented
229:             */
230:            public Scene load(java.io.Reader reader)
231:                    throws java.io.FileNotFoundException,
232:                    com.sun.j3d.loaders.IncorrectFormatException,
233:                    com.sun.j3d.loaders.ParsingErrorException {
234:
235:                throw new RuntimeException("NOT IMPLEMENTED");
236:            }
237:
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.