FileDocCategorySizeDatePackage
Graphics2D.javaAPI DocAndroid 1.5 API17821Wed May 06 22:41:54 BST 2009java.awt

Graphics2D

public abstract class Graphics2D extends Graphics
The Graphics2D class extends Graphics class and provides more capabilities for rendering text, images, shapes. This provides methods to perform transformation of coordinate system, color management, and text layout. The following attributes exist for rendering:
  • Color - current Graphics2D color;
  • Font - current Graphics2D font;
  • Stroke - pen with a width of 1 pixel;
  • Transform - current Graphics2D Transformation;
  • Composite - alpha compositing rules for combining source and destination colors.
since
Android 1.0

Fields Summary
Constructors Summary
protected Graphics2D()
Instantiates a new Graphics2D object. This constructor should never be called directly.

        super();
    
Methods Summary
public abstract voidaddRenderingHints(java.util.Map hints)
Adds preferences for the rendering algorithms. The preferences are arbitrary and specified by Map objects. All specified by Map object preferences can be modified.

param
hints the rendering hints.

public abstract voidclip(java.awt.Shape s)
Intersects the current clipping area with the specified Shape and the result becomes a new clipping area. If current clipping area is not defined, the Shape becomes the new clipping area. No rendering operations are allowed outside the clipping area.

param
s the specified Shape object which will be intersected with current clipping area.

public abstract voiddraw(java.awt.Shape s)
Draws the outline of the specified Shape.

param
s the Shape which outline is drawn.

public voiddraw3DRect(int x, int y, int width, int height, boolean raised)
Draws the highlighted outline of a rectangle.

param
x the X coordinate of the rectangle's top left corner.
param
y the Y coordinate of the rectangle's top left corner.
param
width the width of rectangle.
param
height the height of rectangle.
param
raised a boolean value that determines whether the rectangle is drawn as raised or indented.
see
java.awt.Graphics#draw3DRect(int, int, int, int, boolean)

        // According to the spec, color should be used instead of paint,
        // so Graphics.draw3DRect resets paint and
        // it should be restored after the call
        Paint savedPaint = getPaint();
        super.draw3DRect(x, y, width, height, raised);
        setPaint(savedPaint);
    
public abstract voiddrawGlyphVector(java.awt.font.GlyphVector g, float x, float y)
Draws the specified GlyphVector object's text at the point x, y.

param
g the GlyphVector object to be drawn.
param
x the X position where the GlyphVector's text should be rendered.
param
y the Y position where the GlyphVector's text should be rendered.

public abstract voiddrawImage(java.awt.image.BufferedImage img, java.awt.image.BufferedImageOp op, int x, int y)
Draws the BufferedImage -- modified according to the operation BufferedImageOp -- at the point x, y.

param
img the BufferedImage to be rendered.
param
op the filter to be applied to the image before rendering.
param
x the X coordinate of the point where the image's upper left corner will be placed.
param
y the Y coordinate of the point where the image's upper left corner will be placed.

public abstract booleandrawImage(java.awt.Image img, java.awt.geom.AffineTransform xform, java.awt.image.ImageObserver obs)
Draws BufferedImage transformed from image space into user space according to the AffineTransform xform and notifies the ImageObserver.

param
img the BufferedImage to be rendered.
param
xform the affine transformation from the image to the user space.
param
obs the ImageObserver to be notified about the image conversion.
return
true, if the image is successfully loaded and rendered, or it's null, otherwise false.

public abstract voiddrawRenderableImage(java.awt.image.renderable.RenderableImage img, java.awt.geom.AffineTransform xform)
Draws a RenderableImage which is transformed from image space into user according to the AffineTransform xform.

param
img the RenderableImage to be rendered.
param
xform the affine transformation from image to user space.

public abstract voiddrawRenderedImage(java.awt.image.RenderedImage img, java.awt.geom.AffineTransform xform)
Draws a RenderedImage which is transformed from image space into user according to the AffineTransform xform.

param
img the RenderedImage to be rendered.
param
xform the affine transformation from image to user space.

public abstract voiddrawString(java.text.AttributedCharacterIterator iterator, float x, float y)
Draws the string specified by the AttributedCharacterIterator. The first character's position is specified by the X, Y parameters.

param
iterator whose text is drawn.
param
x the X position where the first character is drawn.
param
y the Y position where the first character is drawn.

public abstract voiddrawString(java.text.AttributedCharacterIterator iterator, int x, int y)
Draws the string specified by the AttributedCharacterIterator. The first character's position is specified by the X, Y parameters.

param
iterator whose text is drawn.
param
x the X position where the first character is drawn.
param
y the Y position where the first character is drawn.
see
java.awt.Graphics#drawString(AttributedCharacterIterator, int, int)

public abstract voiddrawString(java.lang.String s, float x, float y)
Draws the String whose the first character position is specified by the parameters X, Y.

param
s the String to be drawn.
param
x the X position of the first character.
param
y the Y position of the first character.

public abstract voiddrawString(java.lang.String str, int x, int y)
Draws the String whose the first character coordinates are specified by the parameters X, Y.

param
str the String to be drawn.
param
x the X coordinate of the first character.
param
y the Y coordinate of the first character.
see
java.awt.Graphics#drawString(String, int, int)

public abstract voidfill(java.awt.Shape s)
Fills the interior of the specified Shape.

param
s the Shape to be filled.

public voidfill3DRect(int x, int y, int width, int height, boolean raised)
Fills a 3D rectangle with the current color. The rectangle is specified by its width, height, and top left corner coordinates.

param
x the X coordinate of the rectangle's top left corner.
param
y the Y coordinate of the rectangle's top left corner.
param
width the width of rectangle.
param
height the height of rectangle.
param
raised a boolean value that determines whether the rectangle is drawn as raised or indented.
see
java.awt.Graphics#fill3DRect(int, int, int, int, boolean)

        // According to the spec, color should be used instead of paint,
        // so Graphics.fill3DRect resets paint and
        // it should be restored after the call
        Paint savedPaint = getPaint();
        super.fill3DRect(x, y, width, height, raised);
        setPaint(savedPaint);
    
public abstract java.awt.ColorgetBackground()
Gets the background color.

return
the current background color.

public abstract java.awt.CompositegetComposite()
Gets the current composite of the Graphics2D.

return
the current composite which specifies the compositing style.

public abstract java.awt.GraphicsConfigurationgetDeviceConfiguration()
Gets the device configuration.

return
the device configuration.

public abstract java.awt.font.FontRenderContextgetFontRenderContext()
Gets the rendering context of the Font.

return
the FontRenderContext.

public abstract java.awt.PaintgetPaint()
Gets the current Paint of Graphics2D.

return
the current Paint of Graphics2D.

public abstract java.lang.ObjectgetRenderingHint(java.awt.RenderingHints$Key key)
Gets the value of single preference for specified key.

param
key the specified key of the rendering hint.
return
the value of rendering hint for specified key.

public abstract java.awt.RenderingHintsgetRenderingHints()
Gets the set of the rendering preferences as a collection of key/value pairs.

return
the RenderingHints which contains the rendering preferences.

public abstract java.awt.StrokegetStroke()
Gets current stroke of the Graphics2D.

return
current stroke of the Graphics2D.

public abstract java.awt.geom.AffineTransformgetTransform()
Gets current affine transform of the Graphics2D.

return
current AffineTransform of the Graphics2D.

public abstract booleanhit(java.awt.Rectangle rect, java.awt.Shape s, boolean onStroke)
Determines whether or not the specified Shape intersects the specified Rectangle. If the onStroke parameter is true, this method checks whether or not the specified Shape outline intersects the specified Rectangle, otherwise this method checks whether or not the specified Shape's interior intersects the specified Rectangle.

