001: /*
002: * Copyright (c) 2001 Silvere Martin-Michiellot All Rights Reserved.
003: *
004: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
005: * royalty free, license to use, modify and redistribute this
006: * software in source and binary code form,
007: * provided that i) this copyright notice and license appear on all copies of
008: * the software; and ii) Licensee does not utilize the software in a manner
009: * which is disparaging to Silvere Martin-Michiellot.
010: *
011: * This software is provided "AS IS," without a warranty of any kind. ALL
012: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
013: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
014: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
015: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
016: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
017: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
018: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
019: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
020: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
021: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
022: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
023: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
024: *
025: * This software is not designed or intended for use in on-line control of
026: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
027: * the design, construction, operation or maintenance of any nuclear
028: * facility. Licensee represents and warrants that it will not use or
029: * redistribute the Software for such purposes.
030: *
031: * @Author: Silvere Martin-Michiellot
032: *
033: */
034:
035: package com.db.viewpoint;
036:
037: // This code is repackaged after the software The Carnival by Douglas Pew
038: // Site http://www.access.digex.net/~dpew/carnival (link is dead)
039: // Email dpew@gmu.edu
040:
041: /*
042: *
043: * This program is free software; you can redistribute it and/or modify
044: * it under the terms of the GNU General Public License as published by
045: * the Free Software Foundation; either version 2 of the License, or
046: * (at your option) any later version.
047: *
048: * This program is distributed in the hope that it will be useful,
049: * but WITHOUT ANY WARRANTY; without even the implied warranty of
050: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
051: * GNU General Public License for more details.
052: *
053: * You should have received a copy of the GNU General Public License
054: * along with this program; if not, write to the Free Software
055: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
056: *
057: */
058:
059: import javax.media.j3d.*;
060:
061: /** This class defines what an actual viewpoint is based on. It is called by
062: * ViewPoint and you should therefore get ViewSites by defining a ViewPoint and
063: * calling getViewSites();
064: */
065: public class ViewSite extends Object {
066:
067: private ViewControl[] control;
068: private ViewPlatform platform;
069: private TransformGroup tgroup;
070: private boolean active = false;
071: private String name;
072:
073: /** Builds a new ViewSite */
074: public ViewSite() {
075:
076: super ();
077:
078: }
079:
080: /** Builds a new ViewSite
081: * @param name The name of the ViewSite
082: */
083: public ViewSite(String name) {
084:
085: this (name, null, null);
086:
087: }
088:
089: /** Builds a new ViewSite
090: * @param name The name of the ViewSite
091: * @param control The ViewControls for the ViewSite
092: * @param platform The ViewPlatform to which this ViewSite is attached.
093: */
094: public ViewSite(String name, ViewControl[] control,
095: ViewPlatform platform) {
096:
097: this .name = name;
098: this .control = control;
099: this .platform = platform;
100: if (platform != null)
101: tgroup = (TransformGroup) platform.getParent();
102:
103: }
104:
105: /** Retrieves the name for this ViewSite.
106: * @return The name for this ViewSite.
107: */
108: public String getName() {
109:
110: return name;
111:
112: }
113:
114: /** Retrieves the name for this ViewSite.
115: * @return The name for this ViewSite.
116: */
117: public String toString() {
118:
119: return name;
120:
121: }
122:
123: /** Retrieves the ViewControl array for this ViewSite.
124: * @return The ViewControl array for this ViewSite.
125: */
126: public ViewControl[] getViewControls() {
127:
128: return control;
129:
130: }
131:
132: /** Retrieves the ViewPlatform for this ViewSite.
133: * @return The ViewPlatform for this ViewSite.
134: */
135: public ViewPlatform getViewPlatform() {
136:
137: return platform;
138:
139: }
140:
141: /** Retrieves the TransformGroup for this ViewSite. It is the parent node of the
142: * ViewPlateform.
143: * @return The TransformGroup for this ViewSite.
144: */
145: public TransformGroup getTransformGroup() {
146:
147: return tgroup;
148:
149: }
150:
151: /** Sets the ViewControl array for this ViewSite.
152: * @param c The ViewControl array for this ViewSite.
153: */
154: public void setViewControls(ViewControl[] c) {
155:
156: control = c;
157:
158: }
159:
160: /** Sets the (only one) ViewControl for this ViewSite.
161: * @param c The ViewControl for this ViewSite.
162: */
163: public void setViewControl(ViewControl c) {
164:
165: control = new ViewControl[1];
166: control[0] = c;
167:
168: }
169:
170: /** Sets the ViewPlatform for this ViewSite.
171: * @param vp The ViewPlatform for this ViewSite.
172: */
173: public void setViewPlatform(ViewPlatform vp) {
174:
175: platform = vp;
176: tgroup = (TransformGroup) platform.getParent();
177:
178: }
179:
180: /** Builds up the ViewPlatform for this ViewSite.
181: * @return The parent node of the ViewPlatform for this ViewSite.
182: */
183: public TransformGroup makeViewPlatform() {
184:
185: tgroup = new TransformGroup();
186:
187: tgroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
188: tgroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
189: platform = new ViewPlatform();
190: platform.setActivationRadius(10000.0f);
191: tgroup.addChild(platform);
192:
193: return tgroup;
194:
195: }
196:
197: /** Sets the name for this ViewSite.
198: * @param name The name for this ViewSite.
199: */
200: public void setName(String name) {
201:
202: this .name = name;
203:
204: }
205:
206: /** If not activated already, attaches the View to the ViewPlatform of this ViewSite, and activates
207: * the i th control of the ViewControl array.
208: * @param view The View to which attach this ViewSite.
209: * @param i The control to activate.
210: */
211: public void activate(View view, int i) {
212:
213: if (active)
214: return;
215:
216: if (i < control.length) {
217: for (int j = 0; j < control.length; j++)
218: control[j].deactivate();
219: control[i].activate();
220:
221: if (platform != null)
222: view.attachViewPlatform(platform);
223: // view.getPhysicalEnvironment().getAudioDevice().initialize();
224:
225: active = true;
226: }
227:
228: }
229:
230: /** If not inactivated already, inactivates
231: * all the controls of the ViewControl array. aDoes not dettach the View to the ViewPlatform of this
232: * ViewSite.
233: */
234: public void deactivate() {
235:
236: if (!active)
237: return;
238: int i;
239: for (i = 0; i < control.length; i++)
240: control[i].deactivate();
241: active = false;
242:
243: }
244:
245: }
|