1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.jbeans.j3d.universe;
24
25 /* ------------------ Import classes (packages) ------------------- *//package-summary/html">class="comment"> ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment"> ------------------ Import classes (packages) ------------------- */
26 import java.util.*;
27 import javax.media.j3d.*;
28
29 import net.jbeans.util.debug.*;
30
31
32
33
34 /***
35 * BranchGroupUtil provides some utility methods for Locale
36 * and World.
37 *
38 * @version $Revision: 1.3 $
39 * @author Masahiro Takatsuka (masa@jbeans.net)
40 */
41
42
43
44
45 class BranchGroupUtil {
46 private static final boolean DEBUG = Debug.getDebugFlag(BranchGroupUtil.class);
47
48 private BranchGroupUtil() {
49 super();
50 }
51
52 static final void setViewCapability(Node node) {
53 if (node instanceof Group) {
54 node.setCapability( Group.ALLOW_CHILDREN_READ );
55 Enumeration enum = ((Group)node).getAllChildren();
56 while (enum.hasMoreElements()) {
57 setViewCapability( (Node)enum.nextElement() );
58 }
59 if (node instanceof Behavior) {
60 node.setCapability( Behavior.ALLOW_BOUNDS_READ );
61 }
62 } else if (node instanceof Shape3D) {
63 node.setCapability( Shape3D.ALLOW_GEOMETRY_READ );
64 } else if (node instanceof Light) {
65 node.setCapability( Light.ALLOW_INFLUENCING_BOUNDS_READ );
66 } else if (node instanceof Fog) {
67 node.setCapability( Fog.ALLOW_INFLUENCING_BOUNDS_READ );
68 } else if (node instanceof Sound) {
69 node.setCapability( Sound.ALLOW_SCHEDULING_BOUNDS_READ );
70 } else {
71 if (DEBUG) {
72 System.out.println("BranchGroupUtil.setViewCapability() : " + node.getClass());
73 }
74 }
75 }
76
77 /***
78 * Adds a new BranchGroup object.
79 */
80 static final BranchGroup addBranchGroup(BranchGroupDetachable root,
81 BranchGroup bg) {
82 Vector detachBG = root.getDetachableBranchGroups();
83
84
85 setViewCapability(bg);
86
87
88
89
90
91 BranchGroup newBG = new net.jbeans.j3d.scenegraph.BranchGroup();
92
93
94
95
96
97
98
99 detachBG.add(newBG);
100 newBG.addChild(bg);
101 bg.setUserData(newBG);
102
103 return newBG;
104 }
105
106 /***
107 * Detaches the specified BranchGroup object.
108 */
109 static final void detachBranchGroup(BranchGroupDetachable root,
110 BranchGroup subRoot) {
111 boolean fail = true;
112 Vector detachBG = root.getDetachableBranchGroups();
113
114 for (int i = 0; i < detachBG.size(); i++) {
115 Group g = (Group) detachBG.get(i);
116 if (g.getChild(0) == subRoot) {
117 ((BranchGroup) (((BranchGroup) g).getChild(0))).detach();
118 ((BranchGroup) g).detach();
119 detachBG.remove(g);
120 i--;
121 fail = false;
122 }
123 }
124
125 if (fail) {
126 if (DEBUG) {
127 System.out.println("The specified BranchGroup was not in the scenegraph.");
128 }
129 }
130 }
131 }
132