APIdia Launch Partner
Top Description Fields Constructors Methods
sun.java2d

public final Class SunGraphics2D

extends Graphics2D
implements ConstrainableGraphics, Cloneable, DestSurfaceProvider
Class Inheritance
All Implemented Interfaces
sun.java2d.DestSurfaceProvider, java.lang.Cloneable, sun.awt.ConstrainableGraphics
Imports
java.awt.AlphaComposite, .BasicStroke, .Color, .Composite, .Font, .FontMetrics, .GradientPaint, .Graphics, .Graphics2D, .GraphicsConfiguration, .Image, .LinearGradientPaint, .Paint, .RadialGradientPaint, .Rectangle, .RenderingHints, .RenderingHints.Key, .Shape, .Stroke, .TexturePaint, .Transparency, java.awt.font.FontRenderContext, .GlyphVector, .TextLayout, java.awt.geom.AffineTransform, .Area, .GeneralPath, .NoninvertibleTransformException, .PathIterator, .Rectangle2D, java.awt.image.AffineTransformOp, .BufferedImage, .BufferedImageOp, .ColorModel, .ImageObserver, .MultiResolutionImage, .Raster, .RenderedImage, .VolatileImage, .WritableRaster, java.awt.image.renderable.RenderContext, .RenderableImage, java.lang.annotation.Native, java.text.AttributedCharacterIterator, java.util.Map, sun.awt.ConstrainableGraphics, .SunHints, sun.awt.image.MultiResolutionToolkitImage, .SurfaceManager, .ToolkitImage, sun.awt.util.PerformanceLogger, sun.font.FontDesignMetrics, .FontUtilities, sun.java2d.loops.Blit, .CompositeType, .FontInfo, .MaskFill, .RenderLoops, .SurfaceType, .XORComposite, sun.java2d.pipe.DrawImagePipe, .LoopPipe, .PixelDrawPipe, .PixelFillPipe, .Region, .ShapeDrawPipe, .ShapeSpanIterator, .TextPipe, .ValidatePipe

This is 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.
Author
Jim Graham

Field Summary

Modifier and TypeField and Description
public MaskFill
public int
public Color
private FontRenderContext
public static final int
public static final int
public static final int
public Region
public int
public static final int
public static final int
public static final int
public static final int
public Composite
public int
public Region
public int
public int
protected static final Composite
private static final Font
protected static final Stroke
protected Region
public PixelDrawPipe
public int
public PixelFillPipe
protected Font
private FontInfo
protected FontMetrics
public Color
protected int
private FontInfo
private FontRenderContext
public RenderingHints
private static final AffineTransform
private static final double[]
public CompositeType
public DrawImagePipe
private int
public int
protected static ValidatePipe
pack-priv Blit
pack-priv Composite
public int
private static int
public RenderLoops
private static final int
public static final double
public static final double
public static final double
pack-priv static final int
pack-priv static final int
public Paint
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public int
public int
public int
private int
public ShapeDrawPipe
public Stroke
public static final int
public static final int
public static final int
public static final int
public int
public int
public SurfaceData
public int
private static final int
private static AffineTransform[]
public TextPipe
private static double[][]
public AffineTransform
public static final int
public static final int
public static final int
public static final int
public static final int
public int
public int
public int
public Shape
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addRenderingHints(Map<?, ?>
The rendering hints to be set
hints
)

Implements abstract java.awt.Graphics2D.addRenderingHints.

Adds a number of preferences for the rendering algorithms.

public FontInfo
public void
clearRect(int x, int y, int w, int h)

Implements abstract java.awt.Graphics.clearRect.

Clears the specified rectangle by filling it with the background color of the current drawing surface.

public void
clip(Shape
The Path to be intersected with the current clip.
s
)

Implements abstract java.awt.Graphics2D.clip.

Intersects the current clip with the specified Path and sets the current clip to the resulting intersection.

public void
clipRect(int x, int y, int w, int h)

Implements abstract java.awt.Graphics.clipRect.

Intersects the current clip with the specified rectangle.

private boolean
clipTo(Rectangle destRect, Rectangle clip)

Intersects destRect with clip and overwrites destRect with the result.

