java.lang.Object | |||
↳ | java.awt.Graphics | ||
↳ | java.awt.Graphics2D | ||
↳ | sun.java2d.SunGraphics2D |
This is a the master Graphics2D superclass for all of the Sun Graphics implementations. This class relies on subclasses to manage the various device information, but provides an overall general framework for performing all of the requests in the Graphics and Graphics2D APIs.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | CLIP_DEVICE | ||||||||||
int | CLIP_RECTANGULAR | ||||||||||
int | CLIP_SHAPE | ||||||||||
int | COMP_ALPHA | ||||||||||
int | COMP_CUSTOM | ||||||||||
int | COMP_ISCOPY | ||||||||||
int | COMP_XOR | ||||||||||
double | MinPenSizeSquared | ||||||||||
int | PAINT_ALPHACOLOR | ||||||||||
int | PAINT_CUSTOM | ||||||||||
int | PAINT_GRADIENT | ||||||||||
int | PAINT_LIN_GRADIENT | ||||||||||
int | PAINT_OPAQUECOLOR | ||||||||||
int | PAINT_RAD_GRADIENT | ||||||||||
int | PAINT_TEXTURE | ||||||||||
int | STROKE_CUSTOM | ||||||||||
int | STROKE_THIN | ||||||||||
int | STROKE_THINDASHED | ||||||||||
int | STROKE_WIDE | ||||||||||
int | TRANSFORM_ANY_TRANSLATE | ||||||||||
int | TRANSFORM_GENERIC | ||||||||||
int | TRANSFORM_INT_TRANSLATE | ||||||||||
int | TRANSFORM_ISIDENT | ||||||||||
int | TRANSFORM_TRANSLATESCALE |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds a number of preferences for the rendering algorithms.
| |||||||||||
Clears the specified rectangle by filling it with the background
color of the current drawing surface.
| |||||||||||
Intersects the current clip with the specified Path and sets the
current clip to the resulting intersection.
| |||||||||||
Intersects the current clip with the specified rectangle.
| |||||||||||
Returns the current Transform ignoring the "constrain"
rectangle.
| |||||||||||
Constrain rendering for lightweight objects.
| |||||||||||
Copies an area of the component by a distance specified by
dx and dy . | |||||||||||
Not part of the advertised API but a useful utility method
to call internally.
| |||||||||||
Create a new SunGraphics2D based on this one.
| |||||||||||
This object has no resources to dispose of per se, but the
doc comments for the base method in java.awt.Graphics imply
that this object will not be useable after it is disposed.
| |||||||||||
Strokes the outline of a Path using the settings of the current
graphics state.
| |||||||||||
Draws the outline of a circular or elliptical arc
covering the specified rectangle.
| |||||||||||
Draws the text given by the specified byte array, using this
graphics context's current font and color.
| |||||||||||
Draws the text given by the specified character array, using this
graphics context's current font and color.
| |||||||||||
Renders the text of the specified
GlyphVector using
the Graphics2D context's rendering attributes. | |||||||||||
Renders a
BufferedImage that is
filtered with a
BufferedImageOp . | |||||||||||
Draws a subrectangle of an image scaled to a destination rectangle in
nonblocking mode with a solid background color and a callback object.
| |||||||||||
Draws an image at x,y in nonblocking mode.
| |||||||||||
Draws an image scaled to x,y,w,h in nonblocking mode with a
solid background color and a callback object.
| |||||||||||
Draws an image at x,y in nonblocking mode with a solid background
color and a callback object.
| |||||||||||
Draw an image, applying a transform from image space into user space
before drawing.
| |||||||||||
Draws an image scaled to x,y,w,h in nonblocking mode with a
callback object.
| |||||||||||
Draws a subrectangle of an image scaled to a destination rectangle
in nonblocking mode with a callback object.
| |||||||||||
Draws a line, using the current color, between the points
(x1, y1) and (x2, y2)
in this graphics context's coordinate system. | |||||||||||
Draws the outline of an oval.
| |||||||||||
Draws a closed polygon defined by
arrays of x and y coordinates.
| |||||||||||
Draws a sequence of connected lines defined by
arrays of x and y coordinates.
| |||||||||||
Draws the outline of the specified rectangle.
| |||||||||||
Renders a
RenderableImage ,
applying a transform from image space into user space before drawing. | |||||||||||
Draws an image, applying a transform from image space into user space
before drawing.
| |||||||||||
Draws an outlined round-cornered rectangle using this graphics
context's current color.
| |||||||||||
Renders the text specified by the specified
String ,
using the current text attribute state in the Graphics2D context. | |||||||||||
Renders the text of the specified
String , using the
current text attribute state in the Graphics2D context. | |||||||||||
Renders the text of the specified iterator applying its attributes
in accordance with the specification of the
TextAttribute class. | |||||||||||
Renders the text of the specified iterator applying its attributes
in accordance with the specification of the
TextAttribute class. | |||||||||||
Fills the interior of a Path using the settings of the current
graphics state.
| |||||||||||
Fills a circular or elliptical arc covering the specified rectangle.
| |||||||||||
Fills an oval bounded by the specified rectangle with the
current color.
| |||||||||||
Fills a closed polygon defined by
arrays of x and y coordinates.
| |||||||||||
Fills the specified rectangle.
| |||||||||||
Fills the specified rounded corner rectangle with the current color.
| |||||||||||
Graphics has a finalize method that automatically calls dispose()
for subclasses.
| |||||||||||
Returns the background color used for clearing a region.
| |||||||||||
Gets the current clipping area.
| |||||||||||
Returns the bounding rectangle of the current clipping area.
| |||||||||||
Returns the bounding rectangle of the current clipping area.
| |||||||||||
Gets this graphics context's current color.
| |||||||||||
Returns the current Composite in the Graphics2D state.
| |||||||||||
Returns destination that this Graphics renders to.
| |||||||||||
Return the ColorModel associated with this Graphics2D.
| |||||||||||
Return the device configuration associated with this Graphics2D.
| |||||||||||
Gets the current font.
| |||||||||||
Gets the font metrics for the specified font.
| |||||||||||
Gets the font metrics of the current font.
| |||||||||||
Get the rendering context of the font
within this Graphics2D context.
| |||||||||||
Returns the current Paint in the Graphics2D state.
| |||||||||||
Returns the preferences for the rendering algorithms.
| |||||||||||
Gets the preferences for the rendering algorithms.
| |||||||||||
Returns the current Stroke in the Graphics2D state.
| |||||||||||
Return the SurfaceData object assigned to manage the destination
drawable surface of this Graphics2D.
| |||||||||||
Returns the current Transform in the Graphics2D state.
| |||||||||||
Checks to see if a Path intersects the specified Rectangle in device
space.
| |||||||||||
Returns true if the specified rectangular area might intersect
the current clipping area.
| |||||||||||
Concatenates the current transform of this Graphics2D with a
translated rotation transformation.
| |||||||||||
Concatenates the current transform of this Graphics2D with a
rotation transformation.
| |||||||||||
Concatenates the current transform of this Graphics2D with a
scaling transformation.
| |||||||||||
Sets the background color in this context used for clearing a region.
| |||||||||||
Sets the current clip to the rectangle specified by the given
coordinates.
| |||||||||||
Sets the current clipping area to an arbitrary clip shape.
| |||||||||||
Sets this graphics context's current color to the specified
color.
| |||||||||||
Sets the Composite in the current graphics state.
| |||||||||||
Sets this graphics context's font to the specified font.
| |||||||||||
Sets the Paint in the current graphics state.
| |||||||||||
Sets the paint mode of this graphics context to overwrite the
destination with this graphics context's current color.
| |||||||||||
Sets the preferences for the rendering algorithms.
| |||||||||||
Sets the preferences for the rendering algorithms.
| |||||||||||
Sets the
Stroke for the Graphics2D context. | |||||||||||
Sets the Transform in the current graphics state.
| |||||||||||
Sets the paint mode of this graphics context to alternate between
this graphics context's current color and the new specified color.
| |||||||||||
Concatenates the current transform of this Graphics2D with a
shearing transformation.
| |||||||||||
Composes a Transform object with the transform in this
Graphics2D according to the rule last-specified-first-applied.
| |||||||||||
Translate
| |||||||||||
Concatenates the current transform of this Graphics2D with a
translation transformation.
| |||||||||||
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates and returns a copy of this object.
| |||||||||||
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() |
Adds a number of preferences for the rendering algorithms. Hint categories include controls for rendering quality and overall time/quality trade-off in the rendering process.
hints | The rendering hints to be set |
---|
Clears the specified rectangle by filling it with the background color of the current drawing surface. This operation does not use the current paint mode.
Beginning with Java 1.1, the background color
of offscreen images may be system dependent. Applications should
use setColor
followed by fillRect
to
ensure that an offscreen image is cleared to a specific color.
x | the x coordinate of the rectangle to clear. |
---|---|
y | the y coordinate of the rectangle to clear. |
w | the width of the rectangle to clear. |
h | the height of the rectangle to clear. |
Intersects the current clip with the specified Path and sets the current clip to the resulting intersection. The clip is transformed with the current transform in the Graphics2D state before being intersected with the current clip. This method is used to make the current clip smaller. To make the clip larger, use any setClip method.
s | the Shape to be intersected with the current
Clip . If s is null ,
this method clears the current Clip .
|
---|
Intersects the current clip with the specified rectangle.
The resulting clipping area is the intersection of the current
clipping area and the specified rectangle. If there is no
current clipping area, either because the clip has never been
set, or the clip has been cleared using setClip(null)
,
the specified rectangle becomes the new clip.
This method sets the user clip, which is independent of the
clipping associated with device bounds and window visibility.
This method can only be used to make the current clip smaller.
To set the current clip larger, use any of the setClip methods.
Rendering operations have no effect outside of the clipping area.
x | the x coordinate of the rectangle to intersect the clip with |
---|---|
y | the y coordinate of the rectangle to intersect the clip with |
w | the width of the rectangle to intersect the clip with |
h | the height of the rectangle to intersect the clip with |
Returns the current Transform ignoring the "constrain" rectangle.
Constrain rendering for lightweight objects. REMIND: This method will back off to the "workaround" of using translate and clipRect if the Graphics to be constrained has a complex transform. The drawback of the workaround is that the resulting clip and device origin cannot be "enforced".
IllegalStateException | If the Graphics to be constrained has a complex transform. |
---|
Copies an area of the component by a distance specified by
dx
and dy
. From the point specified
by x
and y
, this method
copies downwards and to the right. To copy an area of the
component to the left or upwards, specify a negative value for
dx
or dy
.
If a portion of the source rectangle lies outside the bounds
of the component, or is obscured by another window or component,
copyArea
will be unable to copy the associated
pixels. The area that is omitted can be refreshed by calling
the component's paint
method.
x | the x coordinate of the source rectangle. |
---|---|
y | the y coordinate of the source rectangle. |
w | the width of the source rectangle. |
h | the height of the source rectangle. |
dx | the horizontal distance to copy the pixels. |
dy | the vertical distance to copy the pixels. |
Not part of the advertised API but a useful utility method to call internally. This is for the case where we are drawing to/from given coordinates using a given width/height, but we guarantee that the weidth/height of the src and dest areas are equal (no scale needed).
Create a new SunGraphics2D based on this one.
This object has no resources to dispose of per se, but the doc comments for the base method in java.awt.Graphics imply that this object will not be useable after it is disposed. So, we sabotage the object to prevent further use to prevent developers from relying on behavior that may not work on other, less forgiving, VMs that really need to dispose of resources.
Strokes the outline of a Path using the settings of the current graphics state. The rendering attributes applied include the clip, transform, paint or color, composite and stroke attributes.
s | the Shape to be rendered |
---|
Draws the outline of a circular or elliptical arc covering the specified rectangle.
The resulting arc begins at startAngle
and extends
for arcAngle
degrees, using the current color.
Angles are interpreted such that 0 degrees
is at the 3 o'clock position.
A positive value indicates a counter-clockwise rotation
while a negative value indicates a clockwise rotation.
The center of the arc is the center of the rectangle whose origin
is (x, y) and whose size is specified by the
width
and height
arguments.
The resulting arc covers an area
width + 1
pixels wide
by height + 1
pixels tall.
The angles are specified relative to the non-square extents of the bounding rectangle such that 45 degrees always falls on the line from the center of the ellipse to the upper right corner of the bounding rectangle. As a result, if the bounding rectangle is noticeably longer in one axis than the other, the angles to the start and end of the arc segment will be skewed farther along the longer axis of the bounds.
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. |
w | the width of the arc to be drawn. |
h | the height of the arc to be drawn. |
startAngl | the beginning angle. |
arcAngl | the angular extent of the arc, relative to the start angle. |
Draws the text given by the specified byte array, using this graphics context's current font and color. The baseline of the first character is at position (x, y) in this graphics context's coordinate system.
Use of this method is not recommended as each byte is interpreted as a Unicode code point in the range 0 to 255, and so can only be used to draw Latin characters in that range.
data | the data to be drawn |
---|---|
offset | the start offset in the data |
length | the number of bytes that are drawn |
x | the x coordinate of the baseline of the text |
y | the y coordinate of the baseline of the text |
Draws the text given by the specified character array, using this graphics context's current font and color. The baseline of the first character is at position (x, y) in this graphics context's coordinate system.
data | the array of characters to be drawn |
---|---|
offset | the start offset in the data |
length | the number of characters to be drawn |
x | the x coordinate of the baseline of the text |
y | the y coordinate of the baseline of the text |
Renders the text of the specified
GlyphVector
using
the Graphics2D
context's rendering attributes.
The rendering attributes applied include the Clip
,
Transform
, Paint
, and
Composite
attributes. The GlyphVector
specifies individual glyphs from a Font
.
The GlyphVector
can also contain the glyph positions.
This is the fastest way to render a set of characters to the
screen.
gv | the GlyphVector to be rendered |
---|---|
x | the x position in User Space where the glyphs should be rendered |
y | the y position in User Space where the glyphs should be rendered |
Renders a BufferedImage
that is
filtered with a
BufferedImageOp
.
The rendering attributes applied include the Clip
,
Transform
and Composite
attributes. This is equivalent to:
img1 = op.filter(img, null); drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);
bImg | the specified BufferedImage to be rendered.
This method does nothing if img is null. |
---|---|
op | the filter to be applied to the image before rendering |
x | the x coordinate of the location in user space where the upper left corner of the image is rendered |
y | the y coordinate of the location in user space where the upper left corner of the image is rendered |
Draws a subrectangle of an image scaled to a destination rectangle in nonblocking mode with a solid background color and a callback object.
img | the specified image to be drawn. This method does
nothing if img is null. |
---|---|
dx1 | the x coordinate of the first corner of the destination rectangle. |
dy1 | the y coordinate of the first corner of the destination rectangle. |
dx2 | the x coordinate of the second corner of the destination rectangle. |
dy2 | the y coordinate of the second corner of the destination rectangle. |
sx1 | the x coordinate of the first corner of the source rectangle. |
sy1 | the y coordinate of the first corner of the source rectangle. |
sx2 | the x coordinate of the second corner of the source rectangle. |
sy2 | the y coordinate of the second corner of the source rectangle. |
bgcolor | the background color to paint under the non-opaque portions of the image. |
observer | object to be notified as more of the image is scaled and converted. |
false
if the image pixels are still changing;
true
otherwise.Draws an image at x,y in nonblocking mode.
img | the specified image to be drawn. This method does
nothing if img is null. |
---|---|
x | the x coordinate. |
y | the y coordinate. |
observer | object to be notified as more of the image is converted. |
false
if the image pixels are still changing;
true
otherwise.Draws an image scaled to x,y,w,h in nonblocking mode with a solid background color and a callback object.
img | the specified image to be drawn. This method does
nothing if img is null. |
---|---|
x | the x coordinate. |
y | the y coordinate. |
width | the width of the rectangle. |
height | the height of the rectangle. |
bg | the background color to paint under the non-opaque portions of the image. |
observer | object to be notified as more of the image is converted. |
false
if the image pixels are still changing;
true
otherwise.Draws an image at x,y in nonblocking mode with a solid background color and a callback object.
img | the specified image to be drawn. This method does
nothing if img is null. |
---|---|
x | the x coordinate. |
y | the y coordinate. |
bg | the background color to paint under the non-opaque portions of the image. |
observer | object to be notified as more of the image is converted. |
false
if the image pixels are still changing;
true
otherwise.Draw an image, applying a transform from image space into user space before drawing. The transformation from user space into device space is done with the current transform in the Graphics2D. The given transformation is applied to the image before the transform attribute in the Graphics2D state is applied. The rendering attributes applied include the clip, transform, paint or color and composite attributes. Note that the result is undefined, if the given transform is non-invertible.
img | The image to be drawn. |
---|---|
xform | The transformation from image space into user space. |
observer | The image observer to be notified on the image producing progress. |
true
if the Image
is
fully loaded and completely rendered, or if it's null;
false
if the Image
is still being loaded.Draws an image scaled to x,y,w,h in nonblocking mode with a callback object.
img | the specified image to be drawn. This method does
nothing if img is null. |
---|---|
x | the x coordinate. |
y | the y coordinate. |
width | the width of the rectangle. |
height | the height of the rectangle. |
observer | object to be notified as more of the image is converted. |
false
if the image pixels are still changing;
true
otherwise.Draws a subrectangle of an image scaled to a destination rectangle in nonblocking mode with a callback object.
img | the specified image to be drawn. This method does
nothing if img is null. |
---|---|
dx1 | the x coordinate of the first corner of the destination rectangle. |
dy1 | the y coordinate of the first corner of the destination rectangle. |
dx2 | the x coordinate of the second corner of the destination rectangle. |
dy2 | the y coordinate of the second corner of the destination rectangle. |
sx1 | the x coordinate of the first corner of the source rectangle. |
sy1 | the y coordinate of the first corner of the source rectangle. |
sx2 | the x coordinate of the second corner of the source rectangle. |
sy2 | the y coordinate of the second corner of the source rectangle. |
observer | object to be notified as more of the image is scaled and converted. |
false
if the image pixels are still changing;
true
otherwise.Draws a line, using the current color, between the points
(x1, y1)
and (x2, y2)
in this graphics context's coordinate system.
x1 | the first point's x coordinate. |
---|---|
y1 | the first point's y coordinate. |
x2 | the second point's x coordinate. |
y2 | the second point's y coordinate. |
Draws the outline of an oval.
The result is a circle or ellipse that fits within the
rectangle specified by the x
, y
,
width
, and height
arguments.
The oval covers an area that is
width + 1
pixels wide
and height + 1
pixels tall.
x | the x coordinate of the upper left corner of the oval to be drawn. |
---|---|
y | the y coordinate of the upper left corner of the oval to be drawn. |
w | the width of the oval to be drawn. |
h | the height of the oval to be drawn. |
Draws a closed polygon defined by arrays of x and y coordinates. Each pair of (x, y) coordinates defines a point.
This method draws the polygon defined by nPoint
line
segments, where the first nPoint - 1
line segments are line segments from
(xPoints[i - 1], yPoints[i - 1])
to (xPoints[i], yPoints[i])
, for
1 ≤ i ≤ nPoints
.
The figure is automatically closed by drawing a line connecting
the final point to the first point, if those points are different.
xPoints | a an array of x coordinates. |
---|---|
yPoints | a an array of y coordinates. |
nPoints | a the total number of points. |
Draws a sequence of connected lines defined by arrays of x and y coordinates. Each pair of (x, y) coordinates defines a point. The figure is not closed if the first point differs from the last point.
xPoints | an array of x points |
---|---|
yPoints | an array of y points |
nPoints | the total number of points |
Draws the outline of the specified rectangle.
The left and right edges of the rectangle are at
x
and x + width
.
The top and bottom edges are at
y
and y + height
.
The rectangle is drawn using the graphics context's current color.
x | the x coordinate of the rectangle to be drawn. |
---|---|
y | the y coordinate of the rectangle to be drawn. |
w | the width of the rectangle to be drawn. |
h | the height of the rectangle to be drawn. |
Renders a
RenderableImage
,
applying a transform from image space into user space before drawing.
The transformation from user space into device space is done with
the current Transform
in the Graphics2D
.
The specified transformation is applied to the image before the
transform attribute in the Graphics2D
context is applied.
The rendering attributes applied include the Clip
,
Transform
, and Composite
attributes. Note
that no rendering is done if the specified transform is
noninvertible.
Rendering hints set on the Graphics2D
object might
be used in rendering the RenderableImage
.
If explicit control is required over specific hints recognized by a
specific RenderableImage
, or if knowledge of which hints
are used is required, then a RenderedImage
should be
obtained directly from the RenderableImage
and rendered using
drawRenderedImage
.
img | the image to be rendered. This method does
nothing if img is null. |
---|---|
xform | the transformation from image space into user space |
Draws an image, applying a transform from image space into user space before drawing. The transformation from user space into device space is done with the current transform in the Graphics2D. The given transformation is applied to the image before the transform attribute in the Graphics2D state is applied. The rendering attributes applied include the clip, transform, and composite attributes. Note that the result is undefined, if the given transform is noninvertible.
img | The image to be drawn. Does nothing if img is null. |
---|---|
xform | The transformation from image space into user space. |
Draws an outlined round-cornered rectangle using this graphics
context's current color. The left and right edges of the rectangle
are at x
and x + width
,
respectively. The top and bottom edges of the rectangle are at
y
and y + height
.
x | the x coordinate of the rectangle to be drawn. |
---|---|
y | the y coordinate of the rectangle to be drawn. |
w | the width of the rectangle to be drawn. |
h | the height of the rectangle to be drawn. |
arcW | the horizontal diameter of the arc at the four corners. |
arcH | the vertical diameter of the arc at the four corners. |
Renders the text specified by the specified String
,
using the current text attribute state in the Graphics2D
context.
The baseline of the first character is at position
(x, y) in the User Space.
The rendering attributes applied include the Clip
,
Transform
, Paint
, Font
and
Composite
attributes. For characters in script systems
such as Hebrew and Arabic, the glyphs can be rendered from right to
left, in which case the coordinate supplied is the location of the
leftmost character on the baseline.
str | the String to be rendered |
---|---|
x | the x coordinate of the location where the
String should be rendered |
y | the y coordinate of the location where the
String should be rendered |
Renders the text of the specified String
, using the
current text attribute state in the Graphics2D
context.
The baseline of the
first character is at position (x, y) in
the User Space.
The rendering attributes applied include the Clip
,
Transform
, Paint
, Font
and
Composite
attributes. For characters in script
systems such as Hebrew and Arabic, the glyphs can be rendered from
right to left, in which case the coordinate supplied is the
location of the leftmost character on the baseline.
str | the string to be rendered |
---|---|
x | the x coordinate of the location where the
String should be rendered |
y | the y coordinate of the location where the
String should be rendered |
Renders the text of the specified iterator applying its attributes
in accordance with the specification of the TextAttribute
class.
The baseline of the first character is at position (x, y) in User Space. For characters in script systems such as Hebrew and Arabic, the glyphs can be rendered from right to left, in which case the coordinate supplied is the location of the leftmost character on the baseline.
iterator | the iterator whose text is to be rendered |
---|---|
x | the x coordinate where the iterator's text is to be rendered |
y | the y coordinate where the iterator's text is to be rendered |
Renders the text of the specified iterator applying its attributes
in accordance with the specification of the TextAttribute
class.
The baseline of the first character is at position (x, y) in User Space. For characters in script systems such as Hebrew and Arabic, the glyphs can be rendered from right to left, in which case the coordinate supplied is the location of the leftmost character on the baseline.
iterator | the iterator whose text is to be rendered |
---|---|
x | the x coordinate where the iterator's text is to be rendered |
y | the y coordinate where the iterator's text is to be rendered |
Fills the interior of a Path using the settings of the current graphics state. The rendering attributes applied include the clip, transform, paint or color, and composite.
s | the Shape to be filled |
---|
Fills a circular or elliptical arc covering the specified rectangle.
The resulting arc begins at startAngle
and extends
for arcAngle
degrees.
Angles are interpreted such that 0 degrees
is at the 3 o'clock position.
A positive value indicates a counter-clockwise rotation
while a negative value indicates a clockwise rotation.
The center of the arc is the center of the rectangle whose origin
is (x, y) and whose size is specified by the
width
and height
arguments.
The resulting arc covers an area
width + 1
pixels wide
by height + 1
pixels tall.
The angles are specified relative to the non-square extents of the bounding rectangle such that 45 degrees always falls on the line from the center of the ellipse to the upper right corner of the bounding rectangle. As a result, if the bounding rectangle is noticeably longer in one axis than the other, the angles to the start and end of the arc segment will be skewed farther along the longer axis of the bounds.
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. |
w | the width of the arc to be filled. |
h | the height of the arc to be filled. |
startAngl | the beginning angle. |
arcAngl | the angular extent of the arc, relative to the start angle. |
Fills an oval bounded by the specified rectangle with the current color.
x | the x coordinate of the upper left corner of the oval to be filled. |
---|---|
y | the y coordinate of the upper left corner of the oval to be filled. |
w | the width of the oval to be filled. |
h | the height of the oval to be filled. |
Fills a closed polygon defined by arrays of x and y coordinates.
This method draws the polygon defined by nPoint
line
segments, where the first nPoint - 1
line segments are line segments from
(xPoints[i - 1], yPoints[i - 1])
to (xPoints[i], yPoints[i])
, for
1 ≤ i ≤ nPoints
.
The figure is automatically closed by drawing a line connecting
the final point to the first point, if those points are different.
The area inside the polygon is defined using an even-odd fill rule, also known as the alternating rule.
xPoints | a an array of x coordinates. |
---|---|
yPoints | a an array of y coordinates. |
nPoints | a the total number of points. |
Fills the specified rectangle.
The left and right edges of the rectangle are at
x
and x + width - 1
.
The top and bottom edges are at
y
and y + height - 1
.
The resulting rectangle covers an area
width
pixels wide by
height
pixels tall.
The rectangle is filled using the graphics context's current color.
x | the x coordinate of the rectangle to be filled. |
---|---|
y | the y coordinate of the rectangle to be filled. |
w | the width of the rectangle to be filled. |
h | the height of the rectangle to be filled. |
Fills the specified rounded corner rectangle with the current color.
The left and right edges of the rectangle
are at x
and x + width - 1
,
respectively. The top and bottom edges of the rectangle are at
y
and y + height - 1
.
x | the x coordinate of the rectangle to be filled. |
---|---|
y | the y coordinate of the rectangle to be filled. |
w | the width of the rectangle to be filled. |
h | the height of the rectangle to be filled. |
arcW | the horizontal diameter of the arc at the four corners. |
arcH | the vertical diameter of the arc at the four corners. |
Graphics has a finalize method that automatically calls dispose() for subclasses. For SunGraphics2D we do not need to be finalized so that method simply causes us to be enqueued on the Finalizer queues for no good reason. Unfortunately, that method and implementation are now considered part of the public contract of that base class so we can not remove or gut the method. We override it here with an empty method and the VM is smart enough to know that if our override is empty then it should not mark us as finalizeable.
Returns the background color used for clearing a region.
Graphics2D
Color
,
which defines the background color.Gets the current clipping area.
This method returns the user clip, which is independent of the
clipping associated with device bounds and window visibility.
If no clip has previously been set, or if the clip has been
cleared using setClip(null)
, this method returns
null
.
Shape
object representing the
current clipping area, or null
if
no clip is set.Returns the bounding rectangle of the current clipping area.
This method refers to the user clip, which is independent of the
clipping associated with device bounds and window visibility.
If no clip has previously been set, or if the clip has been
cleared using setClip(null)
, this method returns
null
.
The coordinates in the rectangle are relative to the coordinate
system origin of this graphics context.
null
if no clip is set.Returns the bounding rectangle of the current clipping area.
The coordinates in the rectangle are relative to the coordinate
system origin of this graphics context. This method differs
from getClipBounds
in that an existing
rectangle is used instead of allocating a new one.
This method refers to the user clip, which is independent of the
clipping associated with device bounds and window visibility.
If no clip has previously been set, or if the clip has been
cleared using setClip(null)
, this method returns the
specified Rectangle
.
r | the rectangle where the current clipping area is copied to. Any current values in this rectangle are overwritten. |
---|
Gets this graphics context's current color.
Returns the current Composite in the Graphics2D state.
Graphics2D
Composite
,
which defines a compositing style.Returns destination that this Graphics renders to. This could be either an Image or a Component; subclasses of SurfaceData are responsible for returning the appropriate object.
Return the device configuration associated with this Graphics2D.
Graphics2D
.
Gets the font metrics for the specified font.
font | the specified font |
---|
Gets the font metrics of the current font.
Get the rendering context of the font within this Graphics2D context.
Returns the current Paint in the Graphics2D state.
Graphics2D
Paint
,
which defines a color or pattern.Returns the preferences for the rendering algorithms.
hintKey | the key corresponding to the hint to get. |
---|
Gets the preferences for the rendering algorithms. Hint categories include controls for rendering quality and overall time/quality trade-off in the rendering process.
RenderingHints
that contains the current preferences.Returns the current Stroke in the Graphics2D state.
Graphics2D
Stroke
,
which defines the line style.Return the SurfaceData object assigned to manage the destination drawable surface of this Graphics2D.
Returns the current Transform in the Graphics2D state.
AffineTransform
in the
Graphics2D
context.Checks to see if a Path intersects the specified Rectangle in device space. The rendering attributes taken into account include the clip, transform, and stroke attributes.
rect | The area in device space to check for a hit. |
---|---|
s | the Shape to check for a hit |
onStroke | Flag to choose between testing the stroked or the filled path. |
Returns true if the specified rectangular area might intersect the current clipping area. The coordinates of the specified rectangular area are in the user coordinate space and are relative to the coordinate system origin of this graphics context. This method may use an algorithm that calculates a result quickly but which sometimes might return true even if the specified rectangular area does not intersect the clipping area. The specific algorithm employed may thus trade off accuracy for speed, but it will never return false unless it can guarantee that the specified rectangular area does not intersect the current clipping area. The clipping area used by this method can represent the intersection of the user clip as specified through the clip methods of this graphics context as well as the clipping associated with the device or image bounds and window visibility.
x | the x coordinate of the rectangle to test against the clip |
---|---|
y | the y coordinate of the rectangle to test against the clip |
width | the width of the rectangle to test against the clip |
height | the height of the rectangle to test against the clip |
true
if the specified rectangle intersects
the bounds of the current clip; false
otherwise.
Concatenates the current transform of this Graphics2D with a translated rotation transformation. This is equivalent to the following sequence of calls:
translate(x, y); rotate(theta); translate(-x, -y);Rotating with a positive angle theta rotates points on the positive x axis toward the positive y axis.
theta | The angle of rotation in radians. |
---|---|
x | The x coordinate of the origin of the rotation |
y | The x coordinate of the origin of the rotation |
Concatenates the current transform of this Graphics2D with a rotation transformation. This is equivalent to calling transform(R), where R is an AffineTransform represented by the following matrix:
[ cos(theta) -sin(theta) 0 ] [ sin(theta) cos(theta) 0 ] [ 0 0 1 ]Rotating with a positive angle theta rotates points on the positive x axis toward the positive y axis.
theta | The angle of rotation in radians. |
---|
Concatenates the current transform of this Graphics2D with a scaling transformation. This is equivalent to calling transform(S), where S is an AffineTransform represented by the following matrix:
[ sx 0 0 ] [ 0 sy 0 ] [ 0 0 1 ]
sx | the amount by which X coordinates in subsequent rendering operations are multiplied relative to previous rendering operations. |
---|---|
sy | the amount by which Y coordinates in subsequent rendering operations are multiplied relative to previous rendering operations. |
Sets the background color in this context used for clearing a region. When Graphics2D is constructed for a component, the backgroung color is inherited from the component. Setting the background color in the Graphics2D context only affects the subsequent clearRect() calls and not the background color of the component. To change the background of the component, use appropriate methods of the component.
color | The background color that should be used in subsequent calls to clearRect(). |
---|
Sets the current clip to the rectangle specified by the given coordinates. This method sets the user clip, which is independent of the clipping associated with device bounds and window visibility. Rendering operations have no effect outside of the clipping area.
x | the x coordinate of the new clip rectangle. |
---|---|
y | the y coordinate of the new clip rectangle. |
w | the width of the new clip rectangle. |
h | the height of the new clip rectangle. |
Sets the current clipping area to an arbitrary clip shape.
Not all objects that implement the Shape
interface can be used to set the clip. The only
Shape
objects that are guaranteed to be
supported are Shape
objects that are
obtained via the getClip
method and via
Rectangle
objects. This method sets the
user clip, which is independent of the clipping associated
with device bounds and window visibility.
sh | the Shape to use to set the clip |
---|
Sets this graphics context's current color to the specified color. All subsequent graphics operations using this graphics context use this specified color.
color | the new rendering color. |
---|
Sets the Composite in the current graphics state. Composite is used in all drawing methods such as drawImage, drawString, drawPath, and fillPath. It specifies how new pixels are to be combined with the existing pixels on the graphics device in the rendering process.
comp | The Composite object to be used for drawing. |
---|
Sets this graphics context's font to the specified font. All subsequent text operations using this graphics context use this font. A null argument is silently ignored.
font | the font. |
---|
Sets the Paint in the current graphics state.
paint | The Paint object to be used to generate color in the rendering process. |
---|
Sets the paint mode of this graphics context to overwrite the destination with this graphics context's current color. This sets the logical pixel operation function to the paint or overwrite mode. All subsequent rendering operations will overwrite the destination with the current color.
Sets the preferences for the rendering algorithms. Hint categories include controls for rendering quality and overall time/quality trade-off in the rendering process.
hintKey | The key of hint to be set. The strings are defined in the RenderingHints class. |
---|---|
hintValue | The value indicating preferences for the specified hint category. These strings are defined in the RenderingHints class. |
Sets the preferences for the rendering algorithms. Hint categories include controls for rendering quality and overall time/quality trade-off in the rendering process.
hints | The rendering hints to be set |
---|
Sets the Stroke
for the Graphics2D
context.
s | the Stroke object to be used to stroke a
Shape during the rendering process |
---|
Sets the Transform in the current graphics state.
Tx | The Transform object to be used in the rendering process. |
---|
transform
AffineTransform
Sets the paint mode of this graphics context to alternate between this graphics context's current color and the new specified color. This specifies that logical pixel operations are performed in the XOR mode, which alternates pixels between the current color and a specified XOR color.
When drawing operations are performed, pixels which are the current color are changed to the specified color, and vice versa.
Pixels that are of colors other than those two colors are changed in an unpredictable but reversible manner; if the same figure is drawn twice, then all pixels are restored to their original values.
c | the XOR alternation color |
---|
Concatenates the current transform of this Graphics2D with a shearing transformation. This is equivalent to calling transform(SH), where SH is an AffineTransform represented by the following matrix:
[ 1 shx 0 ] [ shy 1 0 ] [ 0 0 1 ]
shx | The factor by which coordinates are shifted towards the positive X axis direction according to their Y coordinate |
---|---|
shy | The factor by which coordinates are shifted towards the positive Y axis direction according to their X coordinate |
Composes a Transform object with the transform in this Graphics2D according to the rule last-specified-first-applied. If the currrent transform is Cx, the result of composition with Tx is a new transform Cx'. Cx' becomes the current transform for this Graphics2D. Transforming a point p by the updated transform Cx' is equivalent to first transforming p by Tx and then transforming the result by the original transform Cx. In other words, Cx'(p) = Cx(Tx(p)). A copy of the Tx is made, if necessary, so further modifications to Tx do not affect rendering.
xform | the AffineTransform object to be composed with
the current Transform |
---|
Translate
x | the specified x coordinate |
---|---|
y | the specified y coordinate |
Concatenates the current transform of this Graphics2D with a translation transformation. This is equivalent to calling transform(T), where T is an AffineTransform represented by the following matrix:
[ 1 0 tx ] [ 0 1 ty ] [ 0 0 1 ]
tx | the distance to translate along the x-axis |
---|---|
ty | the distance to translate along the y-axis |
Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:
will be true, and that the expression:x.clone() != x
will be true, but these are not absolute requirements. While it is typically the case that:x.clone().getClass() == x.getClass()
will be true, this is not an absolute requirement.x.clone().equals(x)
By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().
By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.
The method clone for class Object performs a specific cloning operation. First, if the class of this object does not implement the interface Cloneable, then a CloneNotSupportedException is thrown. Note that all arrays are considered to implement the interface Cloneable. Otherwise, this method creates a new instance of the class of this object and initializes all its fields with exactly the contents of the corresponding fields of this object, as if by assignment; the contents of the fields are not themselves cloned. Thus, this method performs a "shallow copy" of this object, not a "deep copy" operation.
The class Object does not itself implement the interface Cloneable, so calling the clone method on an object whose class is Object will result in throwing an exception at run time.