gnu.java.awt.java2d

Class AbstractGraphics2D

Implemented Interfaces:
Cloneable, Pixelizer
Known Direct Subclasses:
GLGraphics, RasterGraphics, XGraphics2D

public abstract class AbstractGraphics2D
extends Graphics2D
implements Cloneable, Pixelizer

This is a 100% Java implementation of the Java2D rendering pipeline. It is meant as a base class for Graphics2D implementations.

Backend interface

The backend must at the very least provide a Raster which the the rendering pipeline can paint into. This must be implemented in getDestinationRaster(). For some backends that might be enough, like when the target surface can be directly access via the raster (like in BufferedImages). Other targets need some way to synchronize the raster with the surface, which can be achieved by implementing the updateRaster(Raster,int,int,int,int) method, which always gets called after a chunk of data got painted into the raster.

Alternativly the backend can provide a method for filling Shapes by overriding the protected method fillShape(). This can be accomplished by a polygon filling function of the backend. Keep in mind though that Shapes can be quite complex (i.e. non-convex and containing holes, etc) which is not supported by all polygon fillers. Also it must be noted that fillShape() is expected to handle painting and compositing as well as clipping and transformation. If your backend can't support this natively, then you can fallback to the implementation in this class. You'll need to provide a writable Raster then, see above.

Another alternative is to implement fillScanline() which only requires the backend to be able to draw horizontal lines in device space, which is usually very cheap. The implementation should still handle painting and compositing, but no more clipping and transformation is required by the backend.

The backend is free to provide implementations for the various raw* methods for optimized AWT 1.1 style painting of some primitives. This should accelerate painting of Swing greatly. When doing so, the backend must also keep track of the clip and translation, probably by overriding some clip and translate methods. Don't forget to message super in such a case.

Acceleration options

The fact that it is pure Java makes it a little slow. However, there are several ways of accelerating the rendering pipeline:

  1. Optimization hooks for AWT 1.1 - like graphics operations. The most important methods from the Graphics class have a corresponding raw* method, which get called when several optimization conditions are fullfilled. These conditions are described below. Subclasses can override these methods and delegate it directly to a native backend.
  2. Native PaintContexts and CompositeContext. The implementations for the 3 PaintContexts and AlphaCompositeContext can be accelerated using native code. These have proved to two of the most performance critical points in the rendering pipeline and cannot really be done quickly in plain Java because they involve lots of shuffling around with large arrays. In fact, you really would want to let the graphics card to the work, they are made for this.
  3. Provide an accelerated implementation for fillShape(). For instance, OpenGL can fill shapes very efficiently. There are some considerations to be made though, see above for details.

Field Summary

protected static WeakHashMap
HashMap
Caches scaled versions of an image.
protected static WeakHashMap
HashMap
Caches scaled versions of an image.
protected static WeakHashMap
Image>>()
Caches scaled versions of an image.
protected static WeakHashMap
Image>>imageCache
Caches scaled versions of an image.
protected AffineTransform
transform
The transformation for this Graphics2D instance

Constructor Summary

AbstractGraphics2D()
Creates a new AbstractGraphics2D instance.

Method Summary

