/***************************************************************************** * Web3d.org Copyright (c) 2001 * Java Source * * This source is licensed under the GNU LGPL v2.1 * Please read http://www.gnu.org/copyleft/lgpl.html for more information * * This software comes with the standard NO WARRANTY disclaimer for any * purpose. Use it at your own risk. If there's a problem you get to fix it. * ****************************************************************************/ // Standard library imports import org.j3d.ui.navigation.*; import org.ietf.uri.*; import java.net.URL; import java.awt.BorderLayout; import java.awt.Container; import java.io.File; import java.io.InputStream; import java.io.IOException; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Iterator; import java.util.HashMap; import java.util.Map; import javax.media.j3d.BranchGroup; import javax.media.j3d.Canvas3D; import javax.media.j3d.TransformGroup; import javax.media.j3d.View; import javax.swing.JPanel; import javax.swing.JPopupMenu; // Application specific imports import org.web3d.vrml.sav.*; import org.web3d.vrml.nodes.*; import org.web3d.vrml.nodes.runtime.*; import org.web3d.vrml.nodes.loader.*; import org.web3d.vrml.renderer.j3d.input.*; import org.web3d.browser.BrowserCore; import org.web3d.vrml.nodes.loader.ScriptLoader; import org.web3d.vrml.nodes.runtime.RouteManager; import org.web3d.vrml.parser.VRMLParserFactory; import org.web3d.vrml.parser.FactoryConfigurationError; import org.web3d.vrml.renderer.common.input.LinkSelectionListener; import org.web3d.vrml.renderer.common.input.NavigationStateListener; import org.web3d.vrml.renderer.j3d.browser.VRMLBrowserCanvas; import org.web3d.vrml.renderer.j3d.browser.VRMLUniverse; import org.web3d.vrml.scripting.ScriptEngine; import org.web3d.vrml.scripting.jsai.VRML97ScriptEngine; import org.web3d.vrml.scripting.ecmascript.ECMAScriptEngine; /** * A simple browser example that has one window and the coder does all of the * setup locally.. *
* * The simple browser does not respond to changes in the list of viewpoints * in the virtual world. This is OK because scripts are not used or needed in * this simple environment. Once we implement scripts, we have to look at * something different. * * @author Justin Couch * @version $Revision: 1.1.1.1 $ */ public class CanvasBrowser extends DemoFrame implements ViewpointSelectionListener { /** The universe to place our scene into */ private VRMLUniverse universe; /** The toolbar holding viewpoint information */ private ViewpointToolbar vpToolbar; /** The toolbar holding navigation information */ private NavigationToolbar navToolbar; /** Flag to indicate we are in the setup of the scene currently */ private boolean inSetup; /** Mapping of def'd Viewpoints to their real implementation */ private HashMap viewpointDefMap; /** The current viewpoint model */ private VRMLViewpointNodeType currentViewpoint; /** Place for error messages to go */ private ConsoleWindow console; /** The main browser canvas to view stuff with */ private VRMLBrowserCanvas mainCanvas; /** Global clock */ private VRMLClock clock; /** * Create an instance of the demo class. */ public CanvasBrowser() { super("VRMLCanvas Browser"); JPopupMenu.setDefaultLightWeightPopupEnabled(false); viewpointDefMap = new HashMap(); Container content_pane = getContentPane(); JPanel p1 = new JPanel(new BorderLayout()); content_pane.add(p1, BorderLayout.CENTER); console = new ConsoleWindow(); mainCanvas = new VRMLBrowserCanvas(gfxConfig, false); mainCanvas.initialize(); RouteManager route_manager = mainCanvas.getRouteManager(); WorldLoaderManager world_loader = mainCanvas.getWorldLoaderManager(); universe = mainCanvas.getUniverse(); clock = universe.getVRMLClock(); ScriptManager script_manager = mainCanvas.getScriptManager(); ScriptLoader script_loader = script_manager.getScriptLoader(); ScriptEngine jsai = new VRML97ScriptEngine(universe, route_manager, world_loader); jsai.setErrorReporter(console); ScriptEngine ecma = new ECMAScriptEngine(universe, route_manager, world_loader); ecma.setErrorReporter(console); script_loader.registerScriptingEngine(jsai); script_loader.registerScriptingEngine(ecma); p1.add(mainCanvas, BorderLayout.CENTER); JPanel p2 = new JPanel(new BorderLayout()); p1.add(p2, BorderLayout.SOUTH); navToolbar = new NavigationToolbar(); p2.add(navToolbar, BorderLayout.WEST); vpToolbar = new ViewpointToolbar(); vpToolbar.setEnabled(false); vpToolbar.setViewpointSelectionListener(this); p2.add(vpToolbar, BorderLayout.CENTER); // universe.setNavigationStateListener(navToolbar); setupProperties(universe, world_loader); console.setVisible(true); DownloadProgressListener dl_list = new DownloadProgressListener(statusLabel, console); ResourceConnection.addGlobalProgressListener(dl_list); } //---------------------------------------------------------- // Methods required by the ViewpointSelectionListener interface. //---------------------------------------------------------- /** * A new viewpoint has been selected and this is it. Move to this viewpoint * location according to the requested means. * * @param vp The new viewpoint to use */ public void viewpointSelected(ViewpointData vp) { if(inSetup) return; VRMLBindableNodeType vp_node = (VRMLBindableNodeType)vp.userData; vp_node.setBind(true, true, clock.getTime()); } //---------------------------------------------------------- // Implmentation of base class abstract methods //---------------------------------------------------------- /** * Go to the named URL location. No checking is done other than to make * sure it is a valid URL. * * @param url The URL to open */ public void gotoLocation(URL url) { mainCanvas.loadWorld(url.toString()); } /** * Load the named file. The file is checked to make sure that it exists * before calling this method. * * @param file The file to load */ public void gotoLocation(File file) { try { gotoLocation(file.toURL()); } catch(MalformedURLException mue) { statusLabel.setText(mue.getMessage()); console.errorReport(mue.getMessage(), mue); } } protected void setWarning(String msg) { statusLabel.setText(msg); console.warningReport(msg, null); } protected void setError(String msg) { statusLabel.setText(msg); console.errorReport(msg, null); } /** * Create an instance of this class and run it. The single argument, if * supplied is the name of the file to load initially. If not supplied it * will start with a blank document. * * @param argv The list of arguments for this application. */ public static void main(String[] argv) { CanvasBrowser browser = new CanvasBrowser(); browser.show(); } }