com.mucommander.ui.icon
Class AnimatedIcon

java.lang.Object
  extended by com.mucommander.ui.icon.AnimatedIcon
All Implemented Interfaces:
javax.swing.Icon
Direct Known Subclasses:
SpinningDial

public abstract class AnimatedIcon
extends java.lang.Object
implements javax.swing.Icon

javax.swing.Icon implementation that manages animation.

This heavily borrows code from Technomage's furbelow package, distributed under the GNU Lesser General Public License.
The original source code can be found here.

Author:
twall, Nicolas Rinaudo

Field Summary
static int DEFAULT_FRAME_COUNT
          Default number of frames per animation.
static int DEFAULT_FRAME_DELAY
          Default number of milliseconds between each frame.
 
Constructor Summary
AnimatedIcon()
          Creates a new animated icon.
AnimatedIcon(int frameCount)
          Creates a new animated icon with the specified number of frames.
AnimatedIcon(int frameCount, int repaintDelay)
          Creates a new animated icon with the specified number of frames and repaint delay.
 
Method Summary
protected  void finalize()
           
 int getFrame()
          Returns the index of the current frame in the animation.
 int getFrameCount()
          Returns the total number of frames in the animation.
 int getFrameDelay()
          Returns the number of milliseconds the animation will sleep between each frame.
abstract  int getIconHeight()
          Returns the icon's height.
abstract  int getIconWidth()
          Returns the icon's width.
 boolean isAnimated()
          Returns true if the animation is currently running.
 void nextFrame()
          Takes the animation to its next frame.
protected abstract  void paintFrame(java.awt.Component c, java.awt.Graphics g, int x, int y)
          Paints the current frame.
 void paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)
          Paints the icon's current frame.
protected  void repaint()
          Forces the icon to repaint.
 void setAnimated(boolean a)
          Starts / stops the animation.
 void setFrame(int frame)
          Sets the index of the current frame in the animation.
 void setFrameCount(int count)
          Sets the total number of frames in the animation.
 void setFrameDelay(int delay)
          Sets the number of milliseconds the animation will sleep between each frame.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FRAME_COUNT

public static final int DEFAULT_FRAME_COUNT
Default number of frames per animation.

See Also:
Constant Field Values

DEFAULT_FRAME_DELAY

public static final int DEFAULT_FRAME_DELAY
Default number of milliseconds between each frame.

See Also:
Constant Field Values
Constructor Detail

AnimatedIcon

public AnimatedIcon()
Creates a new animated icon.

This is a convenience constructor and is strictly equivalent to calling AnimatedIcon(int,int)(DEFAULT_FRAME_COUNT, DEFAULT_FRAME_DELAY);


AnimatedIcon

public AnimatedIcon(int frameCount)
Creates a new animated icon with the specified number of frames.

This is a convenience constructor and is strictly equivalent to calling AnimatedIcon(int,int)(frameCount, DEFAULT_FRAME_DELAY);

Parameters:
frameCount - number of frames in the animation.

AnimatedIcon

public AnimatedIcon(int frameCount,
                    int repaintDelay)
Creates a new animated icon with the specified number of frames and repaint delay.

Parameters:
frameCount - number of frames in the animation.
repaintDelay - number of milliseconds to sleep between each frame.
Method Detail

getIconWidth

public abstract int getIconWidth()
Returns the icon's width.

Specified by:
getIconWidth in interface javax.swing.Icon
Returns:
the icon's width.

getIconHeight

public abstract int getIconHeight()
Returns the icon's height.

Specified by:
getIconHeight in interface javax.swing.Icon
Returns:
the icon's height.

paintFrame

protected abstract void paintFrame(java.awt.Component c,
                                   java.awt.Graphics g,
                                   int x,
                                   int y)
Paints the current frame.

Parameters:
c - component in which the frame is being painted.
g - graphics in which to paint the frame.
x - horizontal coordinate at which to paint the frame.
y - vertical coordinate at which to paint the frame.

setFrameCount

public void setFrameCount(int count)
Sets the total number of frames in the animation.

Parameters:
count - total number of frames in the animation.

getFrameCount

public int getFrameCount()
Returns the total number of frames in the animation.

Returns:
the total number of frames in the animation.

getFrame

public int getFrame()
Returns the index of the current frame in the animation.

Returns:
the index of the current frame in the animation.

setFrame

public void setFrame(int frame)
Sets the index of the current frame in the animation.

If the method does actually change the current frame, it will trigger a repaint.

Parameters:
frame - index of the current frame in the animation.

nextFrame

public void nextFrame()
Takes the animation to its next frame.

This is a convenience method and is strictly equivalent to calling setFrame(getFrame() + 1).


setFrameDelay

public void setFrameDelay(int delay)
Sets the number of milliseconds the animation will sleep between each frame.

If set to 0, the animation will stop.

Parameters:
delay - number of milliseconds the animation will sleep between each frame.

setAnimated

public void setAnimated(boolean a)
Starts / stops the animation.

Parameters:
a - whether the animation should be started or stopped.

isAnimated

public boolean isAnimated()
Returns true if the animation is currently running.

Note that this method will return true if the animation is meant to be running, for example if the icon is not visible but would be animated if it was.

Returns:
true if the animation is currently running, false.

getFrameDelay

public int getFrameDelay()
Returns the number of milliseconds the animation will sleep between each frame.

Returns:
the number of milliseconds the animation will sleep between each frame.

paintIcon

public void paintIcon(java.awt.Component c,
                      java.awt.Graphics g,
                      int x,
                      int y)
Paints the icon's current frame.

Specified by:
paintIcon in interface javax.swing.Icon
Parameters:
c - component in which to paint the icon.
g - graphic context in which to paint the icon.
x - horizontal coordinate at which to paint the icon.
y - vertical coordinate at which to paint the icon.

repaint

protected void repaint()
Forces the icon to repaint.


finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable


This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard