Package com.formdev.flatlaf.util
Interface AnimatedIcon
- All Superinterfaces:
Icon
- All Known Implementing Classes:
FlatAnimatedIcon
Icon that automatically animates painting on component value changes.
getValue(Component)
returns the value of the component.
If the value changes, then paintIconAnimated(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 to
paintIcon(Component, Graphics, int, int)
is an instance of JComponent
.
A client property is set on the component to store the animation state.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
Animation support class that stores the animation state and implements the animation. -
Method Summary
Modifier and TypeMethodDescriptiondefault int
Returns the duration of the animation in milliseconds (default is 150).default Animator.Interpolator
Returns the interpolator for the animation.default int
Returns the resolution of the animation in milliseconds (default is 10).default Object
Returns the client property key used to store the animation support.float
Gets the value of the component.default boolean
Returns whether animation is enabled for this icon (default istrue
).default void
void
paintIconAnimated
(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 Details
-
paintIcon
-
paintIconAnimated
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
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
0
for off and1
for 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
Returns the interpolator for the animation. Default isCubicBezierEasing.STANDARD_EASING
. -
getClientPropertyKey
Returns the client property key used to store the animation support.
-