void
addRenderingHints(Map<K,V> hints)
Adds the specified rendering hints.
void
clearRect(int x, int y, int width, int height)
Fills a rectangle with the current background color.
void
clip(Shape s)
Intersects the clip of this graphics object with the specified clip.
void
clipRect(int x, int y, int width, int height)
Intersects the current clipping region with the specified rectangle.
protected Object
clone()
Creates and returns a copy of this Graphics object.
void
copyArea(int x, int y, int width, int height, int dx, int dy)
Copies the specified rectangle to the specified offset location.
Graphics
create()
Creates a copy of this graphics object.
void
dispose()
Disposes this graphics object.
void
draw(Shape shape)
Draws the specified shape.
void
drawArc(int x, int y, int width, int height, int arcStart, int arcAngle)
Draws an arc.
void
drawGlyphVector(GlyphVector gv, float x, float y)
Draws the specified glyph vector at the specified location.
boolean
drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
Draws an image fragment to a rectangular area of the target.
boolean
drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
Draws an image fragment to a rectangular area of the target.
boolean
drawImage(Image image, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
Draws the specified image at the specified location.
boolean
drawImage(Image image, int x, int y, int width, int height, ImageObserver observer)
Draws the specified image at the specified location.
boolean
drawImage(Image image, int x, int y, Color bgcolor, ImageObserver observer)
Draws the specified image at the specified location.
boolean
drawImage(Image image, int x, int y, ImageObserver observer)
Draws the specified image at the specified location.
boolean
drawImage(Image image, AffineTransform xform, ImageObserver obs)
Draws the specified image and apply the transform for image space -> user space conversion.
void
drawImage(BufferedImage image, BufferedImageOp op, int x, int y)
Renders a BufferedImage and applies the specified BufferedImageOp before to filter the BufferedImage somehow.
void
drawLine(int x1, int y1, int x2, int y2)
Draws a line from (x1, y1) to (x2, y2).
void
drawOval(int x, int y, int width, int height)
Draws the outline of an oval.
void
drawPolygon(int[] xPoints, int[] yPoints, int npoints)
Draws the outline of a polygon.
void
drawPolyline(int[] xPoints, int[] yPoints, int npoints)
void
drawRect(int x, int y, int w, int h)
Draws the outline of the specified rectangle.
void
drawRenderableImage(RenderableImage image, AffineTransform xform)
Renders a renderable image.
void
drawRenderedImage(RenderedImage image, AffineTransform xform)
Renders the specified image to the destination raster.
void
drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
Draws a rounded rectangle.
void
drawString(String text, float x, float y)
Draws the specified string at the specified location.
void
drawString(String text, int x, int y)
Draws the specified string at the specified location.
void
drawString(AttributedCharacterIterator iterator, float x, float y)
Draws the specified string (as AttributedCharacterIterator) at the specified location.
void
drawString(AttributedCharacterIterator iterator, int x, int y)
Draws the specified string (as AttributedCharacterIterator) at the specified location.
void
fill(Shape shape)
Fills the specified shape with the current foreground.
void
fillArc(int x, int y, int width, int height, int arcStart, int arcAngle)
Fills an arc.
void
fillOval(int x, int y, int width, int height)
Fills an oval.
void
fillPolygon(int[] xPoints, int[] yPoints, int npoints)
Fills the outline of a polygon.
void
fillRect(int x, int y, int width, int height)
Fills a rectangle with the current paint.
void
fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
Fills a rounded rectangle.
protected void
fillShape(Shape s, boolean isFont)
Fills the specified shape.
Color
getBackground()
Returns the current background.
Shape
getClip()
Returns the current clip.
Rectangle
getClipBounds()
Returns the bounds of the current clip.
Color
getColor()
Returns the current foreground.
protected abstract ColorModel
getColorModel()
Returns the color model of this Graphics object.
Composite
getComposite()
Returns the current composite.
protected WritableRaster
getDestinationRaster()
Returns a WritableRaster that is used by this class to perform the rendering in.
protected abstract Rectangle
getDeviceBounds()
Returns the bounds of the target.
Font
getFont()
Returns the current font.
FontMetrics
getFontMetrics(Font font)
Returns the font metrics for the specified font.
FontRenderContext
getFontRenderContext()
Returns the font render context.
Paint
getPaint()
Returns the current foreground.
Object
getRenderingHint(RenderingHints.Key hintKey)
Returns the rendering hint for the specified key.
RenderingHints
getRenderingHints()
Returns the current rendering hints.
Stroke
getStroke()
Returns the current stroke.
AffineTransform
getTransform()
Returns the transformation of this coordinate system.
boolean
hit(Rectangle rect, Shape text, boolean onStroke)
protected void
init()
Initializes this graphics object.
static Image
prepareImage(Image image, int w, int h)
Scales an image to the specified width and height.
protected void
rawClearRect(int x, int y, int w, int h)
Clears a rectangle in optimization mode.
protected void
rawCopyArea(int x, int y, int w, int h, int dx, int dy)
Copies a rectangular region to another location.
protected boolean
rawDrawImage(Image image, int x, int y, ImageObserver obs)
Draws an image in optimization mode.
protected void
rawDrawLine(int x0, int y0, int x1, int y1)
Draws a line in optimization mode.
protected void
rawDrawRect(int x, int y, int w, int h)
protected void
rawFillRect(int x, int y, int w, int h)
Fills a rectangle in optimization mode.
void
renderScanline(int y, ScanlineCoverage c)
Paints a scanline between x0 and x1.
void
rotate(double theta)
Rotates the coordinate system by theta degrees.
void
rotate(double theta, double x, double y)
Rotates the coordinate system by theta around the point (x, y).
void
scale(double scaleX, double scaleY)
Scales the coordinate system by the factors scaleX and scaleY.
void
setBackground(Color color)
Sets the current background.
void
setClip(int x, int y, int width, int height)
Sets the clip to the specified rectangle.
void
setClip(Shape c)
Sets the current clipping area to clip.
void
setColor(Color color)
Sets the current foreground.
void
setComposite(Composite comp)
Sets the composite.
void
setFont(Font f)
Sets the font on this graphics object.
void
setPaint(Paint p)
Sets the current foreground.
void
setPaintMode()
Sets this context into "paint" mode, where the target pixels are completely overwritten when drawn on.
void
setRenderingHint(RenderingHints.Key hintKey, Object hintValue)
Sets the specified rendering hint.
void
setRenderingHints(Map<K,V> hints)
Sets the specified rendering hints.
void
setStroke(Stroke s)
Sets the stroke for this graphics object.
void
setTransform(AffineTransform t)
Sets the transformation for this Graphics object.
void
setXORMode(Color color)
Sets this context info "XOR" mode, where the targe pixles are XOR-ed when drawn on.
void
shear(double shearX, double shearY)
Shears the coordinate system by shearX and shearY.
void
transform(AffineTransform t)
Transforms the coordinate system using the specified transform t.
void
translate(double tx, double ty)
Translates the coordinate system by (tx, ty).
void
translate(int x, int y)
Translates the coordinate system by (x, y).
protected void
updateRaster(Raster raster, int x, int y, int w, int h)
Notifies the backend that the raster has changed in the specified rectangular area.

Methods inherited from class java.awt.Graphics2D

addRenderingHints, clip, draw, draw3DRect, drawGlyphVector, drawImage, drawImage, drawRenderableImage, drawRenderedImage, drawString, drawString, drawString, drawString, fill, fill3DRect, getBackground, getComposite, getDeviceConfiguration, getFontRenderContext, getPaint, getRenderingHint, getRenderingHints, getStroke, getTransform, hit, rotate, rotate, scale, setBackground, setComposite, setPaint, setRenderingHint, setRenderingHints, setStroke, setTransform, shear, transform, translate, translate

Methods inherited from class java.awt.Graphics

clearRect, clipRect, copyArea, create, create, dispose, draw3DRect, drawArc, drawBytes, drawChars, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawLine, drawOval, drawPolygon, drawPolygon, drawPolyline, drawRect, drawRoundRect, drawString, drawString, fill3DRect, fillArc, fillOval, fillPolygon, fillPolygon, fillRect, fillRoundRect, finalize, getClip, getClipBounds, getClipBounds, getClipRect, getColor, getFont, getFontMetrics, getFontMetrics, hitClip, setClip, setClip, setColor, setFont, setPaintMode, setXORMode, toString, translate

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

HashMap
protected static final WeakHashMapHashMap
Caches scaled versions of an image.


HashMap
protected static final WeakHashMapHashMap
Caches scaled versions of an image.


Image>>()

protected static final WeakHashMapImage>>()
Caches scaled versions of an image.

Image>>imageCache

protected static final WeakHashMapImage>>imageCache
Caches scaled versions of an image.

transform

protected AffineTransform transform
The transformation for this Graphics2D instance

Constructor Details

AbstractGraphics2D

protected AbstractGraphics2D()
Creates a new AbstractGraphics2D instance.

Method Details

addRenderingHints

public void addRenderingHints(Map<K,V> hints)
Adds the specified rendering hints.
Parameters:
hints - the rendering hints to add

clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height)
Fills a rectangle with the current background color. This implementation temporarily sets the foreground color to the background and forwards the call to fillRect(int,int,int,int).
Overrides:
clearRect in interface Graphics
Parameters:
x - the upper left corner, X coordinate
y - the upper left corner, Y coordinate
width - the width of the rectangle
height - the height of the rectangle

