Java Graphics Draw drawInnerButtonDecoration(Graphics g, int x, int y, int w, int h, Color baseColor)

Here you can find the source of drawInnerButtonDecoration(Graphics g, int x, int y, int w, int h, Color baseColor)

Description

Draws a button border for an xp button with the given colors.

License

Open Source License

Declaration

private static void drawInnerButtonDecoration(Graphics g, int x, int y,
        int w, int h, Color baseColor) 

Method Source Code

//package com.java2s;
import java.awt.Color;
import java.awt.Graphics;

public class Main {
    /**/*from  w  w w. j a  v a 2  s  .co  m*/
     * Draws a button border for an xp button with the given colors.
     */
    private static void drawInnerButtonDecoration(Graphics g, int x, int y,
            int w, int h, Color baseColor) {

        Color lightColor = translucentColor(baseColor, 90);
        Color mediumColor = translucentColor(baseColor, 120);
        Color darkColor = translucentColor(baseColor, 200);

        g.translate(x, y);
        g.setColor(lightColor);
        g.fillRect(2, 1, w - 4, 1);

        g.setColor(mediumColor);
        g.fillRect(1, 2, 1, h - 4);
        g.fillRect(w - 2, 2, 1, h - 4);
        drawRect(g, 2, 2, w - 5, h - 5);

        g.setColor(darkColor);
        g.fillRect(2, h - 2, w - 4, 1);
        g.translate(-x, -y);
    }

    /**
     * Returns a color that is a translucent copy of the given color.
     *
     * @param baseColor     the base color
     * @param alpha         the alpha value
     * @return the translucent color with specified alpha
     */
    private static Color translucentColor(Color baseColor, int alpha) {
        return new Color(baseColor.getRed(), baseColor.getGreen(),
                baseColor.getBlue(), alpha);
    }

    /**
     * An optimized version of Graphics.drawRect.
     */
    static void drawRect(Graphics g, int x, int y, int w, int h) {
        g.fillRect(x, y, w + 1, 1);
        g.fillRect(x, y + 1, 1, h);
        g.fillRect(x + 1, y + h, w, 1);
        g.fillRect(x + w, y + 1, 1, h);
    }
}

Related

  1. drawGlow(Graphics2D g2, Area area, double width, Color color)
  2. drawGroove(Graphics g, int x, int y, int w, int h, Color shadow, Color highlight)
  3. drawGroove(Graphics g, int x, int y, int width, int height, Color shadow, Color highlight)
  4. drawHandles(final Graphics g, final int[] x, final int[] y)
  5. drawIcon(Graphics g, String icon, int x, int y)
  6. drawISPip(Graphics2D g2d, float width, float height)
  7. drawLightBeamVertical(Graphics g, Color c, int midx, int y1, int y2)
  8. drawLoweredBezel(Graphics g, int x, int y, int w, int h, Color shadow, Color darkShadow, Color highlight, Color lightHighlight)
  9. drawMarker(Graphics2D g, int markerWidth, int markerHeight, Point location)