package Savage.Tools.Animation;

import org.web3d.x3d.jsail.Core.*;
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.Scripting.*;
import org.web3d.x3d.jsail.Shape.*;
import org.web3d.x3d.jsail.Text.*;

// Javadoc metadata annotations follow, see below for X3DJSAIL Java source code.
/**
 * <p> A Slider prototype enabling mouse input where float output values are needed. Size, min/max values and color are defined by the author. </p>
 <p> Related links: Catalog page <a href="../../../../Tools/Animation/SliderFloatPrototypeIndex.html" target="_blank">SliderFloatPrototype</a>,  source <a href="../../../../Tools/Animation/SliderFloatPrototype.java">SliderFloatPrototype.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/Animation/SliderFloatPrototype.x3d">SliderFloatPrototype.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> description </i> </td>
			<td> A Slider prototype enabling mouse input where float output values are needed. Size, min/max values and color are defined by the author. </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> creator </i> </td>
			<td> Mike Hunsberger, Jane Wu </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> created </i> </td>
			<td> 17 October 2001 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> modified </i> </td>
			<td> 15 October 2023 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> subject </i> </td>
			<td> animation slider </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/Animation/SliderFloatPrototype.x3d" target="_blank">https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/SliderFloatPrototype.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/Animation/../../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 Mike Hunsberger, Jane Wu
 */

