Class Property

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 - use
invalid reference
p(String id)
to access the backing Property.
  • Constructor Details

    • Property

      protected Property()
  • Method Details

    • attach

      protected void attach(CodeContext<?> context, Property previous)
    • setImpl

      protected abstract void setImpl(long time, Value arg) throws Exception
      Throws:
      Exception
    • 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:
      • invalid reference
        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.
      Parameters:
      def - default value to return if value is not 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:
      • invalid reference
        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.
      Parameters:
      def - default value to return if value is not numeric
      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.
      Parameters:
      def - default value to return if value is not convertible to a 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 for doubles().link(consumer);. The double value will be as if calling getDouble().
      Parameters:
      consumer - double consumer
      Returns:
      this
    • doubles

      public Linkable.Double doubles()
      Return a new Linkable.Double for observing changing values. The double value will be as if calling getDouble().
      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 for valuesAs(converter).link(consumer);.
      Type Parameters:
      T - type
      Parameters:
      converter - convert Value into required type
      consumer -
      Returns:
      this
    • linkAs

      public <T> Property linkAs(Function<Value,T> converter, Consumer<T>... consumers)
    • valuesAs

      public <T> Linkable<T> valuesAs(Function<Value,T> converter)
      Return a new Linkable 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 new Linkable 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 calling animator().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
    • sync

      public Property.Sync sync()
      Return the Property.Sync for this Property, creating it if necessary. The Sync instance allows to synchronize the value of this property with another control.

      The Sync works using Linkables. Clearing links will also disable synchronization.

      Returns:
      property's Sync
    • 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()