protected Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.

protected static Shape
public AffineTransform
cloneTransform()

Returns the current Transform ignoring the "constrain" rectangle.

public void
constrain(int x, int y, int w, int h, Region region)

Constrain rendering for lightweight objects.

public void
constrain(int x, int y, int w, int h)

Implements sun.awt.ConstrainableGraphics.constrain.

Constrain rendering for lightweight objects.

public void
copyArea(int x, int y, int w, int h, int dx, int dy)

Implements abstract java.awt.Graphics.copyArea.

Copies an area of the component by a distance specified by dx and dy.

public boolean
copyImage(Image img, int dx, int dy, int sx, int sy, int width, int height, Color bgcolor, ImageObserver observer)

Not part of the advertised API but a useful utility method to call internally.

public Graphics
create()

Implements abstract java.awt.Graphics.create.

Create a new SunGraphics2D based on this one.

public void
dispose()

Implements abstract java.awt.Graphics.dispose.

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 usable after it is disposed.

private void
doCopyArea(int x, int y, int w, int h, int dx, int dy)

public void
draw(Shape
The path to be drawn.
s
)

Implements abstract java.awt.Graphics2D.draw.

Strokes the outline of a Path using the settings of the current graphics state.

public void
drawArc(int x, int y, int w, int h, int startAngl, int arcAngl)

Implements abstract java.awt.Graphics.drawArc.

Draws the outline of a circular or elliptical arc covering the specified rectangle.

public void
drawBytes(byte[] data, int offset, int length, int x, int y)

Overrides java.awt.Graphics.drawBytes.

Draws the text given by the specified byte array, using this graphics context's current font and color.

public void
drawChars(char[] data, int offset, int length, int x, int y)

Overrides java.awt.Graphics.drawChars.

Draws the text given by the specified character array, using this graphics context's current font and color.

public void
drawGlyphVector(GlyphVector gv, float x, float y)

Implements abstract java.awt.Graphics2D.drawGlyphVector.

Renders the text of the specified GlyphVector using the Graphics2D context's rendering attributes.

private Boolean
drawHiDPIImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer, AffineTransform xform)

public boolean
drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)

Implements abstract java.awt.Graphics.drawImage.

Draws an image scaled to x,y,w,h in nonblocking mode with a callback object.

public boolean
drawImage(Image img, int x, int y, int width, int height, Color bg, ImageObserver observer)

Implements abstract java.awt.Graphics.drawImage.

Draws an image scaled to x,y,w,h in nonblocking mode with a solid background color and a callback object.

public boolean
drawImage(Image img, int x, int y, ImageObserver observer)

Implements abstract java.awt.Graphics.drawImage.

Draws an image at x,y in nonblocking mode.

public boolean
drawImage(Image img, int x, int y, Color bg, ImageObserver observer)

Implements abstract java.awt.Graphics.drawImage.

Draws an image at x,y in nonblocking mode with a solid background color and a callback object.

public boolean
drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)

Implements abstract java.awt.Graphics.drawImage.

Draws a subrectangle of an image scaled to a destination rectangle in nonblocking mode with a callback object.

public boolean
drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)

Implements abstract java.awt.Graphics.drawImage.

Draws a subrectangle of an image scaled to a destination rectangle in nonblocking mode with a solid background color and a callback object.

public boolean
drawImage(Image
The image to be drawn.
img
,
AffineTransform
The transformation from image space into user space.
xform
,
ImageObserver
The image observer to be notified on the image producing progress.
observer
)

Implements abstract java.awt.Graphics2D.drawImage.

Draw an image, applying a transform from image space into user space before drawing.

public void
drawImage(BufferedImage bImg, BufferedImageOp op, int x, int y)

Implements abstract java.awt.Graphics2D.drawImage.

Renders a BufferedImage that is filtered with a BufferedImageOp.

public void
drawLine(int x1, int y1, int x2, int y2)

Implements abstract java.awt.Graphics.drawLine.

Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.

public void
drawOval(int x, int y, int w, int h)

Implements abstract java.awt.Graphics.drawOval.

Draws the outline of an oval.