param
rect the specified Rectangle.
param
s the Shape to check for intersection.
param
onStroke the parameter determines whether or not this method checks for intersection of the Shape outline or of the Shape interior with the Rectangle.
return
true, if there is a hit, false otherwise.

public abstract voidrotate(double theta)
Performs a rotation transform relative to current Graphics2D Transform. The coordinate system is rotated by the specified angle in radians relative to current origin.

param
theta the angle of rotation in radians.

public abstract voidrotate(double theta, double x, double y)
Performs a translated rotation transform relative to current Graphics2D Transform. The coordinate system is rotated by the specified angle in radians relative to current origin and then moved to point (x, y). Is this right?

param
theta the angle of rotation in radians.
param
x the X coordinate.
param
y the Y coordinate.

public abstract voidscale(double sx, double sy)
Performs a linear scale transform relative to current Graphics2D Transform. The coordinate system is rescaled vertically and horizontally by the specified parameters.

param
sx the scaling factor by which the X coordinate is multiplied.
param
sy the scaling factor by which the Y coordinate is multiplied.

public abstract voidsetBackground(java.awt.Color color)
Sets a new background color for clearing rectangular areas. The clearRect method uses the current background color.

param
color the new background color.

public abstract voidsetComposite(java.awt.Composite comp)
Sets the current composite for Graphics2D.

param
comp the Composite object.

public abstract voidsetPaint(java.awt.Paint paint)
Sets the paint for Graphics2D.

param
paint the Paint object.

public abstract voidsetRenderingHint(java.awt.RenderingHints$Key key, java.lang.Object value)
Sets a key-value pair in the current RenderingHints map.

param
key the key of the rendering hint to set.
param
value the value to set for the rendering hint.

public abstract voidsetRenderingHints(java.util.Map hints)
Replaces the current rendering hints with the specified rendering preferences.

param
hints the new Map of rendering hints.

public abstract voidsetStroke(java.awt.Stroke s)
Sets the stroke for the Graphics2D.

param
s the Stroke object.

public abstract voidsetTransform(java.awt.geom.AffineTransform Tx)
Overwrite the current Transform of the Graphics2D. The specified Transform should be received from the getTransform() method and should be used only for restoring the original Graphics2D transform after calling draw or fill methods.

param
Tx the specified Transform.

public abstract voidshear(double shx, double shy)
Performs a shear transform relative to current Graphics2D Transform. The coordinate system is shifted by the specified multipliers relative to current position.

param
shx the multiplier by which the X coordinates shift position along X axis as a function of Y coordinates.
param
shy the multiplier by which the Y coordinates shift position along Y axis as a function of X coordinates.

public abstract voidtransform(java.awt.geom.AffineTransform Tx)
Concatenates the AffineTransform object with current Transform of this Graphics2D. The transforms are applied in reverse order with the last specified transform applied first and the next transformation applied to the result of previous transformation. More precisely, if Cx is the current Graphics2D transform, the transform method's result with Tx as the parameter is the transformation Rx, where Rx(p) = Cx(Tx(p)), for p - a point in current coordinate system. Rx becomes the current Transform for this Graphics2D.

param
Tx the AffineTransform object to be concatenated with current Transform.

public abstract voidtranslate(double tx, double ty)
Performs a translate transform relative to current Graphics2D Transform. The coordinate system is moved by the specified distance relative to current position.

param
tx the translation distance along the X axis.
param
ty the translation distance along the Y axis.

public abstract voidtranslate(int x, int y)
Moves the origin Graphics2D Transform to the point with x, y coordinates in current coordinate system. The new origin of coordinate system is moved to the (x, y) point accordingly. All rendering and transform operations are performed relative to this new origin.

param
x the X coordinate.
param
y the Y coordinate.
see
java.awt.Graphics#translate(int, int)