fr.lri.swingstates.animations
Class ATag

java.lang.Object
  extended by fr.lri.swingstates.sm.Tag
      extended by fr.lri.swingstates.animations.ATag
All Implemented Interfaces:
java.util.Iterator
Direct Known Subclasses:
AExtensionalTag

public class ATag
extends Tag

ATags are labels associated to canvas' animations. ATag class has most of the methods of the Animation class. Calling one of these ATag's methods calls the method for each tagged Animation.

A tag is an object corresponding to a set of Animations that can be browsed:

 aTag.reset();
 while(aTag.hasNext())
    Animation a = aTag.nextAnimation();
 

Tags can be used to in Animation* transitions in a CStateMachine to know when an animation has been started, stopped, suspended or resumed.

 class MyTag extends ATag { ... }
 ...
 Transition anAnimationStopped = new AnimationStopped(MyTag.class) {
          public void action() {
       System.out.println(anAnimationStopped+" has just stopped.");
       // start a new animation for example
    }
 };
 

A tag can be attached to any number of animations. An animation can have any number of tags attached to it.

Some tags, AExtensionalTag tags, can be explicitely attached to and detached from an animation, i.e. an animation can be added to or removed from the tag's collection, while others can not. ANamedTag are special extensional tags that can be referenced by their key string.

Tags are used for grouping animations. for example, one can decide to start several animations at the same time. For example, to animate two rectangles that move towards two opposite directions (we use a ANamedTag):

 Animation onePart = new AnimationTranslateBy(-2, 0);
 onePart.setAnimatedElement(canvas.newRectangle(100, 100, 20, 20).addTag("part"));
 Animation anotherPart = new AnimationTranslateBy(2, 0);
 anotherPart.setAnimatedElement(canvas.newRectangle(120, 120, 20, 20).addTag("part"));
 ...
 ANamedTag.getTag("part").start();
 

Author:
Caroline Appert
See Also:
Tag

Constructor Summary
ATag()
          Builds a ATag that can tag animations.
 
Method Summary
 ATag action()
          Calls action(Animation s) for every Animation a that has this tag.
 void action(Animation a)
          Method called by action().
 ATag addTag(AExtensionalTag t)
          Calls addTag(animations.AExtensionalTag t) for every animation that has this tag.
 ATag addTag(java.lang.String t)
          Calls addTag(String t) for every animation that has this tag.
 boolean hasNext()
          Tests if there is other objects tagged by this tag.
 java.lang.Object next()
          
 Animation nextAnimation()
           
 ATag removeTag(AExtensionalTag t)
          Calls removeTag(animations.ATag t) for every animation that has this tag only if t is a AExtensionalTag, does nothing otherwise.
 ATag removeTag(java.lang.String t)
          Calls removeTag(String t) for every animation that has this tag.
 void reset()
          Inits the tag's iterator.
 ATag resume()
          Calls resume() for every Animation that has this tag.
 ATag setAnimatedElement(CElement ce)
          Calls setAnimatedElement(CElement ce) for every Animation that has this tag.
 ATag setDelay(int d)
          Calls setDelay(int d) for every Animation that has this tag.
 ATag setDurationLap(long d)
          Calls setDurationLap(long d) for every Animation that has this tag.
 ATag setFunction(short t)
          Calls setFunction(int t) for every Animation that has this tag.
 ATag setNbLaps(int laps)
          Calls setNbLaps(int laps) for every Animation that has this tag.
 ATag start()
          Calls start() for every Animation that has this tag.
 ATag stop()
          Calls stop() for every Animation that has this tag.
 ATag suspend()
          Calls suspend() for every Animation that has this tag.
 boolean tagsAnimation(Animation a)
          Tests if the animation a is tagged by this tag.
 
Methods inherited from class fr.lri.swingstates.sm.Tag
getCollection, remove, size
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ATag

public ATag()
Builds a ATag that can tag animations.

Method Detail

next

public final java.lang.Object next()
Description copied from class: Tag

