bibliothek.extension.gui.dock.theme.bubble
Class BubbleColorAnimation

java.lang.Object
  extended by bibliothek.extension.gui.dock.theme.bubble.BubbleColorAnimation

public class BubbleColorAnimation
extends java.lang.Object

A BubbleColorAnimation has the ability to convert one color smoothly into another. The animation does not store colors directly, it uses a String as a key to read the color from a BubbleTheme using BubbleTheme.getColor(String). The transformation takes duration milliseconds, a task can be executed whenever the colors have changed.
The animation can handle multiple color-pairs asynchronously.

Author:
Benjamin Sigg

Nested Class Summary
private  class BubbleColorAnimation.Entry
          One pair of colors.
 
Field Summary
private  java.util.Map<java.lang.String,BubbleColorAnimation.Entry> colors
          The color pairs that can be animated
private  int duration
          How long a transformation takes
private  java.util.List<java.lang.Runnable> tasks
          The tasks that are executed at every step of the animation
private  BubbleTheme theme
          the theme from which colors are read
private  long time
          The current time in milliseconds
private  javax.swing.Timer timer
          The timer that triggers steps of the animation
 
Constructor Summary
BubbleColorAnimation(BubbleTheme theme)
          Creates a new animation.
 
Method Summary
 void addTask(java.lang.Runnable runnable)
          Adds a task to this animation.
 java.awt.Color getColor(java.lang.String key)
          Gets the current color of the pair key.
 int getDuration()
          Gets the length of one transformation.
protected  void pulse()
          Called when the animation has to perform another step.
 void putColor(java.lang.String key, java.lang.String color)
          Starts a new animation which will transform the color of the pair key to color.
 void putColors(java.lang.String key, java.lang.String source, java.lang.String destination)
          Sets a color-pair.
 void removeTask(java.lang.Runnable runnable)
          Removes a task which was earlier added to this animation.
 void setDuration(int duration)
          Sets the length of one transformation.
protected  void start()
          Starts the animation if it is not yet running.
 void stop()
          Stops the animation immediately, possibly leaving the animation in an unfinished state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

duration

private int duration
How long a transformation takes


colors

private java.util.Map<java.lang.String,BubbleColorAnimation.Entry> colors
The color pairs that can be animated


timer

private javax.swing.Timer timer
The timer that triggers steps of the animation


time

private long time
The current time in milliseconds


tasks

private java.util.List<java.lang.Runnable> tasks
The tasks that are executed at every step of the animation


theme

private BubbleTheme theme
the theme from which colors are read

Constructor Detail

BubbleColorAnimation

public BubbleColorAnimation(BubbleTheme theme)
Creates a new animation.

Parameters:
theme - the theme from which colors are read
Method Detail

putColors

public void putColors(java.lang.String key,
                      java.lang.String source,
                      java.lang.String destination)
Sets a color-pair. The color destination is shown after maximal duration milliseconds. This method does not start a new animation, but modifies currently running animations.

Parameters:
key - the key of the pair
source - where the animation starts
destination - the destination of the animation

putColor

public void putColor(java.lang.String key,
                     java.lang.String color)
Starts a new animation which will transform the color of the pair key to color.

Parameters:
key - the key of the pair
color - the destination of the animation

getColor

public java.awt.Color getColor(java.lang.String key)
Gets the current color of the pair key.

Parameters:
key - the key of the pair
Returns:
the color of the pair or null

addTask

public void addTask(java.lang.Runnable runnable)
Adds a task to this animation. The task will be executed whenever the animation makes a new step.

Parameters:
runnable - the task to execute

removeTask

public void removeTask(java.lang.Runnable runnable)
Removes a task which was earlier added to this animation.

Parameters:
runnable - the task to remove

setDuration

public void setDuration(int duration)
Sets the length of one transformation.

Parameters:
duration - the duration in milliseconds

getDuration

public int getDuration()
Gets the length of one transformation.

Returns:
the duration in milliseconds

stop

public void stop()
Stops the animation immediately, possibly leaving the animation in an unfinished state.


start

protected void start()
Starts the animation if it is not yet running.


pulse

protected void pulse()
Called when the animation has to perform another step.