clip

public void clip(Shape s)
Intersects the clip of this graphics object with the specified clip.
Overrides:
clip in interface Graphics2D
Parameters:
s - the clip with which the current clip should be intersected

clipRect

public void clipRect(int x,
                     int y,
                     int width,
                     int height)
Intersects the current clipping region with the specified rectangle.
Overrides:
clipRect in interface Graphics
Parameters:
x - the x coordinate of the rectangle
y - the y coordinate of the rectangle
width - the width of the rectangle
height - the height of the rectangle

clone

protected Object clone()
Creates and returns a copy of this Graphics object. This should be overridden by subclasses if additional state must be handled when cloning. This is called by create().
Overrides:
clone in interface Object
Returns:
a copy of this Graphics object

copyArea

public void copyArea(int x,
                     int y,
                     int width,
                     int height,
                     int dx,
                     int dy)
Copies the specified rectangle to the specified offset location.
Overrides:
copyArea in interface Graphics
Parameters:
x - The X coordinate of the upper left corner of the copy rect.
y - The Y coordinate of the upper left corner of the copy rect.
width - The width of the copy rect.
height - The height of the copy rect.
dx - The offset from the X value to start drawing.
dy - The offset from the Y value to start drawing.

create

public Graphics create()
Creates a copy of this graphics object.
Overrides:
create in interface Graphics
Returns:
a copy of this graphics object

