FileDocCategorySizeDatePackage
MetalBumps.javaAPI DocJava SE 5 API6781Fri Aug 26 14:58:06 BST 2005javax.swing.plaf.metal

MetalBumps

public class MetalBumps extends Object implements Icon
Implements the bumps used throughout the Metal Look and Feel.
version
1.25 12/19/03
author
Tom Santos
author
Steve Wilson

Fields Summary
static final Color
ALPHA
protected int
xBumps
protected int
yBumps
protected Color
topColor
protected Color
shadowColor
protected Color
backColor
protected static Vector
buffers
protected BumpBuffer
buffer
Constructors Summary
public MetalBumps(Dimension bumpArea)

    
         
        this( bumpArea.width, bumpArea.height );
    
public MetalBumps(int width, int height)

        this(width, height, MetalLookAndFeel.getPrimaryControlHighlight(),
             MetalLookAndFeel.getPrimaryControlDarkShadow(),
             MetalLookAndFeel.getPrimaryControlShadow());
    
public MetalBumps(int width, int height, Color newTopColor, Color newShadowColor, Color newBackColor)
Creates MetalBumps of the specified size with the specified colors. If newBackColor is null, the background will be transparent.

        setBumpArea( width, height );
	setBumpColors( newTopColor, newShadowColor, newBackColor );
    
Methods Summary
private javax.swing.plaf.metal.BumpBuffergetBuffer(java.awt.GraphicsConfiguration gc, java.awt.Color aTopColor, java.awt.Color aShadowColor, java.awt.Color aBackColor)

        if (buffer != null && buffer.hasSameConfiguration(
                              gc, aTopColor, aShadowColor, aBackColor)) {
            return buffer;
        }
        BumpBuffer result = null;

        Enumeration elements = buffers.elements();

	while ( elements.hasMoreElements() ) {
	    BumpBuffer aBuffer = (BumpBuffer)elements.nextElement();
	    if ( aBuffer.hasSameConfiguration(gc, aTopColor, aShadowColor,
                                              aBackColor)) {
	        result = aBuffer;
		break;
	    }
	}
        if (result == null) {
            result = new BumpBuffer(gc, topColor, shadowColor, backColor);
            buffers.addElement(result);
        }
	return result;
    
public intgetIconHeight()

        return yBumps * 2;
    
public intgetIconWidth()

        return xBumps * 2;
    
public voidpaintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)

        GraphicsConfiguration gc = (g instanceof Graphics2D) ?
                                     (GraphicsConfiguration)((Graphics2D)g).
                                     getDeviceConfiguration() : null;

        buffer = getBuffer(gc, topColor, shadowColor, backColor);

	int bufferWidth = buffer.getImageSize().width;
	int bufferHeight = buffer.getImageSize().height;
	int iconWidth = getIconWidth();
	int iconHeight = getIconHeight();
	int x2 = x + iconWidth;
	int y2 = y + iconHeight;
	int savex = x;

	while (y < y2) {
	    int h = Math.min(y2 - y, bufferHeight);
	    for (x = savex; x < x2; x += bufferWidth) {
		int w = Math.min(x2 - x, bufferWidth);
		g.drawImage(buffer.getImage(),
			    x, y, x+w, y+h,
			    0, 0, w, h,
			    null);
	    }
	    y += bufferHeight;
	}
    
public voidsetBumpArea(java.awt.Dimension bumpArea)

        setBumpArea( bumpArea.width, bumpArea.height );
    
public voidsetBumpArea(int width, int height)

        xBumps = width / 2;
	yBumps = height / 2;
    
public voidsetBumpColors(java.awt.Color newTopColor, java.awt.Color newShadowColor, java.awt.Color newBackColor)

        topColor = newTopColor;
	shadowColor = newShadowColor;
        if (newBackColor == null) {
            backColor = ALPHA;
        }
        else {
            backColor = newBackColor;
        }