search

Class myphysicslab.lab.util.ParameterString

Provided By
All Implemented Interfaces

Provides access to a string value of a Subject. See myphysicslab.lab.util.Parameter for more documentation.

How to Represent an Enum

To create a ParameterString that represents a string enum requires some extra code for satisfying the compiler about the conversion between string and enum. Here is an example from myphysicslab.lab.engine2D.ContactSim:

new ParameterString(this, RigidBodySim.en.EXTRA_ACCEL,
  RigidBodySim.i18n.EXTRA_ACCEL,
  this.getExtraAccel,
  (/** function(this:myphysicslab.lab.engine2D.ContactSim, string) * /}
  (function(s) { this.setExtraAccel(ExtraAccel.stringToEnum(s)); })),
  ExtraAccel.getChoices(), ExtraAccel.getValues());

This defines a special setter function because setExtraAccel takes an argument of the enum type ExtraAccel, not of type string. (The code example uses a closure compiler 'type cast': the type is in a comment followed by the object in parenthesis.)

See Enums for more information.

new ParameterString( subject, name, localName, getter, setter, opt_choices, opt_values )

Parameters
subjectmyphysicslab.lab.util.Subject

the Subject whose value this ParameterString represents

namestring

the name of this Parameter; this will be underscorized so the English name can be passed in here. See myphysicslab.lab.util.UtilityCore#toName.

localNamestring

the localized name of this Parameter

getterfunction(this: myphysicslab.lab.util.Subject): string

A method of subject with no arguments that returns the value of this Parameter

setterfunction(this: myphysicslab.lab.util.Subject, string): ?

A method of subject with one argument that sets the value of this Parameter

opt_choices(Array<string>|undefined)

the translated localized strings corresponding to the values (optional)

opt_values(Array<string>|undefined)

the language-independent strings that the parameter can be set to (optional) When specified, only these values are allowed.

Instance Methods