dispose

public void dispose()
Disposes this graphics object.
Overrides:
dispose in interface Graphics

draw

public void draw(Shape shape)
Draws the specified shape. The shape is passed through the current stroke and is then forwarded to fillShape(Shape,boolean).
Overrides:
draw in interface Graphics2D
Parameters:
shape - the shape to draw

drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int arcStart,
                    int arcAngle)
Draws an arc.
Overrides:
drawArc in interface Graphics

drawGlyphVector

public void drawGlyphVector(GlyphVector gv,
                            float x,
                            float y)
Draws the specified glyph vector at the specified location.
Overrides:
drawGlyphVector in interface Graphics2D
Parameters:
gv - the glyph vector to draw
x - the location, x coordinate
y - the location, y coordinate

drawImage

public boolean drawImage(Image image,
                         int dx1,
                         int dy1,
                         int dx2,
                         int dy2,
                         int sx1,
                         int sy1,
                         int sx2,
                         int sy2,
                         Color bgcolor,
                         ImageObserver observer)
Draws an image fragment to a rectangular area of the target.
Overrides:
drawImage in interface Graphics
Parameters:
image - the image to render
dx1 - the first corner of the destination rectangle
dy1 - the first corner of the destination rectangle
dx2 - the second corner of the destination rectangle
dy2 - the second corner of the destination rectangle
sx1 - the first corner of the source rectangle
sy1 - the first corner of the source rectangle
sx2 - the second corner of the source rectangle
sy2 - the second corner of the source rectangle
bgcolor - the background color to use for transparent pixels
observer - the image observer to be notified

drawImage

public boolean drawImage(Image image,
                         int dx1,
                         int dy1,
                         int dx2,
                         int dy2,
                         int sx1,
                         int sy1,
                         int sx2,
                         int sy2,
                         ImageObserver observer)
Draws an image fragment to a rectangular area of the target.
Overrides:
drawImage in interface Graphics
Parameters:
image - the image to render
dx1 - the first corner of the destination rectangle
dy1 - the first corner of the destination rectangle
dx2 - the second corner of the destination rectangle
dy2 - the second corner of the destination rectangle
sx1 - the first corner of the source rectangle
sy1 - the first corner of the source rectangle
sx2 - the second corner of the source rectangle
sy2 - the second corner of the source rectangle
observer - the image observer to be notified

drawImage

public boolean drawImage(Image image,
                         int x,
                         int y,
                         int width,
                         int height,
                         Color bgcolor,
                         ImageObserver observer)
Draws the specified image at the specified location. The image is scaled to the specified width and height. This forwards to drawImage(Image,AffineTransform,ImageObserver).
Overrides:
drawImage in interface Graphics
Parameters:
image - the image to render
x - the x location to render to
y - the y location to render to
width - the target width of the image
height - the target height of the image
bgcolor - the background color to use for transparent pixels
observer - the image observer to receive notification

drawImage

public boolean drawImage(Image image,
                         int x,
                         int y,
                         int width,
                         int height,
                         ImageObserver observer)
Draws the specified image at the specified location. The image is scaled to the specified width and height. This forwards to drawImage(Image,AffineTransform,ImageObserver).
Overrides:
drawImage in interface Graphics
Parameters:
image - the image to render
x - the x location to render to
y - the y location to render to
width - the target width of the image
height - the target height of the image
observer - the image observer to receive notification

