org.jgraph.example
Class JGraphAbstractIconAnimator

java.lang.Object
  extended by org.jgraph.example.JGraphAbstractIconAnimator

public abstract class JGraphAbstractIconAnimator
extends java.lang.Object

Provides animated ImageIcons for Component s which have CellRenderer-like functionality. Ordinarily, you'd get no animation with ordinary TreeCellRendereror TableCellRenderersince a single component is used to paint multiple locations on the Component. Animated icons must be tracked independently, one per animated cell. This class provides for maintaining a number of independently animated icons for a given Componentcontext. A key must be provided which must be unique across all elements of substructure (a table might provide "row x col", while a tree might provide the actual value in a row).

Subclasses should be instantiated near the Component context and override the getRepaintRect(Component,Object)method to trigger a refresh of its corresponding Component substructure location.

Subclasses should take care to invoke stop()when you want to stop the animation on a particular location.

This class assumes that all operations will take place on the event dispatch thread, thus there is no class-level synchronization.

See Also:
TreeCellRenderer, DefaultTreeCellRenderer, TableCellRenderer, DefaultTableCellRenderer

Constructor Summary
JGraphAbstractIconAnimator(java.awt.Component context, java.lang.Object key, javax.swing.ImageIcon icon)
          Create an object to animate icon on the given Component at the substructure location represented by the key.
 
Method Summary
static JGraphAbstractIconAnimator get(java.awt.Component context, java.lang.Object key)
          Return any existing, cached animator for the given context/key, or null if there is none.
 javax.swing.Icon getIcon()
          Returns the icon to be used for the renderer corresponding to this AbstractIconAnimator.
abstract  java.awt.Rectangle getRepaintRect(java.awt.Component context, java.lang.Object key)
          Based on the Component context and key, return the Component -relative rectangle to be repainted.
static boolean isAnimated(javax.swing.Icon icon)
          Return whether the given icon is animated.
 void stop()
          Stop animating this instance of AbstractIconAnimator.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JGraphAbstractIconAnimator

public JGraphAbstractIconAnimator(java.awt.Component context,
                                  java.lang.Object key,
                                  javax.swing.ImageIcon icon)
Create an object to animate icon on the given Component at the substructure location represented by the key.

Parameters:
context - Component on which the animation is to be painted
key - Substructure location identifier
icon - The animated icon
Method Detail

isAnimated

public static boolean isAnimated(javax.swing.Icon icon)
Return whether the given icon is animated. Currently assumes the original filename ends with "animated.gif".


get

public static JGraphAbstractIconAnimator get(java.awt.Component context,
                                             java.lang.Object key)
Return any existing, cached animator for the given context/key, or null if there is none.


getRepaintRect

public abstract java.awt.Rectangle getRepaintRect(java.awt.Component context,
                                                  java.lang.Object key)
Based on the Component context and key, return the Component -relative rectangle to be repainted.


stop

public void stop()
Stop animating this instance of AbstractIconAnimator.


getIcon

public javax.swing.Icon getIcon()
Returns the icon to be used for the renderer corresponding to this AbstractIconAnimator.