public void
drawPolygon(int[] xPoints, int[] yPoints, int nPoints)

Implements abstract java.awt.Graphics.drawPolygon.

Draws a closed polygon defined by arrays of x and y coordinates.

public void
drawPolyline(int[] xPoints, int[] yPoints, int nPoints)

Implements abstract java.awt.Graphics.drawPolyline.

Draws a sequence of connected lines defined by arrays of x and y coordinates.

public void
drawRect(int x, int y, int w, int h)

Overrides java.awt.Graphics.drawRect.

Draws the outline of the specified rectangle.

public void
drawRenderableImage(RenderableImage img, AffineTransform xform)

Implements abstract java.awt.Graphics2D.drawRenderableImage.

Renders a RenderableImage, applying a transform from image space into user space before drawing.

public void
drawRenderedImage(RenderedImage
The image to be drawn. Does nothing if img is null.
img
,
AffineTransform
The transformation from image space into user space.
xform
)

Implements abstract java.awt.Graphics2D.drawRenderedImage.

Draws an image, applying a transform from image space into user space before drawing.

public void
drawRoundRect(int x, int y, int w, int h, int arcW, int arcH)

Implements abstract java.awt.Graphics.drawRoundRect.

Draws an outlined round-cornered rectangle using this graphics context's current color.

public void
drawString(String str, int x, int y)

Implements abstract java.awt.Graphics2D.drawString.

Renders the text of the specified String, using the current text attribute state in the Graphics2D context.

public void
drawString(String str, float x, float y)

Implements abstract java.awt.Graphics2D.drawString.

Renders the text specified by the specified String, using the current text attribute state in the Graphics2D context.

public void
drawString(AttributedCharacterIterator iterator, int x, int y)

Implements abstract java.awt.Graphics2D.drawString.

Renders the text of the specified iterator applying its attributes in accordance with the specification of the TextAttribute class.

public void
drawString(AttributedCharacterIterator iterator, float x, float y)

Implements abstract java.awt.Graphics2D.drawString.

Renders the text of the specified iterator applying its attributes in accordance with the specification of the TextAttribute class.

private void
drawTranslatedRenderedImage(RenderedImage img, Rectangle region, int i2uTransX, int i2uTransY)

Draw a portion of a RenderedImage tile-by-tile with a given integer image to user space translation.

public void
fill(Shape s)

Implements abstract java.awt.Graphics2D.fill.

Fills the interior of a Path using the settings of the current graphics state.

public void
fillArc(int x, int y, int w, int h, int startAngl, int arcAngl)

Implements abstract java.awt.Graphics.fillArc.

Fills a circular or elliptical arc covering the specified rectangle.

public void
fillOval(int x, int y, int w, int h)

Implements abstract java.awt.Graphics.fillOval.

Fills an oval bounded by the specified rectangle with the current color.

public void
fillPolygon(int[] xPoints, int[] yPoints, int nPoints)

Implements abstract java.awt.Graphics.fillPolygon.

Fills a closed polygon defined by arrays of x and y coordinates.

public void
fillRect(int x, int y, int w, int h)

Implements abstract java.awt.Graphics.fillRect.

Fills the specified rectangle.

public void
fillRoundRect(int x, int y, int w, int h, int arcW, int arcH)

Implements abstract java.awt.Graphics.fillRoundRect.

Fills the specified rounded corner rectangle with the current color.

public void
finalize()

Overrides java.awt.Graphics.finalize.

Graphics has a finalize method that automatically calls dispose() for subclasses.

private static void
fixRectangleOrientation(double[] m, Rectangle2D clip)

Sets orientation of the rectangle according to the clip.

public Color
getBackground()

Implements abstract java.awt.Graphics2D.getBackground.

Returns the background color used for clearing a region.

public Shape
getClip()

Implements abstract java.awt.Graphics.getClip.

Gets the current clipping area.

public Rectangle
getClipBounds()

Implements abstract java.awt.Graphics.getClipBounds.

Returns the bounding rectangle of the current clipping area.

public Rectangle
getClipBounds(Rectangle r)

Overrides java.awt.Graphics.getClipBounds.

Returns the bounding rectangle of the current clipping area.