drawImage

public boolean drawImage(Image image,
                         int x,
                         int y,
                         Color bgcolor,
                         ImageObserver observer)
Draws the specified image at the specified location. This forwards to drawImage(Image,AffineTransform,ImageObserver).
Overrides:
drawImage in interface Graphics
Parameters:
image - the image to render
x - the x location to render to
y - the y location to render to
bgcolor - the background color to use for transparent pixels
observer - the image observer to receive notification

drawImage

public boolean drawImage(Image image,
                         int x,
                         int y,
                         ImageObserver observer)
Draws the specified image at the specified location. This forwards to drawImage(Image,AffineTransform,ImageObserver).
Overrides:
drawImage in interface Graphics
Parameters:
image - the image to render
x - the x location to render to
y - the y location to render to
observer - the image observer to receive notification

drawImage

public boolean drawImage(Image image,
                         AffineTransform xform,
                         ImageObserver obs)
Draws the specified image and apply the transform for image space -> user space conversion. This method is implemented to special case RenderableImages and RenderedImages and delegate to drawRenderableImage(RenderableImage,AffineTransform) and drawRenderedImage(RenderedImage,AffineTransform) accordingly. Other image types are not yet handled.
Overrides:
drawImage in interface Graphics2D
Parameters:
image - the image to be rendered
xform - the transform from image space to user space
obs - the image observer to be notified

drawImage

public void drawImage(BufferedImage image,
                      BufferedImageOp op,
                      int x,
                      int y)
Renders a BufferedImage and applies the specified BufferedImageOp before to filter the BufferedImage somehow. The resulting BufferedImage is then passed on to drawRenderedImage(RenderedImage,AffineTransform) to perform the final rendering.
Overrides:
drawImage in interface Graphics2D
Parameters:
image - the source buffered image
op - the filter to apply to the buffered image before rendering
x - the x coordinate to render the image to
y - the y coordinate to render the image to

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
Draws a line from (x1, y1) to (x2, y2). This implementation transforms the coordinates and forwards the call to rawDrawLine(int,int,int,int).
Overrides:
drawLine in interface Graphics

drawOval

public void drawOval(int x,
                     int y,
                     int width,
                     int height)
Draws the outline of an oval.
Overrides:
drawOval in interface Graphics
Parameters:
x - the upper left corner of the bounding rectangle of the ellipse
y - the upper left corner of the bounding rectangle of the ellipse
width - the width of the ellipse
height - the height of the ellipse

drawPolygon

public void drawPolygon(int[] xPoints,
                        int[] yPoints,
                        int npoints)
Draws the outline of a polygon.

drawPolyline

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

drawRect

public void drawRect(int x,
                     int y,
                     int w,
                     int h)
Draws the outline of the specified rectangle.
Overrides:
drawRect in interface Graphics
Parameters:
x - The X coordinate of the upper left corner of the draw rect.
y - The Y coordinate of the upper left corner of the draw rect.

drawRenderableImage

public void drawRenderableImage(RenderableImage image,
                                AffineTransform xform)
Renders a renderable image. This produces a RenderedImage, which is then passed to drawRenderedImage(RenderedImage,AffineTransform) to perform the final rendering.
Overrides:
drawRenderableImage in interface Graphics2D
Parameters:
image - the renderable image to be rendered
xform - the transform from image space to user space

drawRenderedImage

public void drawRenderedImage(RenderedImage image,
                              AffineTransform xform)
Renders the specified image to the destination raster. The specified transform is used to convert the image into user space. The transform of this AbstractGraphics2D object is used to transform from user space to device space. The rendering is performed using the scanline algorithm that performs the rendering of other shapes and a custom Paint implementation, that supplies the pixel values of the rendered image.
Overrides:
drawRenderedImage in interface Graphics2D
Parameters:
image - the image to render to the destination raster
xform - the transform from image space to user space

drawRoundRect

public void drawRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Draws a rounded rectangle.
Overrides:
drawRoundRect in interface Graphics
Parameters:
x - the x coordinate of the rectangle
y - the y coordinate of the rectangle
width - the width of the rectangle
height - the height of the rectangle
arcWidth - the width of the arcs
arcHeight - the height of the arcs

drawString

public void drawString(String text,
                       float x,
                       float y)
Draws the specified string at the specified location.
Overrides:
drawString in interface Graphics2D
Parameters:
text - the string to draw
x - the x location, relative to the bounding rectangle of the text
y - the y location, relative to the bounding rectangle of the text

