Source Code Cross Referenced for J3dNodeTable.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: J3dNodeTable.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.5 $
028:         * $Date: 2008/02/28 20:17:25 $
029:         * $State: Exp $
030:         */
031:
032:        package javax.media.j3d;
033:
034:        import java.io.DataOutputStream;
035:        import java.io.OutputStream;
036:        import java.util.Hashtable;
037:        import javax.vecmath.Color3f;
038:        import javax.vecmath.Tuple3f;
039:
040:        /**
041:         * The J3dNodeTable object provides utilities for the save/load
042:         * methods in the Java3d nodes.  Specifically, it holds an enumerated
043:         * list of the Java3D node types and their respective Class names.
044:         * It keeps these lists in a Hashtable and an array and allows
045:         * other classes to get an enumerated value associated with an Object
046:         * type or an instance of an Object associated with an enumerated value.
047:         *
048:         */
049:        class J3dNodeTable {
050:
051:            // nodeTable holds the enumerated value/Classname pairs.  This is
052:            // used to look up enumerated values given a Class name.
053:            Hashtable nodeTable = new Hashtable();
054:
055:            // nodeArray holds the value/Classname pairs also, but allows lookups
056:            // in the other direction (given a value, what's the Class name?)
057:            String nodeArray[];
058:
059:            // Following is a list of the current scene graph objects of java3D.
060:            // In order to make later node insertion easier, and to add some logic to
061:            // this arbitrary list, the groups of nodes are grouped in terms of
062:            // similar functionality of node types.
063:
064:            // Maximum number of nodes
065:            static final int MAX_NUM_NODES = 200;
066:
067:            // Nothing occupies slot 0 - thus we can return 0 from this class'
068:            // methods to denote failure.
069:            static final int NOTHING = 0;
070:
071:            // 1 - 9: Groups
072:            static final int GROUP = 1;
073:            static final int TRANSFORM_GROUP = 2;
074:            static final int SWITCH_GROUP = 3;
075:            static final int ORDERED_GROUP = 4;
076:            static final int BRANCH_GROUP = 5;
077:            static final int ENDGROUP = 9; // denotes done with group
078:
079:            // 10 - 19: Shape3D (in a class by itself)
080:            static final int SHAPE3D = 10;
081:
082:            // 20 - 49: Appearance and all of its attributes
083:            static final int APPEARANCE = 20;
084:            static final int MATERIAL = 21;
085:            static final int TEXTURE = 22;
086:            static final int TEX_COORD_GENERATION = 23;
087:            static final int TEXTURE_ATTRIBUTES = 24;
088:            static final int COLORING_ATTRIBUTES = 25;
089:            static final int TRANSPARENCY_ATTRIBUTES = 26;
090:            static final int RENDERING_ATTRIBUTES = 27;
091:            static final int POLYGON_ATTRIBUTES = 28;
092:            static final int LINE_ATTRIBUTES = 29;
093:            static final int POINT_ATTRIBUTES = 30;
094:            static final int TEXTURE_2D = 31;
095:            static final int TEXTURE_3D = 32;
096:            static final int IMAGE_COMPONENT = 33;
097:            static final int IMAGE_COMPONENT_2D = 34;
098:            static final int IMAGE_COMPONENT_3D = 35;
099:            static final int ENDAPPEARANCE = 49;
100:
101:            // 100 - 149: All Geometry types
102:            static final int GEOMETRY = 100;
103:            static final int COMPRESSED_GEOMETRY = 101;
104:            static final int GEOMETRY_ARRAY = 102;
105:            static final int GEOMETRY_STRIP_ARRAY = 103;
106:            static final int INDEXED_GEOMETRY_ARRAY = 104;
107:            static final int INDEXED_GEOMETRY_STRIP_ARRAY = 105;
108:            static final int INDEXED_LINE_ARRAY = 106;
109:            static final int INDEXED_LINE_STRIP_ARRAY = 107;
110:            static final int INDEXED_POINT_ARRAY = 108;
111:            static final int INDEXED_QUAD_ARRAY = 109;
112:            static final int INDEXED_TRIANGLE_ARRAY = 110;
113:            static final int INDEXED_TRIANGLE_FAN_ARRAY = 111;
114:            static final int INDEXED_TRIANGLE_STRIP_ARRAY = 112;
115:            static final int LINE_ARRAY = 113;
116:            static final int LINE_STRIP_ARRAY = 114;
117:            static final int POINT_ARRAY = 115;
118:            static final int QUAD_ARRAY = 116;
119:            static final int TRIANGLE_ARRAY = 117;
120:            static final int TRIANGLE_FAN_ARRAY = 118;
121:            static final int TRIANGLE_STRIP_ARRAY = 119;
122:            static final int BACKGROUND_SOUND = 120;
123:            static final int POINT_SOUND = 121;
124:            static final int CONE_SOUND = 122;
125:            static final int MEDIA_CONTAINER = 123;
126:
127:            // 150 - 169: Behaviors
128:            static final int ROTATION_INTERPOLATOR = 150;
129:            static final int ROTPOSSCALEPATH_INTERPOLATOR = 151;
130:            static final int ROTATIONPATH_INTERPOLATOR = 152;
131:            static final int POSITIONPATH_INTERPOLATOR = 153;
132:            static final int ROTPOSPATH_INTERPOLATOR = 154;
133:            static final int POSITION_INTERPOLATOR = 155;
134:            static final int SWITCHVALUE_INTERPOLATOR = 156;
135:            static final int COLOR_INTERPOLATOR = 157;
136:            static final int SCALE_INTERPOLATOR = 158;
137:            // Problem: these next two are non j3d-core items
138:            static final int SOUND_PLAYER = 159;
139:            static final int SOUND_FADER = 160;
140:
141:            // 170 - 189: Various utility nodes
142:            static final int BOUNDS = 170;
143:            static final int BOUNDING_SPHERE = 171;
144:            static final int BOUNDING_BOX = 172;
145:            static final int BOUNDING_POLYTOPE = 173;
146:            static final int TRANSFORM3D = 180;
147:            static final int BACKGROUND = 181;
148:
149:            // 190 - 199: Lights
150:            static final int LIGHT = 190;
151:            static final int POINT_LIGHT = 191;
152:            static final int SPOT_LIGHT = 192;
153:            static final int DIRECTIONAL_LIGHT = 193;
154:            static final int AMBIENT_LIGHT = 194;
155:
156:            /**
157:             * Constructs this Object, which initializes the array and Hashtable
158:             */
159:            J3dNodeTable() {
160:                nodeArray = new String[MAX_NUM_NODES];
161:                //Initialize all table entries to null
162:                for (int i = 0; i < MAX_NUM_NODES; ++i)
163:                    nodeArray[i] = null;
164:                // Setup slots of nodeArray where there should be valid values
165:                nodeArray[GROUP] = "Group";
166:                nodeArray[TRANSFORM_GROUP] = "TransformGroup";
167:                nodeArray[SWITCH_GROUP] = "Switch";
168:                nodeArray[ORDERED_GROUP] = "OrderedGroup";
169:                nodeArray[BRANCH_GROUP] = "BranchGroup";
170:
171:                nodeArray[SHAPE3D] = "Shape3D";
172:
173:                nodeArray[APPEARANCE] = "Appearance";
174:                nodeArray[MATERIAL] = "Material";
175:                nodeArray[TEXTURE] = "Texture";
176:                nodeArray[TEXTURE_2D] = "Texture2D";
177:                nodeArray[TEXTURE_3D] = "Texture3D";
178:                nodeArray[IMAGE_COMPONENT] = "ImageComponent";
179:                nodeArray[IMAGE_COMPONENT_2D] = "ImageComponent2D";
180:                nodeArray[IMAGE_COMPONENT_3D] = "ImageComponent3D";
181:                nodeArray[TRANSPARENCY_ATTRIBUTES] = "TransparencyAttributes";
182:
183:                nodeArray[GEOMETRY] = "Geometry";
184:                nodeArray[COMPRESSED_GEOMETRY] = "CompressedGeometry";
185:                nodeArray[GEOMETRY_ARRAY] = "GeometryArray";
186:                nodeArray[GEOMETRY_STRIP_ARRAY] = "GeometryStripArray";
187:                nodeArray[INDEXED_GEOMETRY_ARRAY] = "IndexedGeometryArray";
188:                nodeArray[INDEXED_GEOMETRY_STRIP_ARRAY] = "IndexedGeometryStripArray";
189:                nodeArray[INDEXED_LINE_ARRAY] = "IndexedLineArray";
190:                nodeArray[INDEXED_LINE_STRIP_ARRAY] = "IndexedLineStripArray";
191:                nodeArray[INDEXED_POINT_ARRAY] = "IndexedPointArray";
192:                nodeArray[INDEXED_QUAD_ARRAY] = "IndexedQuadArray";
193:                nodeArray[INDEXED_TRIANGLE_ARRAY] = "IndexedTriangleArray";
194:                nodeArray[INDEXED_TRIANGLE_FAN_ARRAY] = "IndexedTriangleFanArray";
195:                nodeArray[INDEXED_TRIANGLE_STRIP_ARRAY] = "indexedTriangleStripArray";
196:                nodeArray[LINE_ARRAY] = "LineArray";
197:                nodeArray[LINE_STRIP_ARRAY] = "LineStripArray";
198:                nodeArray[POINT_ARRAY] = "PointArray";
199:                nodeArray[QUAD_ARRAY] = "QuadArray";
200:                nodeArray[TRIANGLE_ARRAY] = "TriangleArray";
201:                nodeArray[TRIANGLE_FAN_ARRAY] = "TriangleFanArray";
202:                nodeArray[TRIANGLE_STRIP_ARRAY] = "TriangleStripArray";
203:                nodeArray[BACKGROUND_SOUND] = "BackgroundSound";
204:                nodeArray[POINT_SOUND] = "PointSound";
205:                nodeArray[CONE_SOUND] = "ConeSound";
206:                nodeArray[MEDIA_CONTAINER] = "MediaContainer";
207:
208:                nodeArray[ROTATION_INTERPOLATOR] = "RotationInterpolator";
209:                nodeArray[ROTPOSSCALEPATH_INTERPOLATOR] = "RotPosScalePathInterpolator";
210:                nodeArray[ROTATIONPATH_INTERPOLATOR] = "RotationPathInterpolator";
211:                nodeArray[POSITIONPATH_INTERPOLATOR] = "PositionPathInterpolator";
212:                nodeArray[ROTPOSPATH_INTERPOLATOR] = "RotPosPathInterpolator";
213:                nodeArray[POSITION_INTERPOLATOR] = "PositionInterpolator";
214:                nodeArray[SWITCHVALUE_INTERPOLATOR] = "SwitchValueInterpolator";
215:                nodeArray[COLOR_INTERPOLATOR] = "ColorInterpolator";
216:                nodeArray[SCALE_INTERPOLATOR] = "ScaleInterpolator";
217:                nodeArray[SOUND_PLAYER] = "SoundPlayer";
218:                nodeArray[SOUND_FADER] = "SoundFader";
219:
220:                nodeArray[BOUNDS] = "Bounds";
221:                nodeArray[BOUNDING_SPHERE] = "BoundingSphere";
222:                nodeArray[BOUNDING_BOX] = "BoundingBox";
223:                nodeArray[BOUNDING_POLYTOPE] = "BoundingPolytope";
224:                nodeArray[TRANSFORM3D] = "Transform3D";
225:                nodeArray[BACKGROUND] = "Background";
226:
227:                nodeArray[LIGHT] = "Light";
228:                nodeArray[POINT_LIGHT] = "PointLight";
229:                nodeArray[SPOT_LIGHT] = "SpotLight";
230:                nodeArray[DIRECTIONAL_LIGHT] = "DirectionalLight";
231:                nodeArray[AMBIENT_LIGHT] = "AmbientLight";
232:
233:                for (int i = 0; i < MAX_NUM_NODES; ++i) {
234:                    if (nodeArray[i] != null)
235:                        nodeTable.put(nodeArray[i], new Integer(i));
236:                }
237:
238:            }
239:
240:            /**
241:             * Returns the enumerated value associated with an Object.  This
242:             * method retrieves the base class name (with no package name and
243:             * with no "Retained" portion (if it's part of the Object's name);
244:             * we're just looking for the base Java3d node type here.
245:             */
246:            int getNodeValue(Object object) {
247:                Integer i;
248:                String fullName = object.getClass().getName();
249:                int firstIndex;
250:                int lastIndex;
251:                if ((firstIndex = fullName.lastIndexOf(".")) == -1)
252:                    firstIndex = 0;
253:                else
254:                    firstIndex++;
255:                if ((lastIndex = fullName.lastIndexOf("Retained")) == -1)
256:                    lastIndex = fullName.length();
257:                String nodeName = fullName.substring(firstIndex, lastIndex);
258:                if ((i = (Integer) nodeTable.get(nodeName)) != null) {
259:                    return i.intValue();
260:                } else {
261:                    // This conditional exists because if a group node is
262:                    // actually a subclass of some standard Java3d Group type
263:                    // (e.g., VrmlParser), then we'll just save it and reload
264:                    // it as a Group.
265:                    if (object instanceof  TransformGroup
266:                            || object instanceof  TransformGroupRetained)
267:                        return TRANSFORM_GROUP;
268:                    else if (object instanceof  BranchGroup
269:                            || object instanceof  BranchGroupRetained)
270:                        return BRANCH_GROUP;
271:                    else if (object instanceof  Switch
272:                            || object instanceof  SwitchRetained)
273:                        return SWITCH_GROUP;
274:                    else if (object instanceof  Group
275:                            || object instanceof  GroupRetained)
276:                        return GROUP;
277:                    else if (object instanceof  Shape3D)
278:                        return SHAPE3D; // For Text2D object in particular
279:                    else {
280:                        System.err
281:                                .println("Warning: Don't know how to save object of type "
282:                                        + object);
283:                        return 0;
284:                    }
285:                }
286:            }
287:
288:            /**
289:             * Returns new instance of an object with the Class name
290:             * associated with the given enumerated value.
291:             */
292:            Object getObject(int nodeValue) {
293:                try {
294:                    if (nodeArray[nodeValue] != null) {
295:                        String nodeName = "javax.media.j3d."
296:                                + nodeArray[nodeValue];
297:                        return Class.forName(nodeName).newInstance();
298:                    }
299:                } catch (Exception e) {
300:                    throw new RuntimeException(
301:                            "Exception creating object for nodeValue "
302:                                    + nodeValue
303:                                    + "\n  nodeName = javax.media.j3d."
304:                                    + nodeArray[nodeValue]);
305:                }
306:                return null;
307:            }
308:
309:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.