public Color
getColor()

Implements abstract java.awt.Graphics.getColor.

Gets this graphics context's current color.

public Region
public Composite
getComposite()

Implements abstract java.awt.Graphics2D.getComposite.

Returns the current Composite in the Graphics2D state.

private AffineTransform
public Object
getDestination()

Returns destination that this Graphics renders to.

public Surface
getDestSurface()

Implements sun.java2d.DestSurfaceProvider.getDestSurface.

Returns a surface currently used as a destination surface for rendering.

public ColorModel
getDeviceColorModel()

Return the ColorModel associated with this Graphics2D.

public GraphicsConfiguration
getDeviceConfiguration()

Implements abstract java.awt.Graphics2D.getDeviceConfiguration.

Return the device configuration associated with this Graphics2D.

public Font
getFont()

Implements abstract java.awt.Graphics.getFont.

Gets the current font.

public FontInfo
public FontMetrics
getFontMetrics()

Overrides java.awt.Graphics.getFontMetrics.

Gets the font metrics of the current font.

public FontMetrics
getFontMetrics(Font font)

Implements abstract java.awt.Graphics.getFontMetrics.

Gets the font metrics for the specified font.

public FontRenderContext
getFontRenderContext()

Implements abstract java.awt.Graphics2D.getFontRenderContext.

Get the rendering context of the font within this Graphics2D context.

public FontInfo
private static Rectangle
getImageRegion(RenderedImage img, Region compClip, AffineTransform transform, AffineTransform xform, int padX, int padY)

Returns a rectangle in image coordinates that may be required in order to draw the given image into the given clipping region through a pair of AffineTransforms.

public Paint
getPaint()

Implements abstract java.awt.Graphics2D.getPaint.

Returns the current Paint in the Graphics2D state.

public Object

Returns:

The preferences for rendering algorithms. The strings are defined in the RenderingHints class.
getRenderingHint
(RenderingHints.Key
The category of hint to be set. The strings are defined in the RenderingHints class.
hintKey
)

Implements abstract java.awt.Graphics2D.getRenderingHint.

Returns the preferences for the rendering algorithms.

public RenderingHints
getRenderingHints()

Implements abstract java.awt.Graphics2D.getRenderingHints.

Gets the preferences for the rendering algorithms.

private Image
getResolutionVariant(MultiResolutionImage img, int srcWidth, int srcHeight, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, AffineTransform xform)

public Stroke
getStroke()

Implements abstract java.awt.Graphics2D.getStroke.

Returns the current Stroke in the Graphics2D state.

public SurfaceData
getSurfaceData()

Return the SurfaceData object assigned to manage the destination drawable surface of this Graphics2D.

private static int
getTileIndex(int p, int tileGridOffset, int tileSize)

Returns the index of the tile corresponding to the supplied position given the tile grid offset and size along the same axis.

public AffineTransform
getTransform()

Implements abstract java.awt.Graphics2D.getTransform.

Returns the current Transform in the Graphics2D state.

public boolean

Returns:

True if there is a hit, false otherwise.
hit
(Rectangle
The area in device space to check for a hit.
rect
,
Shape
The path to check for a hit.
s
,
boolean
Flag to choose between testing the stroked or the filled path.
onStroke
)

Implements abstract java.awt.Graphics2D.hit.

Checks to see if a Path intersects the specified Rectangle in device space.

public boolean
hitClip(int x, int y, int width, int height)

Overrides java.awt.Graphics.hitClip.

Returns true if the specified rectangular area might intersect the current clipping area.

pack-priv Shape
intersectByArea(Shape s1, Shape s2, boolean keep1, boolean keep2)

pack-priv Shape
intersectRectShape(Rectangle2D r, Shape s, boolean keep1, boolean keep2)

pack-priv Shape
intersectShapes(Shape s1, Shape s2, boolean keep1, boolean keep2)

protected void
protected void
private static boolean
isIntegerTranslation(AffineTransform xform)

Returns true if the given AffineTransform is an integer translation.

pack-priv RenderingHints
makeHints(Map<?, ?> hints)

private void
public void
rotate(double
The angle of rotation in radians.
theta
)