drawString

public void drawString(String text,
                       int x,
                       int y)
Draws the specified string at the specified location.
Overrides:
drawString in interface Graphics2D
Parameters:
text - the string to draw
x - the x location, relative to the bounding rectangle of the text
y - the y location, relative to the bounding rectangle of the text

drawString

public void drawString(AttributedCharacterIterator iterator,
                       float x,
                       float y)
Draws the specified string (as AttributedCharacterIterator) at the specified location.
Overrides:
drawString in interface Graphics2D
Parameters:
iterator - the string to draw
x - the x location, relative to the bounding rectangle of the text
y - the y location, relative to the bounding rectangle of the text

drawString

public void drawString(AttributedCharacterIterator iterator,
                       int x,
                       int y)
Draws the specified string (as AttributedCharacterIterator) at the specified location.
Overrides:
drawString in interface Graphics2D
Parameters:
iterator - the string to draw
x - the x location, relative to the bounding rectangle of the text
y - the y location, relative to the bounding rectangle of the text

fill

public void fill(Shape shape)
Fills the specified shape with the current foreground.
Overrides:
fill in interface Graphics2D
Parameters:
shape - the shape to fill

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int arcStart,
                    int arcAngle)
Fills an arc.
Overrides:
fillArc in interface Graphics

fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height)
Fills an oval.
Overrides:
fillOval in interface Graphics
Parameters:
x - the upper left corner of the bounding rectangle of the ellipse
y - the upper left corner of the bounding rectangle of the ellipse
width - the width of the ellipse
height - the height of the ellipse

fillPolygon

public void fillPolygon(int[] xPoints,
                        int[] yPoints,
                        int npoints)
Fills the outline of a polygon.

fillRect

public void fillRect(int x,
                     int y,
                     int width,
                     int height)
Fills a rectangle with the current paint.
Overrides:
fillRect in interface Graphics
Parameters:
x - the upper left corner, X coordinate
y - the upper left corner, Y coordinate
width - the width of the rectangle
height - the height of the rectangle

fillRoundRect

public void fillRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Fills a rounded rectangle.
Overrides:
fillRoundRect in interface Graphics
Parameters:
x - the x coordinate of the rectangle
y - the y coordinate of the rectangle
width - the width of the rectangle
height - the height of the rectangle
arcWidth - the width of the arcs
arcHeight - the height of the arcs

fillShape

protected void fillShape(Shape s,
                         boolean isFont)
Fills the specified shape. Override this if your backend can efficiently fill shapes. This is possible on many systems via a polygon fill method or something similar. But keep in mind that Shapes can be quite complex (non-convex, with holes etc), which is not necessarily supported by all polygon fillers. Also note that you must perform clipping before filling the shape.
Parameters:
s - the shape to fill
isFont - true if the shape is a font outline

getBackground

public Color getBackground()
Returns the current background.
Overrides:
getBackground in interface Graphics2D
Returns:
the current background

getClip

public Shape getClip()
Returns the current clip.
Overrides:
getClip in interface Graphics
Returns:
the current clip

getClipBounds

public Rectangle getClipBounds()
Returns the bounds of the current clip.
Overrides:
getClipBounds in interface Graphics
Returns:
the bounds of the current clip

getColor

public Color getColor()
Returns the current foreground.
Overrides:
getColor in interface Graphics

getColorModel

protected abstract ColorModel getColorModel()
Returns the color model of this Graphics object.
Returns:
the color model of this Graphics object

getComposite

public Composite getComposite()
Returns the current composite.
Overrides:
getComposite in interface Graphics2D
Returns:
the current composite

getDestinationRaster

protected WritableRaster getDestinationRaster()
Returns a WritableRaster that is used by this class to perform the rendering in. It is not necessary that the target surface immediately reflects changes in the raster. Updates to the raster are notified via updateRaster(Raster,int,int,int,int).
Returns:
the destination raster

getDeviceBounds

protected abstract Rectangle getDeviceBounds()
Returns the bounds of the target.
Returns:
the bounds of the target

getFont

public Font getFont()
Returns the current font.
Overrides:
getFont in interface Graphics
Returns:
the current font

getFontMetrics

