Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.awt.Graphics
java.awt.Graphics2D
gnu.java.awt.java2d.AbstractGraphics2D
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.
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.Field Summary | |
protected static WeakHashMap |
|
protected static WeakHashMap |
|
protected static WeakHashMap |
|
protected static WeakHashMap |
|
protected AffineTransform |
|
Constructor Summary | |
|
Method Summary | |
void |
|
void |
|
void | |
void |
|
protected Object |
|
void |
|
Graphics |
|
void |
|
void | |
void |
|
void |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void | |
void |
|
void |
|
void |
|
void |
|
void |
|
protected void | |
Color |
|
Shape |
|
Rectangle |
|
Color |
|
protected abstract ColorModel |
|
Composite |
|
protected WritableRaster |
|
protected abstract Rectangle |
|
Font |
|
FontMetrics |
|
FontRenderContext |
|
Paint |
|
Object |
|
RenderingHints |
|
Stroke |
|
AffineTransform |
|
boolean | |
protected void |
|
static Image |
|
protected void |
|
protected void |
|
protected boolean |
|
protected void |
|
protected void |
|
protected void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void | |
void | |
void |
|
void | |
void | |
void |
|
void |
|
void |
|
void | |
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
protected void |
|
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 |
protected static final WeakHashMapHashMap
Caches scaled versions of an image.
protected static final WeakHashMapHashMap
Caches scaled versions of an image.
protected static final WeakHashMapImage>>()
Caches scaled versions of an image.
protected static final WeakHashMapImage>>imageCache
Caches scaled versions of an image.
public void addRenderingHints(Map<K,V> hints)
Adds the specified rendering hints.
- Parameters:
hints
- the rendering hints to add
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 tofillRect(int,int,int,int)
.
- Parameters:
x
- the upper left corner, X coordinatey
- the upper left corner, Y coordinatewidth
- the width of the rectangleheight
- the height of the rectangle
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
public void clipRect(int x, int y, int width, int height)
Intersects the current clipping region with the specified rectangle.
- Parameters:
x
- the x coordinate of the rectangley
- the y coordinate of the rectanglewidth
- the width of the rectangleheight
- the height of the rectangle
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 bycreate()
.
- Returns:
- a copy of this Graphics object
public void copyArea(int x, int y, int width, int height, int dx, int dy)
Copies the specified rectangle to the specified offset location.
- 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.
public Graphics create()
Creates a copy of this graphics object.
- Returns:
- a copy of this graphics object
public void draw(Shape shape)
Draws the specified shape. The shape is passed through the current stroke and is then forwarded tofillShape(Shape,boolean)
.
- Overrides:
- draw in interface Graphics2D
- Parameters:
shape
- the shape to draw
public void drawArc(int x, int y, int width, int height, int arcStart, int arcAngle)
Draws an arc.
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 drawx
- the location, x coordinatey
- the location, y coordinate
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.
- Parameters:
image
- the image to renderdx1
- the first corner of the destination rectangledy1
- the first corner of the destination rectangledx2
- the second corner of the destination rectangledy2
- the second corner of the destination rectanglesx1
- the first corner of the source rectanglesy1
- the first corner of the source rectanglesx2
- the second corner of the source rectanglesy2
- the second corner of the source rectanglebgcolor
- the background color to use for transparent pixelsobserver
- the image observer to be notified
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.
- Parameters:
image
- the image to renderdx1
- the first corner of the destination rectangledy1
- the first corner of the destination rectangledx2
- the second corner of the destination rectangledy2
- the second corner of the destination rectanglesx1
- the first corner of the source rectanglesy1
- the first corner of the source rectanglesx2
- the second corner of the source rectanglesy2
- the second corner of the source rectangleobserver
- the image observer to be notified
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 todrawImage(Image,AffineTransform,ImageObserver)
.
- Parameters:
image
- the image to renderx
- the x location to render toy
- the y location to render towidth
- the target width of the imageheight
- the target height of the imagebgcolor
- the background color to use for transparent pixelsobserver
- the image observer to receive notification
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 todrawImage(Image,AffineTransform,ImageObserver)
.
- Parameters:
image
- the image to renderx
- the x location to render toy
- the y location to render towidth
- the target width of the imageheight
- the target height of the imageobserver
- the image observer to receive notification
public boolean drawImage(Image image, int x, int y, Color bgcolor, ImageObserver observer)
Draws the specified image at the specified location. This forwards todrawImage(Image,AffineTransform,ImageObserver)
.
- Parameters:
image
- the image to renderx
- the x location to render toy
- the y location to render tobgcolor
- the background color to use for transparent pixelsobserver
- the image observer to receive notification
public boolean drawImage(Image image, int x, int y, ImageObserver observer)
Draws the specified image at the specified location. This forwards todrawImage(Image,AffineTransform,ImageObserver)
.
- Parameters:
image
- the image to renderx
- the x location to render toy
- the y location to render toobserver
- the image observer to receive notification
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 todrawRenderableImage(RenderableImage,AffineTransform)
anddrawRenderedImage(RenderedImage,AffineTransform)
accordingly. Other image types are not yet handled.
- Overrides:
- drawImage in interface Graphics2D
- Parameters:
image
- the image to be renderedxform
- the transform from image space to user spaceobs
- the image observer to be notified
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 todrawRenderedImage(RenderedImage,AffineTransform)
to perform the final rendering.
- Overrides:
- drawImage in interface Graphics2D
- Parameters:
image
- the source buffered imageop
- the filter to apply to the buffered image before renderingx
- the x coordinate to render the image toy
- the y coordinate to render the image to
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 torawDrawLine(int,int,int,int)
.
public void drawOval(int x, int y, int width, int height)
Draws the outline of an oval.
- Parameters:
x
- the upper left corner of the bounding rectangle of the ellipsey
- the upper left corner of the bounding rectangle of the ellipsewidth
- the width of the ellipseheight
- the height of the ellipse
public void drawPolygon(int[] xPoints, int[] yPoints, int npoints)
Draws the outline of a polygon.
public void drawRect(int x, int y, int w, int h)
Draws the outline of the specified rectangle.
- 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.
public void drawRenderableImage(RenderableImage image, AffineTransform xform)
Renders a renderable image. This produces a RenderedImage, which is then passed todrawRenderedImage(RenderedImage,AffineTransform)
to perform the final rendering.
- Overrides:
- drawRenderableImage in interface Graphics2D
- Parameters:
image
- the renderable image to be renderedxform
- the transform from image space to user space
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 rasterxform
- the transform from image space to user space
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 rectangley
- the y coordinate of the rectanglewidth
- the width of the rectangleheight
- the height of the rectanglearcWidth
- the width of the arcsarcHeight
- the height of the arcs
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 drawx
- the x location, relative to the bounding rectangle of the texty
- the y location, relative to the bounding rectangle of the text
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 drawx
- the x location, relative to the bounding rectangle of the texty
- the y location, relative to the bounding rectangle of the text
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 drawx
- the x location, relative to the bounding rectangle of the texty
- the y location, relative to the bounding rectangle of the text
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 drawx
- the x location, relative to the bounding rectangle of the texty
- the y location, relative to the bounding rectangle of the text
public void fill(Shape shape)
Fills the specified shape with the current foreground.
- Overrides:
- fill in interface Graphics2D
- Parameters:
shape
- the shape to fill
public void fillArc(int x, int y, int width, int height, int arcStart, int arcAngle)
Fills an arc.
public void fillOval(int x, int y, int width, int height)
Fills an oval.
- Parameters:
x
- the upper left corner of the bounding rectangle of the ellipsey
- the upper left corner of the bounding rectangle of the ellipsewidth
- the width of the ellipseheight
- the height of the ellipse
public void fillPolygon(int[] xPoints, int[] yPoints, int npoints)
Fills the outline of a polygon.
public void fillRect(int x, int y, int width, int height)
Fills a rectangle with the current paint.
- Parameters:
x
- the upper left corner, X coordinatey
- the upper left corner, Y coordinatewidth
- the width of the rectangleheight
- the height of the rectangle
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 rectangley
- the y coordinate of the rectanglewidth
- the width of the rectangleheight
- the height of the rectanglearcWidth
- the width of the arcsarcHeight
- the height of the arcs
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 fillisFont
-true
if the shape is a font outline
public Color getBackground()
Returns the current background.
- Overrides:
- getBackground in interface Graphics2D
- Returns:
- the current background
public Rectangle getClipBounds()
Returns the bounds of the current clip.
- Overrides:
- getClipBounds in interface Graphics
- Returns:
- the bounds of the current clip
protected abstract ColorModel getColorModel()
Returns the color model of this Graphics object.
- Returns:
- the color model of this Graphics object
public Composite getComposite()
Returns the current composite.
- Overrides:
- getComposite in interface Graphics2D
- Returns:
- the current composite
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 viaupdateRaster(Raster,int,int,int,int)
.
- Returns:
- the destination raster
protected abstract Rectangle getDeviceBounds()
Returns the bounds of the target.
- Returns:
- the bounds of the target
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
public FontRenderContext getFontRenderContext()
Returns the font render context.
- Overrides:
- getFontRenderContext in interface Graphics2D
- Returns:
- The font render context.
public Paint getPaint()
Returns the current foreground.
- Overrides:
- getPaint in interface Graphics2D
- Returns:
- the current foreground
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
public RenderingHints getRenderingHints()
Returns the current rendering hints.
- Overrides:
- getRenderingHints in interface Graphics2D
- Returns:
- the current rendering hints
public Stroke getStroke()
Returns the current stroke.
- Overrides:
- getStroke in interface Graphics2D
- Returns:
- the current stroke
public AffineTransform getTransform()
Returns the transformation of this coordinate system.
- Overrides:
- getTransform in interface Graphics2D
- Returns:
- the transformation of this coordinate system
public boolean hit(Rectangle rect, Shape text, boolean onStroke)
- Overrides:
- hit in interface Graphics2D
protected void init()
Initializes this graphics object. This must be called by subclasses in order to correctly initialize the state of this object.
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 implementToolkit.prepareImage(Image,int,int,ImageObserver)
. This usesToolkit.createImage(ImageProducer)
to create the actual image.
- Parameters:
image
- the image to preparew
- the widthh
- the height
- Returns:
- the scaled image
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 coordinatey
- the upper left corner, Y coordinatew
- the widthh
- the height
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 coordinatey
- the upper left corner, Y coordinatew
- the widthh
- the heightdx
-dy
-
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 paintedx
- the location, X coordinatey
- the location, Y coordinateobs
- the image observer to be notified
- Returns:
true
when the image is painted completely,false
if it is still rendered
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 coordinatey0
- the starting point, Y coordinatex1
- the end point, X coordinatey1
- the end point, Y coordinate
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 coordinatey
- the upper left corner, Y coordinatew
- the widthh
- the height
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
public void rotate(double theta)
Rotates the coordinate system bytheta
degrees.
- Overrides:
- rotate in interface Graphics2D
- Parameters:
theta
- the angle be which to rotate the coordinate system
public void rotate(double theta, double x, double y)
Rotates the coordinate system bytheta
around the point (x, y).
- Overrides:
- rotate in interface Graphics2D
- Parameters:
theta
- the angle by which to rotate the coordinate systemx
- the point around which to rotate, X coordinatey
- the point around which to rotate, Y coordinate
public void scale(double scaleX, double scaleY)
Scales the coordinate system by the factorsscaleX
andscaleY
.
- Overrides:
- scale in interface Graphics2D
- Parameters:
scaleX
- the factor by which to scale the X axisscaleY
- the factor by which to scale the Y axis
public void setBackground(Color color)
Sets the current background.
- Overrides:
- setBackground in interface Graphics2D
- Parameters:
color
- the background to set.
public void setClip(int x, int y, int width, int height)
Sets the clip to the specified rectangle.
- Parameters:
x
- the x coordinate of the clip rectangley
- the y coordinate of the clip rectanglewidth
- the width of the clip rectangleheight
- the height of the clip rectangle
public void setClip(Shape c)
Sets the current clipping area toclip
.
- Parameters:
c
- the clip to set
public void setColor(Color color)
Sets the current foreground.
- Parameters:
color
- the foreground to set
public void setComposite(Composite comp)
Sets the composite.
- Overrides:
- setComposite in interface Graphics2D
- Parameters:
comp
- the composite to set
public void setFont(Font f)
Sets the font on this graphics object. Whenf == null
, the current setting is not changed.
- Parameters:
f
- the font to set
public void setPaint(Paint p)
Sets the current foreground.
- Overrides:
- setPaint in interface Graphics2D
- Parameters:
p
- the foreground to set.
public void setPaintMode()
Sets this context into "paint" mode, where the target pixels are completely overwritten when drawn on.
- Overrides:
- setPaintMode in interface Graphics
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 hinthintValue
- the value
public void setRenderingHints(Map<K,V> hints)
Sets the specified rendering hints.
- Parameters:
hints
- the rendering hints to set
public void setStroke(Stroke s)
Sets the stroke for this graphics object.
- Overrides:
- setStroke in interface Graphics2D
- Parameters:
s
- the stroke to set
public void setTransform(AffineTransform t)
Sets the transformation for this Graphics object.
- Overrides:
- setTransform in interface Graphics2D
- Parameters:
t
- the transformation to set
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.
public void shear(double shearX, double shearY)
Shears the coordinate system byshearX
andshearY
.
- Overrides:
- shear in interface Graphics2D
- Parameters:
shearX
- the X shearingshearY
- the Y shearing
public void transform(AffineTransform t)
Transforms the coordinate system using the specified transformt
.
- Overrides:
- transform in interface Graphics2D
- Parameters:
t
- the transform
public void translate(double tx, double ty)
Translates the coordinate system by (tx, ty).
- Overrides:
- translate in interface Graphics2D
- Parameters:
tx
- the translation X coordinatety
- the translation Y coordinate
public void translate(int x, int y)
Translates the coordinate system by (x, y).
- Overrides:
- translate in interface Graphics2D
- Parameters:
x
- the translation X coordinatey
- the translation Y coordinate
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 ingetDestinationRaster()
. 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 bygetDestinationRaster()
x
- the upper left corner of the updated region, X coordinatey
- the upper lef corner of the updated region, Y coordinatew
- the width of the updated regionh
- the height of the updated region