Package com.formdev.flatlaf.util
Interface AnimatedIcon
-
- All Superinterfaces:
javax.swing.Icon
- All Known Implementing Classes:
FlatAnimatedIcon
public interface AnimatedIcon extends javax.swing.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 class
AnimatedIcon.AnimationSupport
Animation 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 int
getAnimationDuration()
Returns the duration of the animation in milliseconds (default is 150).default Animator.Interpolator
getAnimationInterpolator()
Returns the interpolator for the animation.default int
getAnimationResolution()
Returns the resolution of the animation in milliseconds (default is 10).default java.lang.Object
getClientPropertyKey()
Returns the client property key used to store the animation support.float
getValue(java.awt.Component c)
Gets the value of the component.default boolean
isAnimationEnabled()
Returns whether animation is enabled for this icon (default istrue
).default void
paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)
void
paintIconAnimated(java.awt.Component c, java.awt.Graphics g, int x, int y, float animatedValue)
Paints the icon for the given animated value.
-
-
-
Method Detail
-
paintIcon
default void paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)
- Specified by:
paintIcon
in interfacejavax.swing.Icon
-
paintIconAnimated
void paintIconAnimated(java.awt.Component c, java.awt.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(java.awt.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
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
default Animator.Interpolator getAnimationInterpolator()
Returns the interpolator for the animation. Default isCubicBezierEasing.STANDARD_EASING
.
-
getClientPropertyKey
default java.lang.Object getClientPropertyKey()
Returns the client property key used to store the animation support.
-
-