package Savage.Tools.HeadsUpDisplays;

import org.web3d.x3d.jsail.Core.*;
import org.web3d.x3d.jsail.EnvironmentalSensor.*;
import org.web3d.x3d.jsail.fields.*;
import org.web3d.x3d.jsail.Geometry3D.*;
import org.web3d.x3d.jsail.Grouping.*;
import org.web3d.x3d.jsail.Networking.*;
import org.web3d.x3d.jsail.PointingDeviceSensor.*;
import org.web3d.x3d.jsail.Rendering.*;
import org.web3d.x3d.jsail.Scripting.*;
import org.web3d.x3d.jsail.Shape.*;
import org.web3d.x3d.jsail.Text.*;
import org.web3d.x3d.jsail.Time.*;

// Javadoc metadata annotations follow, see below for X3DJSAIL Java source code.
/**
 * <p> Digital Virtual Display (DVD) Controller Prototype definition to control animation timing. Heads-up display keeps DVD Controller on screen. </p>
 <p> Related links: Catalog page <a href="../../../../Tools/HeadsUpDisplays/DvdControllerPrototypeIndex.html" target="_blank">DvdControllerPrototype</a>,  source <a href="../../../../Tools/HeadsUpDisplays/DvdControllerPrototype.java">DvdControllerPrototype.java</a>, <a href="https://www.web3d.org/x3d/content/examples/X3dResources.html" target="_blank">X3D Resources</a>, <a href="https://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html" target="_blank">X3D Scene Authoring Hints</a>, and <a href="https://www.web3d.org/x3d/content/X3dTooltips.html" target="_blank">X3D Tooltips</a>. </p>
	<table style="color:black; border:0px solid; border-spacing:10px 0px;">
        <caption>Scene Meta Information</caption>
		<tr style="background-color:silver; border-color:silver;">
			<td style="text-align:center; padding:10px 0px;"><i>meta tags</i></td>
			<td style="text-align:left;   padding:10px 0px;">&nbsp; Document Metadata </td>
		</tr>

		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> title </i> </td>
			<td> <a href="../../../../Tools/HeadsUpDisplays/DvdControllerPrototype.x3d">DvdControllerPrototype.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> description </i> </td>
			<td> Digital Virtual Display (DVD) Controller Prototype definition to control animation timing. Heads-up display keeps DVD Controller on screen. </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> creator </i> </td>
			<td> Jane Wu, Don Brutzman, Jonathan Roberts </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> created </i> </td>
			<td> 19 July 2001 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> modified </i> </td>
			<td> 5 March 2024 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> subject </i> </td>
			<td> DvdController animation control </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> TODO </i> </td>
			<td> check handling of beginning/end buttos </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> TODO </i> </td>
			<td> X3D-Edit ExternProtoDeclare panel autocheck missed notifying that some fields are not in original ProtoDeclare </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> identifier </i> </td>
			<td> <a href="https://www.web3d.org/x3d/content/examples/Savage/Tools/HeadsUpDisplays/DvdControllerPrototype.x3d" target="_blank">https://www.web3d.org/x3d/content/examples/Savage/Tools/HeadsUpDisplays/DvdControllerPrototype.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> generator </i> </td>
			<td> X3D-Edit 4.0, <a href="https://www.web3d.org/x3d/tools/X3D-Edit" target="_blank">https://www.web3d.org/x3d/tools/X3D-Edit</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> license </i> </td>
			<td> <a href="../../../../Tools/HeadsUpDisplays/../../license.html">../../license.html</a> </td>
		</tr>
		<tr style="background-color:silver; border-color:silver;">
			<td style="text-align:center;" colspan="2">  &nbsp; </td>
		</tr>
	</table>

	<p>
		This program uses the
		<a href="https://www.web3d.org/specifications/java/X3DJSAIL.html" target="_blank">X3D Java Scene Access Interface Library (X3DJSAIL)</a>.
		It has been produced using the 
		<a href="https://www.web3d.org/x3d/stylesheets/X3dToJava.xslt" target="_blank">X3dToJava.xslt</a>
		stylesheet
	       (<a href="https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/X3dToJava.xslt" target="_blank">version control</a>)
                which is used to create Java source code from an original <code>.x3d</code> model.
	</p>

	* @author Jane Wu, Don Brutzman, Jonathan Roberts
 */

public class DvdControllerPrototype
{
	/** Default constructor to create this object. */
	public DvdControllerPrototype ()
	{
	  initialize();
	}

	/** Create and initialize the X3D model for this object. */
	public final void initialize()
	{
            try { // catch-all
  x3dModel = new X3D().setProfile(X3D.PROFILE_IMMERSIVE).setVersion(X3D.VERSION_3_0)
  .setHead(new head()
    .addMeta(new meta().setName(meta.NAME_TITLE      ).setContent("DvdControllerPrototype.x3d"))
    .addMeta(new meta().setName(meta.NAME_DESCRIPTION).setContent("Digital Virtual Display (DVD) Controller Prototype definition to control animation timing. Heads-up display keeps DVD Controller on screen."))
    .addMeta(new meta().setName(meta.NAME_CREATOR    ).setContent("Jane Wu, Don Brutzman, Jonathan Roberts"))
    .addMeta(new meta().setName(meta.NAME_CREATED    ).setContent("19 July 2001"))
    .addMeta(new meta().setName(meta.NAME_MODIFIED   ).setContent("5 March 2024"))
    .addMeta(new meta().setName(meta.NAME_SUBJECT    ).setContent("DvdController animation control"))
    .addMeta(new meta().setName(meta.NAME_TODO       ).setContent("check handling of beginning/end buttos"))
    .addMeta(new meta().setName(meta.NAME_TODO       ).setContent("X3D-Edit ExternProtoDeclare panel autocheck missed notifying that some fields are not in original ProtoDeclare"))
    .addMeta(new meta().setName(meta.NAME_IDENTIFIER ).setContent("https://www.web3d.org/x3d/content/examples/Savage/Tools/HeadsUpDisplays/DvdControllerPrototype.x3d"))
    .addMeta(new meta().setName(meta.NAME_GENERATOR  ).setContent("X3D-Edit 4.0, https://www.web3d.org/x3d/tools/X3D-Edit"))
    .addMeta(new meta().setName(meta.NAME_LICENSE    ).setContent("../../license.html")))
  .setScene(new Scene()
    .addChild(new WorldInfo().setTitle("DvdControllerPrototype.x3d"))
    .addChild(new ExternProtoDeclare("SliderFloat").setName("SliderFloat").setAppinfo("Slider user-interface widget that produces floating-point output values").setUrl(new String[] {"../../../Savage/Tools/Animation/SliderFloatPrototype.x3d#SliderFloat","https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/SliderFloatPrototype.x3d#SliderFloat","../../../Savage/Tools/Animation/SliderFloatPrototype.wrl#SliderFloat","https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/SliderFloatPrototype.wrl#SliderFloat"})
      .addComments(" TODO autocheck missed that these are not in original ProtoDeclare... do these go into DvdController interface? <field accessType='outputOnly' name='isDragged' type='SFBool'/> <field accessType='initializeOnly' appinfo='default value true' name='dragEnabled' type='SFBool'/> <field accessType='inputOnly' name='setDragEnabled' type='SFBool'/> <field accessType='outputOnly' name='dragEnabledChanged' type='SFBool'/> <field accessType='initializeOnly' appinfo='default value true' name='clickEnabled' type='SFBool'/> <field accessType='inputOnly' name='setClickEnabled' type='SFBool'/> <field accessType='outputOnly' name='clickEnabledChanged' type='SFBool'/> ")
      .addField(new field().setName("layoutDirection").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("Allowed values: vertical, horizontal"))
      .addField(new field().setName("height").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("default value 1.0"))
      .addField(new field().setName("radius").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("default value 0.1"))
      .addField(new field().setName("barRadius").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("default value 0.02"))
      .addField(new field().setName("sliderBarColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("default value .8 .4 .8"))
      .addField(new field().setName("sliderBallColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("default value .3 .4 .8"))
      .addField(new field().setName("sliderEndColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("default value .2 .3 .9"))
      .addField(new field().setName("min").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("default value 0.0"))
      .addField(new field().setName("max").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("default value 10.0"))
      .addField(new field().setName("value").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("default value 0.0"))
      .addField(new field().setName("setMin").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY))
      .addField(new field().setName("setMax").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY))
      .addField(new field().setName("setValue").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY))
      .addField(new field().setName("valueChanged").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
      .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("Enable/disable console output for troubleshooting")))
    .addChild(new ProtoDeclare("DvdController").setName("DvdController").setAppinfo("Digital Virtual Display (DVD) Controller Prototype is a heads-up display (HUD) to control animation timing")
      .setProtoInterface(new ProtoInterface()
        .addField(new field().setName("testTimeVal").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(-2).setAppinfo("default value -2"))
        .addField(new field().setName("description").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("Short description of what is animated by this DvdController."))
        .addField(new field().setName("playEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false).setAppinfo("Whether or not play mode is enabled including during startup."))
        .addField(new field().setName("displayMode").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue("PLAYBACK_SLIDER").setAppinfo("Initializes how control buttons and slider are displayed. The control buttons include DIS control (i.e. Master Ghost Local) and Playback control (i.e. Reset to Start Fast Rewind Rewind Pause Play Fast Forward Reset to End). Possible values are (case sensitive): ALL DIS_ONLY PLAYBACK_ONLY SLIDER_ONLY DIS_PLAYBACK DIS_SLIDER PLAYBACK_SLIDER and NONE."))
        .addField(new field().setName("setDisplayMode").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("Sets how control buttons and slider are displayed. The control buttons include DIS control (i.e. Master Ghost Local) and Playback control (i.e. Reset to Start Fast Rewind Rewind Pause Play Fast Forward Reset to End). Possible values are (case sensitive): ALL DIS_ONLY PLAYBACK_ONLY SLIDER_ONLY DIS_PLAYBACK DIS_SLIDER PLAYBACK_SLIDER and NONE."))
        .addField(new field().setName("buttonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFColor(0.55,0.55,0.55)).setAppinfo("Default button color."))
        .addField(new field().setName("selectedButtonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFColor(0.75,0.75,0.75)).setAppinfo("Button color when selected by user."))
        .addField(new field().setName("labelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFColor(0.0,0.0,0.0)).setAppinfo("Default label color."))
        .addField(new field().setName("selectedLabelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFColor(0.1,0.65,0.2)).setAppinfo("Label color when selected by user."))
        .addField(new field().setName("locationOffset").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFVec3f(-2.0,-2.0,0.0)).setAppinfo("Modified screen location and distance (for size)."))
        .addField(new field().setName("clockEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(true).setAppinfo("default value true"))
        .addField(new field().setName("cycleInterval").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(1.0).setAppinfo("Time for complete loop cycle in seconds."))
        .addField(new field().setName("set_cycleInterval").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INPUTONLY))
        .addField(new field().setName("cycleInterval_changed").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
        .addField(new field().setName("speedFactor").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(10).setAppinfo("Factor used to determine the speed increase/decrease for Fast Rewind and Fast Forward action."))
        .addField(new field().setName("isActive").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
        .addField(new field().setName("startTime_changed").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
        .addField(new field().setName("stopTime_changed").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
        .addField(new field().setName("time_changed").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
        .addField(new field().setName("fraction_changed").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
        .addField(new field().setName("secondsElapsed").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
        .addField(new field().setName("isMaster").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY).setAppinfo("isMaster isRemote and isLocal are booleans represent a 3-way toggle. Only one of them can have a true value at any time."))
        .addField(new field().setName("isRemote").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY).setAppinfo("isMaster isRemote and isLocal are booleans represent a 3-way toggle. Only one of them can have a true value at any time."))
        .addField(new field().setName("isLocal").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY).setAppinfo("isMaster isRemote and isLocal are booleans represent a 3-way toggle. Only one of them can have a true value at any time."))
        .addField(new field().setName("isPaused").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY).setAppinfo("isPaused and isRunning always have opposite values. When isPaused is true isRunning will be false and vice versa."))
        .addField(new field().setName("isRunning").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY).setAppinfo("isPaused and isRunning always have opposite values. When isPaused is true isRunning will be false and vice versa."))
        .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false).setAppinfo("Enable/disable console output for troubleshooting")))
      .setProtoBody(new ProtoBody()
        .addChild(new Transform("LocationOffset")
          .setIS(new IS()
            .addConnect(new connect().setNodeField("translation").setProtoField("locationOffset")))
          .addChild(new ProximitySensor("WhereSensor").setSize(1000000000.0,1000000000.0,1000000000.0))
          .addChild(new Transform("FixedLocation")
            .addChild(new Transform("MovableLocation")
              .addChild(new Transform().setTranslation(0.0,0.0,-10.0)
                .addChild(new Group("PlaneMovementSensorGroup")
                  .addChild(new PlaneSensor("PlaneMovementSensor").setDescription("select and drag to move interface"))
                  .addChild(new VisibilitySensor("MovementVisibilitySensor"))
                  .addChild(new Script("VisibilityControlScript").setSourceCode("""
ecmascript:

function tracePrint (text)
{
    if (traceEnabled) Browser.println ('[DvdController ' + description + ' VisibilityControlScript] ' + text);
}
function initialize ()
{
    translationOffsetChanged = locationOffset;
    planeSensorTranslation   = locationOffset;
    setPlaneSensorIsActive (false, -1); // dummy timeStamp
}
function setIsVisible (value, timeStamp)
{
    isVisible = value;
    tracePrint('isVisible=' + value);
}
function setPlaneSensorIsActive (value, timeStamp)
{
    tracePrint('PlaneSensor isActive=' + value + ', translationOffsetChanged=' + translationOffsetChanged.toString());

    if (value == false)
    {
            tracePrint('planeSensorTranslation=' + planeSensorTranslation.toString());
            if (isVisible)
            {
                    translationChanged = planeSensorTranslation;
            }
            else
            {
                    translationChanged = new SFVec3f(0, 0, 0);
                    translationOffsetChanged  = new SFVec3f(0, 0, 0);
            }
    }
}
function setPlaneSensorTranslation (value, timeStamp)
{
	planeSensorTranslation = value;
	tracePrint('planeSensorTranslation=' + value.toString());
}
""")
                    .addField(new field().setName("description").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                    .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                    .addField(new field().setName("isVisible").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(true))
                    .addField(new field().setName("locationOffset").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                    .addField(new field().setName("planeSensorTranslation").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFVec3f(0.0,0.0,0.0)))
                    .addField(new field().setName("setIsVisible").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                    .addField(new field().setName("setPlaneSensorIsActive").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                    .addField(new field().setName("setPlaneSensorTranslation").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INPUTONLY))
                    .addField(new field().setName("translationChanged").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                    .addField(new field().setName("translationOffsetChanged").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                    .setIS(new IS()
                      .addConnect(new connect().setNodeField("description").setProtoField("description"))
                      .addConnect(new connect().setNodeField("traceEnabled").setProtoField("traceEnabled"))
                      .addConnect(new connect().setNodeField("locationOffset").setProtoField("locationOffset"))))
                  .addChild(new ROUTE().setFromNode("PlaneMovementSensor").setFromField("isActive").setToNode("VisibilityControlScript").setToField("setPlaneSensorIsActive"))
                  .addChild(new ROUTE().setFromNode("PlaneMovementSensor").setFromField("translation_changed").setToNode("VisibilityControlScript").setToField("setPlaneSensorTranslation"))
                  .addChild(new ROUTE().setFromNode("MovementVisibilitySensor").setFromField("isActive").setToNode("VisibilityControlScript").setToField("setIsVisible"))
                  .addChild(new Switch("MovementControlSwitch").setWhichChoice(0)
                    .addChild(new Transform("AllLayer").setTranslation(-0.25,0.0,0.0)
                      .addChild(new Shape()
                        .setAppearance(new Appearance("MovementControlAppearance")
                          .setMaterial(new Material().setDiffuseColor(0.65,0.65,0.65)))
                        .setGeometry(new Box().setSize(0.25,1.75,0.05))))
                    .addChild(new Transform("TwoLayer").setTranslation(-0.25,-0.285,0.0)
                      .addChild(new Shape()
                        .setAppearance(new Appearance().setUSE("MovementControlAppearance"))
                        .setGeometry(new Box().setSize(0.25,1.175,0.05))))
                    .addChild(new Transform("OneLayer").setTranslation(-0.25,-0.575,0.0)
                      .addChild(new Shape()
                        .setAppearance(new Appearance().setUSE("MovementControlAppearance"))
                        .setGeometry(new Box().setSize(0.25,0.6,0.05))))))
                .addChild(new Switch("DisplayControlSwitch").setWhichChoice(0)
                  .addChild(new Transform("DisplayAllLayer")
                    .addChild(new Transform("DisplayAllToggle")
                      .addChild(new Shape()
                        .setAppearance(new Appearance("ButtonBaseAppearance")
                          .setMaterial(new Material().setDiffuseColor(0.65,0.65,0.65)))
                        .setGeometry(new Box().setSize(0.25,1.75,0.05)))
                      .addChild(new TouchSensor("DisplayAllSensor").setDescription("display/hide all rows"))
                      .addChild(new Shape()
                        .setAppearance(new Appearance()
                          .setMaterial(new Material("DisplayAllMaterial").setDiffuseColor(0.0,0.35,0.8)))
                        .setGeometry(new Cylinder().setHeight(1.65).setRadius(0.1))))
                    .addChild(new Transform("DisplayTopLayerToggle").setTranslation(0.25,0.575,0.0)
                      .addChild(new Shape()
                        .setAppearance(new Appearance().setUSE("ButtonBaseAppearance"))
                        .setGeometry(new Box().setSize(0.25,0.6,0.05)))
                      .addChild(new TouchSensor("DisplayTopLayerSensor").setDescription("hide top row"))
                      .addChild(new Shape()
                        .setAppearance(new Appearance()
                          .setMaterial(new Material("DisplayControlMaterial").setDiffuseColor(0.0,0.35,0.8)))
                        .setGeometry(new Cylinder().setHeight(0.5).setRadius(0.1))))
                    .addChild(new Transform("DisplayMidLayerToggle").setTranslation(0.25,0.0,0.0)
                      .addChild(new Shape()
                        .setAppearance(new Appearance().setUSE("ButtonBaseAppearance"))
                        .setGeometry(new Box().setSize(0.25,0.6,0.05)))
                      .addChild(new TouchSensor("DisplayMidLayerSensor").setDescription("hide middle row"))
                      .addChild(new Shape()
                        .setAppearance(new Appearance()
                          .setMaterial(new Material().setUSE("DisplayControlMaterial")))
                        .setGeometry(new Cylinder().setHeight(0.5).setRadius(0.1))))
                    .addChild(new Transform("DisplayBottomLayerToggle").setTranslation(0.25,-0.575,0.0)
                      .addChild(new Shape()
                        .setAppearance(new Appearance().setUSE("ButtonBaseAppearance"))
                        .setGeometry(new Box().setSize(0.25,0.6,0.05)))
                      .addChild(new TouchSensor("DisplayBottomLayerSensor").setDescription("hide bottom row"))
                      .addChild(new Shape()
                        .setAppearance(new Appearance()
                          .setMaterial(new Material().setUSE("DisplayControlMaterial")))
                        .setGeometry(new Cylinder().setHeight(0.5).setRadius(0.1)))))
                  .addChild(new Transform("DisplayTwoLayer")
                    .addChild(new Transform("DisplayTwoToggle").setTranslation(0.0,-0.285,0.0)
                      .addChild(new Shape()
                        .setAppearance(new Appearance().setUSE("ButtonBaseAppearance"))
                        .setGeometry(new Box().setSize(0.25,1.175,0.05)))
                      .addChild(new TouchSensor().setUSE("DisplayAllSensor"))
                      .addChild(new Shape()
                        .setAppearance(new Appearance()
                          .setMaterial(new Material().setUSE("DisplayAllMaterial")))
                        .setGeometry(new Cylinder().setHeight(1.08).setRadius(0.1))))
                    .addChild(new Transform().setUSE("DisplayMidLayerToggle"))
                    .addChild(new Transform().setUSE("DisplayBottomLayerToggle")))
                  .addChild(new Transform("DisplayOneLayer")
                    .addChild(new Transform("DisplayOneToggle").setTranslation(0.0,-0.575,0.0)
                      .addChild(new Shape()
                        .setAppearance(new Appearance().setUSE("ButtonBaseAppearance"))
                        .setGeometry(new Box().setSize(0.25,0.6,0.05)))
                      .addChild(new TouchSensor().setUSE("DisplayAllSensor"))
                      .addChild(new Shape()
                        .setAppearance(new Appearance()
                          .setMaterial(new Material().setUSE("DisplayAllMaterial")))
                        .setGeometry(new Cylinder().setHeight(0.5).setRadius(0.1))))
                    .addChild(new Transform().setUSE("DisplayBottomLayerToggle")))
                  .addChild(new Transform("DisplayNoLayer")
                    .addChild(new Transform("DisplayNoToggle").setTranslation(0.0,-0.575,0.0)
                      .addChild(new Shape()
                        .setAppearance(new Appearance().setUSE("ButtonBaseAppearance"))
                        .setGeometry(new Box().setSize(0.25,0.6,0.05)))
                      .addChild(new TouchSensor().setUSE("DisplayAllSensor"))
                      .addChild(new Shape()
                        .setAppearance(new Appearance()
                          .setMaterial(new Material().setUSE("DisplayAllMaterial")))
                        .setGeometry(new Cylinder().setHeight(0.5).setRadius(0.1))))))
                .addChild(new Script("DisplayLayerScript").setSourceCode("""
ecmascript:

function initialize()
{
	setDisplayMode(displayMode, -1);
}
function tracePrint (text)
{
	if (traceEnabled) Browser.println ('[DvdController ' + description + ' DisplayLayerScript] ' + text);
}
function setDisplayMode(value, timeStamp)
{
	// javascript switch statement is convenient but not consistently supported, so test the old-fashioned way:
        
        if (displayMode == 'ALL')
	{
            movementControlSwitchSelection = 0; //AllLayer
            displayControlSwitchSelection = 0;  //DisplayAllLayer
            displayAllColor = new SFColor(0, 0.35, 0.8);
            topLayerSwitchSelection = 0;
            midLayerSwitchSelection = 0;
            bottomLayerSwitchSelection = 0;
	}
        else if (displayMode == 'DIS_ONLY')
        {
            movementControlSwitchSelection = 2; //OneLayer
            displayControlSwitchSelection = 2;  //DisplayOneLayer
            displayAllColor = new SFColor(1, 0, 0);
            topLayerSwitchSelection = 1;        //DisplayNoneTop
            midLayerSwitchSelection = 2;        //DisplayNoneMid
            bottomLayerSwitchSelection = 1;     //DisplayDISModeBottom
	}
        else if (displayMode == 'PLAYBACK_ONLY')
        {
            movementControlSwitchSelection = 2; //OneLayer
            displayControlSwitchSelection = 2;  //DisplayOneLayer
            displayAllColor = new SFColor(1, 0, 0);
            topLayerSwitchSelection = 1;        //DisplayNoneTop
            midLayerSwitchSelection = 2;        //DisplayNoneMid
            bottomLayerSwitchSelection = 2;     //DisplayPlaybackButtonsBottom
	}
        else if (displayMode == 'SLIDER_ONLY')
        {
            movementControlSwitchSelection = 2; //OneLayer
            displayControlSwitchSelection = 2;  //DisplayOneLayer
            displayAllColor = new SFColor(1, 0, 0);
            topLayerSwitchSelection = 1;        //DisplayNoneTop
            midLayerSwitchSelection = 2;        //DisplayNoneMid
            bottomLayerSwitchSelection = 0;     //DiaplaySliderBottom
	}
        else if (displayMode == 'DIS_PLAYBACK')
        {
            movementControlSwitchSelection = 1; //TwoLayer
            displayControlSwitchSelection = 1;  //DisplayTwoLayer
            displayAllColor = new SFColor(1, 0, 0);
            topLayerSwitchSelection = 1;        //DisplayNoneTop
            midLayerSwitchSelection = 1;        //DisplayDISModeMid
            bottomLayerSwitchSelection = 2;     //DisplayPlaybackButtonsBottom
	}
        else if (displayMode == 'DIS_SLIDER')
        {
            movementControlSwitchSelection = 1; //TwoLayer
            displayControlSwitchSelection = 1;  //DisplayTwoLayer
            displayAllColor = new SFColor(1, 0, 0);
            topLayerSwitchSelection = 1;        //DisplayNoneTop
            midLayerSwitchSelection = 1;        //DisplayDISModeMid
            bottomLayerSwitchSelection = 0;     //DisplaySliderBottom
	}
        else if (displayMode == 'PLAYBACK_SLIDER')
        {
            movementControlSwitchSelection = 1; //TwoLayer
            displayControlSwitchSelection = 1;  //DisplayTwoLayer
            displayAllColor = new SFColor(1, 0, 0);
            topLayerSwitchSelection = 1;        //DisplayNoneTop
            midLayerSwitchSelection = 0;        //DisplayPlaybackButtosMid
            bottomLayerSwitchSelection = 0;     //DisplaySliderBottom
	}
        else
        {
            if (displayMode != 'NONE')
                Browser.println ('Unknown value for displayMode=' + displayMode + ', assuming value of NONE');
                
            movementControlSwitchSelection = 2; //OneLayer
            displayControlSwitchSelection = 3;  //DisplayNoLayer
            displayAllColor = new SFColor(1, 0, 0);
            topLayerSwitchSelection = 1;        //DisplayNoneTop
            midLayerSwitchSelection = 2;        //DisplayNoneMid
            bottomLayerSwitchSelection = 3;     //DisplayNoneBottom
	}
}

function displayAllToggleEnabled(value, timeStamp) {
	if (displayAllToggleArmed == false)
	{
		displayAllToggleArmed = true;
		if (displayControlSwitchSelection == 0)
		{
			movementControlSwitchSelection = 2;
			displayControlSwitchSelection = 3;
			displayAllColor = new SFColor(1, 0, 0);
			topLayerSwitchSelection = 1;
			midLayerSwitchSelection = 2;
			bottomLayerSwitchSelection = 3;
			tracePrint('movementControlSwitchSelection =' + movementControlSwitchSelection);
			tracePrint('displayControlSwitchSelection =' + displayControlSwitchSelection);
			tracePrint('topLayerSwitchSelection =' + topLayerSwitchSelection);
			tracePrint('midLayerSwitchSelection =' + midLayerSwitchSelection);
			tracePrint('bottomLayerSwitchSelection =' + bottomLayerSwitchSelection);
		}
		else //displayControlSwitchSelection not 0
		{
			movementControlSwitchSelection = 0;
			displayControlSwitchSelection = 0;
			displayAllColor = new SFColor(0, 0.35, 0.8);
			topLayerSwitchSelection = 0;
			midLayerSwitchSelection = 0;
			bottomLayerSwitchSelection = 0;
			tracePrint('movementControlSwitchSelection =' + movementControlSwitchSelection);
			tracePrint('displayControlSwitchSelection =' + displayControlSwitchSelection);
			tracePrint('topLayerSwitchSelection =' + topLayerSwitchSelection);
			tracePrint('midLayerSwitchSelection =' + midLayerSwitchSelection);
			tracePrint('bottomLayerSwitchSelection =' + bottomLayerSwitchSelection);
		}
	}
	else
	{
		displayAllToggleArmed = false;
		return;
	}
}

function topLayerToggleEnabled(value, timeStamp) {
	if (topLayerToggleArmed == false)
	{
		topLayerToggleArmed = true;
		displayControlSwitchSelection += 1;
		if (displayControlSwitchSelection == 3)
			movementControlSwitchSelection = 2;
		else
			movementControlSwitchSelection = displayControlSwitchSelection;
		displayAllColor = new SFColor(1, 0, 0);
		topLayerSwitchSelection = 1;
		tracePrint('movementControlSwitchSelection =' + movementControlSwitchSelection);
		tracePrint('displayControlSwitchSelection =' + displayControlSwitchSelection);
		tracePrint('topLayerSwitchSelection =' + topLayerSwitchSelection);
	}
	else
	{
		topLayerToggleArmed = false;
		return;
	}
}

function midLayerToggleEnabled(value, timeStamp) {
	if (midLayerToggleArmed == false)
	{
		midLayerToggleArmed = true;
		displayControlSwitchSelection += 1;
		if (displayControlSwitchSelection == 3)
			movementControlSwitchSelection = 2;
		else
			movementControlSwitchSelection = displayControlSwitchSelection;
		displayAllColor = new SFColor(1, 0, 0);
		if (topLayerSwitchSelection == 0)
		{
			topLayerSwitchSelection = 1;
			midLayerSwitchSelection = 1;
		}
		else
		{
			midLayerSwitchSelection = 2;
		}
		tracePrint('movementControlSwitchSelection =' + movementControlSwitchSelection);
		tracePrint('displayControlSwitchSelection =' + displayControlSwitchSelection);
		tracePrint('topLayerSwitchSelection =' + topLayerSwitchSelection);
		tracePrint('midLayerSwitchSelection =' + midLayerSwitchSelection);
	}
	else
	{
		midLayerToggleArmed = false;
		return;
	}
}

function bottomLayerToggleEnabled(value, timeStamp) {
	if (bottomLayerToggleArmed == false)
	{
		bottomLayerToggleArmed = true;
		displayControlSwitchSelection += 1;
		if (displayControlSwitchSelection == 3)
			movementControlSwitchSelection = 2;
		else
			movementControlSwitchSelection = displayControlSwitchSelection;
		displayAllColor = new SFColor(1, 0, 0);
		if (topLayerSwitchSelection == 0) //if top display animation mode selection
		{
			topLayerSwitchSelection = 1; //top display nothing
			midLayerSwitchSelection = 1; //mid display animation mode selection
			bottomLayerSwitchSelection = 2; //bottom display playback control buttons
		}
		else if (midLayerSwitchSelection == 0) //if mid display playback control buttons
		{
			//top display nothing implied
			midLayerSwitchSelection = 2; //mid display nothing
			bottomLayerSwitchSelection = 2; //bottom display playback control buttons
		}
		else if (midLayerSwitchSelection == 1) //if mid display animation mode selection
		{
			//top display nothing implied
			midLayerSwitchSelection = 2; //mid display nothing
			bottomLayerSwitchSelection = 1; //bottom display animation mode selection
		}
		else //if mid display nothing
		{
			//top display nothing implied
			//mid display nothing implied
			bottomLayerSwitchSelection = 3; //bottom display nothing
		}

		tracePrint('movementControlSwitchSelection =' + movementControlSwitchSelection);
		tracePrint('displayControlSwitchSelection =' + displayControlSwitchSelection);
		tracePrint('topLayerSwitchSelection =' + topLayerSwitchSelection);
		tracePrint('midLayerSwitchSelection =' + midLayerSwitchSelection);
		tracePrint('bottomLayerSwitchSelection =' + bottomLayerSwitchSelection);
	}
	else
	{
		bottomLayerToggleArmed = false;
		return;
	}
}
""")
                  .addField(new field().setName("description").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                  .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                  .addField(new field().setName("displayMode").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                  .addField(new field().setName("setDisplayMode").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INPUTONLY))
                  .addField(new field().setName("displayAllToggleArmed").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false))
                  .addField(new field().setName("topLayerToggleArmed").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false))
                  .addField(new field().setName("midLayerToggleArmed").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false))
                  .addField(new field().setName("bottomLayerToggleArmed").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false))
                  .addField(new field().setName("displayAllToggleEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                  .addField(new field().setName("topLayerToggleEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                  .addField(new field().setName("midLayerToggleEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                  .addField(new field().setName("bottomLayerToggleEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                  .addField(new field().setName("displayAllColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                  .addField(new field().setName("movementControlSwitchSelection").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_OUTPUTONLY).setAppinfo("0 - Display all three animation controls (DIS Mode Selection Playback Controls and Time scale) in a three layer stack. 1 - Display two of the three animation controls in a two layer stack. 2 - Display one of the three animation controls in a one layer stack."))
                  .addField(new field().setName("displayControlSwitchSelection").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_OUTPUTONLY).setAppinfo("0 - Display all three animation controls (DIS Mode Selection Playback Controls and Time scale) in a three layer stack. 1 - Display two of the three animation controls in a two layer stack. 2 - Display one of the three animation controls in a one layer stack. 3 - Display no layers of animation controls."))
                  .addField(new field().setName("topLayerSwitchSelection").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_OUTPUTONLY).setAppinfo("0 - Display DIS Mode (Master Remote Local) Selection at top layer. 1 - Do not display anything at top layer."))
                  .addField(new field().setName("midLayerSwitchSelection").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_OUTPUTONLY).setAppinfo("0 - Display Playback Control Buttons (Reset to Start Fast Rewind Rewind Pause Play Fast Forward Reset To End) at the mid layer. 1 - Display DIS Mode Selection at the mid layer. 2 - Display nothing at the mid layer."))
                  .addField(new field().setName("bottomLayerSwitchSelection").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_OUTPUTONLY).setAppinfo("0 - Display Time Scale at the bottom layer. 1 - Display DIS Mode Selection at the bottom layer. 2 - Display Playback Control Buttons at the bottom layer. 3 - Display nothing at the bottom layer."))
                  .setIS(new IS()
                    .addConnect(new connect().setNodeField("description").setProtoField("description"))
                    .addConnect(new connect().setNodeField("traceEnabled").setProtoField("traceEnabled"))
                    .addConnect(new connect().setNodeField("displayMode").setProtoField("displayMode"))
                    .addConnect(new connect().setNodeField("setDisplayMode").setProtoField("setDisplayMode"))))
                .addChild(new ROUTE().setFromNode("DisplayAllSensor").setFromField("isActive").setToNode("DisplayLayerScript").setToField("displayAllToggleEnabled"))
                .addChild(new ROUTE().setFromNode("DisplayTopLayerSensor").setFromField("isActive").setToNode("DisplayLayerScript").setToField("topLayerToggleEnabled"))
                .addChild(new ROUTE().setFromNode("DisplayMidLayerSensor").setFromField("isActive").setToNode("DisplayLayerScript").setToField("midLayerToggleEnabled"))
                .addChild(new ROUTE().setFromNode("DisplayBottomLayerSensor").setFromField("isActive").setToNode("DisplayLayerScript").setToField("bottomLayerToggleEnabled"))
                .addChild(new ROUTE().setFromNode("DisplayLayerScript").setFromField("movementControlSwitchSelection").setToNode("MovementControlSwitch").setToField("whichChoice"))
                .addChild(new ROUTE().setFromNode("DisplayLayerScript").setFromField("displayControlSwitchSelection").setToNode("DisplayControlSwitch").setToField("whichChoice"))
                .addChild(new ROUTE().setFromNode("DisplayLayerScript").setFromField("displayAllColor").setToNode("DisplayAllMaterial").setToField("diffuseColor"))
                .addChild(new Switch("TopLayerSwitch").setWhichChoice(0)
                  .addChild(new Transform("DisplayDISModeTop").setTranslation(2.86,0.58,0.0)
                    .addChild(new Transform("DISModeButtons")
                      .addChild(new Shape("GroupButtonBaseShape")
                        .setAppearance(new Appearance().setUSE("ButtonBaseAppearance"))
                        .setGeometry(new Box().setSize(5.0,0.6,0.05)))
                      .addChild(new Transform().setTranslation(-1.6,0.0,0.0)
                        .addChild(new TouchSensor("MasterSensor").setDescription("Master entity, send DIS PDU packets"))
                        .addChild(new Shape("PushButton")
                          .setAppearance(new Appearance()
                            .setMaterial(new Material("MasterButtonMaterial").setDiffuseColor(0.9,0.9,0.9).setTransparency(1)))
                          .setGeometry(new IndexedFaceSet("DISModePushButton").setDEF("DISModePushButton").setCcw(false).setSolid(false).setCoordIndex(new int[] {0,1,2,3,0,-1})
                            .setCoord(new Coordinate().setPoint(new MFVec3f(new double[] {-0.8,0.25,0.05,0.8,0.25,0.05,0.8,-0.25,0.05,-0.8,-0.25,0.05})))))
                        .addChild(new Transform().setTranslation(0.0,0.0,0.15)
                          .addChild(new Shape()
                            .setAppearance(new Appearance()
                              .setMaterial(new Material("MasterLabelMaterial")))
                            .setGeometry(new Text().setString(new String[] {"networkWriter"})
                              .setFontStyle(new FontStyle("LabelFont").setJustify(FontStyle.JUSTIFY_MIDDLE_MIDDLE).setSize(0.2).setCssStyle("BOLD"))))))
                      .addChild(new Transform()
                        .addChild(new TouchSensor("RemoteSensor").setDescription("Remote entity, read DIS PDU packets"))
                        .addChild(new Shape().setUSE("PushButton"))
                        .addChild(new Transform().setTranslation(0.1,0.0,0.25)
                          .addChild(new Shape()
                            .setAppearance(new Appearance()
                              .setMaterial(new Material("RemoteLabelMaterial")))
                            .setGeometry(new Text().setString(new String[] {"networkReader"})
                              .setFontStyle(new FontStyle().setUSE("LabelFont"))))))
                      .addChild(new Transform().setTranslation(1.6,0.0,0.0)
                        .addChild(new TouchSensor("LocalSensor").setDescription("Local entity, no DIS traffic"))
                        .addChild(new Shape().setUSE("PushButton"))
                        .addChild(new Transform().setTranslation(0.0,0.0,0.15)
                          .addChild(new Shape()
                            .setAppearance(new Appearance()
                              .setMaterial(new Material("LocalLabelMaterial")))
                            .setGeometry(new Text().setString(new String[] {"standAlone"})
                              .setFontStyle(new FontStyle().setUSE("LabelFont"))))))
                      .addChild(new Script("DISModeScript").setSourceCode("""
ecmascript:

function tracePrint (text)
{
	if (traceEnabled) Browser.println ('[DvdController ' + description + ' DISModeScript] ' + text);
}

function initialize()
{
	masterButtonColor = buttonColor;
	remoteButtonColor = buttonColor;
	localButtonColor  = activeButtonColor;

	masterLabelColor = labelColor;
	remoteLabelColor = labelColor;
	localLabelColor  = activeLabelColor;

	isMaster = false;
	isRemote = false;
	isLocal  = true;
	arePlaybackButtonsActive = true;

	//set default mode
	localToggleEnabled(true, -1);
}

function masterToggleEnabled(value, timeStamp)
{
	masterButtonColor = activeButtonColor;
	remoteButtonColor = buttonColor;
	localButtonColor  = buttonColor;

	masterLabelColor = activeLabelColor;
	remoteLabelColor = labelColor;
	localLabelColor  = labelColor;

	isMaster = true;
	isRemote = false;
	isLocal  = false;

	if (!arePlaybackButtonsActive)
		playbackButtonLabelColor = labelColor;

	arePlaybackButtonsActive = true;
}

function remoteToggleEnabled(value, timeStamp)
{
	masterButtonColor = buttonColor;
	remoteButtonColor = activeButtonColor;
	localButtonColor  = buttonColor;

	masterLabelColor = labelColor;
	remoteLabelColor = activeLabelColor;
	localLabelColor  = labelColor;

	isMaster = false;
	isRemote = true;
	isLocal  = false;

	arePlaybackButtonsActive = false;
	playbackButtonLabelColor = labelColor;
	resetToStartEnabled = true;
}

function localToggleEnabled(value, timeStamp)
{
	masterButtonColor = buttonColor;
	remoteButtonColor = buttonColor;
	localButtonColor  = activeButtonColor;

	masterLabelColor = labelColor;
	remoteLabelColor = labelColor;
	localLabelColor  = activeLabelColor;

	isMaster = false;
	isRemote = false;
	isLocal  = true;

	if (!arePlaybackButtonsActive)
		playbackButtonLabelColor = labelColor;

	arePlaybackButtonsActive = true;
}
""")
                        .addField(new field().setName("description").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                        .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                        .addField(new field().setName("buttonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                        .addField(new field().setName("activeButtonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                        .addField(new field().setName("labelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                        .addField(new field().setName("activeLabelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                        .addField(new field().setName("masterToggleEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                        .addField(new field().setName("remoteToggleEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                        .addField(new field().setName("localToggleEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                        .addField(new field().setName("masterButtonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("masterLabelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("remoteButtonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("remoteLabelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("localButtonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("localLabelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("isMaster").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("isRemote").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("isLocal").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("arePlaybackButtonsActive").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("playbackButtonLabelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("resetToStartEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .setIS(new IS()
                          .addConnect(new connect().setNodeField("description").setProtoField("description"))
                          .addConnect(new connect().setNodeField("traceEnabled").setProtoField("traceEnabled"))
                          .addConnect(new connect().setNodeField("buttonColor").setProtoField("buttonColor"))
                          .addConnect(new connect().setNodeField("activeButtonColor").setProtoField("selectedButtonColor"))
                          .addConnect(new connect().setNodeField("labelColor").setProtoField("labelColor"))
                          .addConnect(new connect().setNodeField("activeLabelColor").setProtoField("selectedLabelColor"))
                          .addConnect(new connect().setNodeField("isMaster").setProtoField("isMaster"))
                          .addConnect(new connect().setNodeField("isRemote").setProtoField("isRemote"))
                          .addConnect(new connect().setNodeField("isLocal").setProtoField("isLocal"))))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("masterButtonColor").setToNode("MasterButtonMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("masterLabelColor").setToNode("MasterLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("remoteLabelColor").setToNode("RemoteLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("localLabelColor").setToNode("LocalLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("MasterSensor").setFromField("isActive").setToNode("DISModeScript").setToField("masterToggleEnabled"))
                      .addChild(new ROUTE().setFromNode("RemoteSensor").setFromField("isActive").setToNode("DISModeScript").setToField("remoteToggleEnabled"))
                      .addChild(new ROUTE().setFromNode("LocalSensor").setFromField("isActive").setToNode("DISModeScript").setToField("localToggleEnabled"))))
                  .addChild(new Transform("DisplayNoneTop")))
                .addChild(new ROUTE().setFromNode("DisplayLayerScript").setFromField("topLayerSwitchSelection").setToNode("TopLayerSwitch").setToField("whichChoice"))
                .addChild(new Switch("MidLayerSwitch").setWhichChoice(0)
                  .addChild(new Transform("DisplayPlaybackButtonsMid").setTranslation(2.86,0.0,0.0)
                    .addChild(new Transform("PlaybackButtons")
                      .addChild(new Shape().setUSE("GroupButtonBaseShape"))
                      .addChild(new Transform().setTranslation(-2.05,0.0,0.0)
                        .addChild(new TouchSensor("ResetToStartSensor").setDescription("reset clock to beginning"))
                        .addChild(new Transform("InvisibleButtonBox").setTranslation(0.03,0.02,0.1)
                          .addChild(new Shape()
                            .setAppearance(new Appearance()
                              .setMaterial(new Material().setTransparency(1)))
                            .setGeometry(new Box().setSize(0.6,0.4,0.001))))
                        .addChild(new Shape()
                          .setAppearance(new Appearance()
                            .setMaterial(new Material("ResetToStartButtonMaterial").setTransparency(0.9)))
                          .setGeometry(new IndexedFaceSet("PlaybackButton").setDEF("PlaybackButton").setSolid(false).setCoordIndex(new int[] {3,2,1,0,3,-1})
                            .setCoord(new Coordinate().setPoint(new MFVec3f(new double[] {-0.375,0.25,0.05,0.375,0.25,0.05,0.375,-0.25,0.05,-0.375,-0.25,0.05})))))
                        .addChild(new Transform()
                          .addChild(new Transform().setTranslation(-0.12,0.0,0.0)
                            .addChild(new Shape()
                              .setAppearance(new Appearance()
                                .setMaterial(new Material("ResetToStartLabelMaterial")))
                              .setGeometry(new Box("Bar").setSize(0.04,0.3,0.12))))
                          .addChild(new Transform().setTranslation(0.01,0.0,0.0)
                            .addChild(new Shape()
                              .setAppearance(new Appearance()
                                .setMaterial(new Material().setUSE("ResetToStartLabelMaterial")))
                              .setGeometry(new IndexedFaceSet("Triangle").setDEF("Triangle").setCoordIndex(new int[] {0,1,2,-1})
                                .setCoord(new Coordinate().setPoint(new MFVec3f(new double[] {-0.15,0.0,0.051,0.15,-0.15,0.051,0.15,0.15,0.051}))))))))
                      .addChild(new Transform().setTranslation(-1.36,0.0,0.0)
                        .addChild(new TouchSensor("FastRewindSensor").setDescription("fast rewind"))
                        .addChild(new Transform().setUSE("InvisibleButtonBox"))
                        .addChild(new Shape()
                          .setAppearance(new Appearance()
                            .setMaterial(new Material("FastRewindButtonMaterial").setTransparency(0.9)))
                          .setGeometry(new IndexedFaceSet().setUSE("PlaybackButton")))
                        .addChild(new Transform()
                          .addChild(new Transform().setTranslation(-0.15,0.0,0.0)
                            .addChild(new Shape()
                              .setAppearance(new Appearance()
                                .setMaterial(new Material("FastRewindLabelMaterial")))
                              .setGeometry(new IndexedFaceSet().setUSE("Triangle"))))
                          .addChild(new Transform().setTranslation(0.1,0.0,0.0)
                            .addChild(new Shape()
                              .setAppearance(new Appearance()
                                .setMaterial(new Material().setUSE("FastRewindLabelMaterial")))
                              .setGeometry(new IndexedFaceSet().setUSE("Triangle"))))))
                      .addChild(new Transform().setTranslation(-0.68,0.0,0.0)
                        .addChild(new TouchSensor("RewindSensor").setDescription("rewind"))
                        .addChild(new Transform().setUSE("InvisibleButtonBox"))
                        .addChild(new Shape()
                          .setAppearance(new Appearance()
                            .setMaterial(new Material("RewindButtonMaterial").setTransparency(0.9)))
                          .setGeometry(new IndexedFaceSet().setUSE("PlaybackButton")))
                        .addChild(new Transform()
                          .addChild(new Shape()
                            .setAppearance(new Appearance()
                              .setMaterial(new Material("RewindLabelMaterial")))
                            .setGeometry(new IndexedFaceSet().setUSE("Triangle")))))
                      .addChild(new Transform()
                        .addChild(new TouchSensor("PauseSensor").setDescription("pause"))
                        .addChild(new Transform().setUSE("InvisibleButtonBox"))
                        .addChild(new Shape()
                          .setAppearance(new Appearance()
                            .setMaterial(new Material("PauseButtonMaterial").setTransparency(0.9)))
                          .setGeometry(new IndexedFaceSet().setUSE("PlaybackButton")))
                        .addChild(new Transform()
                          .addChild(new Transform().setTranslation(-0.05,0.0,0.0)
                            .addChild(new Shape()
                              .setAppearance(new Appearance()
                                .setMaterial(new Material("PauseLabelMaterial")))
                              .setGeometry(new Box().setUSE("Bar"))))
                          .addChild(new Transform().setTranslation(0.085,0.0,0.0)
                            .addChild(new Shape()
                              .setAppearance(new Appearance()
                                .setMaterial(new Material().setUSE("PauseLabelMaterial")))
                              .setGeometry(new Box().setUSE("Bar"))))))
                      .addChild(new Transform().setTranslation(0.68,0.0,0.0)
                        .addChild(new TouchSensor("PlaySensor").setDescription("play"))
                        .addChild(new Transform().setUSE("InvisibleButtonBox"))
                        .addChild(new Shape()
                          .setAppearance(new Appearance()
                            .setMaterial(new Material("PlayButtonMaterial").setTransparency(0.9)))
                          .setGeometry(new IndexedFaceSet().setUSE("PlaybackButton")))
                        .addChild(new Transform().setRotation(0.0,0.0,1.0,3.14).setTranslation(0.05,0.0,0.0)
                          .addChild(new Shape()
                            .setAppearance(new Appearance()
                              .setMaterial(new Material("PlayLabelMaterial")))
                            .setGeometry(new IndexedFaceSet().setUSE("Triangle")))))
                      .addChild(new Transform().setTranslation(1.36,0.0,0.0)
                        .addChild(new TouchSensor("FastForwardSensor").setDescription("fast forward"))
                        .addChild(new Transform().setUSE("InvisibleButtonBox"))
                        .addChild(new Shape()
                          .setAppearance(new Appearance()
                            .setMaterial(new Material("FastForwardButtonMaterial").setTransparency(0.9)))
                          .setGeometry(new IndexedFaceSet().setUSE("PlaybackButton")))
                        .addChild(new Transform().setRotation(0.0,0.0,1.0,3.14)
                          .addChild(new Transform().setTranslation(-0.15,0.0,0.0)
                            .addChild(new Shape()
                              .setAppearance(new Appearance()
                                .setMaterial(new Material("FastForwardLabelMaterial")))
                              .setGeometry(new IndexedFaceSet().setUSE("Triangle"))))
                          .addChild(new Transform().setTranslation(0.1,0.0,0.0)
                            .addChild(new Shape()
                              .setAppearance(new Appearance()
                                .setMaterial(new Material().setUSE("FastForwardLabelMaterial")))
                              .setGeometry(new IndexedFaceSet().setUSE("Triangle"))))))
                      .addChild(new Transform().setTranslation(2.05,0.0,0.0)
                        .addChild(new TouchSensor("ResetToEndSensor").setDescription("reset clock to end"))
                        .addChild(new Transform().setUSE("InvisibleButtonBox"))
                        .addChild(new Shape()
                          .setAppearance(new Appearance()
                            .setMaterial(new Material("ResetToEndButtonMaterial").setTransparency(0.9)))
                          .setGeometry(new IndexedFaceSet().setUSE("PlaybackButton")))
                        .addChild(new Transform()
                          .addChild(new Transform().setRotation(0.0,0.0,1.0,3.14)
                            .addChild(new Shape()
                              .setAppearance(new Appearance()
                                .setMaterial(new Material("ResetToEndLabelMaterial")))
                              .setGeometry(new IndexedFaceSet().setUSE("Triangle"))))
                          .addChild(new Transform().setTranslation(0.12,0.0,0.0)
                            .addChild(new Shape()
                              .setAppearance(new Appearance()
                                .setMaterial(new Material().setUSE("ResetToEndLabelMaterial")))
                              .setGeometry(new Box().setUSE("Bar"))))))
                      .addChild(new Script("PlaybackControlScript").setSourceCode("""
ecmascript:

function tracePrint (text)
{
	if (traceEnabled) Browser.println ('[DvdController ' + description + ' PlaybackControlScript] ' + text);
}
function TraceLabelColors ()
{
	if (traceEnabled == false) return;

	Browser.println ('	buttonColor=' + buttonColor.toString());
	Browser.println ('	activeButtonColor=' + activeButtonColor.toString());
	Browser.println ('	labelColor=' + labelColor.toString());
	Browser.println ('	activeLabelColor=' + activeLabelColor.toString());

	Browser.println ('	resetToStartLabelColor=' + resetToStartLabelColor.toString());
	Browser.println ('	fastRewindLabelColor=' + fastRewindLabelColor.toString());
	Browser.println ('	rewindLabelColor=' + rewindLabelColor.toString());
	Browser.println ('	pauseLabelColor=' + pauseLabelColor.toString());
	Browser.println ('	playLabelColor=' + playLabelColor.toString());
	Browser.println ('	fastForwardLabelColor=' + fastForwardLabelColor.toString());
	Browser.println ('	resetToEndLabelColor=' + resetToEndLabelColor.toString());
}
function initialize()
{
	tracePrint ('initialize() starting...');
	if (!playEnabled)
	{
		resetToStartButtonColor = buttonColor;
		fastRewindButtonColor   = buttonColor;
		rewindButtonColor       = buttonColor;
		pauseButtonColor        = activeButtonColor;
		playButtonColor         = buttonColor;
		fastForwardButtonColor  = buttonColor;
		resetToEndButtonColor   = buttonColor;

		resetToStartLabelColor  = labelColor;
		fastRewindLabelColor    = labelColor;
		rewindLabelColor        = labelColor;
		pauseLabelColor         = activeLabelColor;
		playLabelColor          = labelColor;
		fastForwardLabelColor   = labelColor;
		resetToEndLabelColor    = labelColor;

		isPaused = true;
		isRunning = false;
		TraceLabelColors ();
	}
	else //	playEnabled == true
	{
		playToggleEnabled(true, -1); // dummy timeStamp
		playToggleArmed = false;
	}
	tracePrint ('...initialize() complete');
}
function setIsActive(value, timeStamp)
{
	isActive = value;
}
function resetToStartToggleEnabled(value, timeStamp)
{
	if (value == false) return;
	tracePrint ('resetToStartToggleEnabled (' + value + ')' + ', resetToStartToggleArmed=' + resetToStartToggleArmed);

	if (!resetToStartToggleArmed)
	{
		resetToStartButtonColor = activeButtonColor;
		resetToStartLabelColor  = activeLabelColor;
		resetToStartToggleArmed = true;
		return;
	}
	isPaused  = true;
	isRunning = false;
	resetToStartChanged = true;

	if (!isActive) return;

	resetToStartButtonColor = activeButtonColor;
	fastRewindButtonColor   = buttonColor;
	rewindButtonColor       = buttonColor;
	pauseButtonColor        = buttonColor;
	playButtonColor         = buttonColor;
	fastForwardButtonColor  = buttonColor;
	resetToEndButtonColor   = buttonColor;

	resetToStartLabelColor = activeLabelColor;
	fastRewindLabelColor   = labelColor;
	rewindLabelColor       = labelColor;
	pauseLabelColor        = labelColor;
	playLabelColor         = labelColor;
	fastForwardLabelColor  = labelColor;
	resetToEndLabelColor   = labelColor;

	TraceLabelColors ();
}
function fastRewindToggleEnabled(value, timeStamp)
{
	if (value == false) return;
	tracePrint ('fastRewindToggleEnabled (' + value + ')' + ', fastRewindToggleArmed=' + fastRewindToggleArmed);

	if (fastRewindToggleArmed)
	{
		fastRewindToggleArmed = false;
		return;
	}
	isPaused  = true;
	isRunning = false;
	fastRewindChanged = true;

	if (!isActive) return;

	resetToStartButtonColor = buttonColor;
	fastRewindButtonColor   = activeButtonColor;
	rewindButtonColor       = buttonColor;
	pauseButtonColor        = buttonColor;
	playButtonColor         = buttonColor;
	fastForwardButtonColor  = buttonColor;
	resetToEndButtonColor   = buttonColor;

	resetToStartLabelColor = labelColor;
	fastRewindLabelColor   = activeLabelColor;
	rewindLabelColor       = labelColor;
	pauseLabelColor        = labelColor;
	playLabelColor         = labelColor;
	fastForwardLabelColor  = labelColor;
	resetToEndLabelColor   = labelColor;

	TraceLabelColors ();
}

function rewindToggleEnabled(value, timeStamp)
{
	if (value == false) return;
	tracePrint ('rewindToggleEnabled (' + value + ')' + ', rewindToggleArmed=' + rewindToggleArmed);

	if (rewindToggleArmed)
	{
		rewindToggleArmed = false;
		return;
	}
	isPaused  = true;
	isRunning = false;
	rewindChanged = true;

	if (!isActive) return;

	resetToStartButtonColor = buttonColor;
	fastRewindButtonColor   = buttonColor;
	rewindButtonColor       = activeButtonColor;
	pauseButtonColor        = buttonColor;
	playButtonColor         = buttonColor;
	fastForwardButtonColor  = buttonColor;
	resetToEndButtonColor   = buttonColor;

	resetToStartLabelColor = labelColor;
	fastRewindLabelColor   = labelColor;
	rewindLabelColor       = activeLabelColor;
	pauseLabelColor        = labelColor;
	playLabelColor         = labelColor;
	fastForwardLabelColor  = labelColor;
	resetToEndLabelColor   = labelColor;

	TraceLabelColors ();
}

function pauseToggleEnabled(value, timeStamp)
{
	if (value == false) return;
	tracePrint ('pauseToggleEnabled (' + value + ')' + ', pauseToggleArmed=' + pauseToggleArmed);

	if (pauseToggleArmed)
	{
		pauseToggleArmed = false;
		return;
	}
	isPaused  = true;
	isRunning = false;
	pauseChanged = true;

	if (!isActive) return;

	resetToStartButtonColor = buttonColor;
	fastRewindButtonColor   = buttonColor;
	rewindButtonColor       = buttonColor;
	pauseButtonColor        = activeButtonColor;
	playButtonColor         = buttonColor;
	fastForwardButtonColor  = buttonColor;
	resetToEndButtonColor   = buttonColor;

	resetToStartLabelColor = labelColor;
	fastRewindLabelColor   = labelColor;
	rewindLabelColor       = labelColor;
	pauseLabelColor        = activeLabelColor;
	playLabelColor         = labelColor;
	fastForwardLabelColor  = labelColor;
	resetToEndLabelColor   = labelColor;

	TraceLabelColors ();
}

function playToggleEnabled(value, timeStamp)
{
	if (value == false) return;
	tracePrint ('playToggleEnabled (' + value + ')' + ', pauseToggleArmed=' + playToggleArmed);

	if (playToggleArmed)
	{
		playToggleArmed = false;
		return;
	}
	isPaused  = false;
	isRunning = true;
	playChanged = true;

	if (!isActive) return;

	resetToStartButtonColor = buttonColor;
	fastRewindButtonColor   = buttonColor;
	rewindButtonColor       = buttonColor;
	pauseButtonColor        = buttonColor;
	playButtonColor         = activeButtonColor;
	fastForwardButtonColor  = buttonColor;
	resetToEndButtonColor   = buttonColor;

	resetToStartLabelColor = labelColor;
	fastRewindLabelColor   = labelColor;
	rewindLabelColor       = labelColor;
	pauseLabelColor        = labelColor;
	playLabelColor         = activeLabelColor;
	fastForwardLabelColor  = labelColor;
	resetToEndLabelColor   = labelColor;

	TraceLabelColors ();
}

function fastForwardToggleEnabled(value, timeStamp)
{
	if (value == false) return;
	tracePrint ('fastForwardToggleEnabled (' + value + ')' + ', fastForwardToggleArmed=' + fastForwardToggleArmed);

	if (fastForwardToggleArmed)
	{
		fastForwardToggleArmed = false;
		return;
	}
	isPaused  = false;
	isRunning = true;
	fastForwardChanged = true;

	if (!isActive) return;

	resetToStartButtonColor = buttonColor;
	fastRewindButtonColor   = buttonColor;
	rewindButtonColor       = buttonColor;
	pauseButtonColor        = buttonColor;
	playButtonColor         = buttonColor;
	fastForwardButtonColor  = activeButtonColor;
	resetToEndButtonColor   = buttonColor;

	resetToStartLabelColor = labelColor;
	fastRewindLabelColor   = labelColor;
	rewindLabelColor       = labelColor;
	pauseLabelColor        = labelColor;
	playLabelColor         = labelColor;
	fastForwardLabelColor  = activeLabelColor;
	resetToEndLabelColor   = labelColor;

	TraceLabelColors ();
}

function resetToEndToggleEnabled(value, timeStamp)
{
	if (value == false) return;
	tracePrint ('resetToEndToggleEnabled (' + value + ')' + ', resetToEndToggleArmed=' + resetToEndToggleArmed);

	if (!resetToEndToggleArmed)
	{
		resetToEndButtonColor = activeButtonColor;
		resetToEndLabelColor = activeLabelColor;
		resetToEndToggleArmed = true;
		return;
	}
	isPaused  = true;
	isRunning = false;
	resetToEndChanged = true;

	if (!isActive) return;

	resetToStartButtonColor = buttonColor;
	fastRewindButtonColor   = buttonColor;
	rewindButtonColor       = buttonColor;
	pauseButtonColor        = buttonColor;
	playButtonColor         = buttonColor;
	fastForwardButtonColor  = buttonColor;
	resetToEndButtonColor   = activeButtonColor;

	resetToStartLabelColor = labelColor;
	fastRewindLabelColor   = labelColor;
	rewindLabelColor       = labelColor;
	pauseLabelColor        = labelColor;
	playLabelColor         = labelColor;
	fastForwardLabelColor  = labelColor;
	resetToEndLabelColor   = activeLabelColor;

	TraceLabelColors ();
}
""")
                        .addField(new field().setName("description").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                        .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                        .addField(new field().setName("playEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                        .addField(new field().setName("buttonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                        .addField(new field().setName("activeButtonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                        .addField(new field().setName("labelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                        .addField(new field().setName("activeLabelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                        .addField(new field().setName("isActive").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(true))
                        .addField(new field().setName("setIsActive").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                        .addField(new field().setName("resetToStartToggleArmed").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false))
                        .addField(new field().setName("fastRewindToggleArmed").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false))
                        .addField(new field().setName("rewindToggleArmed").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false))
                        .addField(new field().setName("pauseToggleArmed").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false))
                        .addField(new field().setName("playToggleArmed").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false))
                        .addField(new field().setName("fastForwardToggleArmed").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false))
                        .addField(new field().setName("resetToEndToggleArmed").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false))
                        .addField(new field().setName("resetToStartToggleEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                        .addField(new field().setName("fastRewindToggleEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                        .addField(new field().setName("rewindToggleEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                        .addField(new field().setName("pauseToggleEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                        .addField(new field().setName("playToggleEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                        .addField(new field().setName("fastForwardToggleEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                        .addField(new field().setName("resetToEndToggleEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
                        .addField(new field().setName("resetToStartButtonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("resetToStartLabelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("fastRewindButtonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("fastRewindLabelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("rewindButtonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("rewindLabelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("pauseButtonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("pauseLabelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("playButtonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("playLabelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("fastForwardButtonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("fastForwardLabelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("resetToEndButtonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("resetToEndLabelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("isPaused").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("isRunning").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("resetToStartChanged").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("fastRewindChanged").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("rewindChanged").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("pauseChanged").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("playChanged").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("fastForwardChanged").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .addField(new field().setName("resetToEndChanged").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                        .setIS(new IS()
                          .addConnect(new connect().setNodeField("description").setProtoField("description"))
                          .addConnect(new connect().setNodeField("traceEnabled").setProtoField("traceEnabled"))
                          .addConnect(new connect().setNodeField("playEnabled").setProtoField("playEnabled"))
                          .addConnect(new connect().setNodeField("buttonColor").setProtoField("buttonColor"))
                          .addConnect(new connect().setNodeField("activeButtonColor").setProtoField("selectedButtonColor"))
                          .addConnect(new connect().setNodeField("labelColor").setProtoField("labelColor"))
                          .addConnect(new connect().setNodeField("activeLabelColor").setProtoField("selectedLabelColor"))
                          .addConnect(new connect().setNodeField("isPaused").setProtoField("isPaused"))
                          .addConnect(new connect().setNodeField("isRunning").setProtoField("isRunning"))))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("arePlaybackButtonsActive").setToNode("PlaybackControlScript").setToField("setIsActive"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("resetToStartEnabled").setToNode("PlaybackControlScript").setToField("resetToStartToggleEnabled"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("playbackButtonLabelColor").setToNode("ResetToStartLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("playbackButtonLabelColor").setToNode("FastRewindLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("playbackButtonLabelColor").setToNode("RewindLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("playbackButtonLabelColor").setToNode("PauseLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("playbackButtonLabelColor").setToNode("PlayLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("playbackButtonLabelColor").setToNode("FastForwardLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("playbackButtonLabelColor").setToNode("ResetToEndLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("arePlaybackButtonsActive").setToNode("ResetToStartSensor").setToField("enabled"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("arePlaybackButtonsActive").setToNode("FastRewindSensor").setToField("enabled"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("arePlaybackButtonsActive").setToNode("RewindSensor").setToField("enabled"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("arePlaybackButtonsActive").setToNode("PauseSensor").setToField("enabled"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("arePlaybackButtonsActive").setToNode("PlaySensor").setToField("enabled"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("arePlaybackButtonsActive").setToNode("FastForwardSensor").setToField("enabled"))
                      .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("arePlaybackButtonsActive").setToNode("ResetToEndSensor").setToField("enabled"))
                      .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("resetToStartButtonColor").setToNode("ResetToStartButtonMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("resetToStartLabelColor").setToNode("ResetToStartLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("fastRewindButtonColor").setToNode("FastRewindButtonMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("fastRewindLabelColor").setToNode("FastRewindLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("rewindButtonColor").setToNode("RewindButtonMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("rewindLabelColor").setToNode("RewindLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("pauseButtonColor").setToNode("PauseButtonMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("pauseLabelColor").setToNode("PauseLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("playButtonColor").setToNode("PlayButtonMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("playLabelColor").setToNode("PlayLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("fastForwardButtonColor").setToNode("FastForwardButtonMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("fastForwardLabelColor").setToNode("FastForwardLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("resetToEndButtonColor").setToNode("ResetToEndButtonMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("resetToEndLabelColor").setToNode("ResetToEndLabelMaterial").setToField("diffuseColor"))
                      .addChild(new ROUTE().setFromNode("ResetToStartSensor").setFromField("isActive").setToNode("PlaybackControlScript").setToField("resetToStartToggleEnabled"))
                      .addChild(new ROUTE().setFromNode("FastRewindSensor").setFromField("isActive").setToNode("PlaybackControlScript").setToField("fastRewindToggleEnabled"))
                      .addChild(new ROUTE().setFromNode("RewindSensor").setFromField("isActive").setToNode("PlaybackControlScript").setToField("rewindToggleEnabled"))
                      .addChild(new ROUTE().setFromNode("PauseSensor").setFromField("isActive").setToNode("PlaybackControlScript").setToField("pauseToggleEnabled"))
                      .addChild(new ROUTE().setFromNode("PlaySensor").setFromField("isActive").setToNode("PlaybackControlScript").setToField("playToggleEnabled"))
                      .addChild(new ROUTE().setFromNode("FastForwardSensor").setFromField("isActive").setToNode("PlaybackControlScript").setToField("fastForwardToggleEnabled"))
                      .addChild(new ROUTE().setFromNode("ResetToEndSensor").setFromField("isActive").setToNode("PlaybackControlScript").setToField("resetToEndToggleEnabled"))))
                  .addChild(new Transform("DisplayDISModeMid").setTranslation(2.86,0.0,0.0)
                    .addChild(new Transform().setUSE("DISModeButtons")))
                  .addChild(new Transform("DisplayNoneMid")))
                .addChild(new ROUTE().setFromNode("DisplayLayerScript").setFromField("midLayerSwitchSelection").setToNode("MidLayerSwitch").setToField("whichChoice"))
                .addChild(new Switch("BottomLayerSwitch").setWhichChoice(0)
                  .addChild(new Transform("DisplaySliderBottom").setTranslation(2.86,-0.58,0.0)
                    .addChild(new Transform("TimeScale")
                      .addChild(new Shape().setUSE("GroupButtonBaseShape"))
                      .addChild(new Transform().setTranslation(0.0,-0.15,0.0)
                        .addChild(new ProtoInstance("SliderFloat", "Slider").setContainerField("children")
                          .addFieldValue(new fieldValue().setName("layoutDirection").setValue("horizontal"))
                          .addFieldValue(new fieldValue().setName("height").setValue(4.725))
                          .addFieldValue(new fieldValue().setName("radius").setValue(0.1))
                          .addFieldValue(new fieldValue().setName("barRadius").setValue(0.035))
                          .addFieldValue(new fieldValue().setName("min").setValue(0.0))
                          .addFieldValue(new fieldValue().setName("max").setValue(1.0))
                          .addFieldValue(new fieldValue().setName("value").setValue(0.0))
                          .addFieldValue(new fieldValue().setName("traceEnabled").setValue(true))))
                      .addChild(new Transform().setTranslation(0.0,0.0,0.05)
                        .addChild(new Transform().setTranslation(-1.4,0.0,0.0)
                          .addChild(new Shape()
                            .setAppearance(new Appearance("TimeLabelAppearance")
                              .setMaterial(new Material("TimeLabelMaterial")
                                .setIS(new IS()
                                  .addConnect(new connect().setNodeField("diffuseColor").setProtoField("labelColor")))))
                            .setGeometry(new Text("DurationText").setString(new String[] {"00h00m00s"})
                              .setFontStyle(new FontStyle("TimeLabelFont").setSize(0.2).setCssStyle("ITALIC")))))
                        .addChild(new Transform().setTranslation(-2.4,0.0,0.0)
                          .addChild(new Shape()
                            .setAppearance(new Appearance().setUSE("TimeLabelAppearance"))
                            .setGeometry(new Text().setString(new String[] {"duration:"})
                              .setFontStyle(new FontStyle().setUSE("TimeLabelFont")))))
                        .addChild(new Transform().setTranslation(0.0,0.0,0.0)
                          .addChild(new Shape()
                            .setAppearance(new Appearance()
                              .setMaterial(new Material().setUSE("TimeLabelMaterial")))
                            .setGeometry(new Text().setString(new String[] {"elapsed:"})
                              .setFontStyle(new FontStyle().setUSE("TimeLabelFont")))))
                        .addChild(new Transform().setTranslation(0.9,0.0,0.0)
                          .addChild(new Shape()
                            .setAppearance(new Appearance()
                              .setMaterial(new Material().setUSE("TimeLabelMaterial")))
                            .setGeometry(new Text("secondsElapsedText").setString(new String[] {"00h00m00s"})
                              .setFontStyle(new FontStyle().setUSE("TimeLabelFont")))))
                        .addChild(new Script("TimeScaleScript").setSourceCode("""
ecmascript:

function tracePrint (text)
{
	if (traceEnabled) forcePrint (text);
}

function forcePrint (text)
{
	Browser.println ('[DvdController ' + description + ' TimeScaleScript] ' + text);
}

function initialize()
{
        tracePrint ('initialize duration:');
	set_duration(duration, -1); // dummy timeStamp
	secondsElapsedOutput = new MFString('00h00m00s');
}

function set_duration(value, timeStamp)
{
	duration = Math.floor(value);
        tracePrint ('set_cycleInterval value=' + value + ', duration=' + duration);
	durationOutput = new MFString(printTime(duration));
        forcePrint ('duration=' + durationOutput.toString());
}

function setSecondsElapsed(value, timeStamp)
{
	secondsElapsed = Math.floor(value);
	secondsElapsedOutput = new MFString(printTime(secondsElapsed));
        tracePrint ('secondsElapsedOutput=' + secondsElapsedOutput.toString());
}

function printTime(value)
{
	timeInSeconds = value;
	seconds = timeInSeconds % 60;
	minute = ((timeInSeconds - seconds) / 60) % 60;
	hour = (timeInSeconds - minute * 60 - seconds) / 3600;
	hStr = (hour    < 10 ? '0' + hour    : '' + hour);
	mStr = (minute  < 10 ? '0' + minute  : '' + minute);
	sStr = (seconds < 10 ? '0' + seconds : '' + seconds);
	timeString = new SFString( hStr + 'h' + mStr + 'm' + sStr + 's');
        tracePrint ('timeString=' + timeString.toString());
	return timeString;
}
""")
                          .addField(new field().setName("description").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                          .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
                          .addField(new field().setName("duration").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INPUTOUTPUT))
                          .addField(new field().setName("secondsElapsed").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0))
                          .addField(new field().setName("setSecondsElapsed").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INPUTONLY))
                          .addField(new field().setName("durationOutput").setType(field.TYPE_MFSTRING).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                          .addField(new field().setName("secondsElapsedOutput").setType(field.TYPE_MFSTRING).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
                          .setIS(new IS()
                            .addConnect(new connect().setNodeField("description").setProtoField("description"))
                            .addConnect(new connect().setNodeField("traceEnabled").setProtoField("traceEnabled"))
                            .addConnect(new connect().setNodeField("duration").setProtoField("cycleInterval"))))
                        .addChild(new ROUTE().setFromNode("TimeScaleScript").setFromField("durationOutput").setToNode("DurationText").setToField("string"))
                        .addChild(new ROUTE().setFromNode("TimeScaleScript").setFromField("secondsElapsedOutput").setToNode("secondsElapsedText").setToField("string")))))
                  .addChild(new Transform("DisplayDISModeBottom").setTranslation(2.86,-0.58,0.0)
                    .addChild(new Transform().setUSE("DISModeButtons")))
                  .addChild(new Transform("DisplayPlaybackButtonsBottom").setTranslation(2.86,-0.58,0.0)
                    .addChild(new Transform().setUSE("PlaybackButtons")))
                  .addChild(new Transform("DisplayNoneBottom")))
                .addChild(new ROUTE().setFromNode("DisplayLayerScript").setFromField("bottomLayerSwitchSelection").setToNode("BottomLayerSwitch").setToField("whichChoice")))
              .addChild(new ROUTE().setFromNode("PlaneMovementSensor").setFromField("translation_changed").setToNode("MovableLocation").setToField("set_translation"))
              .addChild(new ROUTE().setFromNode("VisibilityControlScript").setFromField("translationChanged").setToNode("MovableLocation").setToField("set_translation"))
              .addChild(new ROUTE().setFromNode("VisibilityControlScript").setFromField("translationOffsetChanged").setToNode("PlaneMovementSensor").setToField("set_offset"))))
          .addChild(new ROUTE().setFromNode("WhereSensor").setFromField("position_changed").setToNode("FixedLocation").setToField("set_translation"))
          .addChild(new ROUTE().setFromNode("WhereSensor").setFromField("orientation_changed").setToNode("FixedLocation").setToField("set_rotation"))
          .addChild(new TimeSensor("ForwardClock"))
          .addChild(new TimeSensor("FastForwardClock"))
          .addChild(new TimeSensor("RewindClock"))
          .addChild(new TimeSensor("FastRewindClock"))
          .addChild(new TimeSensor("SliderClock"))
          .addChild(new Script("ClockScript").setSourceCode("""
ecmascript:

function tracePrint (text)
{
	if (traceEnabled) Browser.println ('[DvdController ' + description + ' ClockScript] ' + text);
}
function alwaysPrint(output)
{
	Browser.println ('[DvdController ' + description + ' ClockScript] ' + output);
}

function initialize()
{
	isResetToStart = false;
	isFastRewind = false;
	isRewinding = false;
	isPlaying = false;
	isFastForward = false;
	isResetToEnd = false;

	durationChanged = duration;
	forwardCycleInterval = duration;
	fastForwardCycleInterval = duration;
	rewindCycleInterval = duration;
	fastRewindCycleInterval = duration;
	sliderClockCycleInterval = duration;

	fraction = 0;
	fastRewind_level = 0;
	fastForward_level = 0;
	sliderClockStart_fraction = 0;
}

function set_duration(value, timeStamp)
{
	duration = value;
	durationChanged = value;
	forwardCycleInterval = duration;
	fastForwardCycleInterval = duration;
	rewindCycleInterval = duration;
	fastRewindCycleInterval = duration;
	sliderClockCycleInterval = duration;
	alwaysPrint ('set_duration (' + duration + ') complete');
}

function setarePlaybackButtonsActive(value, timeStamp)
{
	arePlaybackButtonsActive = value;
	tracePrint('arePlaybackButtonsActive=' + arePlaybackButtonsActive);
}

function setIsClockActive(value, timeStamp)
{
	isClockActive = isClockActiveChanged = value;
	tracePrint('isClockActive=' + isClockActive);
}

function setResetToStart(value, timeStamp)
{
	tracePrint('setResetToStart(' + value + ')');
	isResetToStart = true;

	//Stop all clocks
	isPlaying = false;
	isRewinding = false;
	isFastForward = false;
	isFastRewind = false;
	sliderClockEnabled = false;

	fraction = fraction_changed = 0.0;
	secondsElapsed = 0.0;
	startTime = startTime_changed = timeStamp;
	stopTime = stopTime_changed = startTime + duration;
	deactivateButtonColorChanged = deactivateButtonColor;

	if (!arePlaybackButtonsActive)
		return;

	deactivateLabelColorChanged = deactivateLabelColor;
}

function setFastRewind(value, timeStamp)
{
	tracePrint('setFastRewind(' + value + ')');
	if (!isFastRewind)
		fastRewindStart_fraction = fraction;

	isFastRewind = true;
	isPlaying = false;
	isRewinding = false;
	isFastForward = false;
	sliderClockEnabled = false;

	if (fastRewind_level < 1)
	{
		++fastRewind_level;
		fastRewindCycleInterval = duration / (speedFactor * fastRewind_level);
	}

	if (fraction == 0) //start reached
	{
		deactivateButtonColorChanged = deactivateButtonColor;
		deactivateLabelColorChanged = deactivateLabelColor;
		return;
	}

	fastRewindStartTime = timeStamp;
	fastRewindStopTime = fastRewindStartTime + secondsElapsed / (speedFactor * fastRewind_level);

	startTime = startTime_changed = fastRewindStopTime;
}

function setRewind(value, timeStamp)
{
	tracePrint('setRewind(' + value + ')');
	if (!isRewinding)
		rewindStart_fraction = fraction;

	isRewinding = true;
	isPlaying = false;
	isFastForward = false;
	isFastRewind = false;
	sliderClockEnabled = false;

	fastRewind_level = 0;  //reset
	rewindCycleInterval = duration;

	if (fraction == 0)  //start reached
	{
		deactivateButtonColorChanged = deactivateButtonColor;
		deactivateLabelColorChanged = deactivateLabelColor;
		return;
	}

	rewindStartTime = timeStamp;
	rewindStopTime = rewindStartTime + secondsElapsed;

	startTime = startTime_changed = rewindStopTime;
}

function setPaused(value, timeStamp)
{
	tracePrint('setPaused(' + value + ')');
	if (value == true)
	{
		now = new Date();
		pauseTime = now.getTime() / 1000.0;

		isFastRewind = false;
		isRewinding = false;
		isPlaying = false;
		isFastForward = false;
		sliderClockEnabled = false;
	}
}

function setPlay(value, timeStamp)
{
	tracePrint('setPlay(' + value + ')');
	isPlaying = true;
	isRewinding = false;
	isFastForward = false;
	isFastRewind = false;
	sliderClockEnabled = false;

	fastRewind_level = 0; //reset fast rewind
	forwardCycleInterval = duration;

	if (fraction == 0 || fraction == 1)  //start or restart from beginning
	{
		startTime = startTime_changed = timeStamp;
		stopTime = stopTime_changed = startTime + duration;
	}
	else
	{
		startTime = startTime_changed = timeStamp - secondsElapsed;
		stopTime = stopTime_changed = startTime + duration;
	}
}

function setFastForward(value, timeStamp)
{
	tracePrint('setFastForward(' + value + ')');
	isFastForward = true;
	isPlaying = false;
	isRewinding = false;
	isFastRewind = false;
	sliderClockEnabled = false;

	if (fastForward_level < 1)
	{
		++fastForward_level;
		fastForwardCycleInterval = duration / (speedFactor * fastForward_level);
	}

	fastForwardStartTime = timeStamp - secondsElapsed / (speedFactor * fastForward_level);
	fastForwardStopTime = fastForwardStartTime + duration / (speedFactor * fastForward_level);

	startTime = startTime_changed = fastForwardStartTime;
}

function setResetToEnd(value, timeStamp)
{
	tracePrint('setResetToEnd(' + value + ')');
	isResetToEnd = true;

	//Stop all clocks
	isPlaying = false;
	isRewinding = false;
	isFastForward = false;
	isFastRewind = false;
	sliderClockEnabled = false;

	fraction = fraction_changed = 1.0;
	secondsElapsed = duration;

	stopTime = stopTime_changed = timeStamp;
	startTime = startTime_changed = stopTime - duration;
	deactivateButtonColorChanged = deactivateButtonColor;
	deactivateLabelColorChanged = deactivateLabelColor;
}

function setFraction(value, timeStamp)
{
	if (isRewinding || isFastForward || isFastRewind || sliderClockEnabled || sliderDragArmed)
        {
//              tracePrint('setFraction immediate return..');
		return;
        }
//	tracePrint('setFraction(' + value + ')');

	if (isResetToStart)
	{
                tracePrint('setFraction isResetToStart=true, reset..');
		isResetToStart = false; //reset
		return;
	}
	else if (isResetToEnd)
	{
                tracePrint('setFraction isResetToEnd=true, reset..');
		isResetToEnd = false; //reset
		return;
	}

	fraction = fraction_changed = value;
        tracePrint('fraction_changed=' + fraction_changed);

	if (fraction >= 1) //end reached
	{
		deactivateButtonColorChanged = deactivateButtonColor;
		deactivateLabelColorChanged = deactivateLabelColor;
		fraction = fraction_changed = 1.0;
	}
}

function setFastForwardFraction(value, timeStamp)
{
	tracePrint('setFastForwardFraction(' + value + ')');
	if (isPlaying || isFastRewind || isRewinding || sliderClockEnabled || sliderDragArmed)
		return;

	if (isResetToStart)
	{
		isResetToStart = false; //reset
		return;
	}
	else if (isResetToEnd)
	{
		isResetToEnd = false; //reset
		return;
	}

	fraction = fraction_changed = value;

	if (fraction >= 1) //end reached
	{
		deactivateButtonColorChanged = deactivateButtonColor;
		deactivateLabelColorChanged = deactivateLabelColor;
		isFastForward = false;
		fraction = fraction_changed = 1.0;
		secondsElapsed = duration;
	}
}

function setRewindFraction(value, timeStamp)
{
	tracePrint('setRewindFraction(' + value + ')');
	if (isPlaying || isFastForward || isFastRewind || sliderClockEnabled || sliderDragArmed)
		return;

	if (isResetToStart)
	{
		isResetToStart = false; //reset
		return;
	}
	else if (isResetToEnd)
	{
		isResetToEnd = false; //reset
		return;
	}

	fraction = fraction_changed = 1 - value - (1 - rewindStart_fraction);

	if (fraction <= 0.0000001) //start reached - rounded off
	{
		deactivateButtonColorChanged = deactivateButtonColor;
		deactivateLabelColorChanged  = deactivateLabelColor;
		isRewinding = false;
		fraction = fraction_changed = 0.0;
		secondsElapsed = 0.0;
	}
}

function setFastRewindFraction(value, timeStamp)
{
	tracePrint('setFastRewindFraction(' + value + ')');
	if (isPlaying || isFastForward || isRewinding || sliderClockEnabled || sliderDragArmed)
		return;

	if (isResetToStart)
	{
		isResetToStart = false; //reset
		return;
	}
	else if (isResetToEnd)
	{
		isResetToEnd = false; //reset
		return;
	}

	fraction = fraction_changed = 1 - value - (1 - fastRewindStart_fraction);

	if (fraction <= 0.0000001) //start reached - rounded off
	{
		deactivateButtonColorChanged = deactivateButtonColor;
		deactivateLabelColorChanged  = deactivateLabelColor;
		isFastRewind = false;
		fraction = fraction_changed = 0.0;
		fastRewindStart_fraction = -1; //reset
		secondsElapsed = 0.0;
	}
}

function setTime(value, timeStamp)
{
	// Check if pause option is selected
	if (!isPlaying && !isRewinding && !isFastForward && !isFastRewind && !sliderClockEnabled)
        {
                tracePrint('setTime(' + value + ') immediate return');
		return;
        }
	tracePrint('setTime(' + value + ')');

	time = time_changed = value; // time_changed is output event via IS/connect
	secondsElapsed = Math.abs(value - startTime);
        tracePrint ('time=' + time + ', secondsElapsed=' + secondsElapsed);
	if (isFastRewind)
		secondsElapsed = secondsElapsed * (speedFactor * fastRewind_level);
	else if (isFastForward)
		secondsElapsed = secondsElapsed * (speedFactor * fastForward_level);
	if (fraction == 0)
		secondsElapsed = 0.0;
	else if (fraction == 1)
		secondsElapsed = duration;
}

function setSliderDragged(value, timeStamp)
{
	if (value == true) //Drag started
	{
                tracePrint ('Drag started');
		preDrag_fraction = fraction;
		sliderDragArmed = true;

		isPlaying = false;
		isRewinding = false;
		isFastForward = false;
		isFastRewind = false;
		sliderClockEnabled = false;
	}
	else //Drag finished
	{
                tracePrint ('Drag finished');
		deactivateButtonColorChanged = deactivateButtonColor;
		deactivateLabelColorChanged  = deactivateLabelColor;
		sliderDragArmed = false;

		secondsElapsed = duration * fraction;

		sliderClockEnabled = true;
		if (fraction == 0 || fraction == 1) //start or end reached
			return;

		sliderClockCycleInterval = duration;
		if (fraction >= preDrag_fraction) //play
		{
			drag_forward = true;
			drag_backward = false;
			sliderClockStartTime = timeStamp - secondsElapsed;
			sliderClockStopTime = sliderClockStartTime + duration;
			startTime = startTime_changed = sliderClockStartTime;
			playButtonActivateColorChanged = activateButtonColor;
			playLabelActivateColorChanged  = activateLabelColor;
		}
		else if (fraction < preDrag_fraction) //rewind
		{
			drag_forward = false;
			drag_backward = true;
			sliderClockStartTime = timeStamp;
			sliderClockStopTime = timeStamp + secondsElapsed;
			startTime = startTime_changed = sliderClockStopTime;
			rewindButtonActivateColorChanged = activateButtonColor;
			rewindLabelActivateColorChanged  = activateLabelColor;
	}

		sliderClockStart_fraction = fraction;
	}
}

function setSliderDragFraction(value, timeStamp)
{
	if (isPlaying || isRewinding || isFastForward || isFastRewind || sliderClockEnabled)
        {
//              tracePrint('setSliderDragFraction immediate return');
		return;
        }
	tracePrint('setSliderDragFraction(' + value + ')');

	if (sliderDragArmed)
		fraction = fraction_changed = value;
}

function setSliderClockFraction(value, timeStamp)
{
	if (isPlaying || isRewinding || isFastForward || isFastRewind)
        {
//              tracePrint('setSliderClockFraction immediate return');
		return;
        }
	tracePrint('setSliderClockFraction(' + value + ')');

	if (isResetToStart)
	{
		isResetToStart = false; //reset
		return;
	}
	else if (isResetToEnd)
	{
		isResetToEnd = false; //reset
		return;
	}

	if (drag_forward)
		fraction = fraction_changed = value;
	else if (drag_backward)
		fraction = fraction_changed = 1 - value - (1 - sliderClockStart_fraction);

	if (fraction <= 0.0000001)
	{
		deactivateButtonColorChanged = deactivateButtonColor;
		deactivateLabelColorChanged  = deactivateLabelColor;
		sliderClockEnabled = false;
		fraction = fraction_changed = 0.0;
		secondsElapsed = 0.0;
	}
	else if (fraction >= 1)
	{
		deactivateButtonColorChanged = deactivateButtonColor;
		deactivateLabelColorChanged  = deactivateLabelColor;
		sliderClockEnabled = false;
		fraction = fraction_changed = 1.0;
		secondsElapsed = duration;
	}
}
""")
            .addField(new field().setName("description").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
            .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
            .addField(new field().setName("duration").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
            .addField(new field().setName("set_duration").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("durationChanged").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("forwardCycleInterval").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("fastForwardCycleInterval").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("rewindCycleInterval").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("fastRewindCycleInterval").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("sliderClockCycleInterval").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("speedFactor").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
            .addField(new field().setName("startTime").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(-1))
            .addField(new field().setName("startTime_changed").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("stopTime").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(-1))
            .addField(new field().setName("stopTime_changed").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("rewindStartTime").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("rewindStopTime").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("fastForwardStartTime").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("fastForwardStopTime").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("fastRewindStartTime").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("fastRewindStopTime").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("sliderClockStartTime").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("sliderClockStopTime").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("time").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(-1))
            .addField(new field().setName("setTime").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("time_changed").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("isClockActive").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false))
            .addField(new field().setName("setIsClockActive").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("isClockActiveChanged").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("secondsElapsed").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("fraction").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0))
            .addField(new field().setName("setFraction").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("setFastForwardFraction").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("setRewindFraction").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("setFastRewindFraction").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("setSliderDragFraction").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("setSliderClockFraction").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("fraction_changed").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("isResetToStart").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("setResetToStart").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("isFastRewind").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("setFastRewind").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("isRewinding").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("setRewind").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("setPaused").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("isPlaying").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("setPlay").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("isFastForward").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("setFastForward").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("isResetToEnd").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("setResetToEnd").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("sliderClockEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("sliderDragArmed").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(false))
            .addField(new field().setName("setSliderDragged").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("pauseTime").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(-1))
            .addField(new field().setName("activateButtonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
            .addField(new field().setName("activateLabelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
            .addField(new field().setName("deactivateButtonColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
            .addField(new field().setName("arePlaybackButtonsActive").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(true))
            .addField(new field().setName("setarePlaybackButtonsActive").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("deactivateButtonColorChanged").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("deactivateLabelColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
            .addField(new field().setName("deactivateLabelColorChanged").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("playButtonActivateColorChanged").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("playLabelActivateColorChanged").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("rewindButtonActivateColorChanged").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("rewindLabelActivateColorChanged").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("rewindStart_fraction").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0))
            .addField(new field().setName("fastRewindStart_fraction").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0))
            .addField(new field().setName("sliderClockStart_fraction").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0))
            .addField(new field().setName("fastRewind_level").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0))
            .addField(new field().setName("fastForward_level").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0))
            .addField(new field().setName("preDrag_fraction").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0))
            .setIS(new IS()
              .addConnect(new connect().setNodeField("description").setProtoField("description"))
              .addConnect(new connect().setNodeField("traceEnabled").setProtoField("traceEnabled"))
              .addConnect(new connect().setNodeField("deactivateButtonColor").setProtoField("buttonColor"))
              .addConnect(new connect().setNodeField("activateButtonColor").setProtoField("selectedButtonColor"))
              .addConnect(new connect().setNodeField("deactivateLabelColor").setProtoField("labelColor"))
              .addConnect(new connect().setNodeField("activateLabelColor").setProtoField("selectedLabelColor"))
              .addConnect(new connect().setNodeField("duration").setProtoField("cycleInterval"))
              .addConnect(new connect().setNodeField("set_duration").setProtoField("set_cycleInterval"))
              .addConnect(new connect().setNodeField("durationChanged").setProtoField("cycleInterval_changed"))
              .addConnect(new connect().setNodeField("speedFactor").setProtoField("speedFactor"))
              .addConnect(new connect().setNodeField("isClockActiveChanged").setProtoField("isActive"))
              .addConnect(new connect().setNodeField("startTime_changed").setProtoField("startTime_changed"))
              .addConnect(new connect().setNodeField("stopTime_changed").setProtoField("stopTime_changed"))
              .addConnect(new connect().setNodeField("time_changed").setProtoField("time_changed"))
              .addConnect(new connect().setNodeField("fraction_changed").setProtoField("fraction_changed"))
              .addConnect(new connect().setNodeField("secondsElapsed").setProtoField("secondsElapsed"))))
          .addChild(new ROUTE().setFromNode("DISModeScript").setFromField("arePlaybackButtonsActive").setToNode("ClockScript").setToField("setarePlaybackButtonsActive"))
          .addComments(" TODO use or remove <ROUTE fromField='arePlaybackButtonsActive' fromNode='DISModeScript' toField='setDragEnabled' toNode='Slider'/> ")
          .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("resetToStartChanged").setToNode("ClockScript").setToField("setResetToStart"))
          .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("fastRewindChanged").setToNode("ClockScript").setToField("setFastRewind"))
          .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("rewindChanged").setToNode("ClockScript").setToField("setRewind"))
          .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("pauseChanged").setToNode("ClockScript").setToField("setPaused"))
          .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("playChanged").setToNode("ClockScript").setToField("setPlay"))
          .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("fastForwardChanged").setToNode("ClockScript").setToField("setFastForward"))
          .addChild(new ROUTE().setFromNode("PlaybackControlScript").setFromField("resetToEndChanged").setToNode("ClockScript").setToField("setResetToEnd"))
          .addChild(new ROUTE().setFromNode("ForwardClock").setFromField("isActive").setToNode("ClockScript").setToField("setIsClockActive"))
          .addChild(new ROUTE().setFromNode("ForwardClock").setFromField("fraction_changed").setToNode("ClockScript").setToField("setFraction"))
          .addChild(new ROUTE().setFromNode("ForwardClock").setFromField("time").setToNode("ClockScript").setToField("setTime"))
          .addChild(new ROUTE().setFromNode("RewindClock").setFromField("isActive").setToNode("ClockScript").setToField("setIsClockActive"))
          .addChild(new ROUTE().setFromNode("RewindClock").setFromField("fraction_changed").setToNode("ClockScript").setToField("setRewindFraction"))
          .addChild(new ROUTE().setFromNode("RewindClock").setFromField("time").setToNode("ClockScript").setToField("setTime"))
          .addChild(new ROUTE().setFromNode("FastForwardClock").setFromField("isActive").setToNode("ClockScript").setToField("setIsClockActive"))
          .addChild(new ROUTE().setFromNode("FastForwardClock").setFromField("fraction_changed").setToNode("ClockScript").setToField("setFastForwardFraction"))
          .addChild(new ROUTE().setFromNode("FastForwardClock").setFromField("time").setToNode("ClockScript").setToField("setTime"))
          .addChild(new ROUTE().setFromNode("FastRewindClock").setFromField("isActive").setToNode("ClockScript").setToField("setIsClockActive"))
          .addChild(new ROUTE().setFromNode("FastRewindClock").setFromField("fraction_changed").setToNode("ClockScript").setToField("setFastRewindFraction"))
          .addChild(new ROUTE().setFromNode("FastRewindClock").setFromField("time").setToNode("ClockScript").setToField("setTime"))
          .addChild(new ROUTE().setFromNode("SliderClock").setFromField("isActive").setToNode("ClockScript").setToField("setIsClockActive"))
          .addChild(new ROUTE().setFromNode("SliderClock").setFromField("fraction_changed").setToNode("ClockScript").setToField("setSliderClockFraction"))
          .addChild(new ROUTE().setFromNode("SliderClock").setFromField("time").setToNode("ClockScript").setToField("setTime"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("isPlaying").setToNode("ForwardClock").setToField("set_enabled"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("isRewinding").setToNode("RewindClock").setToField("set_enabled"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("isFastForward").setToNode("FastForwardClock").setToField("set_enabled"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("isFastRewind").setToNode("FastRewindClock").setToField("set_enabled"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("sliderClockEnabled").setToNode("SliderClock").setToField("set_enabled"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("forwardCycleInterval").setToNode("ForwardClock").setToField("set_cycleInterval"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("rewindCycleInterval").setToNode("RewindClock").setToField("set_cycleInterval"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("fastForwardCycleInterval").setToNode("FastForwardClock").setToField("set_cycleInterval"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("fastRewindCycleInterval").setToNode("FastRewindClock").setToField("set_cycleInterval"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("sliderClockCycleInterval").setToNode("SliderClock").setToField("set_cycleInterval"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("startTime_changed").setToNode("ForwardClock").setToField("set_startTime"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("stopTime_changed").setToNode("ForwardClock").setToField("set_stopTime"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("rewindStartTime").setToNode("RewindClock").setToField("set_startTime"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("rewindStopTime").setToNode("RewindClock").setToField("set_stopTime"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("fastForwardStartTime").setToNode("FastForwardClock").setToField("set_startTime"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("fastForwardStopTime").setToNode("FastForwardClock").setToField("set_stopTime"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("fastRewindStartTime").setToNode("FastRewindClock").setToField("set_startTime"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("fastRewindStopTime").setToNode("FastRewindClock").setToField("set_stopTime"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("sliderClockStartTime").setToNode("SliderClock").setToField("set_startTime"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("sliderClockStopTime").setToNode("SliderClock").setToField("set_stopTime"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("fraction_changed").setToNode("Slider").setToField("setValue"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("deactivateButtonColorChanged").setToNode("ResetToStartButtonMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("deactivateLabelColorChanged").setToNode("ResetToStartLabelMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("deactivateButtonColorChanged").setToNode("FastRewindButtonMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("deactivateLabelColorChanged").setToNode("FastRewindLabelMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("deactivateButtonColorChanged").setToNode("RewindButtonMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("deactivateLabelColorChanged").setToNode("RewindLabelMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("deactivateButtonColorChanged").setToNode("PauseButtonMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("deactivateLabelColorChanged").setToNode("PauseLabelMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("deactivateButtonColorChanged").setToNode("PlayButtonMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("deactivateLabelColorChanged").setToNode("PlayLabelMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("deactivateButtonColorChanged").setToNode("FastForwardButtonMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("deactivateLabelColorChanged").setToNode("FastForwardLabelMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("deactivateButtonColorChanged").setToNode("ResetToEndButtonMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("deactivateLabelColorChanged").setToNode("ResetToEndLabelMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("playButtonActivateColorChanged").setToNode("PlayButtonMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("playLabelActivateColorChanged").setToNode("PlayLabelMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("rewindButtonActivateColorChanged").setToNode("RewindButtonMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("rewindLabelActivateColorChanged").setToNode("RewindLabelMaterial").setToField("diffuseColor"))
          .addChild(new ROUTE().setFromNode("Slider").setFromField("valueChanged").setToNode("ClockScript").setToField("setSliderDragFraction"))
          .addComments(" fix or omit <ROUTE fromField='isDragged' fromNode='Slider' toField='setSliderDragged' toNode='ClockScript'/> ")
          .addChild(new ROUTE().setFromNode("ClockScript").setFromField("secondsElapsed").setToNode("TimeScaleScript").setToField("setSecondsElapsed")))))
    .addComments(" ==================== ")
    .addChild(new Anchor().setDescription("DvdController Example").setUrl(new String[] {"DvdControllerExample.x3d","https://www.web3d.org/x3d/content/examples/Savage/Tools/HeadsUpDisplays/DvdControllerExample.x3d","DvdControllerExample.wrl","https://www.web3d.org/x3d/content/examples/Savage/Tools/HeadsUpDisplays/DvdControllerExample.wrl"})
      .addChild(new Shape()
        .setAppearance(new Appearance()
          .setMaterial(new Material().setDiffuseColor(0.0,1.0,1.0).setEmissiveColor(0.0,1.0,1.0)))
        .setGeometry(new Text().setString(new String[] {"DvdControllerPrototype","is a Prototype definition file.","","To see an example scene","select this text and view","DvdControllerExample"})
          .setFontStyle(new FontStyle().setJustify(FontStyle.JUSTIFY_MIDDLE_MIDDLE).setSize(0.8))))));
            }
            catch (Exception ex)
            {       
                System.err.println ("*** Further hints on X3DJSAIL errors and exceptions at");
                System.err.println ("*** https://www.web3d.org/specifications/java/X3DJSAIL.html");
                throw (ex);
            }
	}
	// end of initialize() method

	/** The initialized model object, created within initialize() method. */
	private X3D x3dModel;

	/** 
	 * Provide a 
	 * <a href="https://dzone.com/articles/java-copy-shallow-vs-deep-in-which-you-will-swim" target="_blank">shallow copy</a>
	 * of the X3D model.
	 * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3D.html">X3D</a>
	 * @return DvdControllerPrototype model
	 */
	public X3D getX3dModel()
	{	  
		return x3dModel;
	}
	   
    /** 
     * Default main() method provided for test purposes, uses CommandLine to set global ConfigurationProperties for this object.
     * @param args array of input parameters, provided as arguments
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3D.html#handleArguments-java.lang.String:A-">X3D.handleArguments(args)</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3D.html#validationReport--">X3D.validationReport()</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/CommandLine.html">CommandLine</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/CommandLine.html#USAGE">CommandLine.USAGE</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/ConfigurationProperties.html">ConfigurationProperties</a>
     */
    public static void main(String args[])
    {
        System.out.println("Build this X3D model, showing validation diagnostics...");
        X3D thisExampleX3dModel = new DvdControllerPrototype().getX3dModel();
//      System.out.println("X3D model construction complete.");
	
        // next handle command line arguments
        boolean hasArguments = (args != null) && (args.length > 0);
        boolean validate = true; // default
        boolean argumentsLoadNewModel = false;
        String  fileName = new String();

        if (args != null)
        {
                for (String arg : args)
                {
                        if (arg.toLowerCase().startsWith("-v") || arg.toLowerCase().contains("validate"))
                        {
                                validate = true; // making sure
                        }
                        if (arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_X3D) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_CLASSICVRML) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_X3DB) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_VRML97) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_EXI) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_GZIP) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_ZIP) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_HTML) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_XHTML))
                        {
                                argumentsLoadNewModel = true;
                                fileName = arg;
                        }
                }
        }
        if      (argumentsLoadNewModel)
                System.out.println("WARNING: \"Savage.Tools.HeadsUpDisplays.DvdControllerPrototype\" model invocation is attempting to load file \"" + fileName + "\" instead of simply validating itself... file loading ignored.");
        else if (hasArguments) // if no arguments provided, this method produces usage warning
                thisExampleX3dModel.handleArguments(args);
	
        if (validate)
        {
            //  System.out.println("--- TODO fix duplicated outputs ---"); // omit when duplicated outputs problem is solved/refactored
		String validationResults = thisExampleX3dModel.validationReport();
            //  System.out.println("-----------------------------------"); // omit when duplicated outputs problem is solved/refactored
                System.out.print("Savage.Tools.HeadsUpDisplays.DvdControllerPrototype self-validation test confirmation: ");
                if (!validationResults.equals("success"))
                    System.out.println();
                System.out.println(validationResults.trim());

                // experimental: test X3DJSAIL output files
                // Tools/HeadsUpDisplays/DvdControllerPrototype_JavaExport.* file validation is checked when building X3D Example Archives
                String filenameX3D  = "Tools/HeadsUpDisplays/DvdControllerPrototype_JavaExport.x3d"; 
                String filenameX3DV = "Tools/HeadsUpDisplays/DvdControllerPrototype_JavaExport.x3dv"; 
                String filenameJSON = "Tools/HeadsUpDisplays/DvdControllerPrototype_JavaExport.json";
                thisExampleX3dModel.toFileX3D        (filenameX3D);
                thisExampleX3dModel.toFileClassicVRML(filenameX3DV);
// TODO         thisExampleX3dModel.toFileJSON       (filenameJSON);
        }
    }
}
