javax.swing.plaf.basic

Class BasicGraphicsUtils


public class BasicGraphicsUtils
extends Object

A utility class providing commonly used drawing and measurement routines.

Constructor Summary

BasicGraphicsUtils()
Constructor.

Method Summary

static void
drawBezel(Graphics g, int x, int y, int width, int height, boolean isPressed, boolean isDefault, Color shadow, Color darkShadow, Color highlight, Color lightHighlight)
Draws a border that is suitable for buttons of the Basic look and feel.
static void
drawDashedRect(Graphics g, int x, int y, int width, int height)
Draws a rectangle, simulating a dotted stroke by painting only every second pixel along the one-pixel thick edge.
static void
drawEtchedRect(Graphics g, int x, int y, int width, int height, Color shadow, Color darkShadow, Color highlight, Color lightHighlight)
Draws a rectangle that appears etched into the surface, given four colors that are used for drawing.
static void
drawGroove(Graphics g, int x, int y, int width, int height, Color shadow, Color highlight)
Draws a rectangle that appears etched into the surface, given two colors that are used for drawing.
static void
drawLoweredBezel(Graphics g, int x, int y, int width, int height, Color shadow, Color darkShadow, Color highlight, Color lightHighlight)
Draws a rectangle that appears lowered into the surface, given four colors that are used for drawing.
static void
drawString(Graphics g, String text, int underlinedChar, int x, int y)
Draws a String at the given location, underlining the first occurence of a specified character.
static void
drawStringUnderlineCharAt(Graphics g, String text, int underlinedIndex, int x, int y)
Draws a String at the given location, underlining the character at the specified index.
static Insets
getEtchedInsets()
Determines the width of the border that gets painted by drawEtchedRect(Graphics,int,int,int,int,Color,Color,Color,Color).
static Insets
getGrooveInsets()
Determines the width of the border that gets painted by drawGroove(Graphics,int,int,int,int,Color,Color).
static Dimension
getPreferredButtonSize(AbstractButton b, int textIconGap)
Determines the preferred width and height of an AbstractButton, given the gap between the button’s text and icon.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

BasicGraphicsUtils

public BasicGraphicsUtils()
Constructor. It is utterly unclear why this class should be constructable, but this is what the API specification says.

Method Details

drawBezel

public static void drawBezel(Graphics g,
                             int x,
                             int y,
                             int width,
                             int height,
                             boolean isPressed,
                             boolean isDefault,
                             Color shadow,
                             Color darkShadow,
                             Color highlight,
                             Color lightHighlight)
Draws a border that is suitable for buttons of the Basic look and feel.

[An illustration that shows which pixels
 get painted in what color]

Parameters:
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.
isPressed - true to draw the button border with a pressed-in appearance; false for normal (unpressed) appearance.
isDefault - true to draw the border with the appearance it has when hitting the enter key in a dialog will simulate a click to this button; false for normal appearance.
shadow - the shadow color.
darkShadow - a darker variant of the shadow color.
highlight - the highlight color.
lightHighlight - a brighter variant of the highlight color.

drawDashedRect

public static void drawDashedRect(Graphics g,
                                  int x,
                                  int y,
                                  int width,
                                  int height)
Draws a rectangle, simulating a dotted stroke by painting only every second pixel along the one-pixel thick edge. The color of those pixels is the current color of the Graphics g. Any other pixels are left unchanged.

[An illustration that shows which pixels
 get painted]

Parameters:
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.

drawEtchedRect

public static void drawEtchedRect(Graphics g,
                                  int x,
                                  int y,
                                  int width,
                                  int height,
                                  Color shadow,
                                  Color darkShadow,
                                  Color highlight,
                                  Color lightHighlight)
Draws a rectangle that appears etched into the surface, given four colors that are used for drawing.

[An illustration that shows which pixels
 get painted in what color]

Parameters:
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.

drawGroove

