PulpCore

pulpcore.animation
Class Property

java.lang.Object
  extended by pulpcore.animation.Property
Direct Known Subclasses:
Bool, Color, Fixed, Int

public abstract class Property
extends Object

The Property class is the base class for animating values. Properties have a value, a behavior to control how the value changes, and listeners to alert when the value changes.

Properties have an abstract 32-bit value, and it's up to subclasses to interpret that value with get and set methods.


Constructor Summary
Property(PropertyListener listener, int value)
          Creates a property with the specified listener and initial value.
 
Method Summary
 void addListener(PropertyListener listener)
          Adds the specified listener to receive events from this Property.
abstract  boolean equals(Object obj)
           
 Behavior getBehavior()
          Gets the behavior for this property, or null if this property currently does not have a behavior.
 PropertyListener[] getListeners()
          Returns a newly allocated array of all the listeners registered on this Property.
protected  int getValue()
          Gets the value for this property.
abstract  int hashCode()
           
 boolean isAnimating()
          Checks if this property has a behavior and it is not finished animating.
 void removeListener(PropertyListener listener)
          Removes the specified listener so that it no longer receives events from this Property.
 void setBehavior(Behavior behavior)
          Sets the behavior for this property, which may be null.
protected  void setValue(int value)
          Sets the value for this property.
protected abstract  void setValue(Number value)
          Sets the value for this property.
 void stopAnimation(boolean gracefully)
          Stops the behavior, if any.
 void update(int elapsedTime)
          Updates this Property, possibly modifying its value if it has a Behavior.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Property

public Property(PropertyListener listener,
                int value)
Creates a property with the specified listener and initial value. The listener may be null. The behavior is null.

Method Detail

setValue

protected abstract void setValue(Number value)
Sets the value for this property. If the new value is different from the old value, any listeners are alerted. The behavior, if any, is not changed.

Parameters:
value - the new value.

equals

public abstract boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public abstract int hashCode()
Overrides:
hashCode in class Object

setValue

protected final void setValue(int value)
Sets the value for this property. If the new value is different from the old value, any listeners are alerted. The behavior, if any, is not changed.

Parameters:
value - the new value.

getValue

protected final int getValue()
Gets the value for this property.

Returns:
the value.

setBehavior

public final void setBehavior(Behavior behavior)
Sets the behavior for this property, which may be null. The value of this property is immediately set if behavior.update(0) returns true.

Parameters:
behavior - The new behavior.

getBehavior

public final Behavior getBehavior()
Gets the behavior for this property, or null if this property currently does not have a behavior.

Returns:
the behavior.

getListeners

public final PropertyListener[] getListeners()
Returns a newly allocated array of all the listeners registered on this Property.

Returns:
all of this Property's PropertyListeners or an empty array if no listeners are registered.

addListener

public final void addListener(PropertyListener listener)
Adds the specified listener to receive events from this Property. If the listener is null, no exception is thrown and no action is performed.

Parameters:
listener - The listener to add.

removeListener

public final void removeListener(PropertyListener listener)
Removes the specified listener so that it no longer receives events from this Property. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added to this Property. If the listener is null, no exception is thrown and no action is performed.

Parameters:
listener - The listener to remove.

update

public final void update(int elapsedTime)
Updates this Property, possibly modifying its value if it has a Behavior. This method should be called once per frame, and a Sprite typically handles property updating.

Parameters:
elapsedTime - Elapsed time since the last update, in milliseconds.

isAnimating

public final boolean isAnimating()
Checks if this property has a behavior and it is not finished animating.

Returns:
true if this property has a behavior and it is not finished animating.

stopAnimation

public final void stopAnimation(boolean gracefully)
Stops the behavior, if any.

Parameters:
gracefully - if true, the behavior is fast-forwarded to it's end and the property's value is immediately set.

PulpCore

Copyright © 2007-2009 Interactive Pulp, LLC.