public FontMetrics getFontMetrics(Font font)
Returns the font metrics for the specified font.
Overrides:
getFontMetrics in interface Graphics
Parameters:
font - the font for which to fetch the font metrics
Returns:
the font metrics for the specified font

getFontRenderContext

public FontRenderContext getFontRenderContext()
Returns the font render context.
Overrides:
getFontRenderContext in interface Graphics2D
Returns:
The font render context.

getPaint

public Paint getPaint()
Returns the current foreground.
Overrides:
getPaint in interface Graphics2D
Returns:
the current foreground

getRenderingHint

public Object getRenderingHint(RenderingHints.Key hintKey)
Returns the rendering hint for the specified key.
Overrides:
getRenderingHint in interface Graphics2D
Parameters:
hintKey - the rendering hint key
Returns:
the rendering hint for the specified key

getRenderingHints

public RenderingHints getRenderingHints()
Returns the current rendering hints.
Overrides:
getRenderingHints in interface Graphics2D
Returns:
the current rendering hints

getStroke

public Stroke getStroke()
Returns the current stroke.
Overrides:
getStroke in interface Graphics2D
Returns:
the current stroke

getTransform

public AffineTransform getTransform()
Returns the transformation of this coordinate system.
Overrides:
getTransform in interface Graphics2D
Returns:
the transformation of this coordinate system

hit

public boolean hit(Rectangle rect,
                   Shape text,
                   boolean onStroke)
Overrides:
hit in interface Graphics2D

init

protected void init()
Initializes this graphics object. This must be called by subclasses in order to correctly initialize the state of this object.

prepareImage

public static Image prepareImage(Image image,
                                 int w,
                                 int h)
Scales an image to the specified width and height. This should also be used to implement Toolkit.prepareImage(Image,int,int,ImageObserver). This uses Toolkit.createImage(ImageProducer) to create the actual image.
Parameters:
image - the image to prepare
w - the width
h - the height
Returns:
the scaled image

rawClearRect

protected void rawClearRect(int x,
                            int y,
                            int w,
                            int h)
Clears a rectangle in optimization mode. The implementation should respect the clip and translation. It can assume that the clip is a rectangle and that the transform is only a translating transform.
Parameters:
x - the upper left corner, X coordinate
y - the upper left corner, Y coordinate
w - the width
h - the height

rawCopyArea

protected void rawCopyArea(int x,
                           int y,
                           int w,
                           int h,
                           int dx,
                           int dy)
Copies a rectangular region to another location.
Parameters:
x - the upper left corner, X coordinate
y - the upper left corner, Y coordinate
w - the width
h - the height
dx -
dy -

rawDrawImage

protected boolean rawDrawImage(Image image,
                               int x,
                               int y,
                               ImageObserver obs)
Draws an image in optimization mode. The implementation should respect the clip but can assume that it is a rectangle.
Parameters:
image - the image to be painted
x - the location, X coordinate
y - the location, Y coordinate
obs - the image observer to be notified
Returns:
true when the image is painted completely, false if it is still rendered

rawDrawLine

protected void rawDrawLine(int x0,
                           int y0,
                           int x1,
                           int y1)
Draws a line in optimization mode. The implementation should respect the clip and translation. It can assume that the clip is a rectangle and that the transform is only a translating transform.
Parameters:
x0 - the starting point, X coordinate
y0 - the starting point, Y coordinate
x1 - the end point, X coordinate
y1 - the end point, Y coordinate

rawDrawRect

protected void rawDrawRect(int x,
                           int y,
                           int w,
                           int h)

rawFillRect

protected void rawFillRect(int x,
                           int y,
                           int w,
                           int h)
Fills a rectangle in optimization mode. The implementation should respect the clip but can assume that it is a rectangle.
Parameters:
x - the upper left corner, X coordinate
y - the upper left corner, Y coordinate
w - the width
h - the height

renderScanline

public void renderScanline(int y,
                           ScanlineCoverage c)
Paints a scanline between x0 and x1. Override this when your backend can efficiently draw/fill horizontal lines.
Specified by:
renderScanline in interface Pixelizer
Parameters:
y - the scanline

rotate

public void rotate(double theta)
Rotates the coordinate system by theta degrees.
Overrides:
rotate in interface Graphics2D
Parameters:
theta - the angle be which to rotate the coordinate system

rotate

public void rotate(double theta,
                   double x,
                   double y)
