ilog.views.prototypes
Class IlvTimerBehavior

java.lang.Object
  extended by ilog.views.prototypes.IlvBehavior
      extended by ilog.views.prototypes.IlvSingleBehavior
          extended by ilog.views.prototypes.IlvAnimationBehavior
              extended by ilog.views.prototypes.IlvTimerBehavior
All Implemented Interfaces:
IlvPersistentObject, Serializable

public class IlvTimerBehavior
extends IlvAnimationBehavior

The class IlvTimerBehavior is a subclass of IlvAnimationBehavior that modifies a property of the prototype periodically.

While the IlvBlinkBehavior, IlvInvertBehavior and IlvRotateBehavior classes implement predefined animation effects, the IlvTimerBehavior class lets you define a custom animation. You specify the name of a property of your prototype, and an expression. Every time the animation timer ticks, the expression is evaluated, and the property is set to the result.

For example, if you have designed a prototype that represents a meter and that has a value property, you can add a Timer behavior that increments the value by 10 every second as follows:

   IlvTimerBehavior timer = 
     new IlvTimerBehavior("increment", "1000", "value", "(value+10)%100", "10");
     prototype.addBehavior(timer);
     ...
     prototype.set("increment", true); // starts the timer
 

The last parameter of the timer behavior lets you specify a step count that is used to synchronize an animation on different objects. In the example above, the meter successively takes the 10 values 0, 10, 20, ..., 90. Specifying a step count of 10 insures that all the instances of the prototype will take the same value at a given time, even if their timers are not started simultaneously. Moreover, when a timer is stopped, the meter is reset to its initial value.

See Also:
Serialized Form

Constructor Summary
IlvTimerBehavior(IlvInputStream in)
          Reads the behavior from an IlvInputStream stream.
IlvTimerBehavior(IlvTimerBehavior source)
          Creates a new behavior object by copying an existing one.
IlvTimerBehavior(String name, String period, String target, String source, String count)
          Creates a new IlvTimerBehavior object that modifies a property of the prototype periodically.
 
Method Summary
 IlvBehavior copy()
          Returns a copy of the behavior.
protected  void doit()
          Sets the property specified by the target parameter passed to the constructor to the source expression.
 String getCount()
          Gets the synchronization count.
 String getSource()
          Gets the source expression.
 int getSynchronizationCount()
          Implementation of the Timer interface.
 String getTarget()
          Gets the target property.
 void setCount(String count)
          Sets the synchronization count.
 void setSource(String source)
          Sets the source expression.
 void setTarget(String target)
          Sets the target property.
 String toString()
          Returns a short text describing this behavior object.
 void write(IlvOutputStream out)
          Writes the behavior to an IlvOutputStream.
 
Methods inherited from class ilog.views.prototypes.IlvAnimationBehavior
attach, detach, get, getPeriod, getTimerPeriod, set, setPeriod, start, stop, timerTicked
 
Methods inherited from class ilog.views.prototypes.IlvSingleBehavior
get, getName, getValueNames, set, setName
 
Methods inherited from class ilog.views.prototypes.IlvBehavior
getParameter, isOutput, isReadable, isWritable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IlvTimerBehavior

public IlvTimerBehavior(String name,
                        String period,
                        String target,
                        String source,
                        String count)
Creates a new IlvTimerBehavior object that modifies a property of the prototype periodically.

Parameters:
name - the name of the property defined by this behavior, which is a boolean value used to start or stop the animation.
period - the animation period in milliseconds. This value can be either an immediate value (for example, "100"), or the name of another property which will be read to get the actual period value.
target - the name of the property that will be set when the timer ticks.
source - the expression to which the target property will be set every time the timer ticks. The expression is re-evaluated each time.
count - the step count. This parameter lets you synchronize different animation behaviors. If count is non-zero, all the animation behaviors with the same period and with the same step count will be synchronous. See the example in the general description of the class. If count is zero, the timer is not synchronized.

IlvTimerBehavior

public IlvTimerBehavior(IlvTimerBehavior source)
Creates a new behavior object by copying an existing one.

Parameters:
source - the behavior object to be copied.

IlvTimerBehavior

public IlvTimerBehavior(IlvInputStream in)
                 throws IlvReadFileException
Reads the behavior from an IlvInputStream stream. This constructor must be called by the input constructors of subclasses.

Parameters:
in - The input stream.
Throws:
IlvReadFileException - if the stream format is not correct.
Method Detail

write

public void write(IlvOutputStream out)
           throws IOException
Writes the behavior to an IlvOutputStream.

Specified by:
write in interface IlvPersistentObject
Overrides:
write in class IlvAnimationBehavior
Parameters:
out - The output stream.
Throws:
IOException - thrown when an exception occurs during the write operation for this object.

copy

public IlvBehavior copy()
Returns a copy of the behavior.

Specified by:
copy in class IlvBehavior

toString

public String toString()
Returns a short text describing this behavior object. This text can be used by GUI editors to display the behavior description.

Specified by:
toString in class IlvBehavior

doit

protected void doit()
             throws IlvValueException
Sets the property specified by the target parameter passed to the constructor to the source expression.

Specified by:
doit in class IlvAnimationBehavior
Throws:
IlvValueException - if an error occurred while setting the property.

setTarget

public void setTarget(String target)
Sets the target property.


getTarget

public String getTarget()
Gets the target property.


setSource

public void setSource(String source)
Sets the source expression.


getSource

public String getSource()
Gets the source expression.


setCount

public void setCount(String count)
Sets the synchronization count.


getCount

public String getCount()
Gets the synchronization count.


getSynchronizationCount

public int getSynchronizationCount()
Implementation of the Timer interface. Returns the step count specified by the count parameter passed to the constructor.

Overrides:
getSynchronizationCount in class IlvAnimationBehavior


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.