package mil.navy.nps.testing; // Java JSAI classes for VRML import vrml.*; import vrml.field.*; import vrml.node.*; /** * Test script used by * ScriptNodeFieldControl.wrl * to verify proper operation of the Java Script Authoring Interface (JSAI). * Uses SFNodes as directly modifiable Script node fields. *

* *@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: *
ScriptNodeFieldControl.java *
http://www.web3D.org/WorkingGroups/vrtp/mil/navy/nps/testing/ScriptNodeFieldControl.java *
http://web.nps.navy.mil/~brutzman/vrtp/mil/navy/nps/testing/ScriptNodeFieldControl.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 ScriptNodeEventOutControl */ public class ScriptNodeFieldControl extends Script { public static final boolean DEBUG = true; // Declare EventIn and eventOuts private vrml.field.SFTime startTime; // eventIn private vrml.field.SFNode ChangedText; // field private vrml.field.SFNode ChangedPosition; // field private vrml.node.Node node; private vrml.field.MFString text; private vrml.field.SFVec3f translation; private vrml.field.SFVec3f position; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** * Utility method. */ public String getName() { return "ScriptNodeFieldControl"; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** * Called by VRML browser prior to first rendering the scene. */ public void initialize () { try { // catchAllException to diagnose run-time errors while VRML browser continues // see examples 3.11/3.12 pp. 83-86 // "Java for 3D and VRML Worlds," Lea/Matsuda/Miyashita if (DEBUG) System.out.println (""); if (DEBUG) System.out.println ("initializing ScriptNodeFieldControl script node"); ChangedText = (SFNode) getField ("ChangedText"); // instantiate String [] message = new String [3]; message [0] = "Java ScriptNodeFieldControl.class"; message [1] = "has reinitialized the ChangedText node"; message [2] = "and this text is ready to be clicked..."; node = (Node) (ChangedText.getValue()); text = (MFString) node.getExposedField ("string"); text.setValue (message); if (DEBUG) System.out.println ("ChangedText.string = " + message[0]); if (DEBUG) System.out.println (message[1] + " " + message[2]); ChangedPosition = (SFNode) getField ("ChangedPosition"); // instantiate position = new SFVec3f ( 0, 3, 0 ); node = (Node) (ChangedPosition.getValue()); translation = (SFVec3f) node.getExposedField ("translation"); translation.setValue (position); if (DEBUG) System.out.println("ChangedPosition.translation = " + position); 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 ("ScriptNodeFieldControl 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 SFNode field control."; node = (Node) (ChangedText.getValue()); text = (MFString) node.getExposedField ("string"); text.setValue (message); if (DEBUG) System.out.println ("ChangedText.string = "); if (DEBUG) System.out.println (message[0] + " " + message[1]); if (DEBUG) System.out.println (message[2] + " " + message[3]); position = new SFVec3f ( 0, -1, 0 ); node = (Node) (ChangedPosition.getValue()); translation = (SFVec3f) node.getExposedField ("translation"); translation.setValue (position); if (DEBUG) System.out.println("ChangedPosition.translation = " + 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; } }