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.awt.event.*;
27 import java.net.*;
28 import javax.media.j3d.*;
29 import javax.vecmath.*;
30 import com.sun.j3d.utils.universe.*;
31
32 import net.jbeans.j3d.util.behavior.mouse.*;
33 import net.jbeans.j3d.util.manipulator.*;
34 import net.jbeans.j3d.util.picking.behavior.*;
35
36 import net.jbeans.util.debug.*;
37
38
39
40
41 /***
42 * generally describe SeekableUniverse in here
43 *
44 * @version $Revision: 1.3 $
45 * @author Masahiro Takatsuka (masa@jbeans.net)
46 * @see ManipulatableUniverse
47 * @see ManipulatorCallback
48 */
49
50 public class SeekableUniverse extends ManipulatableUniverse implements ManipulatorCallback {
51 private static final boolean DEBUG = Debug.getDebugFlag(SeekableUniverse.class);
52
53 public static final int MOUSE_SEEK = 0x20;
54
55 transient private int previousMouseMode;
56
57 private Seek seek;
58
59 /***
60 * Creates a locale, a single ViewingPlatform, and
61 * and a Viewer object (both with their default values).
62 *
63 * @see Locale
64 * @see Viewer
65 * @see ViewingPlatform
66 */
67 public SeekableUniverse() {
68 this(null, 1, null, null);
69 }
70
71 /***
72 * Creates a locale, a single ViewingPlatform (with default values), and
73 * and a Viewer object. The Viewer object uses default values for
74 * everything but the canvas.
75 *
76 * @param canvas The canvas to associate with the Viewer object. Passing
77 * in null will cause this parameter to be ignored and a canvas to be
78 * created by the utility.
79 *
80 * @see Locale
81 * @see Viewer
82 * @see ViewingPlatform
83 */
84 public SeekableUniverse(Canvas3D canvas) {
85 this(null, 1, canvas, null);
86 }
87
88 /***
89 * Creates the "view" side of the scene graph. The passed in parameters
90 * override the default values where appropriate.
91 *
92 * @param origin The origin used to set the origin of the Locale object.
93 * If this object is null, then 0.0 is used.
94 * @param numTransforms The number of transforms to be in the
95 * MultiTransformGroup object.
96 * @param canvas The canvas to draw into. If this is null, it is
97 * ignored and a canvas will be created by the utility.
98 * @param userConfig The URL to the user's configuration file, used
99 * by the Viewer object. Passing in null causes the default values
100 * to be used.
101 *
102 * @see Locale
103 * @see Viewer
104 * @see ViewingPlatform
105 * @see MultiTransformGroup
106 */
107 public SeekableUniverse(HiResCoord origin, int numTransforms,
108 Canvas3D canvas, URL userConfig) {
109 super(origin, numTransforms, canvas, userConfig);
110 setMouseMode(getMouseMode() | MOUSE_SEEK);
111 }
112
113 /***
114 * Creates the "view" side of the scene graph.
115 *
116 * @param viewingPlatform The viewingPlatform to use to create
117 * the "view" side of the scene graph.
118 * @param viewer The viewer object to use to create
119 * the "view" side of the scene graph.
120 */
121 public SeekableUniverse(ViewingPlatform viewingPlatform, Viewer viewer) {
122 super(viewingPlatform, viewer);
123 setMouseMode(getMouseMode() | MOUSE_SEEK);
124 }
125
126 protected void setupMouseBehaviors(World world) {
127 super.setupMouseBehaviors(world);
128 this.seek = new Seek(this.viewingTG);
129 this.seek.initForSeek(getCanvas(), world, getViewingPlatform());
130
131 this.mouseBehavior.addPressManipulator(InputEvent.BUTTON1_MASK +
132 InputEvent.ALT_MASK,
133 this.seek);
134 this.seek.setCallback(this);
135 }
136
137 public void setMouseButton1Mode(int mouseMode) {
138 if (this.mouseBehavior == null) {
139 return;
140 }
141 this.previousMouseMode = getMouseButton1Mode();
142 super.setMouseButton1Mode(mouseMode);
143 Manipulator man = null;
144 switch (mouseMode) {
145 case MOUSE_SEEK:
146 man = this.seek;
147 break;
148 default:
149 man = null;
150 break;
151 }
152 this.mouseBehavior.addPressManipulator(InputEvent.BUTTON1_MASK, man);
153 }
154
155 public void transformChanged(int mode, Transform3D transform3d, Object data) {
156 if (mode == ManipulatorCallback.SEEK) {
157 Point3d tmpcenter = (Point3d) data;
158 getCenter().set(tmpcenter.x, tmpcenter.y, tmpcenter.z);
159 updateCenter(getCenter());
160
161
162
163
164
165 if (DEBUG) {
166 System.out.println("previous MouseButton1 = " + this.previousMouseMode);
167 }
168 setMouseButton1Mode(this.previousMouseMode);
169 }
170 }
171
172 /***
173 * Used to add Nodes to the geometry side (as opposed to the view side)
174 * of the scene graph. This is a short cut to getting the Locale object
175 * and calling that object's addBranchGraph() method.
176 *
177 * @param BranchGroup The BranchGroup to attach to this Universe's Locale.
178 */
179 public void addBranchGraph(BranchGroup bg) {
180 super.addBranchGraph(bg);
181 if (DEBUG) {
182 System.out.println("num = " + (getWorld().getWorldTransform().numChildren() - getInitialNumChild()));
183 }
184
185
186
187
188 }
189
190 public void viewAll() {
191 if (DEBUG) {
192 System.out.println("SeekableUniverse.viewAll()");
193 }
194 if (this.currentTG == this.viewingTG) {
195 return;
196 }
197 ViewingPlatform vp = getViewingPlatform();
198 vp.viewAll(this.currentTG);
199 }
200 }