All Packages Class Hierarchy This Package Previous Next Index
Class com.bulletproof.gui.Graphics
java.lang.Object
|
+----com.bulletproof.gui.Graphics
- public class Graphics
- extends Object
Graphics is the abstract base class for all graphics contexts
which allow an application to draw onto components realized on
various devices or onto off-screen images.
A Graphics object encapsulates the state information needed
for the various rendering operations that Java supports. This
state information includes:
- The Component to draw on
- A translation origin for rendering and clipping coordinates
- The current clip
- The current color
- The current font
- The current logical pixel operation function (XOR or Paint)
- The current XOR alternation color
(see setXORMode)
Coordinates are infinitely thin and lie between the pixels of the
output device.
Operations which draw the outline of a figure operate by traversing
along the infinitely thin path with a pixel-sized pen that hangs
down and to the right of the anchor point on the path.
Operations which fill a figure operate by filling the interior
of the infinitely thin path.
Operations which render horizontal text render the ascending
portion of the characters entirely above the baseline coordinate.
Some important points to consider are that drawing a figure that
covers a given rectangle will occupy one extra row of pixels on
the right and bottom edges compared to filling a figure that is
bounded by that same rectangle.
Also, drawing a horizontal line along the same y coordinate as
the baseline of a line of text will draw the line entirely below
the text except for any descenders.
Both of these properties are due to the pen hanging down and to
the right from the path that it traverses.
All coordinates which appear as arguments to the methods of this
Graphics object are considered relative to the translation origin
of this Graphics object prior to the invocation of the method.
All rendering operations modify only pixels which lie within the
area bounded by both the current clip of the graphics context
and the extents of the Component used to create the Graphics object.
-
AND
- Region copy mode: The copied region is AND'ed with the destination.
-
AND_NOT
- Region copy mode: The copied region is AND'ed with the inverted
destination region.
-
ERASE
- Erase mode.
-
GRAY
- Gray drawing mode.
-
INVERT
- Invert mode.
-
NOT
- Region copy mode: The copied region is inverted and overwrites the
destination.
-
OFFSCREEN_WINDOW
-
-
ONSCREEN_WINDOW
-
-
OR
- Region copy mode: The copied region is OR'ed with the destination.
-
OVERWRITE
- Region copy mode: The copied region overwrites the destination.
-
PLAIN
- Plain drawing mode.
-
RAISED
- Constant for a slightly raised border.
-
SIMPLE
- Constant for a plain rectangle border.
-
SOUND_ALARM
- System sound for the alarm.
-
SOUND_CLICK
- System sound for a click.
-
SOUND_CONFIRMATION
- System sound for confirmation.
-
SOUND_ERROR
- System sound for error.
-
SOUND_INFO
- System sound for info.
-
SOUND_STARTUP
- System sound for startup.
-
SOUND_WARNING
- System sound for warning.
-
XOR
- Region copy mode: The copied region is XOR'ed with the destination.
-
Graphics()
- Constructs a new Graphics object.
-
beep()
- Play the default system sound.
-
borderType(int, int, int)
- Constructs a border type.
-
clearRect(int, int, int, int)
-
Clears the specified rectangle by filling it with the background
color of the current drawing surface.
-
colorSupported()
- Determine whether the platform supports color.
-
copyOffScreenRegion(int, int, int, int, int, int, int, int, int)
-
-
copyRegion(int, int, int, int, int, int, int)
- Copy a rectangular region from one place to another.
-
create(int, int, int, int)
- Creates a new Graphics object based on this Graphics object,
but with a new translation and clip area.
-
draw3DRect(int, int, int, int, int)
- Draw a 3D rectangular border.
-
drawArc(int, int, int, int, int, int)
- Draws the outline of an arc covering the specified rectangle,
starting at startAngle and extending for arcAngle degrees,
using the current color.
-
drawBitmap(int, int, Bitmap)
- Draw a bitmap.
-
drawBorder(int, int, int, int, int, int)
- Draw a rectangular border.
-
drawCursor(int, int, int, int)
-
Draws the outline of the specified rectangle using the current
color.
-
drawDots(int, int, int, int)
-
Draws a dotted line between the coordinates (x1,y1) and (x2,y2) using
the current color.
-
drawImage(Image, int, int)
-
Draws an image at the given x and y coordinates.
-
drawLine(int, int, int, int)
-
Draws a line between the coordinates (x1,y1) and (x2,y2) using
the current color.
-
drawPolygon(int[], int[], int)
-
Draws a sequence of connected lines defined by arrays of x coordinates
and y coordinates using the current color.
-
drawRect(int, int, int, int)
-
Draws the outline of the specified rectangle using the current
color.
-
drawRoundRect(int, int, int, int, int, int)
-
Draws the outline of the specified rounded corner rectangle
using the current color.
-
drawString(char[], int, int, int, int)
-
Draws the specified String using the current font and color.
-
drawString(String, int, int)
-
Draws the specified String using the current font and color.
-
fill3DRect(int, int, int, int, int)
-
Draws the outline of the specified rectangle using the current
color.
-
fillArc(int, int, int, int, int, int)
-
Fills an arc bounded by the specified rectangle, starting at
startAngle and extending for arcAngle degrees, with the
current color.
-
fillPolygon(int[], int[], int)
-
Fills a sequence of connected lines defined by arrays of x coordinates
and y coordinates using the current color.
-
fillRect(int, int, int, int)
-
Fills the specified rectangle with the current color.
-
fillRoundRect(int, int, int, int, int, int)
-
Fills the specified rounded corner rectangle with the current color.
-
getFont()
- Gets the current font.
-
getFontMetrics()
- Gets the font metrics of the current font.
-
getFontMetrics(Font)
- Gets the font metrics of the selected font.
-
getHeight()
- Returns the height of the current font in pixels.
-
getLocationOnScreen()
- Set the region in which drawing can be performed.
-
getScreenDimension()
- Get the size of the screen.
-
getWidth(String)
- Returns the width of a string in pixels.
-
isColor()
- Determine whether the platform is drawing in color.
-
playSound(int)
- Play a system sound.
-
playSound(int, int)
- Play a tone of the specified frequency for the specified duration.
-
resetDrawRegion()
- Reset the region in which drawing can be performed to be the whole
screen.
-
setColor(Color)
- Sets the current color to the specified color.
-
setDrawRegion(int, int, int, int, Rectangle)
- /**
Set the region in which drawing can be performed.
-
setFont(Font)
- Sets the font for all subsequent text rendering operations.
-
setPaintMode()
- Sets the logical pixel operation function to the Paint, or
overwrite mode.
-
setXORMode(Color)
- Sets the logical pixel operation function to the XOR mode,
which alternates pixels between the current color and a new
specified XOR alternation color.
-
translate(int, int)
- Translates the origin of the graphics context to the point
(x, y) in the current coordinate system.
SIMPLE
public static final int SIMPLE
- Constant for a plain rectangle border.
RAISED
public static final int RAISED
- Constant for a slightly raised border.
PLAIN
public static final int PLAIN
- Plain drawing mode.
GRAY
public static final int GRAY
- Gray drawing mode.
ERASE
public static final int ERASE
- Erase mode.
INVERT
public static final int INVERT
- Invert mode.
OVERWRITE
public static final int OVERWRITE
- Region copy mode: The copied region overwrites the destination.
AND
public static final int AND
- Region copy mode: The copied region is AND'ed with the destination.
AND_NOT
public static final int AND_NOT
- Region copy mode: The copied region is AND'ed with the inverted
destination region.
XOR
public static final int XOR
- Region copy mode: The copied region is XOR'ed with the destination.
OR
public static final int OR
- Region copy mode: The copied region is OR'ed with the destination.
NOT
public static final int NOT
- Region copy mode: The copied region is inverted and overwrites the
destination.
ONSCREEN_WINDOW
public static final int ONSCREEN_WINDOW
OFFSCREEN_WINDOW
public static final int OFFSCREEN_WINDOW
SOUND_INFO
public static final int SOUND_INFO
- System sound for info.
SOUND_WARNING
public static final int SOUND_WARNING
- System sound for warning.
SOUND_ERROR
public static final int SOUND_ERROR
- System sound for error.
SOUND_STARTUP
public static final int SOUND_STARTUP
- System sound for startup.
SOUND_ALARM
public static final int SOUND_ALARM
- System sound for the alarm.
SOUND_CONFIRMATION
public static final int SOUND_CONFIRMATION
- System sound for confirmation.
SOUND_CLICK
public static final int SOUND_CLICK
- System sound for a click.
Graphics
public Graphics()
- Constructs a new Graphics object. Since Graphics is an abstract
class, and since it must be customized by subclasses for different
output devices, Graphics objects cannot be created directly.
Instead, Graphics objects must be obtained from another Graphics
object or created by a Component.
- See Also:
- getGraphics, create
create
public Graphics create(int x,
int y,
int width,
int height)
- Creates a new Graphics object based on this Graphics object,
but with a new translation and clip area.
The new Graphics object will have its origin translated to the
specified coordinate (x, y) and will also have its current clip
intersected with the specified rectangle. The arguments are all
interpreted in the coordinate system of the original Graphics
object.
- Parameters:
- x - the x coordinate of the new translation origin
and rectangle to intersect the clip with
- y - the y coordinate of the new translation origin
and rectangle to intersect the clip with
- width - the width of the rectangle to intersect the clip with
- height - the height of the rectangle to intersect the clip with
- See Also:
- translate
clearRect
public void clearRect(int x,
int y,
int w,
int h)
- Clears the specified rectangle by filling it with the background
color of the current drawing surface.
- Parameters:
- x - the x coordinate of the rectangle to clear
- y - the y coordinate of the rectangle to clear
- width - the width of the rectangle to clear
- height - the height of the rectangle to clear
drawLine
public void drawLine(int x1,
int y1,
int x2,
int y2)
- Draws a line between the coordinates (x1,y1) and (x2,y2) using
the current color.
- Parameters:
- x1 - the x coordinate of the start of the line
- y1 - the y coordinate of the start of the line
- x2 - the x coordinate of the end of the line
- y2 - the y coordinate of the end of the line
drawDots
public void drawDots(int x1,
int y1,
int x2,
int y2)
- Draws a dotted line between the coordinates (x1,y1) and (x2,y2) using
the current color.
- Parameters:
- x1 - the x coordinate of the start of the line
- y1 - the y coordinate of the start of the line
- x2 - the x coordinate of the end of the line
- y2 - the y coordinate of the end of the line
drawPolygon
public void drawPolygon(int xPoints[],
int yPoints[],
int nPoints)
- Draws a sequence of connected lines defined by arrays of x coordinates
and y coordinates using the current color.
The figure is not automatically closed if the first coordinate is
different from the last coordinate.
- Parameters:
- xPoints - an array of x points
- yPoints - an array of y points
- nPoints - the total number of points
fillPolygon
public void fillPolygon(int xPoints[],
int yPoints[],
int nPoints)
- Fills a sequence of connected lines defined by arrays of x coordinates
and y coordinates using the current color.
The figure is not automatically closed if the first coordinate is
different from the last coordinate.
- Parameters:
- xPoints - an array of x points
- yPoints - an array of y points
- nPoints - the total number of points
drawRoundRect
public void drawRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
- Draws the outline of the specified rounded corner rectangle
using the current color.
The resulting rectangle will cover an area (width + 1) pixels wide
by (height + 1) pixels tall.
- Parameters:
- x - the x coordinate of the rectangle to be drawn
- y - the y coordinate of the rectangle to be drawn
- width - the width of the rectangle to be drawn
- height - the height of the rectangle to be drawn
- arcWidth - the horizontal diameter of the arc at the four corners
- arcHeight - the vertical diameter of the arc at the four corners
- See Also:
- fillRoundRect
drawString
public void drawString(char text[],
int start,
int len,
int x,
int y)
- Draws the specified String using the current font and color.
The x,y position is the starting point of the baseline of the String.
- Parameters:
- str - the String to be drawn
- x - the x coordinate of the baseline of the text
- y - the y coordinate of the baseline of the text
drawString
public void drawString(String text,
int x,
int y)
- Draws the specified String using the current font and color.
The x,y position is the starting point of the baseline of the String.
- Parameters:
- str - the String to be drawn
- x - the x coordinate of the baseline of the text
- y - the y coordinate of the baseline of the text
drawRect
public void drawRect(int x,
int y,
int width,
int height)
- Draws the outline of the specified rectangle using the current
color.
- Parameters:
- x - the x coordinate of the rectangle to be drawn
- y - the y coordinate of the rectangle to be drawn
- width - the width of the rectangle to be drawn
- height - the height of the rectangle to be drawn
draw3DRect
public void draw3DRect(int x,
int y,
int width,
int height,
int mode)
- Draw a 3D rectangular border. The border is drawn around the rectangle
specified by the given dimensions.
- Parameters:
- left - the x coordinate of the rectangle's top left corner
- top - the y coordinate of the rectangle's top left corner
- width - the width of the rectangle
- height - the height of the rectangle
- mode - the drawing mode to use (one of
GRAY RAISED SIMPLE
or INVERT.
fill3DRect
public void fill3DRect(int x,
int y,
int width,
int height,
int mode)
- Draws the outline of the specified rectangle using the current
color.
- Parameters:
- x - the x coordinate of the rectangle to be drawn
- y - the y coordinate of the rectangle to be drawn
- width - the width of the rectangle to be drawn
- height - the height of the rectangle to be drawn
drawCursor
public void drawCursor(int x,
int y,
int width,
int height)
- Draws the outline of the specified rectangle using the current
color. The resulting rectangle will cover an area (width + 1)
pixels wide by (height + 1) pixels tall.
- Parameters:
- x - the x coordinate of the rectangle to be drawn
- y - the y coordinate of the rectangle to be drawn
- width - the width of the rectangle to be drawn
- height - the height of the rectangle to be drawn
fillRect
public void fillRect(int x,
int y,
int width,
int height)
- Fills the specified rectangle with the current color.
- Parameters:
- x - the x coordinate of the rectangle to be filled
- y - the y coordinate of the rectangle to be filled
- width - the width of the rectangle to be filled
- height - the height of the rectangle to be filled
fillRoundRect
public void fillRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
- Fills the specified rounded corner rectangle with the current color.
- Parameters:
- x - the x coordinate of the rectangle to be filled
- y - the y coordinate of the rectangle to be filled
- width - the width of the rectangle to be filled
- height - the height of the rectangle to be filled
- arcWidth - the horizontal diameter of the arc at the four corners
- arcHeight - the vertical diameter of the arc at the four corners
getFont
public Font getFont()
- Gets the current font.
getFontMetrics
public FontMetrics getFontMetrics()
- Gets the font metrics of the current font.
getFontMetrics
public FontMetrics getFontMetrics(Font font)
- Gets the font metrics of the selected font.
colorSupported
public static boolean colorSupported()
- Determine whether the platform supports color. Used
only to determine if a 3D GUI should be drawn
isColor
public static boolean isColor()
- Determine whether the platform is drawing in color.
setColor
public void setColor(Color c)
- Sets the current color to the specified color. All subsequent
rendering operations will use this specified color.
- Parameters:
- c - the new rendering color
setFont
public void setFont(Font font)
- Sets the font for all subsequent text rendering operations.
- Parameters:
- font - the specified font
setPaintMode
public void setPaintMode()
- Sets the logical pixel operation function to the Paint, or
overwrite mode. All subsequent rendering operations will
overwrite the destination with the current color.
setXORMode
public void setXORMode(Color c2)
- Sets the logical pixel operation function to the XOR mode,
which alternates pixels between the current color and a new
specified XOR alternation color.
When subsequent rendering operations are performed on top of
pixels which are the specified XOR alternation color, they
will be changed to the current color and vice versa.
Drawing an image on a region of pixels of the specified XOR
alternation color will also change those pixels to the colors
in the image.
Drawing on pixels of other colors will not necessarily result
in a predictable final color but all rendering operations will
always be reversible in this mode; if you draw the same figure
twice then all pixels will be restored to their original values.
- Parameters:
- c1 - the XOR alternation color
translate
public void translate(int x,
int y)
- Translates the origin of the graphics context to the point
(x, y) in the current coordinate system. All coordinates
used in subsequent rendering operations on this graphics
context will be relative to this new origin.
- Parameters:
- x - the x coordinate of the new translation origin
- y - the y coordinate of the new translation origin
setDrawRegion
public void setDrawRegion(int left,
int top,
int width,
int height,
Rectangle masterDrawRegion)
- /**
Set the region in which drawing can be performed. If the specified region
is
null then the region is set to be the entire window.
- Parameters:
- left - the x coordinate of the top left position of the region
- left - the y coordinate of the top left position of the region
- width - the width of the region
- height - the height of the region
getLocationOnScreen
public Point getLocationOnScreen()
- Set the region in which drawing can be performed. If the specified region
is
null then the region is set to be the entire window.
- Parameters:
- left - the x coordinate of the top left position of the region
- left - the y coordinate of the top left position of the region
- width - the width of the region
- height - the height of the region
resetDrawRegion
public void resetDrawRegion()
- Reset the region in which drawing can be performed to be the whole
screen.
drawImage
public void drawImage(Image image,
int x,
int y)
- Draws an image at the given x and y coordinates.
copyRegion
public void copyRegion(int left,
int top,
int width,
int height,
int dstX,
int dstY,
int mode)
- Copy a rectangular region from one place to another.
- Parameters:
- left - the x coordinate of the region's top left corner
- top - the y coordinate of the region's top left corner
- width - the width of the region
- height - the height of the region
- dstX - the x coordinate of the point to which the region should
be copied
- dstY - the y coordinate of the point to which the region should
be copied
- mode - the copy mode (one of
OVERWRITE, AND, AND_NOT, XOR, OR, INVERT)
copyOffScreenRegion
public void copyOffScreenRegion(int left,
int top,
int width,
int height,
int dstX,
int dstY,
int mode,
int srcWind,
int dstWind)
getScreenDimension
public static Dimension getScreenDimension()
- Get the size of the screen.
drawBitmap
public void drawBitmap(int left,
int top,
Bitmap bitmap)
- Draw a bitmap.
- Parameters:
- left - the x coordinate of the bitmap's top left corner
- top - the y coordinate of the bitmap's top left corner
- bitmap - the bitmap to be drawn
drawBorder
public void drawBorder(int left,
int top,
int width,
int height,
int mode,
int frameType)
- Draw a rectangular border. The border is drawn around the rectangle
specified by the given dimensions.
- Parameters:
- left - the x coordinate of the rectangle's top left corner
- top - the y coordinate of the rectangle's top left corner
- width - the width of the rectangle
- height - the height of the rectangle
- mode - the drawing mode to use (one of
PLAIN, GRAY, ERASE
or INSERT.
- frameType - one of
SIMPLE, RAISED or a
type constructed by a call to borderType.
borderType
public int borderType(int cornerDiam,
int shadow,
int width)
- Constructs a border type.
- Parameters:
- cornerDiam - the diameter of four imaginary circles used to form
rounded corners. Must be in the range 0..38.
- shadow - the width of a shadow. Must be in the range 0..3.
- width - width of the border.Must be in the range 0..3.
- Returns:
- a value representing the specified type
drawArc
public void drawArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
- Draws the outline of an arc covering the specified rectangle,
starting at startAngle and extending for arcAngle degrees,
using the current color.
The angles are interpreted such that 0 degrees is at the 3-o'clock
position, and positive values indicate counter-clockwise rotations
while negative values indicate clockwise rotations.
The resulting arc will cover an area (width + 1) pixels wide
by (height + 1) pixels tall.
- Parameters:
- x - the x coordinate of the upper left corner of the arc
to be drawn
- y - the y coordinate of the upper left corner of the arc
to be drawn
- width - the width of the arc to be drawn
- height - the height of the arc to be drawn
- startAngle - the beginning angle
- arcAngle - the angular extent of the arc (relative to startAngle)
- See Also:
- fillArc
fillArc
public void fillArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
- Fills an arc bounded by the specified rectangle, starting at
startAngle and extending for arcAngle degrees, with the
current color.
This method generates a pie shape.
The angles are interpreted such that 0 degrees is at the 3-o'clock
position, and positive values indicate counter-clockwise rotations
while negative values indicate clockwise rotations.
- Parameters:
- x - the x coordinate of the upper left corner of the arc
to be filled
- y - the y coordinate of the upper left corner of the arc
to be filled
- width - the width of the arc to be filled
- height - the height of the arc to be filled
- startAngle - the beginning angle
- arcAngle - the angular extent of the arc (relative to startAngle).
- See Also:
- drawArc
getWidth
public int getWidth(String s)
- Returns the width of a string in pixels.
- Parameters:
- s - the String to measure
- Returns:
- the width of the given String in pixels
getHeight
public int getHeight()
- Returns the height of the current font in pixels.
- Returns:
- the height of the current font in pixels.
playSound
public void playSound(int sound)
- Play a system sound.
- Parameters:
- sound - one of the SOUND_xxx constants
beep
public void beep()
- Play the default system sound.
playSound
public void playSound(int freq,
int duration)
- Play a tone of the specified frequency for the specified duration.
All Packages Class Hierarchy This Package Previous Next Index