View Javadoc

1   /* -------------------------------------------------------------------
2    * Java source file for the class World
3    * 
4    * Copyright (c), 2003, Masahiro Takatsuka.
5    * All Rights Researved.
6    * 
7    * Original Author: Masahiro Takatsuka (masa@jbeans.net)
8    * $Author: takatsukam $
9    * 
10   * $Date: 2004/03/03 11:53:06 $
11   * 
12   * $Id: World.java,v 1.3 2004/03/03 11:53:06 takatsukam Exp $
13   * 
14   * Reference:		Document no:
15   * ___				___
16   * 
17   * To Do:
18   * ___
19   * 
20  ------------------------------------------------------------------- */
21  
22  /* --------------------------- Package ---------------------------- */
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  import net.jbeans.util.debug.*;
29  
30  /*====================================================================
31                      Implementation of class World                     
32  ====================================================================*/
33  /***
34   * World is the root BranchGroup for the Content branch.
35   * 
36   * @version $Revision: 1.3 $
37   * @author Masahiro Takatsuka (masa@jbeans.net)
38   * @see BranchGroup
39   * @see BranchGroupDetachable
40   */
41  
42  /*
43   * this class is ok to be package.
44   */ 
45  public class World extends BranchGroup implements BranchGroupDetachable {
46  	private static final boolean DEBUG = Debug.getDebugFlag(World.class);
47  	
48  	/***
49  	* A world transformGroup
50  	*/
51      private MultiTransformGroup mtg;
52  
53  	/***
54  	* the last transformGroup all branchgraphs are attached
55  	*/
56  	private TransformGroup lastTG;
57  
58  	/***
59  	 * the list of BranchGroup objects so that they can be detached later.
60  	 */
61  	//private ArrayList detachBG = new ArrayList();	
62  	//private int nextBranchGroup = 0;
63  	private Vector detachBG = new Vector();
64  	
65  	/***
66  	 * Constructs a new World object.
67  	 */
68      World() {
69          this(1);
70      }
71  
72  	/***
73  	 * Constructs a new World object.
74  	 */
75      World(int i) {
76          setCapability(ALLOW_DETACH);
77  		setCapability(ALLOW_CHILDREN_READ);
78          setCapability(ALLOW_CHILDREN_WRITE);
79          setCapability(ALLOW_CHILDREN_EXTEND);
80          if (i < 1) {
81              i = 1;
82  		}
83          this.mtg = new MultiTransformGroup(i);
84          TransformGroup transformgroup = this.mtg.getTransformGroup(0);
85          addChild(transformgroup);
86  		this.lastTG = this.mtg.getTransformGroup(i - 1);
87          this.lastTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
88          this.lastTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
89          this.lastTG.setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_READ);
90          this.lastTG.setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_WRITE);
91      }
92  
93      /***
94  	 * Get a list of all the detachable subgraphs.
95  	 */
96  	public final Vector getDetachableBranchGroups() {
97  		return this.detachBG;
98  	}
99  
100 //  	/***
101 //  	 * Returns an index number of the next branch group.
102 //  	 */
103 //  	public final int getNextBranchGroup() {
104 //  		return this.nextBranchGroup;
105 //  	}
106 	
107 //  	/***
108 //  	 * Sets a new index number of the next branch group.
109 //  	 */
110 //  	public final void setNextBranchGroup(int next) {
111 //  		this.nextBranchGroup = next;
112 //  	}
113 
114 	/***
115 	 * Returns the MultiTransformGroup object of this World object.
116 	 */
117     final MultiTransformGroup getMultiTransformGroup() {
118         return this.mtg;
119     }
120 
121 	/***
122 	 * Returns the last TransformGroup object in the MultiTransformGroup
123 	 * object of this World object.
124 	 */
125 	final TransformGroup getWorldTransform() {
126         return this.mtg.getTransformGroup(this.mtg.getNumTransforms() - 1);
127 	}
128 
129 	/***
130 	 * Adds a new BranchGroup object.
131 	 */
132 	final void addBranchGraph(BranchGroup bg) {
133 		if (DEBUG) {
134 			System.out.println("World.addBranchGraph() : adding " + bg);
135 		}
136 		BranchGroup newBG = BranchGroupUtil.addBranchGroup(this, bg);
137 		TransformGroup tg = getWorldTransform();
138 		tg.addChild(newBG);
139     }
140 	
141 	/***
142 	 * Detaches the specified BranchGroup object.
143 	 */
144     final void detachBranchGraph(BranchGroup subRoot) {
145 		BranchGroupUtil.detachBranchGroup(this, subRoot);
146     }
147 
148 	final void detachAllBranchGraph() {
149 		for (int i = 0; i < this.detachBG.size(); i++) {
150 			BranchGroup bg = (BranchGroup) this.detachBG.get(0);
151 			detachBranchGraph((BranchGroup) bg.getChild(0));
152 		}
153 	}
154 }