Class DefaultGraphics2D
- All Implemented Interfaces:
Cloneable
AbstractGraphics2D is a
simple help to programmers to get started with their own
implementation of Graphics2D.
DefaultGraphics2D implements all the abstract methods
is AbstractGraphics2D and makes it easy to start
implementing a Graphic2D piece-meal.- See Also:
-
Field Summary
Fields inherited from class AbstractGraphics2D
gc, textAsShapes -
Constructor Summary
ConstructorsConstructorDescriptionDefaultGraphics2D(boolean textAsShapes) Default constructorThis constructor supports the create method -
Method Summary
Modifier and TypeMethodDescriptionvoidcopyArea(int x, int y, int width, int height, int dx, int dy) Copies an area of the component by a distance specified bydxanddy.create()Creates a newGraphicsobject that is a copy of thisGraphicsobject.voiddispose()Disposes of this graphics context and releases any system resources that it is using.voidStrokes the outline of aShapeusing the settings of the currentGraphics2Dcontext.booleandrawImage(Image img, int x, int y, int width, int height, ImageObserver observer) Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.booleandrawImage(Image img, int x, int y, ImageObserver observer) Draws as much of the specified image as is currently available.voiddrawRenderableImage(RenderableImage img, AffineTransform xform) Renders aRenderableImage, applying a transform from image space into user space before drawing.voiddrawRenderedImage(RenderedImage img, AffineTransform xform) Renders aRenderedImage, applying a transform from image space into user space before drawing.voiddrawString(String s, float x, float y) Renders the text specified by the specifiedString, using the currentFontandPaintattributes in theGraphics2Dcontext.voiddrawString(AttributedCharacterIterator iterator, float x, float y) Renders the text of the specified iterator, using theGraphics2Dcontext's currentPaint.voidFills the interior of aShapeusing the settings of theGraphics2Dcontext.Returns the device configuration associated with thisGraphics2D.Gets the font metrics for the specified font.voidsetXORMode(Color c1) Sets the paint mode of this graphics context to alternate between this graphics context's current color and the new specified color.Methods inherited from class AbstractGraphics2D
addRenderingHints, clearRect, clip, clipRect, drawArc, drawGlyphVector, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawLine, drawOval, drawPolygon, drawPolyline, drawRect, drawRoundRect, drawString, drawString, fillArc, fillOval, fillPolygon, fillRect, fillRoundRect, getBackground, getClip, getClipBounds, getColor, getComposite, getFont, getFontRenderContext, getGraphicContext, getPaint, getRenderingHint, getRenderingHints, getStroke, getTransform, hit, rotate, rotate, scale, setBackground, setClip, setClip, setColor, setComposite, setFont, setPaint, setPaintMode, setRenderingHint, setRenderingHints, setStroke, setTransform, shear, transform, translate, translateMethods inherited from class Graphics2D
draw3DRect, fill3DRectMethods inherited from class Graphics
create, drawBytes, drawChars, drawPolygon, fillPolygon, finalize, getClipBounds, getClipRect, getFontMetrics, hitClip, toString
-
Constructor Details
-
DefaultGraphics2D
public DefaultGraphics2D(boolean textAsShapes) Default constructor -
DefaultGraphics2D
This constructor supports the create method
-
-
Method Details
-
create
-
drawImage
Draws as much of the specified image as is currently available. The image is drawn with its top-left corner at (x, y) in this graphics context's coordinate space. Transparent pixels in the image do not affect whatever pixels are already there.This method returns immediately in all cases, even if the complete image has not yet been loaded, and it has not been dithered and converted for the current output device.
If the image has not yet been completely loaded, then
drawImagereturnsfalse. As more of the image becomes available, the process that draws the image notifies the specified image observer. -
drawImage
Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.The image is drawn inside the specified rectangle of this graphics context's coordinate space, and is scaled if necessary. Transparent pixels do not affect whatever pixels are already there.
This method returns immediately in all cases, even if the entire image has not yet been scaled, dithered, and converted for the current output device. If the current output representation is not yet complete, then
drawImagereturnsfalse. As more of the image becomes available, the process that draws the image notifies the image observer by calling itsimageUpdatemethod.A scaled version of an image will not necessarily be available immediately just because an unscaled version of the image has been constructed for this output device. Each size of the image may be cached separately and generated from the original data in a separate image production sequence.
-
dispose
public void dispose()Disposes of this graphics context and releases any system resources that it is using. AGraphicsobject cannot be used afterdisposehas been called.When a Java program runs, a large number of
Graphicsobjects can be created within a short time frame. Although the finalization process of the garbage collector also disposes of the same system resources, it is preferable to manually free the associated resources by calling this method rather than to rely on a finalization process which may not run to completion for a long period of time.Graphics objects which are provided as arguments to the
paintandupdatemethods of components are automatically released by the system when those methods return. For efficiency, programmers should calldisposewhen finished using aGraphicsobject only if it was created directly from a component or anotherGraphicsobject. -
draw
Strokes the outline of aShapeusing the settings of the currentGraphics2Dcontext. The rendering attributes applied include theClip,Transform,Paint,CompositeandStrokeattributes.- Specified by:
drawin classGraphics2D- Parameters:
s- theShapeto be rendered- See Also:
-
drawRenderedImage
Renders aRenderedImage, applying a transform from image space into user space before drawing. The transformation from user space into device space is done with the currentTransformin theGraphics2D. The specified transformation is applied to the image before the transform attribute in theGraphics2Dcontext is applied. The rendering attributes applied include theClip,Transform, andCompositeattributes. Note that no rendering is done if the specified transform is noninvertible.- Specified by:
drawRenderedImagein classGraphics2D- Parameters:
img- the image to be renderedxform- the transformation from image space into user space- See Also:
-
drawRenderableImage
Renders aRenderableImage, applying a transform from image space into user space before drawing. The transformation from user space into device space is done with the currentTransformin theGraphics2D. The specified transformation is applied to the image before the transform attribute in theGraphics2Dcontext is applied. The rendering attributes applied include theClip,Transform, andCompositeattributes. Note that no rendering is done if the specified transform is noninvertible.Rendering hints set on the
Graphics2Dobject might be used in rendering theRenderableImage. If explicit control is required over specific hints recognized by a specificRenderableImage, or if knowledge of which hints are used is required, then aRenderedImageshould be obtained directly from theRenderableImageand rendered usingdrawRenderedImage.- Specified by:
drawRenderableImagein classGraphics2D- Parameters:
img- the image to be renderedxform- the transformation from image space into user space- See Also:
-
drawString
Renders the text specified by the specifiedString, using the currentFontandPaintattributes in theGraphics2Dcontext. The baseline of the first character is at position (x, y) in the User Space. The rendering attributes applied include theClip,Transform,Paint,FontandCompositeattributes. 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.- Specified by:
drawStringin classGraphics2D- Parameters:
s- theStringto be renderedx- the x coordinate where theStringshould be renderedy- the y coordinate where theStringshould be rendered- See Also:
-
drawString
Renders the text of the specified iterator, using theGraphics2Dcontext's currentPaint. The iterator must specify a font for each character. The baseline of the first character is at position (x, y) in the User Space. The rendering attributes applied include theClip,Transform,Paint, andCompositeattributes. 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.- Specified by:
drawStringin classGraphics2D- Parameters:
iterator- the iterator whose text is to be renderedx- the x coordinate where the iterator's text is to be renderedy- the y coordinate where the iterator's text is to be rendered- See Also:
-
fill
Fills the interior of aShapeusing the settings of theGraphics2Dcontext. The rendering attributes applied include theClip,Transform,Paint, andComposite.- Specified by:
fillin classGraphics2D- Parameters:
s- theShapeto be filled- See Also:
-
getDeviceConfiguration
Returns the device configuration associated with thisGraphics2D.- Specified by:
getDeviceConfigurationin classGraphics2D
-
getFontMetrics
Gets the font metrics for the specified font.- Specified by:
getFontMetricsin classGraphics- Parameters:
f- the specified font- Returns:
- the font metrics for the specified font.
- See Also:
-
setXORMode
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.
- Specified by:
setXORModein classGraphics- Parameters:
c1- the XOR alternation color
-
copyArea
public void copyArea(int x, int y, int width, int height, int dx, int dy) Copies an area of the component by a distance specified bydxanddy. From the point specified byxandy, this method copies downwards and to the right. To copy an area of the component to the left or upwards, specify a negative value fordxordy. If a portion of the source rectangle lies outside the bounds of the component, or is obscured by another window or component,copyAreawill be unable to copy the associated pixels. The area that is omitted can be refreshed by calling the component'spaintmethod.- Specified by:
copyAreain classGraphics- Parameters:
x- the x coordinate of the source rectangle.y- the y coordinate of the source rectangle.width- the width of the source rectangle.height- the height of the source rectangle.dx- the horizontal distance to copy the pixels.dy- the vertical distance to copy the pixels.
-