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


001:        /*
002:         *  $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/CapabilityPersistance.java,v 1.1 2005/04/20 22:20:44 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 the Java 3D(tm) Scene Graph Editor.
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.j3dedit.scenegrapheditor;
019:
020:        import java.util.HashMap;
021:        import java.util.Vector;
022:        import java.lang.reflect.Field;
023:        import javax.media.j3d.SceneGraphObject;
024:        import javax.media.j3d.Node;
025:        import javax.media.j3d.Appearance;
026:
027:        import org.jdesktop.j3d.utils.scenegraph.traverser.TreeScan;
028:        import org.jdesktop.j3d.utils.scenegraph.traverser.NodeChangeProcessor;
029:
030:        /**
031:         * Keeps a record of the capabilities required for a node
032:         * and all associated NodeComponents
033:         *
034:         * @author  paulby
035:         */
036:        public class CapabilityPersistance extends Object {
037:
038:            // Key is SceneGraphObject
039:            // Vector of Strings of capability names
040:            protected HashMap capabilities;
041:
042:            /** Creates new CapabilityControl */
043:            public CapabilityPersistance() {
044:                capabilities = new HashMap();
045:            }
046:
047:            /**
048:             * Store the capability settings of this node, all it's children
049:             * and all associated NodeComponents
050:             */
051:            /*
052:            public void storeTreeCapabilities( Node node ) {
053:              NodeChangeProcessor proc = new NodeChangeProcessor() {
054:                public void changeNode( Node node ) {
055:                  doStore( node );
056:                }
057:              };
058:
059:              TreeScan.findNode( node, javax.media.j3d.Node.class, proc, false, true );
060:            }
061:             **/
062:
063:            /**
064:             * Restore the capabilities of this node, all it's children and
065:             * all associated NodeComponents
066:             */
067:            /*
068:            public void restoreTreeCapabilities( Node node ) {
069:              NodeChangeProcessor proc = new NodeChangeProcessor() {
070:                public void changeNode( Node node ) {
071:                  doRestore( node );
072:                }
073:              };
074:
075:              TreeScan.findNode( node, javax.media.j3d.Node.class, proc, false, true );
076:            }
077:             */
078:
079:            /**
080:             * Store the capabilities of this node and it's node Components
081:             */
082:            public void storeCapabilities(SceneGraphObject node) {
083:                if (node instanceof  javax.media.j3d.Shape3D)
084:                    doStore((javax.media.j3d.Shape3D) node);
085:                else
086:                    doStore(node);
087:            }
088:
089:            /**
090:             * Restore the capabilities of this node and it's node components
091:             */
092:            public void restoreCapabilities(SceneGraphObject node) {
093:                if (node instanceof  javax.media.j3d.Shape3D)
094:                    doRestore((javax.media.j3d.Shape3D) node);
095:                else
096:                    doRestore(node);
097:            }
098:
099:            /**
100:             * Return an array of strings of the capability names stored for this node
101:             */
102:            public String[] getCapabilitiesAsStrings(SceneGraphObject obj) {
103:                Object o = capabilities.get(obj);
104:                if (o == null)
105:                    return null;
106:
107:                Vector caps = (Vector) o;
108:                String[] ret = new String[caps.size()];
109:
110:                for (int i = 0; i < caps.size(); i++) {
111:                    ret[i] = (String) caps.get(i);
112:                }
113:
114:                return ret;
115:            }
116:
117:            /**
118:             * Forget all the currently stored capabilities
119:             */
120:            public void clearPersistance() {
121:                capabilities.clear();
122:            }
123:
124:            /**
125:             * Actually store the capability of this node and it's NodeComponents
126:             */
127:            protected void doStore(SceneGraphObject node) {
128:                rememberCapabilities(node);
129:
130:                // Ensure the node being worked has been checked to ensure there
131:                // are no NodeComponents
132:                // When Development is finished remove this check
133:                // TODO - Remove Check
134:                if (node instanceof  javax.media.j3d.Light)
135:                    return;
136:                else if (node instanceof  javax.media.j3d.Behavior)
137:                    return;
138:                else if (node instanceof  javax.media.j3d.Group)
139:                    return;
140:                else if (node instanceof  javax.media.j3d.ViewPlatform)
141:                    return;
142:                else if (node instanceof  javax.media.j3d.Link)
143:                    return;
144:
145:                System.out.println("WARNING - Default do-store for "
146:                        + node.getClass().getName());
147:            }
148:
149:            /**
150:             * Actually restore the capability of this node and it's NodeComponents
151:             */
152:            protected void doRestore(SceneGraphObject node) {
153:                resetCapabilities(node);
154:            }
155:
156:            protected void doStore(javax.media.j3d.Shape3D node) {
157:                rememberCapabilities(node);
158:
159:                Appearance app = node.getAppearance();
160:                if (app != null) {
161:                    rememberCapabilities(app);
162:                    rememberCapabilities(app.getColoringAttributes());
163:                    rememberCapabilities(app.getLineAttributes());
164:                    rememberCapabilities(app.getMaterial());
165:                    rememberCapabilities(app.getPointAttributes());
166:                    rememberCapabilities(app.getPolygonAttributes());
167:                    rememberCapabilities(app.getRenderingAttributes());
168:                    rememberCapabilities(app.getTexCoordGeneration());
169:                    rememberCapabilities(app.getTexture());
170:                    rememberCapabilities(app.getTextureAttributes());
171:                    rememberCapabilities(app.getTransparencyAttributes());
172:                }
173:
174:                rememberCapabilities(node.getGeometry());
175:            }
176:
177:            protected void doRestore(javax.media.j3d.Shape3D node) {
178:                resetCapabilities(node);
179:
180:                Appearance app = node.getAppearance();
181:                if (app != null) {
182:                    resetCapabilities(app);
183:                    resetCapabilities(app.getColoringAttributes());
184:                    resetCapabilities(app.getLineAttributes());
185:                    resetCapabilities(app.getMaterial());
186:                    resetCapabilities(app.getPointAttributes());
187:                    resetCapabilities(app.getPolygonAttributes());
188:                    resetCapabilities(app.getRenderingAttributes());
189:                    resetCapabilities(app.getTexCoordGeneration());
190:                    resetCapabilities(app.getTexture());
191:                    resetCapabilities(app.getTextureAttributes());
192:                    resetCapabilities(app.getTransparencyAttributes());
193:                }
194:                resetCapabilities(node.getGeometry());
195:            }
196:
197:            /**
198:             * If any capabilities are set in obj, remember them
199:             */
200:            private void rememberCapabilities(SceneGraphObject obj) {
201:                if (obj == null)
202:                    return;
203:
204:                Vector caps = extractCapabilities(obj);
205:                if (caps != null) {
206:                    capabilities.put(obj, caps);
207:                    /*
208:                    System.out.println( obj );
209:                    for(int i=0; i<caps.size(); i++)
210:                    System.out.println( caps.get(i) );
211:
212:                    System.out.println();
213:                     */
214:                }
215:            }
216:
217:            /**
218:             * Restore the capability of obj to the state stored by
219:             * rememberCapabilities
220:             */
221:            private void resetCapabilities(SceneGraphObject obj) {
222:                if (obj == null)
223:                    return;
224:
225:                clearAllCapabilities(obj);
226:
227:                Object o = capabilities.get(obj);
228:                if (o == null)
229:                    return;
230:
231:                Vector caps = (Vector) o;
232:
233:                for (int i = 0; i < caps.size(); i++) {
234:                    setCapability(obj, (String) caps.get(i));
235:                    //System.out.println( caps.get(i) );
236:                }
237:            }
238:
239:            /**
240:             * Add the capability to those stored for node
241:             */
242:            public void addCapability(SceneGraphObject node, String capability) {
243:                Object obj = capabilities.get(node);
244:
245:                //System.out.println("Adding Capability "+node+"  "+capability);
246:
247:                if (obj == null) {
248:                    Vector v = new Vector();
249:                    v.add(capability);
250:                    capabilities.put(node, v);
251:                } else {
252:                    ((Vector) obj).add(capability);
253:                    capabilities.put(node, obj);
254:                }
255:            }
256:
257:            /**
258:             * Remove the capability from those store for this node
259:             */
260:            public void removeCapability(SceneGraphObject node,
261:                    String capability) {
262:                Object obj = capabilities.get(node);
263:                if (obj == null)
264:                    throw new RuntimeException("Node not found");
265:                else {
266:                    ((Vector) obj).remove(capability);
267:                }
268:
269:            }
270:
271:            /**
272:             * Set this capabilitiy
273:             */
274:            protected void setCapability(SceneGraphObject node,
275:                    String capability) {
276:                try {
277:                    Class cl = node.getClass();
278:                    Field field = cl.getField(capability);
279:
280:                    node.setCapability(field.getInt(node));
281:                } catch (NoSuchFieldException e) {
282:                    e.printStackTrace();
283:                    System.exit(1);
284:                } catch (IllegalAccessException ex) {
285:                    ex.printStackTrace();
286:                    System.exit(1);
287:                }
288:            }
289:
290:            /**
291:             * Clear all the capabilities for this node
292:             */
293:            protected void clearAllCapabilities(SceneGraphObject node) {
294:                int value;
295:                String str;
296:                Class cl = node.getClass();
297:
298:                Field[] fields = cl.getFields();
299:
300:                try {
301:                    for (int i = 0; i < fields.length; i++) {
302:                        str = fields[i].getName();
303:                        if (str.startsWith("ALLOW_")
304:                                || str.startsWith("ENABLE_")) {
305:                            value = fields[i].getInt(fields[i]);
306:                            node.clearCapability(value);
307:                        }
308:                    }
309:                } catch (Exception e) {
310:                    e.printStackTrace();
311:                    //System.exit(1);
312:                }
313:
314:            }
315:
316:            /**
317:             * Return a String[] of the names of all capabilitities set in this
318:             * object. If no capabilities are set null is returned
319:             */
320:            protected Vector extractCapabilities(SceneGraphObject obj) {
321:
322:                int value;
323:                String str;
324:                Class cl = obj.getClass();
325:                Vector capabilityStrings = new Vector();
326:
327:                Field[] fields = cl.getFields();
328:
329:                try {
330:                    for (int i = 0; i < fields.length; i++) {
331:                        str = fields[i].getName();
332:                        if (fields[i].getType() == Integer.TYPE
333:                                && (str.startsWith("ALLOW_") || str
334:                                        .startsWith("ENABLE_"))) {
335:                            value = fields[i].getInt(fields[i]);
336:                            if (obj.getCapability(value))
337:                                capabilityStrings.add(str);
338:                        }
339:                    }
340:                } catch (Exception e) {
341:                    e.printStackTrace();
342:                    System.exit(1);
343:                }
344:
345:                if (capabilityStrings.size() == 0)
346:                    return null;
347:
348:                return capabilityStrings;
349:            }
350:
351:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.