Rotates the coordinate system by theta around the point (x, y).
Overrides:
rotate in interface Graphics2D
Parameters:
theta - the angle by which to rotate the coordinate system
x - the point around which to rotate, X coordinate
y - the point around which to rotate, Y coordinate

scale

public void scale(double scaleX,
                  double scaleY)
Scales the coordinate system by the factors scaleX and scaleY.
Overrides:
scale in interface Graphics2D
Parameters:
scaleX - the factor by which to scale the X axis
scaleY - the factor by which to scale the Y axis

setBackground

public void setBackground(Color color)
Sets the current background.
Overrides:
setBackground in interface Graphics2D
Parameters:
color - the background to set.

setClip

public void setClip(int x,
                    int y,
                    int width,
                    int height)
Sets the clip to the specified rectangle.
Overrides:
setClip in interface Graphics
Parameters:
x - the x coordinate of the clip rectangle
y - the y coordinate of the clip rectangle
width - the width of the clip rectangle
height - the height of the clip rectangle

setClip

public void setClip(Shape c)
Sets the current clipping area to clip.
Overrides:
setClip in interface Graphics
Parameters:
c - the clip to set

setColor

public void setColor(Color color)
Sets the current foreground.
Overrides:
setColor in interface Graphics
Parameters:
color - the foreground to set

setComposite

public void setComposite(Composite comp)
Sets the composite.
Overrides:
setComposite in interface Graphics2D
Parameters:
comp - the composite to set

setFont

public void setFont(Font f)
Sets the font on this graphics object. When f == null, the current setting is not changed.
Overrides:
setFont in interface Graphics
Parameters:
f - the font to set

setPaint

public void setPaint(Paint p)
Sets the current foreground.
Overrides:
setPaint in interface Graphics2D
Parameters:
p - the foreground to set.

setPaintMode

public void setPaintMode()
Sets this context into "paint" mode, where the target pixels are completely overwritten when drawn on.
Overrides:
setPaintMode in interface Graphics

setRenderingHint

public void setRenderingHint(RenderingHints.Key hintKey,
                             Object hintValue)
Sets the specified rendering hint.
Overrides:
setRenderingHint in interface Graphics2D
Parameters:
hintKey - the key of the rendering hint
hintValue - the value

setRenderingHints

public void setRenderingHints(Map<K,V> hints)
Sets the specified rendering hints.
Parameters:
hints - the rendering hints to set

setStroke

public void setStroke(Stroke s)
Sets the stroke for this graphics object.
Overrides:
setStroke in interface Graphics2D
Parameters:
s - the stroke to set

setTransform

public void setTransform(AffineTransform t)
Sets the transformation for this Graphics object.
Overrides:
setTransform in interface Graphics2D
Parameters:
t - the transformation to set

setXORMode

public void setXORMode(Color color)
Sets this context info "XOR" mode, where the targe pixles are XOR-ed when drawn on.
Overrides:
setXORMode in interface Graphics
Parameters:
color - The color to XOR against.

shear

public void shear(double shearX,
                  double shearY)
Shears the coordinate system by shearX and shearY.
Overrides:
shear in interface Graphics2D
Parameters:
shearX - the X shearing
shearY - the Y shearing

transform

public void transform(AffineTransform t)
Transforms the coordinate system using the specified transform t.
Overrides:
transform in interface Graphics2D
Parameters:
t - the transform

translate

public void translate(double tx,
                      double ty)
Translates the coordinate system by (tx, ty).
Overrides:
translate in interface Graphics2D
Parameters:
tx - the translation X coordinate
ty - the translation Y coordinate

translate

public void translate(int x,
                      int y)
Translates the coordinate system by (x, y).
Overrides:
translate in interface Graphics2D
Parameters:
x - the translation X coordinate
y - the translation Y coordinate

updateRaster

protected void updateRaster(Raster raster,
                            int x,
                            int y,
                            int w,
                            int h)
Notifies the backend that the raster has changed in the specified rectangular area. The raster that is provided in this method is always the same as the one returned in getDestinationRaster(). Backends that reflect changes to this raster directly don't need to do anything here.
Parameters:
raster - the updated raster, identical to the raster returned by getDestinationRaster()
x - the upper left corner of the updated region, X coordinate
y - the upper lef corner of the updated region, Y coordinate
w - the width of the updated region
h - the height of the updated region

AbstractGraphics2D.java -- Abstract Graphics2D implementation Copyright (C) 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.