package Savage.Tools.Animation;

import org.web3d.x3d.jsail.Core.*;
import org.web3d.x3d.jsail.EventUtilities.*;
import org.web3d.x3d.jsail.fields.*;
import org.web3d.x3d.jsail.Geometry3D.*;
import org.web3d.x3d.jsail.Grouping.*;
import org.web3d.x3d.jsail.Interpolation.*;
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.Sound.*;
import org.web3d.x3d.jsail.Text.*;
import org.web3d.x3d.jsail.Time.*;

// Javadoc metadata annotations follow, see below for X3DJSAIL Java source code.
/**
 * <p> PushButton widget prototype declaration, inner button and outer shape can be round or square. </p>
 <p> Related links: Catalog page <a href="../../../../Tools/Animation/PushButtonPrototypeIndex.html" target="_blank">PushButtonPrototype</a>,  source <a href="../../../../Tools/Animation/PushButtonPrototype.java">PushButtonPrototype.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/PushButtonPrototype.x3d">PushButtonPrototype.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> description </i> </td>
			<td> PushButton widget prototype declaration, inner button and outer shape can be round or square </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> creator </i> </td>
			<td> Don Brutzman, Murat Onder and MV4205 class, Spring 2004 Quarter </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> created </i> </td>
			<td> 11 May 2004 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> modified </i> </td>
			<td> 2 January 2025 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="../../../../Tools/Animation/PushButtonExample.x3d">PushButtonExample.x3d</a> </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/PushButtonPrototype.x3d" target="_blank">https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/PushButtonPrototype.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 Don Brutzman, Murat Onder and MV4205 class, Spring 2004 Quarter
 */