public static void drawGroove(Graphics g,
                              int x,
                              int y,
                              int width,
                              int height,
                              Color shadow,
                              Color highlight)
Draws a rectangle that appears etched into the surface, given two colors that are used for drawing.

[An illustration that shows which pixels
 get painted in what color]

Parameters:
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, and for the inner side of the bottom and right ones.
highlight - the color that will be used for painting the inner side of the top and left edges, and for the outer side of the bottom and right ones.

drawLoweredBezel

public static void drawLoweredBezel(Graphics g,
                                    int x,
                                    int y,
                                    int width,
                                    int height,
                                    Color shadow,
                                    Color darkShadow,
                                    Color highlight,
                                    Color lightHighlight)
Draws a rectangle that appears lowered into the surface, given four colors that are used for drawing.

[An illustration that shows which pixels
 get painted in what color]

Compatibility with the Sun reference implementation: The Sun reference implementation seems to ignore the x and y arguments, at least in JDK 1.3.1 and 1.4.1_01. The method always draws the rectangular area at location (0, 0). A bug report has been filed with Sun; its “bug ID” is 4880003. The GNU Classpath implementation behaves correctly, thus not replicating this bug.

Parameters:
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 inner side of the top and left edges.
darkShadow - the color that will be used for painting the outer 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.

drawString

public static void drawString(Graphics g,
                              String text,
                              int underlinedChar,
                              int x,
                              int y)
Draws a String at the given location, underlining the first occurence of a specified character. The algorithm for determining the underlined position is not sensitive to case. If the character is not part of text, the text will be drawn without underlining. Drawing is performed in the current color and font of g.

[An illustration showing how to use the
 method]

Parameters:
g - the graphics into which the String is drawn.
text - the String to draw.
underlinedChar - the character whose first occurence in text will be underlined. It is not clear why the API specification declares this argument to be of type int instead of char. While this would allow to pass Unicode characters outside Basic Multilingual Plane 0 (U+0000 .. U+FFFE), at least the GNU Classpath implementation does not underline anything if underlinedChar is outside the range of char.
x - the x coordinate of the text, as it would be passed to Graphics.drawString(String,int,int).
y - the y coordinate of the text, as it would be passed to Graphics.drawString(String,int,int).

drawStringUnderlineCharAt

public static void drawStringUnderlineCharAt(Graphics g,
                                             String text,
                                             int underlinedIndex,
                                             int x,
                                             int y)
Draws a String at the given location, underlining the character at the specified index. Drawing is performed in the current color and font of g.

[An illustration showing how to use the
 method]

Parameters:
g - the graphics into which the String is drawn.
text - the String to draw.
underlinedIndex - the index of the underlined character in text. If underlinedIndex falls outside the range [0, text.length() - 1], the text will be drawn without underlining anything.
x - the x coordinate of the text, as it would be passed to Graphics.drawString(String,int,int).
y - the y coordinate of the text, as it would be passed to Graphics.drawString(String,int,int).
Since:
1.4

getEtchedInsets

public static Insets getEtchedInsets()
Determines the width of the border that gets painted by drawEtchedRect(Graphics,int,int,int,int,Color,Color,Color,Color).
Returns:
an Insets object whose top, left, bottom and right field contain the border width at the respective edge in pixels.

getGrooveInsets

public static Insets getGrooveInsets()
Determines the width of the border that gets painted by drawGroove(Graphics,int,int,int,int,Color,Color).
Returns:
an Insets object whose top, left, bottom and right field contain the border width at the respective edge in pixels.

getPreferredButtonSize

public static Dimension getPreferredButtonSize(AbstractButton b,
                                               int textIconGap)
Determines the preferred width and height of an AbstractButton, given the gap between the button’s text and icon.
Parameters:
b - the button whose preferred size is determined.
textIconGap - the gap between the button’s text and icon.
Returns:
a Dimension object whose width and height fields indicate the preferred extent in pixels.

BasicGraphicsUtils.java Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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.