Specified by:
next in interface java.util.Iterator
Specified by:
next in class Tag
Returns:
the next animation tagged by this tag as an Object.
See Also:
Iterator.next()

tagsAnimation

public boolean tagsAnimation(Animation a)
Tests if the animation a is tagged by this tag.

Parameters:
a - The animation
Returns:
true if a is tagged by this tag, false otherwise.

action

public void action(Animation a)
Method called by action(). This method does nothing. Redefine it in a subclass to specify the effect of ATag#action()

Parameters:
a - The Animation on which applying specific treatments.

action

public final ATag action()
Calls action(Animation s) for every Animation a that has this tag.

Returns:
this tag

setDelay

public ATag setDelay(int d)
Calls setDelay(int d) for every Animation that has this tag.

Parameters:
d - The delay in milliseconds.
Returns:
this tag.
See Also:
Animation.setDelay(int)

setDurationLap

public ATag setDurationLap(long d)
Calls setDurationLap(long d) for every Animation that has this tag.

Parameters:
d - The duration in milliseconds.
Returns:
this tag.
See Also:
Animation.setLapDuration(long)

setFunction

public ATag setFunction(short t)
Calls setFunction(int t) for every Animation that has this tag.

Parameters:
t - The type of the pacing function.
Returns:
this tag.
See Also:
Animation.setFunction(short)

setNbLaps

public ATag setNbLaps(int laps)
Calls setNbLaps(int laps) for every Animation that has this tag.

Parameters:
laps - The number of laps.
Returns:
this tag.
See Also:
Animation.setNbLaps(int)

setAnimatedElement

public ATag setAnimatedElement(CElement ce)
Calls setAnimatedElement(CElement ce) for every Animation that has this tag.

Parameters:
ce - The CElement to animate.
Returns:
this tag.
See Also:
Animation.setAnimatedElement(CElement)

start

public final ATag start()
Calls start() for every Animation that has this tag.

Returns:
this tag.
See Also:
Animation.start()

stop

public final ATag stop()
Calls stop() for every Animation that has this tag.

Returns:
this tag.
See Also:
Animation.stop()

suspend

public final ATag suspend()
Calls suspend() for every Animation that has this tag.

Returns:
this tag.
See Also:
Animation.suspend()

resume

public final ATag resume()
Calls resume() for every Animation that has this tag.

Returns:
this tag.
See Also:
Animation.resume()

addTag

public ATag addTag(AExtensionalTag t)
Calls addTag(animations.AExtensionalTag t) for every animation that has this tag.

Parameters:
t - The tag to add.
Returns:
this tag.
See Also:
Animation.addTag(fr.lri.swingstates.animations.AExtensionalTag)

addTag

public ATag addTag(java.lang.String t)
Calls addTag(String t) for every animation that has this tag.

Parameters:
t - The name of the tag to add.
Returns:
this tag
See Also:
Animation.addTag(fr.lri.swingstates.animations.AExtensionalTag)

removeTag

public ATag removeTag(AExtensionalTag t)
Calls removeTag(animations.ATag t) for every animation that has this tag only if t is a AExtensionalTag, does nothing otherwise.

Parameters:
t - The tag to remove.
Returns:
this tag
See Also:
Animation.removeTag(fr.lri.swingstates.animations.AExtensionalTag)

removeTag

public ATag removeTag(java.lang.String t)
Calls removeTag(String t) for every animation that has this tag.

Parameters:
t - The name of the tag to remove.
Returns:
this tag
See Also:
Animation.removeTag(String)

nextAnimation

public Animation nextAnimation()
Returns:
the next animation tagged by this tag as an Animation.
See Also:
Iterator.next()

hasNext

public boolean hasNext()
Tests if there is other objects tagged by this tag.

Specified by:
hasNext in interface java.util.Iterator
Specified by:
hasNext in class Tag
Returns:
true if there is other objects tagged by this tag, false otherwise.
See Also:
Iterator.hasNext()

reset

public void reset()
Inits the tag's iterator.

Specified by:
reset in class Tag