- java.lang.Object
-
- org.praxislive.code.userapi.Property
-
- Direct Known Subclasses:
PropertyControl
public abstract class Property extends Object
A field type for properties (see@P). The Property type also backs other none-resource-loading properties - usep(String id)to access the backing Property.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classProperty.AnimatorProvides keyframe animation support for Property.
-
Constructor Summary
Constructors Modifier Constructor Description protectedProperty()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Property.Animatoranimator()Return the Animator for the Property, creating it if necessary.protected voidattach(CodeContext<?> context, Property previous)PropertyclearLinks()Clear all Linkables from the Property.protected voidfinishAnimating()Valueget()Return the current value.booleangetBoolean()Return the current value as a boolean, or false if the value isn't a valid boolean.booleangetBoolean(boolean def)Return the current value as a boolean, or the provided default if the value isn't a valid boolean.doublegetDouble()Return the current value as a double, or zero if the value isn't numeric.doublegetDouble(double def)Return the current value as a double, or the provided default if the value isn't numeric.protected abstract ValuegetImpl()protected abstract doublegetImpl(double def)intgetInt()Return the current value as an int, or zero if the value isn't numeric.intgetInt(int def)Return the current value as an int, or the provided default if the value isn't numeric.protected booleanhasLinks()booleanisAnimating()Return whether the property is currently animating.Propertylink(DoubleConsumer consumer)Call the provided consumer with the double value whenever the value changes.Propertylink(DoubleConsumer... consumers)<T> PropertylinkAs(Function<Value,T> converter, Consumer<T> consumer)Call the provided consumer when the value changes, transformed using the converter into the required type T.<T> PropertylinkAs(Function<Value,T> converter, Consumer<T>... consumers)protected voidreset(boolean full)Propertyset(double value)Set the current value.Propertyset(Value value)Set the current value.protected abstract voidsetImpl(long time, double value)protected abstract voidsetImpl(long time, Value arg)Property.Animatorto(double... to)Animate the property value to the provided values.protected voidupdateLinks(double value)protected voidupdateLinks(Value value)Linkable.Doublevalues()Return a newLinkable.Doublefor observing changing values.<T extends Value>
Linkable<T>valuesAs(Class<T> type)Return a newLinkablefor observing changing values.<T> Linkable<T>valuesAs(Function<Value,T> converter)Return a newLinkablefor observing changing values.
-
-
-
Method Detail
-
attach
protected void attach(CodeContext<?> context, Property previous)
-
setImpl
protected abstract void setImpl(long time, double value) throws Exception- Throws:
Exception
-
getImpl
protected abstract Value getImpl()
-
getImpl
protected abstract double getImpl(double def)
-
get
public Value get()
Return the current value.- Returns:
- value
-
getDouble
public double getDouble()
Return the current value as a double, or zero if the value isn't numeric.- Returns:
- current value as double
- See Also:
DefaultCodeDelegate.d(org.praxislive.code.userapi.Property)
-
getDouble
public double getDouble(double def)
Return the current value as a double, or the provided default if the value isn't numeric.- Returns:
- current value as double
-
getInt
public int getInt()
Return the current value as an int, or zero if the value isn't numeric. Floating point values are rounded to the nearest int.- Returns:
- current value as int
- See Also:
DefaultCodeDelegate.i(org.praxislive.code.userapi.Property)
-
getInt
public int getInt(int def)
Return the current value as an int, or the provided default if the value isn't numeric. Floating point values are rounded to the nearest int.- Returns:
- current value as int
-
getBoolean
public boolean getBoolean()
Return the current value as a boolean, or false if the value isn't a valid boolean.- Returns:
- current value as boolean
-
getBoolean
public boolean getBoolean(boolean def)
Return the current value as a boolean, or the provided default if the value isn't a valid boolean.- Returns:
- current value as boolean
-
set
public Property set(Value value)
Set the current value. Also stops any active animation.- Parameters:
value- Value subclass to set- Returns:
- this
-
set
public Property set(double value)
Set the current value. Also stops any active animation.- Parameters:
value- double value to set- Returns:
- this
-
link
public Property link(DoubleConsumer consumer)
Call the provided consumer with the double value whenever the value changes. This is a shorthand forvalues().link(consumer);. The double value will be as if callinggetDouble().- Parameters:
consumer- double consumer- Returns:
- this
-
link
public Property link(DoubleConsumer... consumers)
-
values
public Linkable.Double values()
Return a newLinkable.Doublefor observing changing values. The double value will be as if callinggetDouble().- Returns:
- Linkable.Double of values.
-
linkAs
public <T> Property linkAs(Function<Value,T> converter, Consumer<T> consumer)
Call the provided consumer when the value changes, transformed using the converter into the required type T. This is shorthand forvaluesAs(converter).link(consumer);.- Type Parameters:
T- type- Parameters:
converter- convert Value into required typeconsumer-- Returns:
- this
-
valuesAs
public <T> Linkable<T> valuesAs(Function<Value,T> converter)
Return a newLinkablefor observing changing values. The value will be mapped to the required type using the passed in converter.- Type Parameters:
T- required type- Parameters:
converter- convert Value into required type- Returns:
- Linkable of values
-
valuesAs
public <T extends Value> Linkable<T> valuesAs(Class<T> type)
Return a newLinkablefor observing changing values. The value will be mapped to the provided Value sub-type. If the value cannot be coerced into the required type no value will be received by the created Linkable.- Type Parameters:
T- required type- Parameters:
type- Sub-type of Value- Returns:
- Linkable of values
-
clearLinks
public Property clearLinks()
Clear all Linkables from the Property.- Returns:
- this
-
animator
public Property.Animator animator()
Return the Animator for the Property, creating it if necessary.- Returns:
- property animator
-
to
public Property.Animator to(double... to)
Animate the property value to the provided values. This is a shorthand for callinganimator().to(...).This method returns the animator so that you can chain calls, eg.
prop.to(1, 0).in(1, 0.25).easeInOut();- Returns:
- property animator
-
isAnimating
public boolean isAnimating()
Return whether the property is currently animating.- Returns:
- property animator active
-
finishAnimating
protected void finishAnimating()
-
updateLinks
protected void updateLinks(double value)
-
updateLinks
protected void updateLinks(Value value)
-
hasLinks
protected boolean hasLinks()
-
reset
protected void reset(boolean full)
-
-