com.jgoodies.validation.extras
Class CompoundIcon

java.lang.Object
  extended by com.jgoodies.validation.extras.CompoundIcon
All Implemented Interfaces:
Icon

public final class CompoundIcon
extends Object
implements Icon

An Icon implementation that paints two icons as compound or overlaid icon using a specified alignment.

Note: This class is not yet part of the binary Validation library; it comes with the Validation distributions as an extra. The API is work in progress and may change without notice; this class may even be completely removed from future distributions. If you want to use this class, you may consider copying it into your code base.

Version:
$Revision: 1.12 $
Author:
Karsten Lentzsch
See Also:
ImageIcon

Nested Class Summary
static class CompoundIcon.Anchor
          Describes how to position the foreground icon to the background icon.
 
Constructor Summary
CompoundIcon(Icon backgroundIcon, Icon foregroundIcon)
          Constructs a compound icon for the given foreground and background icons, using a default anchor.
CompoundIcon(Icon backgroundIcon, Icon foregroundIcon, CompoundIcon.Anchor anchor)
          Constructs a compound icon for the given foreground and background icons, using the specified anchor.
 
Method Summary
 int getIconHeight()
          Returns this icon's height, which is the maximum of the heights of the background and foreground icons.
 int getIconWidth()
          Returns this icon's width, which is the maximum of the widths of the background and foreground icons.
 void paintIcon(Component c, Graphics g, int x, int y)
          Draws this icon at the specified location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompoundIcon

public CompoundIcon(Icon backgroundIcon,
                    Icon foregroundIcon)
Constructs a compound icon for the given foreground and background icons, using a default anchor.

Parameters:
backgroundIcon - the icon in the centered background
foregroundIcon - the icon that overlays the background icon

CompoundIcon

public CompoundIcon(Icon backgroundIcon,
                    Icon foregroundIcon,
                    CompoundIcon.Anchor anchor)
Constructs a compound icon for the given foreground and background icons, using the specified anchor.

Parameters:
backgroundIcon - the icon in the centered background
foregroundIcon - the icon that overlays the background icon
anchor - the position of the foreground icon relative to the background icon
Method Detail

getIconWidth

public int getIconWidth()
Returns this icon's width, which is the maximum of the widths of the background and foreground icons.

Specified by:
getIconWidth in interface Icon
Returns:
an int specifying the fixed width of this icon.

getIconHeight

public int getIconHeight()
Returns this icon's height, which is the maximum of the heights of the background and foreground icons.

Specified by:
getIconHeight in interface Icon
Returns:
an int specifying the fixed height of this icon.

paintIcon

public void paintIcon(Component c,
                      Graphics g,
                      int x,
                      int y)
Draws this icon at the specified location. First paints the background icon at the specified location, then paints the foreground icon using the offsets computed in #setAnchor.

Specified by:
paintIcon in interface Icon


Copyright © 2003-2008 JGoodies Karsten Lentzsch. All Rights Reserved.