001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/interposer/InterposerUniverse.java,v 1.1 2005/04/20 22:20:32 paulby Exp $
003: *
004: * Sun Public License Notice
005: *
006: * The contents of this file are subject to the Sun Public License Version
007: * 1.0 (the "License"). You may not use this file except in compliance with
008: * the License. A copy of the License is available at http://www.sun.com/
009: *
010: * The Original Code is the Java 3D(tm) Scene Graph Editor.
011: * The Initial Developer of the Original Code is Paul Byrne.
012: * Portions created by Paul Byrne are Copyright (C) 2002.
013: * All Rights Reserved.
014: *
015: * Contributor(s): Paul Byrne.
016: *
017: **/
018: package org.jdesktop.j3dedit.interposer;
019:
020: import java.util.Enumeration;
021: import javax.media.j3d.VirtualUniverse;
022: import javax.media.j3d.Locale;
023: import javax.media.j3d.BranchGroup;
024: import javax.media.j3d.Canvas3D;
025: import com.sun.j3d.utils.universe.SimpleUniverse;
026: import com.sun.j3d.utils.universe.Viewer;
027: import com.sun.j3d.utils.universe.ViewingPlatform;
028:
029: import org.jdesktop.j3dfly.utils.developmenttools.DevelopmentLocale;
030: import org.jdesktop.j3dfly.J3dFlyContext;
031:
032: /**
033: * This universe is used to 'wrap' a real universe provided by the user.
034: * The users universe is assumed to NOT be derrived from SimpleUniverse so
035: * this wrapper provides the SimpleUniverse features that J3dFly requires
036: *
037: * @author Paul Byrne
038: * @version $Id: InterposerUniverse.java,v 1.1 2005/04/20 22:20:32 paulby Exp $
039: */
040: public class InterposerUniverse extends SimpleUniverse {
041:
042: private VirtualUniverse userUniverse;
043: private Locale devLocale;
044: private DevelopmentLocale hiddenLocale;
045:
046: private Viewer viewer;
047: private ViewingPlatform vwp;
048:
049: /** Creates a new instance of InterposerUniverse */
050: public InterposerUniverse(VirtualUniverse userUniverse,
051: DevelopmentLocale devLocale) {
052: super ();
053: this .devLocale = devLocale;
054: this .userUniverse = userUniverse;
055:
056: this .removeAllLocales();
057: setupHiddenLocale();
058: }
059:
060: public Locale getLocale() {
061: return devLocale;
062: }
063:
064: private void setupHiddenLocale() {
065: // This locale just contains the J3dFly view portion of the SG.
066: hiddenLocale = new DevelopmentLocale(userUniverse);
067:
068: vwp = new ViewingPlatform(1);
069: viewer = new Viewer(null, null);
070: viewer.setViewingPlatform(vwp);
071: hiddenLocale.addBranchGraph(vwp);
072: }
073:
074: public void finishHiddenLocaleInit(J3dFlyContext context) {
075: // Remove and reattach the vwp so that the editor sees the event and
076: // creates the graph etc.
077: hiddenLocale.removeBranchGraph(vwp);
078: // Create structures for the extra Locale added by InterposerUniverse
079: hiddenLocale
080: .setSceneGraphChangeListeners(((InterposerLocale) context
081: .getLocale(0)).getSceneGraphChangeListeners());
082: context.addLocale(hiddenLocale);
083: hiddenLocale.addBranchGraph(vwp);
084: }
085:
086: public Viewer getViewer() {
087: return viewer;
088: }
089:
090: public ViewingPlatform getViewingPlatform() {
091: return vwp;
092: }
093:
094: public Canvas3D getCanvas3D() {
095: return getCanvas3D(0);
096: }
097:
098: public Canvas3D getCanvas3D(int canvasNum) {
099: return viewer.getCanvas3D(canvasNum);
100: }
101: }
|