public class ComponentAnimator
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
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).
|
Modifier and Type | Method and Description |
---|---|
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.
|
protected java.awt.Component comp
protected java.awt.Rectangle startBounds
protected java.awt.Rectangle endBounds
protected float duration
protected float elapsed
public ComponentAnimator(java.awt.Component comp, java.awt.Rectangle startBounds, java.awt.Rectangle endBounds, float duration, AnimationListener listener)
comp
- the component to animatestartBounds
- initial bounds of the componentendBounds
- end bounds of the componentduration
- duration of animation, expressed in secondslistener
- single listener used for animation notificationpublic ComponentAnimator(java.awt.Component comp, java.awt.Rectangle startBounds, java.awt.Rectangle endBounds, float duration)
start()
method.public void start()
The component is setBounds
ed 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.
public void cancel()
public void addAnimationListener(AnimationListener listener)
listener
- the listenerpublic float getDuration()
public void setDuration(float duration)
Warning : do not change this value during an animation
duration
- the new duration in secondspublic java.awt.Rectangle getEndBounds()
public void setEndBounds(java.awt.Rectangle endBounds)
Warning : do not change end bounds during an animation.
endBounds
- public java.awt.Rectangle getStartBounds()
public void setStartBounds(java.awt.Rectangle startBounds)
Warning :do not change start bounds during an animation
startBounds
- the start bounds of the component.Copyright © 2010-2014 Pacific Biosciences. All Rights Reserved.