org.graffiti.plugin.algorithm.animation
Class BidirectionalAnimation

java.lang.Object
  extended by org.graffiti.plugin.algorithm.animation.AbstractAnimation
      extended by org.graffiti.plugin.algorithm.animation.BidirectionalAnimation
All Implemented Interfaces:
Animation

public class BidirectionalAnimation
extends AbstractAnimation

An animation that supports both steps forward and steps to previous states. This implementation uses delegation to instances of interface Step to implement the methods hasNextStep, nextStep and previousStep: hasNextStep delegates to hasNext and previousStep delegates to undo in interface Step.

The delegation pattern for nextStep depends on this animation's current state. Let a be a newly created bidirectional animation and n be its next step. A call to nextStep has the following effects:

To achieve the second task n is added to a list of performed steps. This course of action is taken as long as nextStep is called.

Let p be the step that was last performed by this animation. Now suppose a client calls previousStep. This call has the following effects:

To achieve the second task it's sufficient to remember p's index in the list of performed steps and to ensure that the next call to nextStep will call redo on p instead of executing p.next() and adding it to the list of steps performed. This course of action is taken every time previousStep called.

Let i be the index of this animation's next step n. Suppose a client calls nextStep. This call has the following effects:

To achieve the second task it's sufficient to increment i by one. This course of action is taken as long as there are steps that can be redone.

Version:
$Revision$ $Date$
Author:
Harald
See Also:
Step, Step.hasNext(), Step.next(), Step.undo(), Step.redo()

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.graffiti.plugin.algorithm.animation.Animation
Animation.GraphModificationPolicy
 
Field Summary
 
Fields inherited from interface org.graffiti.plugin.algorithm.animation.Animation
EMPTY_ANIMATION
 
Constructor Summary
BidirectionalAnimation()
          Default constructor; does nothing.
BidirectionalAnimation(Step first)
          Initializes this animation with the specified initial step.
 
Method Summary
 boolean hasNextStep()
          Returns true if this animation has a next step.
 boolean hasPreviousStep()
          Returns true if this animation has a previous step.
 boolean isCleared()
          Returns true if this animation is cleared; i.e.
 boolean isReady()
          Returns true if the preconditions of the algorithm underlying this animation are satisfied.
 void performClear()
          Resets this animation to its initial state.
 void performNextStep()
          Computes the next state of the underlying algorithm; i.e.
 void performPreviousStep()
          Computes the previous state of the underlying algorithm; i.e.
 void setFirstStep(Step s)
          Set the first step of this animation to the specified value.
 boolean supportsClear()
          Returns true if this animation supports clearing; i.e.
 boolean supportsPreviousStep()
          Returns true if this animation supports steps to previous states of the underlying algorithm.
 
Methods inherited from class org.graffiti.plugin.algorithm.animation.AbstractAnimation
clear, getGraphModificationPolicy, getName, nextStep, previousStep
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BidirectionalAnimation

public BidirectionalAnimation()
Default constructor; does nothing. Note that as long as this animation's first step is not properly initialized (i.e. assigned a non-null value) every attempt to call hasNextStep or nextStep will throw IllegalStateException. You can initalize this animation's first step anytime this animation is in a cleared state, i.e. after initialization or after a call to clear as long as nextStep hasn't been called.

See Also:
setFirstStep(Step)

BidirectionalAnimation

public BidirectionalAnimation(Step first)
Initializes this animation with the specified initial step. Note that as long as this animation's first step is not properly initialized (i.e. assigned a non-null value) every attempt to call hasNextStep or nextStep will throw IllegalStateException. You can initalize this animation's first step anytime this animation is in a cleared state, i.e. after initialization or after a call to clear as long as nextStep hasn't been called.

Parameters:
first - the first step of this animation
See Also:
setFirstStep(Step)
Method Detail

isReady

public boolean isReady()
Returns true if the preconditions of the algorithm underlying this animation are satisfied.

This implementation always returns true.

Specified by:
isReady in interface Animation
Specified by:
isReady in class AbstractAnimation
Returns:
true if the preconditions of the algoritm underlying this animation are satisfied.

supportsClear

public boolean supportsClear()
Description copied from class: AbstractAnimation
Returns true if this animation supports clearing; i.e. a call to clear or isCleared will not throw UnsupportedOperationException.

Specified by:
supportsClear in interface Animation
Overrides:
supportsClear in class AbstractAnimation
Returns:
true if this animation supports clearing.
See Also:
AbstractAnimation.clear(), AbstractAnimation.isCleared()

isCleared

public boolean isCleared()
Description copied from class: AbstractAnimation
Returns true if this animation is cleared; i.e. it is newly created or clear has been called and no change of state has occured yet.

Specified by:
isCleared in interface Animation
Overrides:
isCleared in class AbstractAnimation
Returns:
true if this animation is cleared.
See Also:
AbstractAnimation.supportsClear(), AbstractAnimation.clear()

hasNextStep

public boolean hasNextStep()
Returns true if this animation has a next step.

This implementation returns true if there are steps to redo. Otherwise it delegates to hasNext of this animation's next step.

Specified by:
hasNextStep in interface Animation
Specified by:
hasNextStep in class AbstractAnimation
Returns:
true if this animation has a next step.

supportsPreviousStep

public boolean supportsPreviousStep()
Returns true if this animation supports steps to previous states of the underlying algorithm.

This implementation always returns true.

Specified by:
supportsPreviousStep in interface Animation
Overrides:
supportsPreviousStep in class AbstractAnimation
Returns:
true if this animation supports steps to previous states of the underlying algorithm.

performNextStep

public void performNextStep()
Computes the next state of the underlying algorithm; i.e. moves the animation one step forward.

Uses Step.next to compute the next state of this animation if there are no steps that can be redone; uses Step.redo otherwise.

See Also:
Step.next(), Step.redo()

hasPreviousStep

public boolean hasPreviousStep()
Returns true if this animation has a previous step.

Specified by:
hasPreviousStep in interface Animation
Overrides:
hasPreviousStep in class AbstractAnimation
Returns:
true if this animation has a previous step.
See Also:
Animation.previousStep(), Animation.supportsPreviousStep()

performPreviousStep

public void performPreviousStep()
Computes the previous state of the underlying algorithm; i.e. moves this animation one step backwards.

Throws:
IllegalStateException - if this animation does not have a previous step
See Also:
AbstractAnimation.previousStep()

performClear

public void performClear()
Resets this animation to its initial state.

Overrides:
performClear in class AbstractAnimation
See Also:
AbstractAnimation.clear()

setFirstStep

public void setFirstStep(Step s)
Set the first step of this animation to the specified value.

Parameters:
s - the first step of this animation.
Throws:
IllegalStateException - if this animation is not in a cleared state, i.e. newly created or cleared by a call to clear and nextStep has not yet been called.


Generated at 2012-05-30 11:00:14 PM CEST