Implements abstract java.awt.Graphics2D.rotate.

Concatenates the current transform of this Graphics2D with a rotation transformation.

public void
rotate(double
The angle of rotation in radians.
theta
,
double
The x coordinate of the origin of the rotation
x
,
double
The x coordinate of the origin of the rotation
y
)

Implements abstract java.awt.Graphics2D.rotate.

Concatenates the current transform of this Graphics2D with a translated rotation transformation.

public void
scale(double sx, double sy)

Implements abstract java.awt.Graphics2D.scale.

Concatenates the current transform of this Graphics2D with a scaling transformation.

private boolean
scaleImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)

public void
setBackground(Color
The background color that should be used in subsequent calls to clearRect().
color
)

Implements abstract java.awt.Graphics2D.setBackground.

Sets the background color in this context used for clearing a region.

public void
setClip(int x, int y, int w, int h)

Implements abstract java.awt.Graphics.setClip.

Sets the current clip to the rectangle specified by the given coordinates.

public void
setClip(Shape sh)

Implements abstract java.awt.Graphics.setClip.

Sets the current clipping area to an arbitrary clip shape.

public void
setColor(Color color)

Implements abstract java.awt.Graphics.setColor.

Sets this graphics context's current color to the specified color.

public void
setComposite(Composite
The Composite object to be used for drawing.
comp
)

Implements abstract java.awt.Graphics2D.setComposite.

Sets the Composite in the current graphics state.

public void
setDevClip(int x, int y, int w, int h)

public void
public void
setFont(Font font)

Implements abstract java.awt.Graphics.setFont.

Sets this graphics context's font to the specified font.

public void
setPaint(Paint
The Paint object to be used to generate color in the rendering process.
paint
)

Implements abstract java.awt.Graphics2D.setPaint.

Sets the Paint in the current graphics state.

public void
setPaintMode()

Implements abstract java.awt.Graphics.setPaintMode.

Sets the paint mode of this graphics context to overwrite the destination with this graphics context's current color.

public void
setRenderingHint(RenderingHints.Key
The key of hint to be set. The strings are defined in the RenderingHints class.
hintKey
,
Object
The value indicating preferences for the specified hint category. These strings are defined in the RenderingHints class.
hintValue
)

Implements abstract java.awt.Graphics2D.setRenderingHint.

Sets the preferences for the rendering algorithms.

public void
setRenderingHints(Map<?, ?>
The rendering hints to be set
hints
)

Implements abstract java.awt.Graphics2D.setRenderingHints.

Sets the preferences for the rendering algorithms.

public void
setStroke(Stroke s)

Implements abstract java.awt.Graphics2D.setStroke.

Sets the Stroke for the Graphics2D context.

public void
setTransform(AffineTransform
The Transform object to be used in the rendering process.
Tx
)

Implements abstract java.awt.Graphics2D.setTransform.

Sets the Transform in the current graphics state.

public void
setXORMode(Color c)

Implements abstract java.awt.Graphics.setXORMode.

Sets the paint mode of this graphics context to alternate between this graphics context's current color and the new specified color.

public void
shear(double
The factor by which coordinates are shifted towards the positive X axis direction according to their Y coordinate
shx
,
double
The factor by which coordinates are shifted towards the positive Y axis direction according to their X coordinate
shy
)

Implements abstract java.awt.Graphics2D.shear.

Concatenates the current transform of this Graphics2D with a shearing transformation.

public void
transform(AffineTransform
The Transform object to be composed with the current transform.
xform
)

Implements abstract java.awt.Graphics2D.transform.

Composes a Transform object with the transform in this Graphics2D according to the rule last-specified-first-applied.

private boolean
protected Shape
protected static Shape
transformShape(int tx, int ty, Shape s)

protected static Shape
public void
translate(double tx, double ty)

Implements abstract java.awt.Graphics2D.translate.

Concatenates the current transform of this Graphics2D with a translation transformation.

public void
translate(int x, int y)

Implements abstract java.awt.Graphics2D.translate.

Translate

public Shape
private void
pack-priv void
protected void
public void
Inherited from java.awt.Graphics2D:
draw3DRectfill3DRect