|
Groovy Documentation | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.wordpress.tipsforjava.swing.AnimatedIcon
public class AnimatedIcon extends Object
The AnimatedIcon will display a series of Icons in a predetermined sequence. This animation sequence can be configured to keep repeating or to stop after a specified number of cycles. The size of the Icon is determined to be the largest width or height of any Icon. All other Icons are then aligned within the space available when the Icon is painted. An AnimatedIcon cannot be shared by different components. However, the Icons added to an AnimatedIcon can be shared. The animation sequence is a simple sequential display of each Icon. When the end is reached the animation restarts at the first Icon. Icons are displayed in the order in which they are added. To create custom animation sequences you will need to override the getNextIconIndex() and isCycleCompleted() methods.
| Field Summary | |
|---|---|
static float |
BOTTOM
|
static float |
CENTER
|
private static int |
DEFAULT_CYCLES
|
private static int |
DEFAULT_DELAY
|
static float |
LEFT
|
static float |
RIGHT
|
static float |
TOP
|
private float |
alignmentX
|
private float |
alignmentY
|
private boolean |
animationFinished
|
private JComponent |
component
|
private int |
currentIconIndex
|
private int |
cycles
|
private int |
cyclesCompleted
|
private int |
iconHeight
|
private int |
iconWidth
|
private int |
iconX
|
private int |
iconY
|
private List |
icons
|
private boolean |
showFirstIcon
|
private Timer |
timer
|
| Constructor Summary | |
AnimatedIcon(JComponent component, Icon... icons)
Create an AnimatedIcon that will continuously cycle with the default (500ms). |
|
AnimatedIcon(JComponent component, int delay, Icon... icons)
Create an AnimatedIcon that will continuously cycle |
|
AnimatedIcon(JComponent component, int delay, int cycles, Icon... icons)
Create an AnimatedIcon specifying all the properties. |
|
| Method Summary | |
|---|---|
void
|
actionPerformed(ActionEvent e)
Control the animation of the Icons when the Timer fires. |
void
|
addIcon(Icon... icons)
Add Icons to be used in the animation. |
private void
|
calculateIconDimensions()
Calculate the width and height of the Icon based on the maximum width and height of any individual Icon. |
float
|
getAlignmentX()
Get the alignment of the Icon on the x-axis |
float
|
getAlignmentY()
Get the alignment of the icon on the y-axis |
JComponent
|
getComponent()
|
int
|
getCurrentIconIndex()
Get the index of the currently visible Icon |
int
|
getCycles()
Get the cycles to complete before animation stops. |
int
|
getDelay()
Get the delay between painting each Icon |
Icon
|
getIcon(int index)
Get the Icon at the specified index. |
int
|
getIconCount()
Get the number of Icons contained in this AnimatedIcon. |
int
|
getIconHeight()
Gets the height of this icon. |
int
|
getIconWidth()
Gets the width of this icon. |
protected int
|
getNextIconIndex(int currentIndex, int iconCount)
Get the index of the next Icon to be displayed. |
private int
|
getOffset(int maxValue, int iconValue, float alignment)
|
protected boolean
|
isCycleCompleted(int currentIndex, int iconCount)
Check if the currently visible Icon is the last Icon to be displayed in the animation sequence. |
boolean
|
isShowFirstIcon()
Get the showFirstIcon |
void
|
paintIcon(Component c, Graphics g, int x, int y)
Paint the icons of this compound icon at the specified location |
void
|
pause()
Pause the animation. |
void
|
restart()
Restart the animation from where the animation was paused. |
void
|
run()
|
void
|
setAlignmentX(float alignmentX)
Specify the horizontal alignment of the icon. |
void
|
setAlignmentY(float alignmentY)
Specify the vertical alignment of the Icon. |
void
|
setCurrentIconIndex(int index)
Set the index of the Icon to be displayed and then repaint the Icon. |
void
|
setCycles(int cycles)
Specify the number of times to repeat each animation sequence, or cycle. |
void
|
setDelay(int delay)
Specify the delay |
void
|
setShowFirstIcon(boolean showFirstIcon)
Display the first icon when animation is finished. |
void
|
start()
Start the animation from the beginning. |
void
|
stop()
Stop the animation. |
| Methods inherited from class Object | |
|---|---|
| wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
| Field Detail |
|---|
public static final float BOTTOM
public static final float CENTER
private static final int DEFAULT_CYCLES
private static final int DEFAULT_DELAY
public static final float LEFT
public static final float RIGHT
public static final float TOP
private float alignmentX
private float alignmentY
private boolean animationFinished
private JComponent component
private int currentIconIndex
private int cycles
private int cyclesCompleted
private int iconHeight
private int iconWidth
private int iconX
private int iconY
private List icons
private boolean showFirstIcon
private Timer timer
| Constructor Detail |
|---|
public AnimatedIcon(JComponent component, Icon... icons)
component - the component the icon will be painted onicons - the Icons to be painted as part of the animation
public AnimatedIcon(JComponent component, int delay, Icon... icons)
component - the component the icon will be painted ondelay - the delay between painting each icon, in milli secondsicons - the Icons to be painted as part of the animation
public AnimatedIcon(JComponent component, int delay, int cycles, Icon... icons)
component - the component the icon will be painted ondelay - the delay between painting each icon, in milli secondscycles - the number of times to repeat the animation sequenceicons - the Icons to be painted as part of the animation
| Method Detail |
|---|
public void actionPerformed(ActionEvent e)
public void addIcon(Icon... icons)
icons - the icons to be added
private void calculateIconDimensions()
public float getAlignmentX()
public float getAlignmentY()
public JComponent getComponent()
public int getCurrentIconIndex()
public int getCycles()
public int getDelay()
public Icon getIcon(int index)
index - the index of the Icon to be returned
public int getIconCount()
de public public int getIconHeight()
de public public int getIconWidth()
protected int getNextIconIndex(int currentIndex, int iconCount)
index - the index of the Icon currently displayediconCount - the number of Icons to be displayed
private int getOffset(int maxValue, int iconValue, float alignment)
protected boolean isCycleCompleted(int currentIndex, int iconCount)
index - the index of the Icon currently displayediconCount - the number of Icons to be displayed
public boolean isShowFirstIcon()
de public public void paintIcon(Component c, Graphics g, int x, int y)
c - The component on which the icon is paintedg - the graphics contextx - the X coordinate of the icon's top-left cornery - the Y coordinate of the icon's top-left corner
public void pause()
public void restart()
public void run()
public void setAlignmentX(float alignmentX)
alignmentX - common values are LEFT, CENTER (default) or RIGHT
although any value between 0.0 and 1.0 can be used
public void setAlignmentY(float alignmentY)
alignmentY - common values TOP, CENTER (default) or BOTTOM
although any value between 0.0 and 1.0 can be used
public void setCurrentIconIndex(int index)
index - the index of the Icon to be displayed
public void setCycles(int cycles)
cycles - the number of cycles to complete before the animation
stops. The default is -1, which means the animation is
continuous.
public void setDelay(int delay)
delay - the delay between painting eachIcon (in milli seconds)
public void setShowFirstIcon(boolean showFirstIcon)
showFirstIcon - true when the first icon is to be displayed,
false otherwise
public void start()
public void stop()
Groovy Documentation