Package com.formdev.flatlaf.util
Interface AnimatedIcon
-
- All Superinterfaces:
Icon
- All Known Implementing Classes:
FlatAnimatedIcon
public interface AnimatedIcon extends Icon
Icon that automatically animates painting on component value changes.getValue(Component)returns the value of the component. If the value changes, thenpaintIconAnimated(Component, Graphics, int, int, float)is invoked multiple times with animated value (from old value to new value).Example for an animated icon:
private class AnimatedMinimalTestIcon implements AnimatedIcon { @Override public int getIconWidth() { return 100; } @Override public int getIconHeight() { return 20; } @Override public void paintIconAnimated( Component c, Graphics g, int x, int y, float animatedValue ) { int w = getIconWidth(); int h = getIconHeight(); g.setColor( Color.red ); g.drawRect( x, y, w - 1, h - 1 ); g.fillRect( x, y, Math.round( w * animatedValue ), h ); } @Override public float getValue( Component c ) { return ((AbstractButton)c).isSelected() ? 1 : 0; } } // sample usage JCheckBox checkBox = new JCheckBox( "test" ); checkBox.setIcon( new AnimatedMinimalTestIcon() );Animation works only if the component passed topaintIcon(Component, Graphics, int, int)is an instance ofJComponent. A client property is set on the component to store the animation state.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classAnimatedIcon.AnimationSupportAnimation support class that stores the animation state and implements the animation.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default intgetAnimationDuration()Returns the duration of the animation in milliseconds (default is 150).default Animator.InterpolatorgetAnimationInterpolator()Returns the interpolator for the animation.default intgetAnimationResolution()Returns the resolution of the animation in milliseconds (default is 10).default ObjectgetClientPropertyKey()Returns the client property key used to store the animation support.floatgetValue(Component c)Gets the value of the component.default booleanisAnimationEnabled()Returns whether animation is enabled for this icon (default istrue).default voidpaintIcon(Component c, Graphics g, int x, int y)voidpaintIconAnimated(Component c, Graphics g, int x, int y, float animatedValue)Paints the icon for the given animated value.-
Methods inherited from interface javax.swing.Icon
getIconHeight, getIconWidth
-
-
-
-
Method Detail
-
paintIconAnimated
void paintIconAnimated(Component c, Graphics g, int x, int y, float animatedValue)
Paints the icon for the given animated value.- Parameters:
c- the component that this icon belongs tog- the graphics contextx- the x coordinate of the icony- the y coordinate of the iconanimatedValue- the animated value, which is either equal to whatgetValue(Component)returned, or somewhere between the previous value and the latest value thatgetValue(Component)returned
-
getValue
float getValue(Component c)
Gets the value of the component.This can be any value and depends on the component. If the value changes, then this class animates from the old value to the new one.
For a toggle button this could be
0for off and1for on.
-
isAnimationEnabled
default boolean isAnimationEnabled()
Returns whether animation is enabled for this icon (default istrue).
-
getAnimationDuration
default int getAnimationDuration()
Returns the duration of the animation in milliseconds (default is 150).
-
getAnimationResolution
default int getAnimationResolution()
Returns the resolution of the animation in milliseconds (default is 10). Resolution is the amount of time between timing events.
-
getAnimationInterpolator
default Animator.Interpolator getAnimationInterpolator()
Returns the interpolator for the animation. Default isCubicBezierEasing.STANDARD_EASING.
-
getClientPropertyKey
default Object getClientPropertyKey()
Returns the client property key used to store the animation support.
-
-