public class SliderFloatPrototype
{
	/** Default constructor to create this object. */
	public SliderFloatPrototype ()
	{
	  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("SliderFloatPrototype.x3d"))
    .addMeta(new meta().setName(meta.NAME_DESCRIPTION).setContent("A Slider prototype enabling mouse input where float output values are needed. Size, min/max values and color are defined by the author."))
    .addMeta(new meta().setName(meta.NAME_CREATOR    ).setContent("Mike Hunsberger, Jane Wu"))
    .addMeta(new meta().setName(meta.NAME_CREATED    ).setContent("17 October 2001"))
    .addMeta(new meta().setName(meta.NAME_MODIFIED   ).setContent("15 October 2023"))
    .addMeta(new meta().setName(meta.NAME_SUBJECT    ).setContent("animation slider"))
    .addMeta(new meta().setName(meta.NAME_IDENTIFIER ).setContent("https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/SliderFloatPrototype.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("SliderFloatPrototype.x3d"))
    .addChild(new ProtoDeclare("SliderFloat").setName("SliderFloat").setAppinfo("Slider user-interface widget that produces floating-point output values")
      .setProtoInterface(new ProtoInterface()
        .addField(new field().setName("layoutDirection").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue("vertical").setAppinfo("Allowed values: vertical, horizontal"))
        .addField(new field().setName("height").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(1.0).setAppinfo("default value 1.0"))
        .addField(new field().setName("radius").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0.1).setAppinfo("default value 0.1"))
        .addField(new field().setName("barRadius").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0.02).setAppinfo("default value 0.02"))
        .addField(new field().setName("sliderBarColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFColor(.8,.4,.8)).setAppinfo("default value .8 .4 .8"))
        .addField(new field().setName("sliderBallColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFColor(.3,.4,.8)).setAppinfo("default value .3 .4 .8"))
        .addField(new field().setName("sliderEndColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFColor(.2,.3,.9)).setAppinfo("default value .2 .3 .9"))
        .addField(new field().setName("min").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0.0).setAppinfo("default value 0.0"))
        .addField(new field().setName("max").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(10.0).setAppinfo("default value 10.0"))
        .addField(new field().setName("value").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0.0).setAppinfo("default value 0.0"))
        .addField(new field().setName("setMin").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("set minimum value for slider bar"))
        .addField(new field().setName("setMax").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("set maximum value for slider bar"))
        .addField(new field().setName("setValue").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("set value for slider bar"))
        .addField(new field().setName("valueChanged").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_OUTPUTONLY).setAppinfo("output value for slider bar"))
        .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 Group()
          .addChild(new Transform("LayoutDirectionTransform")
            .addChild(new Transform("SliderBarTransform")
              .addChild(new Shape()
                .setAppearance(new Appearance()
                  .setMaterial(new Material("SliderBarMaterial")
                    .setIS(new IS()
                      .addConnect(new connect().setNodeField("diffuseColor").setProtoField("sliderBarColor"))
                      .addConnect(new connect().setNodeField("emissiveColor").setProtoField("sliderBarColor")))))
                .setGeometry(new Cylinder("SliderBar")
                  .setIS(new IS()
                    .addConnect(new connect().setNodeField("height").setProtoField("height"))
                    .addConnect(new connect().setNodeField("radius").setProtoField("barRadius"))))))
            .addChild(new Transform("SliderBallTransform")
              .addChild(new PlaneSensor("SliderBallPlaneSensor").setDescription("select and drag to change values"))
              .addChild(new Shape()
                .setAppearance(new Appearance()
                  .setMaterial(new Material("SliderBallMaterial")
                    .setIS(new IS()
                      .addConnect(new connect().setNodeField("diffuseColor").setProtoField("sliderBallColor")))))
                .setGeometry(new Sphere("SliderBall")
                  .setIS(new IS()
                    .addConnect(new connect().setNodeField("radius").setProtoField("radius"))))))
            .addChild(new Transform("BottomEndTransform")
              .addChild(new TouchSensor("BottomEndSensor").setDescription("touch bottom end to decrement"))
              .addChild(new Shape()
                .setAppearance(new Appearance()
                  .setMaterial(new Material()
                    .setIS(new IS()
                      .addConnect(new connect().setNodeField("diffuseColor").setProtoField("sliderEndColor")))))
                .setGeometry(new Cylinder().setHeight(.05).setRadius(.1)))
              .addChild(new Transform().setTranslation(0.0,-0.1,0.0)
                .addChild(new Shape("TransparentEndShape")
                  .setAppearance(new Appearance()
                    .setMaterial(new Material().setTransparency(1)))
                  .setGeometry(new Box().setSize(0.2,0.2,0.01)))))
            .addChild(new Transform("TopEndTransform")
              .addChild(new TouchSensor("TopEndSensor").setDescription("touch top end to increment"))
              .addChild(new Shape()
                .setAppearance(new Appearance()
                  .setMaterial(new Material()
                    .setIS(new IS()
                      .addConnect(new connect().setNodeField("diffuseColor").setProtoField("sliderEndColor")))))
                .setGeometry(new Cylinder().setHeight(.05).setRadius(.1)))
              .addChild(new Transform().setTranslation(0.0,0.1,0.0)
                .addChild(new Shape().setUSE("TransparentEndShape"))))
            .addChild(new Script("SliderScript").setSourceCode("""
ecmascript:
function initialize()
{
	tracePrint('initialize() commenced...');

	beginPosition = new SFVec3f(0, (height/2) * (-1) + radius, 0);
	endPosition   = new SFVec3f(0, (height/2) - radius, 0);
	tracePrint('beginPosition=' + beginPosition.toString() + ', endPosition=' + endPosition.toString());
	incrementInterval = (height - (2 * radius)) / (max - min);
	tracePrint('incrementInterval=' + incrementInterval.toString());

	bottomEndPositionChanged = new SFVec3f(0, (height/2) * (-1), 0);
	topEndPositionChanged    = new SFVec3f(0, (height/2), 0);
	tracePrint('bottomEndPositionChanged=' + bottomEndPositionChanged.toString() + ', topEndPositionChanged=' + topEndPositionChanged.toString());

	minBallPositionChanged   = new SFVec2f(0, bottomEndPositionChanged.y + radius);
	maxBallPositionChanged   = new SFVec2f(0, topEndPositionChanged.y - radius);
	tracePrint('minBallPositionChanged=' + minBallPositionChanged.toString() + ', maxBallPositionChanged=' + maxBallPositionChanged.toString());

	ballPositionChanged = new SFVec3f(0, beginPosition.y + (incrementInterval * (value - min)), 0);
	lastBallPosition = ballPositionChanged;

	if (value < min) value = min;
	if (value > max) value = max;

	valueChanged = value;
	tracePrint('value=' + value.toString());
	tracePrint('...initialize() complete');
}

function setMin(inputValue, timeStamp)
{
	min = inputValue;
	if (value < min) value = min;

	incrementInterval = (height - (2 * radius)) / (max - min);
	tracePrint('incrementInterval=' + incrementInterval.toString());

	ballPositionChanged = new SFVec3f(0, beginPosition.y + (incrementInterval * (value - min)), 0);
	lastBallPosition = ballPositionChanged;

	valueChanged = value;
	tracePrint('min=' + min + ', valueChanged=' + valueChanged);
}

function setMax(inputValue, timeStamp)
{
	max = inputValue;
	if (value > max) value = max;

	incrementInterval = (height - (2 * radius)) / (max - min);
	tracePrint('incrementInterval=' + incrementInterval.toString());

	ballPositionChanged = new SFVec3f(0, beginPosition.y + (incrementInterval * (value - min)), 0);
	lastBallPosition = ballPositionChanged;

	valueChanged = value;
	tracePrint('max=' + max + ', valueChanged=' + valueChanged);
}

function setValue(inputValue, timeStamp)
{
        if (inputValue <= min)
	{
		valueChanged = value = min;
		ballPositionChanged = beginPosition;
		lastBallPosition = ballPositionChanged;
	}
	else if (inputValue >= max)
	{
		valueChanged = value = max;
		ballPositionChanged = endPosition;
		lastBallPosition = ballPositionChanged;
	}
	else
	{
		if (inputValue > value) //getting bigger
		{
			ballPositionChanged = new SFVec3f(0, lastBallPosition.y + (incrementInterval * (inputValue - value)), 0);
			lastBallPosition = ballPositionChanged;
		}
		else if (inputValue < value) //getting smaller
		{
			ballPositionChanged = new SFVec3f(0, lastBallPosition.y - (incrementInterval * (value - inputValue)), 0);
			lastBallPosition = ballPositionChanged;
		}
		valueChanged = value = inputValue;
	}
	tracePrint('valueChanged=' + valueChanged);
}

function bottomEndTouched(inputValue, timeStamp)
{
	tracePrint('bottomEndTouched(' + inputValue.toString() + ')');
	if (inputValue == false) return; // ignore deselection

	if (value <= Math.round(value))
		value = Math.round(value);
	else
		value = Math.round(value) + 1;

	partialIncrement = incrementInterval * (valueChanged - (value - 1));

	if (value > min)
	{
		valueChanged = --value;
		if (partialIncrement != incrementInterval)
		{
			ballPositionChanged = new SFVec3f(0, lastBallPosition.y - partialIncrement, 0);
			partialIncrement = incrementInterval;
		}
		else    ballPositionChanged = new SFVec3f(0, lastBallPosition.y - incrementInterval, 0);
		lastBallPosition = ballPositionChanged;
	}
}

function topEndTouched(inputValue, timeStamp)
{
	tracePrint('topEndTouched(' + inputValue.toString() + ')');
	if (inputValue == false) return; // ignore deselection

	if (value < Math.round(value))
		value = Math.round(value) - 1;
	else    value = Math.round(value);

	partialIncrement = incrementInterval * (value + 1 - valueChanged);

	if (value < max)
	{
		valueChanged = ++value;
		if (partialIncrement != incrementInterval)
		{
			ballPositionChanged = new SFVec3f(0, lastBallPosition.y + partialIncrement, 0);
			partialIncrement = incrementInterval;
		}
		else    ballPositionChanged = new SFVec3f(0, lastBallPosition.y + incrementInterval, 0);
		lastBallPosition = ballPositionChanged;
	}
}

function setBallPosition(inputValue, timeStamp)
{
	tracePrint('setBallPosition(' + inputValue.toString() + ')');

	if (inputValue.y > lastBallPosition.y) // moving upwards
	{
		if (value >= max)
		{
			value = max;
			lastBallPosition = endPosition;
		}
		else
		{
			value = (inputValue.y - beginPosition.y) * ((max - min) / (endPosition.y - beginPosition.y));
			lastBallPosition = inputValue;
		}
		valueChanged = value;
		ballPositionChanged = lastBallPosition;
	}
	else if (inputValue.y < lastBallPosition.y) // moving downwards
	{
		if (value <= min)
		{
			value = min;
			lastBallPosition = beginPosition;
		}
		else
		{
			value = (inputValue.y - beginPosition.y) * ((max - min) / (endPosition.y - beginPosition.y));
			lastBallPosition = inputValue;
		}
		valueChanged = value;
		ballPositionChanged = lastBallPosition;
	}
}
function tracePrint (text)
{
	if (traceEnabled) Browser.println ('[SliderFloat SliderScript] ' + text);
}
""")
              .addComments(" local variables ")
              .addField(new field().setName("height").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
              .addField(new field().setName("radius").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
              .addField(new field().setName("min").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
              .addField(new field().setName("max").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
              .addField(new field().setName("value").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
              .addField(new field().setName("lastBallPosition").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFVec3f(0.0,0.0,0.0)))
              .addField(new field().setName("beginPosition").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFVec3f(0.0,0.0,0.0)))
              .addField(new field().setName("endPosition").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFVec3f(0.0,1.0,0.0)))
              .addField(new field().setName("incrementInterval").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0.1))
              .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("bottomEndTouched").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
              .addField(new field().setName("topEndTouched").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
              .addField(new field().setName("setBallPosition").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INPUTONLY))
              .addField(new field().setName("bottomEndPositionChanged").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
              .addField(new field().setName("topEndPositionChanged").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
              .addField(new field().setName("ballPositionChanged").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
              .addField(new field().setName("minBallPositionChanged").setType(field.TYPE_SFVEC2F).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
              .addField(new field().setName("maxBallPositionChanged").setType(field.TYPE_SFVEC2F).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
              .addField(new field().setName("partialIncrement").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(0.0))
              .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
              .setIS(new IS()
                .addConnect(new connect().setNodeField("height").setProtoField("height"))
                .addConnect(new connect().setNodeField("radius").setProtoField("radius"))
                .addConnect(new connect().setNodeField("min").setProtoField("min"))
                .addConnect(new connect().setNodeField("max").setProtoField("max"))
                .addConnect(new connect().setNodeField("value").setProtoField("value"))
                .addConnect(new connect().setNodeField("setMin").setProtoField("setMin"))
                .addConnect(new connect().setNodeField("setMax").setProtoField("setMax"))
                .addConnect(new connect().setNodeField("setValue").setProtoField("setValue"))
                .addConnect(new connect().setNodeField("valueChanged").setProtoField("valueChanged"))
                .addConnect(new connect().setNodeField("traceEnabled").setProtoField("traceEnabled"))))
            .addChild(new ROUTE().setFromNode("SliderBallPlaneSensor").setFromField("translation_changed").setToNode("SliderScript").setToField("setBallPosition"))
            .addChild(new ROUTE().setFromNode("BottomEndSensor").setFromField("isActive").setToNode("SliderScript").setToField("bottomEndTouched"))
            .addChild(new ROUTE().setFromNode("TopEndSensor").setFromField("isActive").setToNode("SliderScript").setToField("topEndTouched"))
            .addChild(new ROUTE().setFromNode("SliderScript").setFromField("minBallPositionChanged").setToNode("SliderBallPlaneSensor").setToField("set_minPosition"))
            .addChild(new ROUTE().setFromNode("SliderScript").setFromField("maxBallPositionChanged").setToNode("SliderBallPlaneSensor").setToField("set_maxPosition"))
            .addChild(new ROUTE().setFromNode("SliderScript").setFromField("bottomEndPositionChanged").setToNode("BottomEndTransform").setToField("set_translation"))
            .addChild(new ROUTE().setFromNode("SliderScript").setFromField("topEndPositionChanged").setToNode("TopEndTransform").setToField("set_translation"))
            .addChild(new ROUTE().setFromNode("SliderScript").setFromField("ballPositionChanged").setToNode("SliderBallTransform").setToField("set_translation")))
          .addChild(new Script("LayoutDirectionScript").setSourceCode("""
ecmascript:

function initialize ()
{
    if      ((direction=='vertical') || (direction=='Vertical') || (direction=='VERTICAL'))
    {
        directionRotation = new SFRotation(0, 0, 1, 0);
    }
    else if ((direction=='horizontal') || (direction=='Horizontal') || (direction=='HORIZONTAL'))
    {
        directionRotation = new SFRotation(0, 0, 1, -1.57);
    }
    else
    {
        Browser.println ('[SliderFloat LayoutDirectionScript] unrecognized direction: ' + direction + ', using vertical');
        directionRotation = new SFRotation(0, 0, 1, 0);
    }
    tracePrint ('direction=' + direction);
}
function tracePrint (text)
{
	if (traceEnabled) Browser.println ('[SliderFloat LayoutDirectionScript] ' + text);
}
""")
            .addField(new field().setName("direction").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
            .addField(new field().setName("directionRotation").setType(field.TYPE_SFROTATION).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
            .setIS(new IS()
              .addConnect(new connect().setNodeField("direction").setProtoField("layoutDirection"))
              .addConnect(new connect().setNodeField("traceEnabled").setProtoField("traceEnabled"))))
          .addChild(new ROUTE().setFromNode("LayoutDirectionScript").setFromField("directionRotation").setToNode("LayoutDirectionTransform").setToField("set_rotation")))))
    .addComments(" ==================== ")
    .addChild(new Anchor().setDescription("SliderFloatExample").setParameter(new String[] {"target=_blank"}).setUrl(new String[] {"SliderFloatExample.x3d","https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/SliderFloatExample.x3d","SliderFloatExample.wrl","https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/SliderFloatExample.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[] {"SliderFloatPrototype","is a Prototype definition file.","","To see an example scene","select this text and view","SliderFloatExample"})
          .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 SliderFloatPrototype 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 SliderFloatPrototype().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.Animation.SliderFloatPrototype\" 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.Animation.SliderFloatPrototype self-validation test confirmation: ");
                if (!validationResults.equals("success"))
                    System.out.println();
                System.out.println(validationResults.trim());

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