PIRL

PIRL.Viewers
Class Animator

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLabel
                  extended by PIRL.Viewers.Animator
All Implemented Interfaces:
ActionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, SwingConstants

public class Animator
extends JLabel
implements ActionListener

An Animator is a JLabel that displays an animation of a series of Icons.

Once started, an Animator will sequentially display the sequence of Icons that it has been given. The rate at which Icons are displayed and the number of animation cycles is controllable. The animation sequence may be stopped and started again from where it left off, or restarted from the beginning of a cycle.

Version:
1.5
Author:
Bradford Castalia, UA/PIRL
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JLabel
JLabel.AccessibleJLabel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static int CYCLES
          The default number of animation cycles: INDEFINITELY.
static int INDEFINITELY
          Constant to specify an indefinate number of animation cycles; i.e. forever until stopped.
static int INITIAL_DELAY
          The default initial delay before animation starts: 0 milliseconds (immediately after start).
static int INTERVAL
          The default animation interval: 1000 milliseconds.
static int MINIMUM_INTERVAL
          The minimum animation interval: 50 milliseconds.
 
Fields inherited from class javax.swing.JLabel
labelFor
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Animator()
          Constructs a disabled Animator with default Animator parameters.
Animator(Icon[] icons)
          Constructs an Animator using all of the default Animator parameters.
Animator(Icon[] icons, int cycles, int initial_delay, int interval)
          Constructs an Icon Animator.
 
Method Summary
 void actionPerformed(ActionEvent event)
          Performs the animation event at the Timer interval.
 int Cycle()
          Gets the current animation cycle.
 int getDelay()
          Gets the delay between the display of each Icon in the animation sequence.
 int getInitialDelay()
          Gets the initial delay.
 int getRepeats()
          Gets the number of animation cycles.
 Icon[] Icons()
          Gets the array of Icons to be animated.
 Animator Icons(Icon[] icons)
          Sets the Icon array to be animated.
 boolean isRunning()
          Tests if the animation sequence is running.
 void restart()
          Restarts the Animator at the beginning of a cycle.
 Animator setDelay(int interval)
          Set the delay between the display of each Icon in the animation sequence.
 Animator setInitialDelay(int initial_delay)
          Sets the initial delay.
 Animator setRepeats(int cycles)
          Sets the maximum number of animation cycles.
 void start()
          Starts the animation.
 int Step()
          Gets the current animation step.
 void stop()
          Stops the animation.
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INDEFINITELY

public static final int INDEFINITELY
Constant to specify an indefinate number of animation cycles; i.e. forever until stopped.

See Also:
Constant Field Values

CYCLES

public static final int CYCLES
The default number of animation cycles: INDEFINITELY.

See Also:
Constant Field Values

INITIAL_DELAY

public static final int INITIAL_DELAY
The default initial delay before animation starts: 0 milliseconds (immediately after start).

See Also:
Constant Field Values

INTERVAL

public static final int INTERVAL
The default animation interval: 1000 milliseconds.

See Also:
Constant Field Values

MINIMUM_INTERVAL

public static final int MINIMUM_INTERVAL
The minimum animation interval: 50 milliseconds.

See Also:
Constant Field Values
Constructor Detail

Animator

public Animator(Icon[] icons,
                int cycles,
                int initial_delay,
                int interval)
Constructs an Icon Animator.

Parameters:
icons - An array of Icon objects to be animated.
cycles - The maximum number of animation cycles. Use the INDEFINITELY value to continue the animation until stopped.
initial_delay - The initial delay, after first starting, before animation begins. A value <= 0 means no initial delay.
interval - The interval between the display of each Icon in the animation sequence. A MINIMUM_INTERVAL is enforced.

Animator

public Animator(Icon[] icons)
Constructs an Animator using all of the default Animator parameters.

Parameters:
icons - An array of Icon objects to be animated.

Animator

public Animator()
Constructs a disabled Animator with default Animator parameters.

Method Detail

start

public void start()
Starts the animation.

If the animator was stopped in the middle of an animation cycle it pickes up from where it left off.

Use restart to start the animation from the beginning of a cycle.


stop

public void stop()
Stops the animation.


restart

public void restart()
Restarts the Animator at the beginning of a cycle.


setRepeats

public Animator setRepeats(int cycles)
Sets the maximum number of animation cycles.

Parameters:
cycles - The maximum number of times to cycle through the Icons. Use the INDEFINITELY value to continue the animation until stopped.
Returns:
This Animator.

getRepeats

public int getRepeats()
Gets the number of animation cycles.

Returns:
The number of times to cycle through the Icon_Sequence animation. For indefinate animation this will be the INDEFINITELY value.

getInitialDelay

public int getInitialDelay()
Gets the initial delay.

Returns:
The intial delay time in milliseconds.
See Also:
setInitialDelay(int)

setInitialDelay

public Animator setInitialDelay(int initial_delay)
Sets the initial delay.

The intial delay occurs before the first animation cycle starts or is restarted.

Parameters:
initial_delay - The intial delay time in milliseconds. A value less than or equal to zero means no initial delay.
Returns:
This Animator.

getDelay

public int getDelay()
Gets the delay between the display of each Icon in the animation sequence.

Returns:
The delay between the display of each Icon during an animation sequence.
See Also:
setDelay(int)

setDelay

public Animator setDelay(int interval)
Set the delay between the display of each Icon in the animation sequence.

After the animation sequence is started the next Icon is displayed after the interval delay. Because the time can not guarantee its accuracy, especially when the display component must be rendered during the interval, the interval may be longer than expected at times. In general, a longer interval is more likely to result in a smoother animation than a short interval.

Parameters:
interval - The delay between the display of each Icon during an animation sequence. A MINIMUM_INTERVAL is enforced.
Returns:
This Animator.

isRunning

public boolean isRunning()
Tests if the animation sequence is running.

Returns:
true if the animation sequence is active; false otherwise.

actionPerformed

public void actionPerformed(ActionEvent event)
Performs the animation event at the Timer interval.

If the animation is active the next Icon is painted.

Specified by:
actionPerformed in interface ActionListener

Icons

public Animator Icons(Icon[] icons)
Sets the Icon array to be animated.

The animation is stopped and the cycle count is reset to zero.

Parameters:
icons - An array of Icon objects to be animated.
Returns:
This Animator.

Icons

public Icon[] Icons()
Gets the array of Icons to be animated.

Returns:
The array of animated Icons.

Step

public int Step()
Gets the current animation step.

Returns:
The current animation step.

Cycle

public int Cycle()
Gets the current animation cycle.

Returns:
The current animation cycle count.

PIRL

Copyright (C) \ 2003-2009 Bradford Castalia, University of Arizona