Java Graphics Draw drawEtchedRect(Graphics g, int x, int y, int width, int height, Color shadow, Color darkShadow, Color highlight, Color lightHighlight)

Here you can find the source of drawEtchedRect(Graphics g, int x, int y, int width, int height, Color shadow, Color darkShadow, Color highlight, Color lightHighlight)

Description

Draws a rectangle that appears etched into the surface, given four colors that are used for drawing.

License

Open Source License

Parameter

Parameter Description
g the graphics into which the rectangle is drawn.
x the x coordinate of the rectangle.
y the y coordinate of the rectangle.
width the width of the rectangle in pixels.
height the height of the rectangle in pixels.
shadow the color that will be used for painting the outer side of the top and left edges.
darkShadow the color that will be used for painting the inner side of the top and left edges.
highlight the color that will be used for painting the inner side of the bottom and right edges.
lightHighlight the color that will be used for painting the outer side of the bottom and right edges.

Declaration

public static void drawEtchedRect(Graphics g, int x, int y, int width, int height, Color shadow,
        Color darkShadow, Color highlight, Color lightHighlight) 

Method Source Code


//package com.java2s;
/* BasicGraphicsUtils.java
   Copyright (C) 2003 Free Software Foundation, Inc.
    /*w w w .j  a v a  2s  . c  o  m*/
This file is part of GNU Classpath.
    
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
    
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
    
Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
    
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */

import java.awt.Color;

import java.awt.Graphics;

public class Main {
    /**
     * Draws a rectangle that appears etched into the surface, given
     * four colors that are used for drawing.
     *
     * <p><img src="doc-files/BasicGraphicsUtils-1.png" width="360"
     * height="200" alt="[An illustration that shows which pixels
     * get painted in what color]" />
     *
     * @param g the graphics into which the rectangle is drawn.
     * @param x the x coordinate of the rectangle.
     * @param y the y coordinate of the rectangle.
     * @param width the width of the rectangle in pixels.
     * @param height the height of the rectangle in pixels.
     *
     * @param shadow the color that will be used for painting
     *        the outer side of the top and left edges.
     *
     * @param darkShadow the color that will be used for painting
     *        the inner side of the top and left edges.
     *
     * @param highlight the color that will be used for painting
     *        the inner side of the bottom and right edges.
     *
     * @param lightHighlight the color that will be used for painting
     *        the outer side of the bottom and right edges.
     *
     * @see #getEtchedInsets()
     * @see javax.swing.border.EtchedBorder
     */
    public static void drawEtchedRect(Graphics g, int x, int y, int width, int height, Color shadow,
            Color darkShadow, Color highlight, Color lightHighlight) {
        Color oldColor;
        int x2, y2;

        oldColor = g.getColor();
        x2 = x + width - 1;
        y2 = y + height - 1;

        try {
            /* To understand this code, it might be helpful to look at the
             * image "BasicGraphicsUtils-1.png" that is included with the
             * JavaDoc. The file is located in the "doc-files" subdirectory.
             *
             * (x2, y2) is the coordinate of the most right and bottom pixel
             * to be painted.
             */
            g.setColor(shadow);
            g.drawLine(x, y, x2 - 1, y); // top, outer
            g.drawLine(x, y + 1, x, y2 - 1); // left, outer

            g.setColor(darkShadow);
            g.drawLine(x + 1, y + 1, x2 - 2, y + 1); // top, inner
            g.drawLine(x + 1, y + 2, x + 1, y2 - 2); // left, inner

            g.setColor(highlight);
            g.drawLine(x + 1, y2 - 1, x2 - 1, y2 - 1); // bottom, inner
            g.drawLine(x2 - 1, y + 1, x2 - 1, y2 - 2); // right, inner

            g.setColor(lightHighlight);
            g.drawLine(x, y2, x2, y2); // bottom, outer
            g.drawLine(x2, y, x2, y2 - 1); // right, outer
        } finally {
            g.setColor(oldColor);
        }
    }
}

Related

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