01: /*
02: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegraph/SGBranchGroup.java,v 1.1 2005/04/20 22:20:40 paulby Exp $
03: *
04: * Sun Public License Notice
05: *
06: * The contents of this file are subject to the Sun Public License Version
07: * 1.0 (the "License"). You may not use this file except in compliance with
08: * the License. A copy of the License is available at http://www.sun.com/
09: *
10: * The Original Code is the Java 3D(tm) Scene Graph Editor.
11: * The Initial Developer of the Original Code is Paul Byrne.
12: * Portions created by Paul Byrne are Copyright (C) 2002.
13: * All Rights Reserved.
14: *
15: * Contributor(s): Paul Byrne.
16: *
17: **/
18: package org.jdesktop.j3dedit.scenegraph;
19:
20: import javax.media.j3d.BranchGroup;
21:
22: /**
23: *
24: * @author paulby
25: * @version
26: */
27: public class SGBranchGroup extends SGGroup {
28:
29: /**
30: * Index of current child (if any) which is not
31: * live
32: */
33: private int liveChildIndex = -1;
34:
35: /**
36: * Create the ancillary SGNode representing node
37: */
38: public SGBranchGroup(javax.media.j3d.Node node,
39: org.jdesktop.j3dedit.J3dEditContext editContext) {
40: super (node, editContext);
41: }
42:
43: /**
44: * Set the Java3D which is represented by this object
45: *
46: * Store the capability bits for the node
47: */
48: public void setJ3dNode(javax.media.j3d.Node node) {
49: super .setJ3dNode(node);
50:
51: // These capabilities are required for the runtime of the editor
52: node.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
53: node.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
54: node.setCapability(BranchGroup.ALLOW_DETACH);
55: node.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
56: }
57:
58: /**
59: * Change the live state of this node, this may change the live
60: * state of other nodes in the graph, but in general the minimum
61: * change will be made
62: */
63: public void setLive(boolean live) {
64: if (parent instanceof SGBranchGroup)
65: ((SGBranchGroup) parent).childSetLive(this , live);
66: else if (parent instanceof SGLocale)
67: ((SGLocale) parent).childSetLive(this , live);
68: else
69: parent.setLive(live);
70: }
71:
72: void childSetLive(SGBranchGroup child, boolean live) {
73: if (live) {
74: if (liveChildIndex == -1)
75: throw new RuntimeException("Internal Error");
76:
77: ((BranchGroup) j3dNode).setChild(child.getJ3dNode(),
78: liveChildIndex);
79: liveChildIndex = -1;
80: } else {
81: if (liveChildIndex != -1)
82: throw new RuntimeException(
83: "Internal Error, attempt to detach second child");
84: liveChildIndex = ((BranchGroup) j3dNode).indexOfChild(child
85: .getJ3dNode());
86: BranchGroup bg = new BranchGroup();
87: bg.setCapability(BranchGroup.ALLOW_DETACH);
88: ((BranchGroup) j3dNode).setChild(bg, liveChildIndex);
89: }
90: }
91:
92: }
|