- 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 class
Property.Animator
Provides keyframe animation support for Property.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Property()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Property.Animator
animator()
Return the Animator for the Property, creating it if necessary.protected void
attach(CodeContext<?> context, Property previous)
Property
clearLinks()
Clear all Linkables from the Property.Linkable.Double
doubles()
Return a newLinkable.Double
for observing changing values.protected void
finishAnimating()
Value
get()
Return the current value.boolean
getBoolean()
Return the current value as a boolean, or false if the value isn't a valid boolean.boolean
getBoolean(boolean def)
Return the current value as a boolean, or the provided default if the value isn't a valid boolean.double
getDouble()
Return the current value as a double, or zero if the value isn't numeric.double
getDouble(double def)
Return the current value as a double, or the provided default if the value isn't numeric.protected abstract Value
getImpl()
protected abstract double
getImpl(double def)
int
getInt()
Return the current value as an int, or zero if the value isn't numeric.int
getInt(int def)
Return the current value as an int, or the provided default if the value isn't numeric.protected boolean
hasLinks()
boolean
isAnimating()
Return whether the property is currently animating.Property
link(DoubleConsumer consumer)
Call the provided consumer with the double value whenever the value changes.Property
link(DoubleConsumer... consumers)
Deprecated, for removal: This API element is subject to removal in a future version.<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.<T> Property
linkAs(Function<Value,T> converter, Consumer<T>... consumers)
protected void
reset(boolean full)
Property
set(double value)
Set the current value.Property
set(Value value)
Set the current value.protected abstract void
setImpl(long time, double value)
protected abstract void
setImpl(long time, Value arg)
Property.Animator
to(double... to)
Animate the property value to the provided values.protected void
updateLinks(double value)
protected void
updateLinks(Value value)
Linkable.Double
values()
Deprecated, for removal: This API element is subject to removal in a future version.<T extends Value>
Linkable<T>valuesAs(Class<T> type)
Return a newLinkable
for observing changing values.<T> Linkable<T>
valuesAs(Function<Value,T> converter)
Return a newLinkable
for 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:
DefaultDelegateAPI.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:
DefaultDelegateAPI.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 fordoubles().link(consumer);
. The double value will be as if callinggetDouble()
.- Parameters:
consumer
- double consumer- Returns:
- this
-
link
@Deprecated(forRemoval=true) public Property link(DoubleConsumer... consumers)
Deprecated, for removal: This API element is subject to removal in a future version.
-
values
@Deprecated(forRemoval=true) public Linkable.Double values()
Deprecated, for removal: This API element is subject to removal in a future version.Return a newLinkable.Double
for observing changing values. The double value will be as if callinggetDouble()
.This method is deprecated. Switch to
doubles()
instead.- Returns:
- Linkable.Double of values.
-
doubles
public Linkable.Double doubles()
Return a newLinkable.Double
for 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 newLinkable
for 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 newLinkable
for 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)
-
-