A silly little class to draw icons with an alpha level. I was going to make
this an anonymous inner class for something else, but I figured it could be useful somewhere else in the future... git-svn-id: https://samskivert.googlecode.com/svn/trunk@1416 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -0,0 +1,63 @@
|
|||||||
|
//
|
||||||
|
// $Id: DimmedIcon.java,v 1.1 2004/04/23 16:46:37 ray Exp $
|
||||||
|
|
||||||
|
package com.samskivert.swing;
|
||||||
|
|
||||||
|
import java.awt.AlphaComposite;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Composite;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
|
||||||
|
import javax.swing.Icon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws an icon with a specified alpha level.
|
||||||
|
*/
|
||||||
|
public class DimmedIcon implements Icon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Construct a dimmed icon that is drawn at 50% normal.
|
||||||
|
*/
|
||||||
|
public DimmedIcon (Icon icon)
|
||||||
|
{
|
||||||
|
this(icon, .5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a dimmed icon that is drawn at the specified alpha level.
|
||||||
|
*/
|
||||||
|
public DimmedIcon (Icon icon, float alpha)
|
||||||
|
{
|
||||||
|
_alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
|
||||||
|
_icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited from interface Icon
|
||||||
|
public int getIconWidth ()
|
||||||
|
{
|
||||||
|
return _icon.getIconWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited from interface Icon
|
||||||
|
public int getIconHeight ()
|
||||||
|
{
|
||||||
|
return _icon.getIconHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited from interface Icon
|
||||||
|
public void paintIcon (Component c, Graphics g, int x, int y)
|
||||||
|
{
|
||||||
|
Graphics2D gfx = (Graphics2D) g;
|
||||||
|
Composite ocomp = gfx.getComposite();
|
||||||
|
gfx.setComposite(_alpha);
|
||||||
|
_icon.paintIcon(c, gfx, x, y);
|
||||||
|
gfx.setComposite(ocomp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The icon we're actually drawing. */
|
||||||
|
protected Icon _icon;
|
||||||
|
|
||||||
|
/** Our alpha composite. */
|
||||||
|
protected Composite _alpha;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user