|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--com.yospace.yae.yogi.Graphics
An abstract class representing the graphics capabilities required from
the underlying graphics system. A Graphics object
represents a "pen", or "Graphics Context" with which drawing may be
performed on some surface. It maintains a current color, pen style,
font, clip area, and translation origin.
Graphics objects are usually acquired as
arguments to the various
paint methods
that are called by the paint system in YogiComponent or
ComponentUI.
The methods in this class are closely based around those provided by
AWT and MIDP,
and in such environments, Graphics will delegate to such a native
implementation.
As with other such systems, it is assumed that there are two axes of integer pixel coordinates: a horizontal axis going from left to right and a vertical axis going from top to bottom. The coordinates define the points on a grid of infinitessimally fine lines; an actual pixel drawn at a particular location hangs below and to the right of that point.
| Field Summary | |
static int |
DOTTED
Constant for specifying DOTTED line-drawing style. |
static int |
SOLID
Constant for specifying SOLID line-drawing style. |
| Constructor Summary | |
Graphics()
|
|
| Method Summary | |
abstract void |
clearRect(int x,
int y,
int width,
int height)
Convenience method for calling fillRect with a paint color
set to white. |
abstract void |
clipRect(int x,
int y,
int width,
int height)
This method sets the clip region to be the overlap of the existing clip region and the rectangle described by the arguments. |
abstract void |
clipRect(Rectangle r)
Convenience method for calling clipRect(int,int,int,int). |
abstract Graphics |
create()
This factory method creates a new instance of a Graphics as an
exact copy of this one. |
Graphics |
create(int x,
int y,
int width,
int height)
This factory method creates a new instance of a Graphics as an
exact copy of this one, but clipped to apply only to the specified sub-region. |
abstract void |
dispose()
This method is called when the Graphics object is no longer
required. |
abstract void |
drawArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
Draws an arc sector of an oval, using the current color and stroke style. |
abstract void |
drawImage(Image image,
int x,
int y)
Draw the specified Image at the given location. |
abstract void |
drawLine(int x1,
int y1,
int x2,
int y2)
Draws a straight line, using the current color and stroke style, joining the points ( x1, y1) and
(x2, y2). |
abstract void |
drawOval(int x,
int y,
int width,
int height)
Draws an oval, using the current color and stroke style, whose bounding rectangle is defined by the x, y, width and height arguments. |
abstract void |
drawPolygon(int[] xPoints,
int[] yPoints,
int numPoints)
Draws a series of lines joining the points defined in the xPoints and
yPoints arrays, in the same style as drawPolyline. |
abstract void |
drawPolyline(int[] xPoints,
int[] yPoints,
int numPoints)
Draws a series of straight lines, using the current color and stroke style, joining the points defined by successive pairs of values in the two arrays. |
abstract void |
drawRect(int x,
int y,
int width,
int height)
This method draws the border of a rectangle described by its arguments, using the current color and stroke style. |
abstract void |
drawRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
Draws a rectangle with rounded corners, using the current color and stroke style. |
abstract void |
drawString(java.lang.String text,
int x,
int y)
Draws the specified text in the current color and font at the specified location. |
abstract void |
drawString(java.lang.String text,
int x,
int y,
int backColor)
Draws the specified text in the current color and font at the specified location. |
abstract void |
fillArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
Fills an arc sector of an oval, using the current color. |
abstract void |
fillOval(int x,
int y,
int width,
int height)
Fills an oval, using the current color, whose bounding rectangle is defined by the x, y, width and height arguments. |
abstract void |
fillRect(int x,
int y,
int width,
int height)
This method fills the rectangle described by the arguments with the current color. |
abstract void |
fillRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
Fills a rectangle with rounded corners, using the current color. |
abstract Rectangle |
getClipBounds()
Convenience method for returning the current clip rectangle in one method call. |
abstract int |
getClipHeight()
Returns the height of the current clip region. |
abstract int |
getClipWidth()
Returns the width of the current clip region. |
abstract int |
getClipX()
Returns the x-coordinate of the top-left corner of the current clip region, relative to the current origin. |
abstract int |
getClipY()
Returns the y-coordinate of the top-left corner of the current clip region, relative to the current origin. |
abstract int |
getColor()
Returns the current drawing color in 0xRRGGBB format. |
abstract int |
getTranslateX()
Returns the x-coordinate of the current origin in Absolute Coordinates. |
abstract int |
getTranslateY()
Returns the y-coordinate of the current origin in Absolute Coordinates. |
abstract boolean |
hitClip(int x,
int y,
int width,
int height)
Determines whether the rectangle described by the arguments and the current clip area intersect. |
abstract void |
setClip(int x,
int y,
int width,
int height)
This method sets the clip rectangle to be precisely that defined by the arguments, relative to the current origin (which is not affected). |
abstract void |
setClip(Rectangle r)
Convenience method for calling setClip(int,int,int,int). |
abstract void |
setColor(int c)
Sets the current drawing color, using 0xRRGGBB format. |
abstract void |
setFont(Font f)
Sets the font to be used for subsequent text drawing operations. |
abstract void |
setStrokeStyle(int strokeStyle)
This method sets the drawing stroke style for subsequent drawing operations. |
abstract void |
translate(int x,
int y)
This method moves the origin of all subsequent graphical operations to the specified location. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int SOLID
SOLID line-drawing style.setStrokeStyle(int)public static final int DOTTED
DOTTED line-drawing style.setStrokeStyle(int)| Constructor Detail |
public Graphics()
| Method Detail |
public abstract Graphics create()
Graphics as an
exact copy of this one. This is useful when multiple
screen areas need drawing independently.Graphics object.create(int, int, int, int)
public Graphics create(int x,
int y,
int width,
int height)
Graphics as an
exact copy of this one, but clipped to apply only to the specified sub-region.
The rectangle defined by the arguments is intersected with the existing clip
area, and then the translation origin is moved to (x, y), so that
the new Graphics can only affect that rectangle and sees its
top-left corner as the origin.
This is a convenience method to replace:
Graphics g = create(); g.clipRect(x, y, width, height); g.translate(x, y);
x - the x coordinate of the top-left corner of the new clip rectangle,
relative to the current origin.y - the y coordinate of the top-left corner of the new clip rectangle,
relative to the current origin.width - the width of the new clip rectangle.height - the height of the new clip rectangle.Graphics object.clipRect(int,int,int,int),
translate(int,int),
create()public abstract void dispose()
Graphics object is no longer
required. It presents an early opportunity for its resources to be freed.
The behavior of a Graphics after it has been disposed is
undefined, and should be avoided.
public abstract void setClip(int x,
int y,
int width,
int height)
As this can make the clip region larger than it was, it is generally
risky to call setClip, as it may allow unwanted corruption
of other graphics areas. In general, the clipRect
method is safer.
x - the x coordinate of the top-left corner of the new clip rectangle,
relative to the current origin.y - the y coordinate of the top-left corner of the new clip rectangle,
relative to the current origin.width - the width of the new clip rectangle.height - the height of the new clip rectangle.public abstract void setClip(Rectangle r)
setClip(int,int,int,int).r - a Rectangle object defining the new clip area
public abstract void clipRect(int x,
int y,
int width,
int height)
setClip.
The origin is not affected.
x - the x coordinate of the top-left corner of the new clip rectangle,
relative to the current origin.y - the y coordinate of the top-left corner of the new clip rectangle,
relative to the current origin.width - the width of the new clip rectangle.height - the height of the new clip rectangle.public abstract void clipRect(Rectangle r)
clipRect(int,int,int,int).r - a Rectangle object defining the new clip area
public abstract boolean hitClip(int x,
int y,
int width,
int height)
x - the x coordinate of the top-left corner of the new clip rectangle,
relative to the current origin.y - the y coordinate of the top-left corner of the new clip rectangle,
relative to the current origin.width - the width of the new clip rectangle.height - the height of the new clip rectangle.public abstract int getClipX()
clipRect(int,int,int,int),
setClip(int,int,int,int),
getClipY(),
getClipWidth(),
getClipHeight()public abstract int getClipY()
clipRect(int,int,int,int),
setClip(int,int,int,int),
getClipX(),
getClipWidth(),
getClipHeight()public abstract int getClipWidth()
clipRect(int,int,int,int),
setClip(int,int,int,int),
getClipX(),
getClipY(),
getClipHeight()public abstract int getClipHeight()
clipRect(int,int,int,int),
setClip(int,int,int,int),
getClipX(),
getClipY(),
getClipWidth()public abstract Rectangle getClipBounds()
getClipX(),
getClipY(),
getClipWidth(),
getClipHeight()
public abstract void translate(int x,
int y)
Note that, although the origin may move, the physical region described by the clip area does not change. Thus, after translating the origin, it will be found that the location of the clip area has apparently moved in the opposite direction.
x - the x-coordinate (in the existing coordinate space) of the new origin.y - the y-coordinate (in the existing coordinate space) of the new origin.public abstract int getTranslateX()
public abstract int getTranslateY()
public abstract void setColor(int c)
c - the new color as a numeric 24-bit color value.ColorUtilpublic abstract int getColor()
ColorUtilpublic abstract void setFont(Font f)
Font.getFont(name)
or Font.getFont(face,size,style) methods.
There is currently no accessor method for this property.
f - the new font.public abstract void setStrokeStyle(int strokeStyle)
SOLID for drawing solid lines, and DOTTED
for drawing dotted lines.
There is currently no accessor method for this property.
strokeStyle - either SOLID or DOTTED.
public abstract void drawLine(int x1,
int y1,
int x2,
int y2)
x1, y1) and
(x2, y2).x1 - the x-coordinate of the first end-point.y1 - the y-coordinate of the first end-point.x2 - the x-coordinate of the second end-point.y2 - the y-coordinate of the second end-point.
public abstract void drawPolyline(int[] xPoints,
int[] yPoints,
int numPoints)
numPoints value.xPoints - an array of x-coordinate values corresponding to the y-coordinates in yPoints.yPoints - an array of y-coordinate values corresponding to the x-coordinates in xPoints.numPoints - the number of points to be connected, if less than the length of either the
xPoints or yPoints arrays.drawPolygon(int[],int[],int)
public abstract void drawRect(int x,
int y,
int width,
int height)
Because pixels hang below and to the right of the coordinate axes, and to
ensure that a drawRect call is equivalent to
the resulting rectangle is actually (w+1) pixels across the top and (h+1) pixels high.drawLine(x, y, x+w, y); //top drawLine(x, y+h, x+w, y+h); //bottom drawLine(x, y, x, y+h); //left drawLine(x+w, y, x+w, y+h); //right
Thus, drawing a rectangle and filling it must be done with a little consideration.
x - the x coordinate of the top-left corner of the rectangle,
relative to the current origin.y - the y coordinate of the top-left corner of the rectangle,
relative to the current origin.width - the width of the rectangle.height - the height of the rectangle.
public abstract void fillRect(int x,
int y,
int width,
int height)
Note that this rectangle is defined in terms of the inter-pixel grid lines,
and hence a call to fillRect(0, 0, 30, 20) will fill exactly
600 pixels. This is therefore a slightly different rectangle to that
produced by drawRect.
x - the x coordinate of the top-left corner of the rectangle,
relative to the current origin.y - the y coordinate of the top-left corner of the rectangle,
relative to the current origin.width - the width of the rectangle.height - the height of the rectangle.
public abstract void clearRect(int x,
int y,
int width,
int height)
fillRect with a paint color
set to white.x - the x coordinate of the top-left corner of the rectangle,
relative to the current origin.y - the y coordinate of the top-left corner of the rectangle,
relative to the current origin.width - the width of the rectangle.height - the height of the rectangle.
public abstract void drawRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
drawRect.x - the x coordinate of the top-left corner of the enclosing rectangle,
relative to the current origin.y - the y coordinate of the top-left corner of the enclosing rectangle,
relative to the current origin.width - the overall width of the rectangle.height - the overall height of the rectangle.arcWidth - the horizontal diameter of the oval whose quarter arc will be drawn in
the corners of the rectangle to create the rounded effect.arcHeight - the vertical diameter of the oval whose quarter arc will be drawn in
the corners of the rectangle to create the rounded effect.
public abstract void fillRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
fillRect.x - the x coordinate of the top-left corner of the enclosing rectangle,
relative to the current origin.y - the y coordinate of the top-left corner of the enclosing rectangle,
relative to the current origin.width - the width of the enclosing rectangle.height - the height of the enclosing rectangle.arcWidth - the horizontal diameter of the oval whose quarter arc will be filled in
the corners of the rectangle to create the rounded effect.arcHeight - the vertical diameter of the oval whose quarter arc will be filled in
the corners of the rectangle to create the rounded effect.
public abstract void drawArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
x, y, width and height arguments.
The arc begins at startAngle degrees and extends for arcAngle
degrees. Zero degrees is interpreted as a 3 o'clock direction, with positive angles
indicating an anti-clockwise direction.
The width and height are interpreted to refer
to the same rectangle as would be drawn by
drawRect.
Note that 45 degrees is interpreted to be the direction defined by the diagonals of the
bounding rectangle. Thus, when width and height have different values,
the 45 degree line will not correspond to 45 degrees on the screen. This is best imagined by considering
an oval to be a stretched circle - the angles are defined in terms of the circle,
and are skewed when the circle is stretched.
x - the x coordinate of the top-left corner of the oval's enclosing rectangle,
relative to the current origin.y - the y coordinate of the top-left corner of the oval's enclosing rectangle,
relative to the current origin.width - the width of the enclosing rectangle.height - the height of the enclosing rectangle.startAngle - the start angle of the arc, measured in degrees.arcHeight - the extent of the arc, relative to startAngle.
public abstract void fillArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
x, y, width and height arguments.
The arc begins at startAngle degrees and extends for arcAngle
degrees. Zero degrees is interpreted as a 3 o'clock direction, with positive angles
indicating an anti-clockwise direction.
The width and height are interpreted to refer
to the same rectangle as would be filled by
fillRect.
x - the x coordinate of the top-left corner of the oval's enclosing rectangle,
relative to the current origin.y - the y coordinate of the top-left corner of the oval's enclosing rectangle,
relative to the current origin.width - the width of the enclosing rectangle.height - the height of the enclosing rectangle.startAngle - the start angle of the arc, measured in degrees.arcHeight - the extent of the arc, relative to startAngle.drawArc(int,int,int,int,int,int)
public abstract void drawPolygon(int[] xPoints,
int[] yPoints,
int numPoints)
xPoints and
yPoints arrays, in the same style as drawPolyline. This method differs only in that the line connecting the first and
last points is also drawn, creating a closed figure.xPoints - an array of x-coordinate values corresponding to the y-coordinates in yPoints.yPoints - an array of y-coordinate values corresponding to the x-coordinates in xPoints.numPoints - the number of points to be used from the arrays, if less than the length of either
of the arrays.drawPolyline(int[],int[],int)
public abstract void drawOval(int x,
int y,
int width,
int height)
x, y, width and height arguments.
The width and height are interpreted to refer
to the same rectangle as would be drawn by
drawRect.
x - the x coordinate of the top-left corner of the oval's enclosing rectangle,
relative to the current origin.y - the y coordinate of the top-left corner of the oval's enclosing rectangle,
relative to the current origin.width - the width of the enclosing rectangle.height - the height of the enclosing rectangle.
public abstract void fillOval(int x,
int y,
int width,
int height)
x, y, width and height arguments.
The width and height are interpreted to refer
to the same rectangle as would be drawn by
fillRect.
x - the x coordinate of the top-left corner of the oval's enclosing rectangle,
relative to the current origin.y - the y coordinate of the top-left corner of the oval's enclosing rectangle,
relative to the current origin.width - the width of the enclosing rectangle.height - the height of the enclosing rectangle.
public abstract void drawString(java.lang.String text,
int x,
int y)
drawString(java.lang.String,int,int,int),
and assumes a white background color with respect to anti-aliasing fonts.text - the text to be drawn.x - the location of the left-hand side of the text.y - the location of top of the text. Note that this is different from
AWT's interpretation of the text location.
public abstract void drawString(java.lang.String text,
int x,
int y,
int backColor)
text - the text to be drawn.x - the position of the left-hand side of the text.y - the top of the text. Note that this is different from
AWT's interpretation of the text location.backColor - the background color for anti-aliasing.
public abstract void drawImage(Image image,
int x,
int y)
image - the image to be drawn.x - the x-coordinate of the top-left of the image.y - the y-coordinate of the top-left of the image.
|
Copyright 2002 Yospace Holdings Ltd. All Rights Reserved. | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||