org.jhotdraw.gui.plaf.palette
Class MultiIcon

java.lang.Object
  extended by org.jhotdraw.gui.plaf.palette.MultiIcon
All Implemented Interfaces:
javax.swing.Icon
Direct Known Subclasses:
SliderThumbIcon

public abstract class MultiIcon
extends java.lang.Object
implements javax.swing.Icon

An icon which paints one out of multiple icons depending on the state of the component. MultiIcon can lazily create the icons from a tiled image.

Version:
$Id: MultiIcon.java 527 2009-06-07 14:28:19Z rawcoder $
Author:
Werner Randelshofer

Field Summary
protected  javax.swing.Icon[] icons
          The icons from which we choose from.
private  boolean isTiledHorizontaly
          Whether the tiledImage needs to be tiled horizontaly or vertically to get the icons out of it.
private  int tileCount
          The number of icons in the tiledImage.
private  java.awt.Image tiledImage
          Holds the icon pictures in a single image.
 
Constructor Summary
MultiIcon(javax.swing.Icon[] icons)
          Creates a new instance from an array of icons.
MultiIcon(java.awt.Image[] images)
          Creates a new instance from an array of images.
MultiIcon(java.awt.Image tiledImage, int tileCount, boolean isTiledHorizontaly)
          Creates a new instance.
 
Method Summary
private  void generateIconsFromTiledImage()
           
protected abstract  void generateMissingIcons()
           
protected abstract  javax.swing.Icon getIcon(java.awt.Component c)
           
 int getIconHeight()
           
 int getIconWidth()
           
 void paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

icons

protected javax.swing.Icon[] icons
The icons from which we choose from. This variable is null, if we are using a tiled image as our base.


tiledImage

private java.awt.Image tiledImage
Holds the icon pictures in a single image. This variable is used only until we create the icons array. Then it is set to null.


tileCount

private int tileCount
The number of icons in the tiledImage.


isTiledHorizontaly

private boolean isTiledHorizontaly
Whether the tiledImage needs to be tiled horizontaly or vertically to get the icons out of it.

Constructor Detail

MultiIcon

public MultiIcon(javax.swing.Icon[] icons)
Creates a new instance from an array of icons. All icons must have the same dimensions. If an icon is null, an icon is derived for the state from the other icons.


MultiIcon

public MultiIcon(java.awt.Image[] images)
Creates a new instance from an array of images. All icons must have the same dimensions. If an icon is null, an icon is derived for the state from the other icons.


MultiIcon

public MultiIcon(java.awt.Image tiledImage,
                 int tileCount,
                 boolean isTiledHorizontaly)
Creates a new instance. The icon representations are created lazily from the tiled image.

Method Detail

getIconHeight

public int getIconHeight()
Specified by:
getIconHeight in interface javax.swing.Icon

getIconWidth

public int getIconWidth()
Specified by:
getIconWidth in interface javax.swing.Icon

paintIcon

public void paintIcon(java.awt.Component c,
                      java.awt.Graphics g,
                      int x,
                      int y)
Specified by:
paintIcon in interface javax.swing.Icon

generateIconsFromTiledImage

private void generateIconsFromTiledImage()

getIcon

protected abstract javax.swing.Icon getIcon(java.awt.Component c)

generateMissingIcons

protected abstract void generateMissingIcons()