Java Graphics Draw drawFilledBox(Graphics2D g, int x, int y, int width, int height)

Here you can find the source of drawFilledBox(Graphics2D g, int x, int y, int width, int height)

Description

Draw a filled box, with some of the edges beveled

License

Open Source License

Parameter

Parameter Description
g The graphics context to use
x The left side of the box
y The top of the box
width The box's width
height The box's height

Declaration

public static void drawFilledBox(Graphics2D g, int x, int y, int width, int height) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.*;

public class Main {
    public static final int BEVEL_CORNER_TOP_LEFT = 0xf01;
    public static final int BEVEL_CORNER_TOP_RIGHT = 0xf02;
    public static final int BEVEL_CORNER_BOTTOM_RIGHT = 0xf04;
    public static final int BEVEL_CORNER_BOTTOM_LEFT = 0xf08;
    public static final int DEFAULT_BEVEL_CORNERS = BEVEL_CORNER_TOP_LEFT | BEVEL_CORNER_BOTTOM_RIGHT;
    public static final int DEFAULT_BEVEL_AMOUNT = 5;

    /**//from   w w  w.  ja  v  a2s.  c o m
     * Draw a filled box, with some of the edges beveled
     * @param g         The graphics context to use
     * @param x         The left side of the box
     * @param y         The top of the box
     * @param width      The box's width
     * @param height   The box's height
     */
    public static void drawFilledBox(Graphics2D g, int x, int y, int width, int height) {
        Polygon p = new Polygon();

        int bevel_amount = DEFAULT_BEVEL_AMOUNT;
        if (width < bevel_amount * 2)
            bevel_amount = width / 2;
        if (height < bevel_amount * 2)
            bevel_amount = height / 2;

        // Top left
        if ((DEFAULT_BEVEL_CORNERS & BEVEL_CORNER_TOP_LEFT) == BEVEL_CORNER_TOP_LEFT) {
            p.addPoint(x, y + bevel_amount);
            p.addPoint(x + bevel_amount, y);
        } else
            p.addPoint(x, y);
        // Top right
        if ((DEFAULT_BEVEL_CORNERS & BEVEL_CORNER_TOP_RIGHT) == BEVEL_CORNER_TOP_RIGHT) {
            p.addPoint(x + width - bevel_amount, y);
            p.addPoint(x + width, y + bevel_amount);
        } else
            p.addPoint(x + width, y);
        // Bottom right
        if ((DEFAULT_BEVEL_CORNERS & BEVEL_CORNER_BOTTOM_RIGHT) == BEVEL_CORNER_BOTTOM_RIGHT) {
            p.addPoint(x + width, y - bevel_amount + height);
            p.addPoint(x + width - bevel_amount, y + height);
        } else
            p.addPoint(x + width, y + height);
        // Bottom left
        if ((DEFAULT_BEVEL_CORNERS & BEVEL_CORNER_BOTTOM_LEFT) == BEVEL_CORNER_BOTTOM_LEFT) {
            p.addPoint(x + bevel_amount, y + height);
            p.addPoint(x, y + height - bevel_amount);
        } else
            p.addPoint(x, y + height);

        g.fill(p);
    }
}

Related

  1. drawDottedDashLine(Graphics2D g, int x1, int y1, int x2, int y2)
  2. drawDottedRect(Graphics g, int x, int y, int w, int h)
  3. drawDropshipISPip(Graphics2D g2d, int width, int height, int circleSize, int fillCircleSize)
  4. drawEdge(Graphics g, int w, int h)
  5. drawEtchedRect(Graphics g, int x, int y, int width, int height, Color shadow, Color darkShadow, Color highlight, Color lightHighlight)
  6. drawFilledOctagon(Graphics2D g, int x, int y, float size)
  7. drawFilter(Graphics g, Color c, double transparency, int midx, int midy, int rx, int ry)
  8. drawFleche1(Graphics g, double x, double y, double x1, double y1, int L)
  9. drawFocus(Graphics g, int x, int y, int w, int h)