package mil.navy.nps.testing; // Java JSAI classes for VRML import vrml.*; import vrml.field.*; import vrml.node.*; /** * Test script used by * ScriptNodeEventOutControl.wrl * to verify proper operation of the Java Script Authoring Interface (JSAI). * Modifies SFNodes by using ROUTEs from Script node eventOuts. *

* *@version 2.0 *

*@author Don Brutzman *(http://web.nps.navy.mil/~brutzman) *

* *

Description: *
VRML-Java paper: * Brutzman, Don, * "The Virtual Reality Modeling Language and Java," *Communications of the ACM, vol. 41 no. 6, June 1998, pp. 57-64. *

* *

Location: *
ScriptNodeEventOutControl.java *
http://www.web3D.org/WorkingGroups/vrtp/mil/navy/nps/testing/ScriptNodeEventOutControl.java *
http://web.nps.navy.mil/~brutzman/vrtp/mil/navy/nps/testing/ScriptNodeEventOutControl.java *

* *

History: * * * *
5 April 99 * Don Brutzman * Revised to include Javadoc and exception handling. *
12 June 2000 * Don Brutzman * Fully specified package for vrml.field.* types to avoid collisions with Java3D classes. *
*

* *

Debugging notes: *
System.out.println text appears on the Netscape Java console when using CosmoPlayer, *
or on WorldView's VRML console *

* *@see ScriptNodeFieldControl */ public class ScriptNodeEventOutControl extends Script { public static final boolean DEBUG = true; // Declare EventIn and eventOuts private vrml.field.SFTime startTime; // eventIn private vrml.field.MFString ChangedText; // eventOut private vrml.field.SFVec3f ChangedPosition; // eventOut // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** * Utility method. */ public String getName() { return "ScriptNodeEventOutControl"; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** * Called by VRML browser prior to first rendering the scene. */ public void initialize () { try { // catchAllException to diagnose run-time errors while VRML browser continues if (DEBUG) System.out.println (""); if (DEBUG) System.out.println ("initializing ScriptNodeEventOutControl script node"); ChangedText = (MFString) getEventOut ("ChangedText"); // instantiate String [] message = new String [3]; message [0] = "Java ScriptNodeEventOutControl.class"; message [1] = "has reinitialized the ChangedText node"; message [2] = "and this text is ready to be clicked..."; ChangedText.setValue ( message ); if (DEBUG) System.out.println ("ChangedText = " + message[0]); if (DEBUG) System.out.println (message[1] + " " + message[2]); ChangedPosition = (SFVec3f) getEventOut ("ChangedPosition"); // instantiate SFVec3f position = new SFVec3f ( 0, 3, 0 ); ChangedPosition.setValue ( position ); if (DEBUG) System.out.println ("ChangedPosition = " + ChangedPosition); if (DEBUG) System.out.println (""); } catch (Exception catchAllException) { System.out.println("initialize () exception: " + catchAllException); catchAllException.printStackTrace(); // can't re-throw (catchAllException); since not supported by class vrml.node.Script } return; } /** * Called by VRML browser when the user touches the intermediate text in the test scene. */ public void processEvent (Event touch) { try { // catchAllException to diagnose run-time errors while VRML browser continues if (DEBUG) System.out.println ("ScriptNodeEventOutControl processEvent startTime = " + startTime); if (DEBUG) System.out.println ("Event touch = " + touch); String [] message = new String [4]; message [0] = "Click seen by Java processEvent"; message [1] = "via Script node eventIn."; message [2] = "Text & position successfully changed"; message [3] = "via eventOut control."; ChangedText.setValue ( message ); if (DEBUG) System.out.println ("ChangedText = "); if (DEBUG) System.out.println (message[0] + " " + message[1]); if (DEBUG) System.out.println (message[2] + " " + message[3]); SFVec3f position = new SFVec3f ( 0, -1, 0 ); ChangedPosition.setValue ( position ); if (DEBUG) System.out.println ("ChangedPosition = " + position ); if (DEBUG) System.out.println (""); } catch (Exception catchAllException) { System.out.println ("processEvent () exception: " + catchAllException); catchAllException.printStackTrace(); // can't re-throw (catchAllException); since not supported by class vrml.node.Script } return; } }