Groovy Documentation

com.wordpress.tipsforjava.swing
[Java] Class AlphaImageIcon

java.lang.Object
  javax.swing.ImageIcon
      com.wordpress.tipsforjava.swing.AlphaImageIcon

public class AlphaImageIcon
extends ImageIcon

An Icon wrapper that paints the contained icon with a specified transparency.

This class is suitable for wrapping an ImageIcon that holds an animated image. To show a non-animated Icon with transparency, the companion class AlphaIcon is a lighter alternative.

Authors:
Rob Camick
Darryl Burke
Version:
1.0 08/16/10


Field Summary
private float alpha

private Icon icon

private Image image

 
Constructor Summary
AlphaImageIcon(Icon icon, float alpha)

Creates an AlphaImageIcon with the specified icon and opacity.

 
Method Summary
float getAlpha()

Gets this AlphaIcon's opacity

Icon getIcon()

Gets the icon wrapped by this AlphaIcon

int getIconHeight()

Gets the height of the bounding rectangle of this AlphaImageIcon.

int getIconWidth()

Gets the width of the bounding rectangle of this AlphaImageIcon.

Image getImage()

Overridden to return the image of a wrapped ImageIcon, or null if the wrapped icon is not an ImageIcon.

int getImageLoadStatus()

Overridden to return the status of the image loading operation of a wrapped ImageIcon, or 0 if the contained icon is not an ImageIcon.

ImageObserver getImageObserver()

Overridden to return the ImageObserver of the image of a wrapped ImageIcon, or null if the contained icon is not an ImageIcon.

void paintIcon(Component c, Graphics g, int x, int y)

Paints the wrapped icon with this AlphaImageIcon's transparency.

void setImage(Image image)

Overridden to forward to a wrapped ImageIcon.

void setImageObserver(ImageObserver observer)

Overridden to forward to a wrapped ImageIcon.

 
Methods inherited from class ImageIcon
toString, getDescription, getAccessibleContext, getIconWidth, getIconHeight, setDescription, getImage, paintIcon, getImageLoadStatus, setImage, setImageObserver, getImageObserver, wait, wait, wait, equals, hashCode, getClass, notify, notifyAll
 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

alpha

private float alpha


icon

private Icon icon


image

private Image image


 
Constructor Detail

AlphaImageIcon

public AlphaImageIcon(Icon icon, float alpha)
Creates an AlphaImageIcon with the specified icon and opacity. The opacity alpha should be in the range 0.0F (fully transparent) to 1.0F (fully opaque).
Parameters:
icon - the Icon to wrap
alpha - the opacity


 
Method Detail

getAlpha

public float getAlpha()
Gets this AlphaIcon's opacity
Returns:
the opacity, in the range 0.0 to 1.0


getIcon

public Icon getIcon()
Gets the icon wrapped by this AlphaIcon
Returns:
the wrapped icon


getIconHeight

@Override
public int getIconHeight()
Gets the height of the bounding rectangle of this AlphaImageIcon. Overridden to return the height of the wrapped icon.
Returns:
the height in pixels


getIconWidth

@Override
public int getIconWidth()
Gets the width of the bounding rectangle of this AlphaImageIcon. Overridden to return the width of the wrapped icom.
Returns:
the width in pixels


getImage

@Override
public Image getImage()
Overridden to return the image of a wrapped ImageIcon, or null if the wrapped icon is not an ImageIcon.
Returns:
the Image object for a wrapped ImageIcon, or null


getImageLoadStatus

@Override
public int getImageLoadStatus()
Overridden to return the status of the image loading operation of a wrapped ImageIcon, or 0 if the contained icon is not an ImageIcon.
Returns:
the loading status as defined by java.awt.MediaTracker


getImageObserver

@Override
public ImageObserver getImageObserver()
Overridden to return the ImageObserver of the image of a wrapped ImageIcon, or null if the contained icon is not an ImageIcon.
Returns:
the loading status as defined by java.awt.MediaTracker


paintIcon

@Override
public void paintIcon(Component c, Graphics g, int x, int y)
Paints the wrapped icon with this AlphaImageIcon's transparency.
Parameters:
c - The component to which the icon is painted
g - the graphics context
x - the X coordinate of the icon's top-left corner
y - the Y coordinate of the icon's top-left corner


setImage

@Override
public void setImage(Image image)
Overridden to forward to a wrapped ImageIcon. Does nothing if the wrapped icon is not an ImageIcon.

In common with ImageIcom, the newly set image will only be shown when the concerned component(s) are repainted.

Parameters:
image - Sets the image displayed by a wrapped ImageIcon


setImageObserver

@Override
public void setImageObserver(ImageObserver observer)
Overridden to forward to a wrapped ImageIcon. Does nothing if the wrapped icon is not an ImageIcon.
Parameters:
observer - the image observer


 

Groovy Documentation