public class PushButtonPrototype
{
	/** Default constructor to create this object. */
	public PushButtonPrototype ()
	{
	  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_3)
  .setHead(new head()
    .addMeta(new meta().setName(meta.NAME_TITLE      ).setContent("PushButtonPrototype.x3d"))
    .addMeta(new meta().setName(meta.NAME_DESCRIPTION).setContent("PushButton widget prototype declaration, inner button and outer shape can be round or square"))
    .addMeta(new meta().setName(meta.NAME_CREATOR    ).setContent("Don Brutzman, Murat Onder and MV4205 class, Spring 2004 Quarter"))
    .addMeta(new meta().setName(meta.NAME_CREATED    ).setContent("11 May 2004"))
    .addMeta(new meta().setName(meta.NAME_MODIFIED   ).setContent("2 January 2025"))
    .addMeta(new meta().setName(meta.NAME_REFERENCE  ).setContent("PushButtonExample.x3d"))
    .addMeta(new meta().setName(meta.NAME_IDENTIFIER ).setContent("https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/PushButtonPrototype.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()
    .addComments(" Material Toggle Prototype is being used to be able to provide the color toggle. ")
    .addChild(new WorldInfo().setTitle("PushButtonPrototype.x3d"))
    .addChild(new ExternProtoDeclare("MaterialToggle").setName("MaterialToggle").setAppinfo("MaterialToggle selects one of two different Material values").setUrl(new String[] {"MaterialTogglePrototype.x3d#MaterialToggle","../../Tools/Animation/MaterialTogglePrototype.x3d#MaterialToggle","https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialTogglePrototype.x3d#MaterialToggle","../../Tools/Animation/MaterialTogglePrototype.wrl#MaterialToggle","MaterialTogglePrototype.wrl#MaterialToggle","https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/MaterialTogglePrototype.wrl#MaterialToggle"})
      .addField(new field().setName("defaultMaterial").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("Material node that is enabled when toggle=false"))
      .addField(new field().setName("toggleMaterial").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("Material node that is enabled when toggle=true"))
      .addField(new field().setName("set_toggle").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY))
      .addField(new field().setName("set_defaultMaterial").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("provide replacement default Material node"))
      .addField(new field().setName("toggle").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("whether to use DefaultMaterial or ToggleMaterial"))
      .addField(new field().setName("toggle_changed").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
      .addField(new field().setName("set_toggleMaterial").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("provide replacement toggle Material node")))
    .addComments(" TimeDelaySensor is being used to provide the time delay for button's color change delay ")
    .addChild(new ExternProtoDeclare("TimeDelaySensor").setName("TimeDelaySensor").setAppinfo("TimeSensor functionality commences after delayInterval pause").setUrl(new String[] {"TimeDelaySensorPrototype.x3d#TimeDelaySensor","../../Tools/Animation/TimeDelaySensorPrototype.x3d#TimeDelaySensor","https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/TimeDelaySensorPrototype.x3d#TimeDelaySensor","../../Tools/Animation/TimeDelaySensorPrototype.wrl#TimeDelaySensor","TimeDelaySensorPrototype.wrl#TimeDelaySensor","https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/TimeDelaySensorPrototype.wrl#TimeDelaySensor"})
      .addField(new field().setName("startTime").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INPUTOUTPUT).setAppinfo("when current time exceeds startTime, isActive becomes true and sensor becomes active"))
      .addField(new field().setName("delayInterval").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INPUTOUTPUT).setAppinfo("seconds"))
      .addField(new field().setName("delayCompleteTime").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
      .addField(new field().setName("enabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTOUTPUT).setAppinfo("whether sensor is active"))
      .addField(new field().setName("description").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INPUTOUTPUT).setAppinfo("describe the purpose of this sensor"))
      .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY)))
    .addComments(" PushButton Prototype definition starts here.. ")
    .addChild(new ProtoDeclare("PushButton").setName("PushButton").setAppinfo("PushButton widget, inner button and outer shape can be round or square")
      .setProtoInterface(new ProtoInterface()
        .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(true).setAppinfo("enables the console print-out in case of assigning wrong values default is true"))
        .addField(new field().setName("outerShapeMaterial").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY)
          .addChild(new Material("Blue").setDiffuseColor(0.0,0.0,1.0)))
        .addField(new field().setName("defaultMaterial").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("defaultMaterial for inner pushbutton")
          .addChild(new Material("Red").setDiffuseColor(0.8,0.1,0.0)))
        .addField(new field().setName("toggleMaterial").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("toggleMaterial for inner pushbutton")
          .addChild(new Material("Green").setDiffuseColor(0.1,0.8,0.0)))
        .addField(new field().setName("value_changed").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY).setAppinfo("boolean output of button selection"))
        .addComments(" switch values for combination of the button, default: round-round ")
        .addField(new field().setName("outerSwitchStyle").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue("round").setAppinfo("allowed values: round or square default is round"))
        .addField(new field().setName("set_outerSwitchStyle").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("allowed values: round or square default is round"))
        .addField(new field().setName("innerSwitchStyle").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue("round").setAppinfo("allowed values: round square. default is round"))
        .addField(new field().setName("set_innerSwitchStyle").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("allowed values: round square. default is round"))
        .addField(new field().setName("delayInterval").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(.5).setAppinfo("time delay for button movement so for color change default is 0.5 sec.")))
      .setProtoBody(new ProtoBody()
        .addChild(new Group()
          .addChild(new ProtoInstance("TimeDelaySensor", "DelayTimer").setContainerField("children")
            .setIS(new IS()
              .addConnect(new connect().setNodeField("delayInterval").setProtoField("delayInterval"))))
          .addChild(new Transform("OuterShapeTransform").setRotation(1.0,0.0,0.0,1.57)
            .addChild(new Switch("OuterShapeSwitchRound").setWhichChoice(-1)
              .addChild(new Shape()
                .setGeometry(new Cylinder().setHeight(.12).setRadius(.5))
                .setAppearance(new Appearance()
                  .setIS(new IS()
                    .addConnect(new connect().setNodeField("material").setProtoField("outerShapeMaterial"))))))
            .addChild(new Switch("OuterShapeSwitchSquare").setWhichChoice(-1)
              .addChild(new Shape()
                .setGeometry(new Box().setSize(1.0,.12,1.0))
                .setAppearance(new Appearance()
                  .setIS(new IS()
                    .addConnect(new connect().setNodeField("material").setProtoField("outerShapeMaterial")))))))
          .addChild(new Transform("InnerShapeTransform").setRotation(1.0,0.0,0.0,1.57).setTranslation(0.0,0.0,.1)
            .addChild(new Switch("InnerShapeSwitchRound").setWhichChoice(-1)
              .addChild(new Shape()
                .setGeometry(new Cylinder().setHeight(.12).setRadius(.35))
                .setAppearance(new Appearance()
                  .setMaterial(new ProtoInstance("MaterialToggle", "PushButtonToggleMaterial").setContainerField("material")
                    .setIS(new IS()
                      .addConnect(new connect().setNodeField("defaultMaterial").setProtoField("defaultMaterial"))
                      .addConnect(new connect().setNodeField("toggleMaterial").setProtoField("toggleMaterial")))))))
            .addChild(new Switch("InnerShapeSwitchSquare").setWhichChoice(-1)
              .addChild(new Shape()
                .setGeometry(new Box().setSize(.57,.12,.57))
                .setAppearance(new Appearance()
                  .setMaterial(new ProtoInstance("MaterialToggle").setUSE("PushButtonToggleMaterial").setContainerField("material")))))
            .addChild(new Sound()
              .setSource(new AudioClip("ClickAudio").setDescription("click sound").setUrl(new String[] {"click.wav","https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/click.wav"})))
            .addChild(new TouchSensor("Toucher").setDescription("touch to push the button"))
            .addChild(new ROUTE().setFromNode("Toucher").setFromField("touchTime").setToNode("ClickAudio").setToField("set_startTime"))
            .addChild(new ROUTE().setFromNode("Toucher").setFromField("touchTime").setToNode("DelayTimer").setToField("startTime")))
          .addChild(new Group("AnimationGroup")
            .addComments(" ============================= ")
            .addChild(new TimeSensor("Clock1"))
            .addChild(new ROUTE().setFromNode("Toucher").setFromField("touchTime").setToNode("Clock1").setToField("set_startTime"))
            .addComments(" ============================= ")
            .addChild(new PositionInterpolator("SwitchAnimator1").setKey(new double[] {0.0,.5,1.0}).setKeyValue(new MFVec3f(new double[] {0.0,0.0,.1,0.0,0.0,.05,0.0,0.0,.007})))
            .addChild(new ROUTE().setFromNode("Clock1").setFromField("fraction_changed").setToNode("SwitchAnimator1").setToField("set_fraction"))
            .addChild(new ROUTE().setFromNode("SwitchAnimator1").setFromField("value_changed").setToNode("InnerShapeTransform").setToField("set_translation"))
            .addComments(" ============================= ")
            .addChild(new TimeSensor("Clock2"))
            .addChild(new ROUTE().setFromNode("DelayTimer").setFromField("delayCompleteTime").setToNode("Clock2").setToField("set_startTime"))
            .addComments(" ============================= ")
            .addChild(new PositionInterpolator("SwitchAnimator2").setKey(new double[] {0.0,.5,1.0}).setKeyValue(new MFVec3f(new double[] {0.0,0.0,.007,0.0,0.0,.05,0.0,0.0,.1})))
            .addChild(new ROUTE().setFromNode("Clock2").setFromField("fraction_changed").setToNode("SwitchAnimator2").setToField("set_fraction"))
            .addChild(new ROUTE().setFromNode("SwitchAnimator2").setFromField("value_changed").setToNode("InnerShapeTransform").setToField("set_translation"))
            .addComments(" ============================= ")
            .addChild(new BooleanToggle("BooleanToggler")
              .setIS(new IS()
                .addConnect(new connect().setNodeField("toggle_changed").setProtoField("value_changed"))))
            .addChild(new ROUTE().setFromNode("Clock2").setFromField("isActive").setToNode("BooleanToggler").setToField("set_boolean"))
            .addChild(new ROUTE().setFromNode("BooleanToggler").setFromField("toggle_changed").setToNode("PushButtonToggleMaterial").setToField("set_toggle"))))
        .addComments(" Only first node in ProtoBody is rendered ")
        .addChild(new Script().setDirectOutput(true).setSourceCode("""
ecmascript:

function initialize()
{
   clock1.cycleInterval = delayInterval;
   clock2.cycleInterval = delayInterval;

   set_innerSwitchStyle(innerSwitchStyle);
   set_outerSwitchStyle(outerSwitchStyle);
}

function set_innerSwitchStyle(stringValue)
{
   if (stringValue != null)  //security check
   {
      if (stringValue != 'round')
      {
         if (stringValue != 'square')
         {
            printError(stringValue, 'inner');
            innerSwitchStyle = 'round';
         }
         else
         {
            innerSwitchStyle = stringValue;
         }
      }
      else
      {
          innerSwitchStyle = stringValue;
      }
   }

   if      (innerSwitchStyle == 'round')
   {
        switchInnerSquare.whichChoice = -1;
         switchInnerRound.whichChoice =  0;
   }
   else // (innerSwitchStyle == 'square')
   {
        switchInnerSquare.whichChoice =  0;
         switchInnerRound.whichChoice = -1;
   }
}

function set_outerSwitchStyle(stringValue)
{
   if (stringValue != null)    //security check
   {
      if (stringValue != 'round')
      {
         if (stringValue != 'square')
         {
            printError(stringValue, 'outer');
            outerSwitchStyle = 'round';
         }
         else
         {
            outerSwitchStyle = stringValue;
         }
      }
      else
      {
          outerSwitchStyle = stringValue;
      }
   }

   if      (outerSwitchStyle == 'round')
   {
        switchOuterSquare.whichChoice = -1;
         switchOuterRound.whichChoice =  0;
   }
   else // (outerSwitchStyle == 'square')
   {
        switchOuterSquare.whichChoice =  0;
         switchOuterRound.whichChoice = -1;
   }
}

function printError(s1, s2)
{
    if (traceEnabled)
    {
        Browser.println ('\nAllowed values are [round] and [square].');
        Browser.println ('Assigned value [' + s1 + '] (The values are case/whitespace-sensitive).');
        Browser.println ('Default value  [round] will be used for [' + s2 + 'SwitchStyle].');
    }
}
""")
          .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
          .addField(new field().setName("delayInterval").setType(field.TYPE_SFTIME).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
          .addField(new field().setName("outerSwitchStyle").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("allowed values: round square. default is round"))
          .addField(new field().setName("set_outerSwitchStyle").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("allowed values: round square. default is round"))
          .addField(new field().setName("innerSwitchStyle").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("allowed values: round square. default is round"))
          .addField(new field().setName("set_innerSwitchStyle").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("allowed values: round square. default is round"))
          .addField(new field().setName("switchOuterRound").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY)
            .addChild(new Switch().setUSE("OuterShapeSwitchRound")))
          .addField(new field().setName("switchOuterSquare").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY)
            .addChild(new Switch().setUSE("OuterShapeSwitchSquare")))
          .addField(new field().setName("switchInnerRound").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY)
            .addChild(new Switch().setUSE("InnerShapeSwitchRound")))
          .addField(new field().setName("switchInnerSquare").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY)
            .addChild(new Switch().setUSE("InnerShapeSwitchSquare")))
          .addField(new field().setName("clock1").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY)
            .addChild(new TimeSensor().setUSE("Clock1")))
          .addField(new field().setName("clock2").setType(field.TYPE_SFNODE).setAccessType(field.ACCESSTYPE_INITIALIZEONLY)
            .addChild(new TimeSensor().setUSE("Clock2")))
          .setIS(new IS()
            .addConnect(new connect().setNodeField("traceEnabled").setProtoField("traceEnabled"))
            .addConnect(new connect().setNodeField("outerSwitchStyle").setProtoField("outerSwitchStyle"))
            .addConnect(new connect().setNodeField("set_outerSwitchStyle").setProtoField("set_outerSwitchStyle"))
            .addConnect(new connect().setNodeField("innerSwitchStyle").setProtoField("innerSwitchStyle"))
            .addConnect(new connect().setNodeField("set_innerSwitchStyle").setProtoField("set_innerSwitchStyle"))
            .addConnect(new connect().setNodeField("delayInterval").setProtoField("delayInterval"))))))
    .addComments(" ==================== ")
    .addChild(new Anchor().setDescription("PushButtonExample").setParameter(new String[] {"target=_blank"}).setUrl(new String[] {"PushButtonExample.x3d","../../Tools/Animation/PushButtonExample.x3d","https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/PushButtonExample.x3d","../../Tools/Animation/PushButtonExample.wrl","PushButtonExample.wrl","https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/PushButtonExample.wrl"})
      .addChild(new Shape()
        .setGeometry(new Text().setString(new String[] {"PushButtonPrototype","defines a prototype","","Click text to see example scene","","You can define 4 different buttons","with the combination of round and square","(default is round-round)"})
          .setFontStyle(new FontStyle().setJustify(FontStyle.JUSTIFY_MIDDLE_MIDDLE).setSize(0.7)))
        .setAppearance(new Appearance()
          .setMaterial(new Material().setDiffuseColor(.8,.7,0.2))))));
            }
            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 PushButtonPrototype 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 PushButtonPrototype().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.PushButtonPrototype\" 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.PushButtonPrototype self-validation test confirmation: ");
                if (!validationResults.equals("success"))
                    System.out.println();
                System.out.println(validationResults.trim());

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