// Navigate.java: Applet to control the navigation demo // // Daniel.Schneider@tecfa.unige.ch 1/98 // this is basically a tiny subset of David Brown's descent applet // ... needs probably some cleaning up import java.awt.*; import java.applet.*; import vrml.external.field.*; import vrml.external.Node; import vrml.external.Browser; import vrml.external.exception.*; public class Navigate extends Applet { // The Browser Browser browser = null; // Various UI widgets Button entryButton, accrossButton, sideview1Button, sideview2Button, birdButton; // Various stuff in the VRML scene we hang on to Node root_node; Node entryVP, accrossVP, LinedUp1VP, LinedUp2VP, BirdsEyeVP; // "Aborted" state (used to disable some UI or code // if we've already had a fatal error) boolean aborted = false; /** Initialize the Applet */ public void init() { // Connect to the browser browser = Browser.getBrowser(this); if (browser == null) { die("init: NULL browser!"); } System.out.println("Got the browser: " + browser); // Add the buttons to the Java Panel add (entryButton = new Button("Entry")); add (accrossButton = new Button("Accross the Room")); add (sideview1Button = new Button("Side View 1")); add (sideview2Button = new Button("Side View 2")); add (birdButton = new Button("Bird's Eye")); // Misc other UI setup Color c = Color.white; System.out.println("Setting bg color to: " + c); setBackground(c); System.out.println("Navigate.init() done."); // Initialize some VRML stuff initScene(); } /** Start the applet running */ public void start(){ System.out.println("Navigate Applet: start()..."); } /** Stop the applet */ public void stop(){ System.out.println("Navigate Applet: stop()..."); } /** * This applet is about to be unloaded. Do final cleanup. */ public void destroy() { System.out.println("Navigate Applet: destroy()..."); } /** Handle a fatal error condition */ public void die(String s) { System.out.println("Navigate Applet: FATAL ERROR!"); System.out.println("--> " + s); System.out.println("Navigate Applet: Aborting...\n"); aborted = true; // Causes update() to display a warning } /** Handle actions from AWT widgets */ public boolean action(Event event, Object what) { if (event.target instanceof Button) { Button b = (Button) event.target; if (b == entryButton) { bindToViewPoint(entryVP); } else if (b == accrossButton) { bindToViewPoint(accrossVP); } else if (b == sideview1Button) { bindToViewPoint(LinedUp1VP); } else if (b == sideview2Button) { bindToViewPoint(LinedUp2VP); } else if (b == birdButton) { bindToViewPoint(BirdsEyeVP); } } // event.target instanceof Button return true; } /** Set up some stuff in the VRML scene */ public void initScene() { System.out.println("initScene()..."); // Get the ViewPoints try { entryVP = browser.getNode("Entry"); accrossVP = browser.getNode("AcrossTheRoom"); LinedUp1VP = browser.getNode("LinedUp1"); LinedUp2VP = browser.getNode("LinedUp2"); BirdsEyeVP = browser.getNode("BirdsEye"); } catch(InvalidNodeException e){ System.out.println("InvalidNodeException: " + e); die("initScene: VP node not found!"); return; } } /** Move to the specified viewpoint */ // the handles to the EventIN fields are generated when needed public void bindToViewPoint(Node vp) { System.out.println("bindToViewpoint(node '" + vp + "')..."); EventInSFBool set_bind = null; try { set_bind = (EventInSFBool)vp.getEventIn("set_bind"); } catch(InvalidEventInException e) { die("bindToViewpoint: InvalidEventInException: " + e); return; } System.out.println("bindToViewpoint: got the EventIn: "+set_bind); set_bind.setValue(true); System.out.println("bindToViewpoint() done."); } }