Various utility functions to draw images, strings, shadows, calculate rectangle intersections, etc.
public static int calcWrapTextHeight(Font font, String string,
int width)
Returns the height, in pixels, of a rectangle which could display all
the text in the string passed as word-wrapped text when
displayed in the given font. The width passed is
the width of the rectangle.
public static void drawImage(Graphics g, Image image,
ImageObserver observer, int imageWidth, int imageHeight,
int alignment, Rectangle rect, Rectangle clipRect)
Draws an image of width imageWidth and height
imageHeight using the Graphics g and ImageObserver
observer given.
The rect parameter indicates the rectangle used to
determine alignment. The clipRect rectangle parameter given
indicates the rectangle used to clip the drawing.
alignment must be one of the following:
ALIGNMENT_TOP_LEFT ALIGNMENT_TOP ALIGNMENT_TOP_RIGHT
ALIGNMENT_LEFT ALIGNMENT_CENTER ALIGNMENT_RIGHT
ALIGNMENT_BOTTOM_LEFT ALIGNMENT_BOTTOM ALIGNMENT_BOTTOM_RIGHT
public static void drawShadow(Graphics g, int x, int y,
int width, int height, int shadowThickness,
Color topColor, Color bottomColor)
Draws a shadow using Graphics g at the given x,
y, width and height with a thickness
defined by shadowThickness. The top color of the shadow
will be drawn in topColor and the bottom color of the
shadow will be drawn in bottomColor.
public static void drawString(Graphics g, String string, Font font,
int alignment, Rectangle rect, Rectangle clipRect)
Draws string using the Graphics g and font
given. The rect parameter indicates the
rectangle used to determine alignment. The clipRect
rectangle parameter given indicates the rectangle used
to clip the drawing. alignment must be one of the following:
ALIGNMENT_TOP_LEFT ALIGNMENT_TOP ALIGNMENT_TOP_RIGHT
ALIGNMENT_LEFT ALIGNMENT_CENTER ALIGNMENT_RIGHT
ALIGNMENT_BOTTOM_LEFT ALIGNMENT_BOTTOM ALIGNMENT_BOTTOM_RIGHT
public static Dimension getImageDimensions(Image image,
ImageObserver observer)
Returns the dimensions of the passed image with
ImageObserver observer.
public static void drawWrapText(Graphics g, Font font, String string,
int yOff, Dimension d)
Draws the passed string as word-wrapped text using the given
Graphics object g and font. The string is drawn
starting at location 0, 0 and will only draw inside the bounds of the
given Dimension d. If yOff is non-zero, it is used
as a y offset which offsets the text drawn from the top of the rectangle
in pixels. This can be used to draw scrolling word wrapped text,
by setting yOff to more and more negative value and redrawing as a
user scrolls down.
public static Dimension getFontDimensions(Font font,
boolean useAverageWidth)
Calculates the overall dimension of the characters in
a given font. The height returned is the height of the tallest
glyph. If useAverageWidth is false, the width returned is the
width of the widest glyph. If true, the width returned is the average
width of all of the glyphs.
public static Dimension getImageDimensions(Image image,
ImageObserver observer)
Calculates the overall dimension of the given image with
the given observer.
public static int rectIntersect(Rectangle r1, Rectangle r2)
Determines the intersection of two rectangles r1 and r2.
Returns RECT_OUTSIDE if r1 is outside r2, RECT_INSIDE if r1 is inside
r2 and RECT_PARTIAL if the two rectangles intersect.
public static int version()
Returns the version number of the toolkit. 100 is returned for 1.00, 201 for
2.01, etc.