com.vlsolutions.swing.docking.animation
Class ComponentAnimator

java.lang.Object
  extended by com.vlsolutions.swing.docking.animation.ComponentAnimator

public class ComponentAnimator
extends java.lang.Object

Utility class used to perform move/resize animation for awt/swing components.

This class moves/resizes a Component given a start and end Rectangle and a duration.

Movements and listeners notifications are processed in the Swing Event Thread.


Field Summary
protected  java.awt.Component comp
          The animated component
protected  float duration
          the animation duration in seconds
protected  float elapsed
          time elapsed since the beginnig of animation
protected  java.awt.Rectangle endBounds
          the component's end bounds
protected  java.awt.Rectangle startBounds
          the component's start bounds
 
Constructor Summary
ComponentAnimator(java.awt.Component comp, java.awt.Rectangle startBounds, java.awt.Rectangle endBounds, float duration)
          Reusable component animator.
ComponentAnimator(java.awt.Component comp, java.awt.Rectangle startBounds, java.awt.Rectangle endBounds, float duration, AnimationListener listener)
          Single-shot animator (use another ComponentAnimator for a new animation).
 
Method Summary
 void addAnimationListener(AnimationListener listener)
          Adds a new listener to the animator
 void cancel()
          Cancels the animation (the component is not reset to its initial location/size)
 float getDuration()
          Returns the duration of the animation
 java.awt.Rectangle getEndBounds()
          Returns the end bounds of the components.
 java.awt.Rectangle getStartBounds()
          Returns the start bounds of the component.
 void setDuration(float duration)
          Sets the duration of the animation.
 void setEndBounds(java.awt.Rectangle endBounds)
          Sets the end bounds of the component.
 void setStartBounds(java.awt.Rectangle startBounds)
          Sets the start bounds of the component for animation.
 void start()
          Starts the animation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

comp

protected java.awt.Component comp
The animated component


startBounds

protected java.awt.Rectangle startBounds
the component's start bounds


endBounds

protected java.awt.Rectangle endBounds
the component's end bounds


duration

protected float duration
the animation duration in seconds


elapsed

protected float elapsed
time elapsed since the beginnig of animation

Constructor Detail

ComponentAnimator

public ComponentAnimator(java.awt.Component comp,
                         java.awt.Rectangle startBounds,
                         java.awt.Rectangle endBounds,
                         float duration,
                         AnimationListener listener)
Single-shot animator (use another ComponentAnimator for a new animation).

Parameters:
comp - the component to animate
startBounds - initial bounds of the component
endBounds - end bounds of the component
duration - duration of animation, expressed in seconds
listener - single listener used for animation notification

ComponentAnimator

public ComponentAnimator(java.awt.Component comp,
                         java.awt.Rectangle startBounds,
                         java.awt.Rectangle endBounds,
                         float duration)
Reusable component animator. To start an animation, don't forget to call the start() method.

Method Detail

start

public void start()
Starts the animation.

The component is setBoundsed to startBounds and made visible, than a Swing timer is started to process the animation (refresh rate is 100 ms).

the ANIMATION_START event is then fired to all listeners.


cancel

public void cancel()
Cancels the animation (the component is not reset to its initial location/size)


addAnimationListener

public void addAnimationListener(AnimationListener listener)
Adds a new listener to the animator

Parameters:
listener - the listener

getDuration

public float getDuration()
Returns the duration of the animation

Returns:
the duration of the animation, in seconds

setDuration

public void setDuration(float duration)
Sets the duration of the animation.

Warning : do not change this value during an animation

Parameters:
duration - the new duration in seconds

getEndBounds

public java.awt.Rectangle getEndBounds()
Returns the end bounds of the components.

Returns:
the end bounds of the components.

setEndBounds

public void setEndBounds(java.awt.Rectangle endBounds)
Sets the end bounds of the component.

Warning : do not change end bounds during an animation.

Parameters:
endBounds -

getStartBounds

public java.awt.Rectangle getStartBounds()
Returns the start bounds of the component.

Returns:
the start bounds of the component (those of when animation starts).

setStartBounds

public void setStartBounds(java.awt.Rectangle startBounds)
Sets the start bounds of the component for animation.

Warning :do not change start bounds during an animation

Parameters:
startBounds - the start bounds of the component.


© Copyright 2004-2007 VLSolutions. All Rights Reserved.
www.vlsolutions.com : Java Components - Smart Client Applications