Source Code Cross Referenced for ConfigView.java in  » 6.0-JDK-Modules » java-3d » com » sun » j3d » utils » universe » 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 » com.sun.j3d.utils.universe 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: ConfigView.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.4 $
041:         * $Date: 2007/02/09 17:20:44 $
042:         * $State: Exp $
043:         */
044:
045:        package com.sun.j3d.utils.universe;
046:
047:        import java.util.*;
048:        import javax.media.j3d.*;
049:        import javax.vecmath.*;
050:
051:        class ConfigView extends ConfigObject {
052:            /**
053:             * The corresponding View and Viewer instances.  These are set when
054:             * createJ3dView() is called after parsing the configuration file.
055:             */
056:            View j3dView = null;
057:            Viewer j3dViewer = null;
058:
059:            /**
060:             * Set of ConfigScreen instances added to this view.
061:             */
062:            Set screens = new HashSet();
063:
064:            /**
065:             * Indicates whether or not stereo viewing should be enabled for this
066:             * ConfigView.  This is set during parsing of the configuration file.
067:             */
068:            boolean stereoEnable = false;
069:
070:            /**
071:             * Indicates whether or not antialiasing is enabled for this ConfigView.
072:             * This is set during parsing of the configuration file.
073:             */
074:            boolean antialiasingEnable = false;
075:
076:            /**
077:             * Reference to the PhysicalBody associated with this ConfigView.  This is
078:             * set when createJ3dView() is called after parsing the configuration
079:             * file.
080:             */
081:            PhysicalBody physicalBody = null;
082:
083:            /**
084:             * Reference to the PhysicalEnvironment associated with this ConfigView.
085:             * This is set when createJ3dView() is called after parsing the
086:             * configuration file.
087:             */
088:            PhysicalEnvironment physicalEnvironment = null;
089:
090:            // All other configurable attributes.
091:            private double fieldOfView = Math.PI / 4.0;
092:            private int backClipPolicy = View.PHYSICAL_EYE;
093:            private int frontClipPolicy = View.PHYSICAL_EYE;
094:            private double backClipDistance = 10.0;
095:            private double frontClipDistance = 0.1;
096:            private int screenScalePolicy = View.SCALE_SCREEN_SIZE;
097:            private double screenScale = 1.0;
098:            private boolean trackingEnable = false;
099:            private int viewPolicy = View.SCREEN_VIEW;
100:            private int windowEyepointPolicy = -1;
101:            private int windowMovementPolicy = -1;
102:            private int windowResizePolicy = -1;
103:            private boolean coeCenteringEnableSet = false;
104:            private boolean coeCenteringEnable = false;
105:            private Point3d centerEyeInCoexistence = null;
106:
107:            private ConfigPhysicalBody configBody = null;
108:            private ConfigPhysicalEnvironment configEnv = null;
109:            private ConfigViewPlatform configViewPlatform = null;
110:
111:            /**
112:             * Overrides initialize() to do nothing.
113:             */
114:            protected void initialize(ConfigCommand command) {
115:            }
116:
117:            /**
118:             * Processes properties for this object.  Handles commands of the form:<p>
119:             * (ViewAttribute {instanceName} {attrName} {attrValue})
120:             * 
121:             * @param command the command that invoked this method
122:             */
123:            protected void setProperty(ConfigCommand command) {
124:
125:                int argc = command.argc;
126:                Object[] argv = command.argv;
127:                String attr = null;
128:                Object val = null;
129:                String sval = null;
130:                ConfigScreen cs = null;
131:
132:                // Check that arg[1] and arg[2] are strings
133:                if (argc != 4) {
134:                    syntaxError("Incorrect number of arguments to "
135:                            + command.commandName);
136:                }
137:
138:                if (!isName(argv[1])) {
139:                    syntaxError("The first argument to " + command.commandName
140:                            + " must be the instance name");
141:                }
142:
143:                if (!isName(argv[2])) {
144:                    syntaxError("The second argument to " + command.commandName
145:                            + " must be a property name");
146:                }
147:
148:                attr = (String) argv[2];
149:                val = argv[3];
150:
151:                if (attr.equals("Screen") || attr.equals("Window")) {
152:                    if (!(val instanceof  String)) {
153:                        syntaxError("Value for " + attr + " must be a name");
154:                    }
155:                    cs = (ConfigScreen) configContainer.findConfigObject(
156:                            "Screen", (String) val);
157:
158:                    if (!screens.add(cs)) {
159:                        syntaxError(attr + " \"" + ((String) val)
160:                                + "\" has already been added to "
161:                                + instanceName);
162:                    }
163:                } else if (attr.equals("ViewPlatform")) {
164:                    if (!(val instanceof  String)) {
165:                        syntaxError("value for ViewPlatform "
166:                                + " must be an instance name");
167:                    }
168:                    configViewPlatform = (ConfigViewPlatform) configContainer
169:                            .findConfigObject("ViewPlatform", (String) val);
170:
171:                    configViewPlatform.addConfigView(this );
172:                } else if (attr.equals("PhysicalEnvironment")) {
173:                    if (!(val instanceof  String)) {
174:                        syntaxError("value for PhysicalEnvironment "
175:                                + "must be an instance name");
176:                    }
177:                    configEnv = (ConfigPhysicalEnvironment) configContainer
178:                            .findConfigObject("PhysicalEnvironment",
179:                                    (String) val);
180:                } else if (attr.equals("PhysicalBody")) {
181:                    if (!(val instanceof  String)) {
182:                        syntaxError("value for PhysicalBody "
183:                                + "must be an instance name");
184:                    }
185:                    configBody = (ConfigPhysicalBody) configContainer
186:                            .findConfigObject("PhysicalBody", (String) val);
187:                } else if (attr.equals("BackClipPolicy")) {
188:                    if (!(val instanceof  String)) {
189:                        syntaxError("value for BackClipPolicy must be a string");
190:                    }
191:                    sval = (String) val;
192:                    if (sval.equals("PHYSICAL_EYE"))
193:                        backClipPolicy = View.PHYSICAL_EYE;
194:                    else if (sval.equals("PHYSICAL_SCREEN"))
195:                        backClipPolicy = View.PHYSICAL_SCREEN;
196:                    else if (sval.equals("VIRTUAL_EYE"))
197:                        backClipPolicy = View.VIRTUAL_EYE;
198:                    else if (sval.equals("VIRTUAL_SCREEN"))
199:                        backClipPolicy = View.VIRTUAL_SCREEN;
200:                    else
201:                        syntaxError("Invalid value for BackClipPolicy " + sval);
202:                } else if (attr.equals("FrontClipPolicy")) {
203:                    if (!(val instanceof  String)) {
204:                        syntaxError("value for FrontClipPolicy must be a string");
205:                    }
206:                    sval = (String) val;
207:                    if (sval.equals("PHYSICAL_EYE"))
208:                        frontClipPolicy = View.PHYSICAL_EYE;
209:                    else if (sval.equals("PHYSICAL_SCREEN"))
210:                        frontClipPolicy = View.PHYSICAL_SCREEN;
211:                    else if (sval.equals("VIRTUAL_EYE"))
212:                        frontClipPolicy = View.VIRTUAL_EYE;
213:                    else if (sval.equals("VIRTUAL_SCREEN"))
214:                        frontClipPolicy = View.VIRTUAL_SCREEN;
215:                    else
216:                        syntaxError("Invalid value for FrontClipPolicy " + sval);
217:                } else if (attr.equals("ScreenScalePolicy")) {
218:                    if (!(val instanceof  String)) {
219:                        syntaxError("value for ScreenScalePolicy must be a string");
220:                    }
221:                    sval = (String) val;
222:                    if (sval.equals("SCALE_SCREEN_SIZE"))
223:                        screenScalePolicy = View.SCALE_SCREEN_SIZE;
224:                    else if (sval.equals("SCALE_EXPLICIT"))
225:                        screenScalePolicy = View.SCALE_EXPLICIT;
226:                    else
227:                        syntaxError("Invalid value for ScreenScalePolicy "
228:                                + sval);
229:                } else if (attr.equals("FieldOfView")) {
230:                    if (!(val instanceof  Double)) {
231:                        syntaxError("value for FieldOfView must be a number");
232:                    }
233:                    fieldOfView = ((Double) val).doubleValue();
234:                } else if (attr.equals("BackClipDistance")) {
235:                    if (!(val instanceof  Double)) {
236:                        syntaxError("value for BackClipDistance must be a number");
237:                    }
238:                    backClipDistance = ((Double) val).doubleValue();
239:                } else if (attr.equals("FrontClipDistance")) {
240:                    if (!(val instanceof  Double)) {
241:                        syntaxError("value for FrontClipDistance must be a number");
242:                    }
243:                    frontClipDistance = ((Double) val).doubleValue();
244:                } else if (attr.equals("ScreenScale")) {
245:                    if (!(val instanceof  Double)) {
246:                        syntaxError("value for ScreenScale must be a number");
247:                    }
248:                    screenScale = ((Double) val).doubleValue();
249:                } else if (attr.equals("TrackingEnable")) {
250:                    if (!(val instanceof  Boolean)) {
251:                        syntaxError("value for TrackingEnable must be a boolean");
252:                    }
253:                    trackingEnable = ((Boolean) val).booleanValue();
254:                } else if (attr.equals("CoexistenceCenteringEnable")) {
255:                    if (!(val instanceof  Boolean)) {
256:                        syntaxError("value for CoexistenceCenteringEnable "
257:                                + "must be a boolean");
258:                    }
259:                    coeCenteringEnable = ((Boolean) val).booleanValue();
260:                    coeCenteringEnableSet = true;
261:                } else if (attr.equals("ViewPolicy")) {
262:                    if (!(val instanceof  String)) {
263:                        syntaxError("value for ViewPolicy must be a string");
264:                    }
265:                    sval = (String) val;
266:                    if (sval.equals("SCREEN_VIEW"))
267:                        viewPolicy = View.SCREEN_VIEW;
268:                    else if (sval.equals("HMD_VIEW"))
269:                        viewPolicy = View.HMD_VIEW;
270:                    else
271:                        syntaxError("Invalid value for ViewPolicy " + sval);
272:                } else if (attr.equals("WindowEyepointPolicy")) {
273:                    if (!(val instanceof  String)) {
274:                        syntaxError("value for WindowEyepointPolicy "
275:                                + "must be a string");
276:                    }
277:                    sval = (String) val;
278:                    if (sval.equals("RELATIVE_TO_SCREEN"))
279:                        windowEyepointPolicy = View.RELATIVE_TO_SCREEN;
280:                    else if (sval.equals("RELATIVE_TO_COEXISTENCE"))
281:                        windowEyepointPolicy = View.RELATIVE_TO_COEXISTENCE;
282:                    else if (sval.equals("RELATIVE_TO_WINDOW"))
283:                        windowEyepointPolicy = View.RELATIVE_TO_WINDOW;
284:                    else if (sval.equals("RELATIVE_TO_FIELD_OF_VIEW"))
285:                        windowEyepointPolicy = View.RELATIVE_TO_FIELD_OF_VIEW;
286:                    else
287:                        syntaxError("Invalid value for WindowEyepointPolicy "
288:                                + sval);
289:                } else if (attr.equals("WindowMovementPolicy")) {
290:                    if (!(val instanceof  String)) {
291:                        syntaxError("value for WindowEyeMovementPolicy "
292:                                + "must be a string");
293:                    }
294:                    sval = (String) val;
295:                    if (sval.equals("VIRTUAL_WORLD"))
296:                        windowMovementPolicy = View.VIRTUAL_WORLD;
297:                    else if (sval.equals("PHYSICAL_WORLD"))
298:                        windowMovementPolicy = View.PHYSICAL_WORLD;
299:                    else
300:                        syntaxError("Invalid value for WindowMovementPolicy "
301:                                + sval);
302:                } else if (attr.equals("WindowResizePolicy")) {
303:                    if (!(val instanceof  String)) {
304:                        syntaxError("value for WindowResizePolicy "
305:                                + "must be a string");
306:                    }
307:                    sval = (String) val;
308:                    if (sval.equals("VIRTUAL_WORLD"))
309:                        windowResizePolicy = View.VIRTUAL_WORLD;
310:                    else if (sval.equals("PHYSICAL_WORLD"))
311:                        windowResizePolicy = View.PHYSICAL_WORLD;
312:                    else
313:                        syntaxError("Invalid value for WindowResizePolicy "
314:                                + sval);
315:                } else if (attr.equals("CenterEyeInCoexistence")) {
316:                    if (val instanceof  Point3d)
317:                        centerEyeInCoexistence = (Point3d) val;
318:                    else
319:                        syntaxError("value for CenterEyeInCoexistence "
320:                                + "must be a Point3d");
321:                } else if (attr.equals("StereoEnable")) {
322:                    if (!(val instanceof  Boolean)) {
323:                        syntaxError("value for StereoEnable must be a boolean");
324:                    }
325:                    stereoEnable = ((Boolean) val).booleanValue();
326:                } else if (attr.equals("AntialiasingEnable")) {
327:                    if (!(val instanceof  Boolean)) {
328:                        syntaxError("value for AntialiasingEnable must be a boolean");
329:                    }
330:                    antialiasingEnable = ((Boolean) val).booleanValue();
331:                } else {
332:                    syntaxError("Unknown " + command.commandName + " \"" + attr
333:                            + "\"");
334:                }
335:            }
336:
337:            /**
338:             * Create a core Java 3D View instance and a utility Viewer instance using
339:             * the attributes gathered by this object.
340:             */
341:            protected Viewer createViewer(boolean setVisible) {
342:                Point3d leftEyeCoe, rightEyeCoe;
343:
344:                j3dView = new View();
345:                j3dView.setViewPolicy(viewPolicy);
346:
347:                if (configBody == null)
348:                    physicalBody = new PhysicalBody();
349:                else
350:                    physicalBody = configBody.j3dPhysicalBody;
351:
352:                if (configEnv == null)
353:                    physicalEnvironment = new PhysicalEnvironment();
354:                else
355:                    physicalEnvironment = configEnv.j3dPhysicalEnvironment;
356:
357:                j3dView.setPhysicalBody(physicalBody);
358:                j3dView.setPhysicalEnvironment(physicalEnvironment);
359:
360:                boolean standardDefaults = true;
361:                if (coeCenteringEnableSet && !coeCenteringEnable) {
362:                    standardDefaults = false;
363:                }
364:                if (configEnv != null
365:                        && configEnv.coexistenceToTrackerBase != null) {
366:                    standardDefaults = false;
367:                } else {
368:                    Iterator i = screens.iterator();
369:                    while (i.hasNext()) {
370:                        ConfigScreen s = (ConfigScreen) i.next();
371:                        if (s.trackerBaseToImagePlate != null) {
372:                            standardDefaults = false;
373:                            break;
374:                        }
375:                    }
376:                }
377:
378:                if (standardDefaults) {
379:                    // Coexistence centering has not been explicitly set false, and
380:                    // the tracker base to image plate and coexistence to tracker base
381:                    // transforms are unset, so use the standard Java 3D defaults.
382:                    if (windowEyepointPolicy == -1)
383:                        windowEyepointPolicy = View.RELATIVE_TO_FIELD_OF_VIEW;
384:                    if (windowMovementPolicy == -1)
385:                        windowMovementPolicy = View.PHYSICAL_WORLD;
386:                    if (windowResizePolicy == -1)
387:                        windowResizePolicy = View.PHYSICAL_WORLD;
388:                    if (!coeCenteringEnableSet)
389:                        coeCenteringEnable = true;
390:                } else {
391:                    // Use multi-screen or calibrated coexistence defaults.
392:                    if (windowEyepointPolicy == -1)
393:                        windowEyepointPolicy = View.RELATIVE_TO_COEXISTENCE;
394:                    if (windowMovementPolicy == -1)
395:                        windowMovementPolicy = View.VIRTUAL_WORLD;
396:                    if (windowResizePolicy == -1)
397:                        windowResizePolicy = View.VIRTUAL_WORLD;
398:                    if (!coeCenteringEnableSet)
399:                        coeCenteringEnable = false;
400:                }
401:
402:                j3dView.setWindowEyepointPolicy(windowEyepointPolicy);
403:                j3dView.setWindowMovementPolicy(windowMovementPolicy);
404:                j3dView.setWindowResizePolicy(windowResizePolicy);
405:                j3dView.setCoexistenceCenteringEnable(coeCenteringEnable);
406:
407:                if (centerEyeInCoexistence == null) {
408:                    centerEyeInCoexistence = new Point3d(0.0, 0.0, 0.4572);
409:                }
410:
411:                leftEyeCoe = new Point3d(centerEyeInCoexistence);
412:                rightEyeCoe = new Point3d(centerEyeInCoexistence);
413:
414:                if (stereoEnable) {
415:                    Point3d leftEyeBody = new Point3d();
416:                    Point3d rightEyeBody = new Point3d();
417:
418:                    physicalBody.getLeftEyePosition(leftEyeBody);
419:                    physicalBody.getRightEyePosition(rightEyeBody);
420:
421:                    leftEyeCoe.add(leftEyeBody);
422:                    rightEyeCoe.add(rightEyeBody);
423:                }
424:
425:                j3dView.setLeftManualEyeInCoexistence(leftEyeCoe);
426:                j3dView.setRightManualEyeInCoexistence(rightEyeCoe);
427:
428:                j3dView.setBackClipPolicy(backClipPolicy);
429:                j3dView.setFrontClipPolicy(frontClipPolicy);
430:                j3dView.setBackClipDistance(backClipDistance);
431:                j3dView.setFrontClipDistance(frontClipDistance);
432:
433:                j3dView.setScreenScalePolicy(screenScalePolicy);
434:                j3dView.setScreenScale(screenScale);
435:
436:                j3dView.setFieldOfView(fieldOfView);
437:                j3dView.setTrackingEnable(trackingEnable);
438:                j3dView.setSceneAntialiasingEnable(antialiasingEnable);
439:
440:                if (screens.size() == 0) {
441:                    throw new IllegalStateException(errorMessage(
442:                            creatingCommand, "View \"" + instanceName
443:                                    + "\" has no canvases or screens"));
444:                }
445:
446:                ConfigScreen[] cs = new ConfigScreen[screens.size()];
447:                screens.toArray(cs);
448:
449:                j3dViewer = new Viewer(cs, this, setVisible);
450:                return j3dViewer;
451:            }
452:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.