|
Java Platform 1.2 Beta 4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Graphics | +--java.awt.Graphics2D
Coordinates in device space usually refer to individual device pixels and are aligned in the infinitely thin gaps between these pixels. Some Graphics2D objects may be used to capture rendering operations for storage into a graphics metafile for playback on a concrete device of unknown physical resolution at a later time. Since the resolution may not be known when the rendering operations are captured, the Transform will be set up to transform user coordinates to a virtual device space that typically approximates the expected resolution of the target device, though further transformation may need to be applied at playback time if the estimate is incorrect.
Some of the operations performed by the rendering attribute objects may operate in the device space, but all methods that are defined on the Graphics2D object work with user space coordinates.
The default transform when a Graphics2D object is created will be specified by the GraphicsConfiguration for the target of the Graphics2D (a Component or Image). This default transform will map the user space coordinate system to screen and printer device coordinates such that the origin maps to the upper left hand corner of the target region of the device with increasing X coordinates extending to the right and increasing Y coordinates extending downward. The scaling of the default transform for screen devices will be set to identity for screen devices. The scaling of the default transform for printers and other high resolution devices will be set to approximate 72 user space coordinates per device inch. For image buffers, the default transform will be the Identity transform.
As a behavioral reference, the steps can be described in the following way:
Stroke.createStrokedShape(java.awt.Shape)
method on the current Stroke
.
AffineTransform
.
PathIterator
using the
Shape.getPathIterator(java.awt.geom.AffineTransform)
method.
Font
is asked to convert the
Unicode characters in the String into a a set of glyphs for presentation
with whatever basic layout and shaping algorithms the font implements.
GlyphVector
, then the GlyphVector
object already contains the appropriate font-specific glyph codes
with explicit coordinates for the position of each glyph.
Graphics2D#rendershape
drawImage(java.awt.Image, java.awt.geom.AffineTransform, java.awt.image.ImageObserver)
method call, then this transform is used to transform the bounding
box from image space to user space, otherwise the bounding box is
treated as if it already was in user space.
Paint
or
Color
object is queried for a
PaintContext
which specifies
what colors are to be rendered in device space.
Composite
object.
GraphicsConfiguration.getDefaultTransform()
for the
GraphicsConfiguration of the Component.
The behavior of these operations given the model presented here is unclear if the current Stroke specifies a wide pen, or if there is a non-identity Transform being applied.
That rendering model was consistent with the capabilities of most of the existing class of platform renderers that needed to resolve integer coordinates to a discrete pen that must fall completely on a given number of pixels. Since the Java 2D API is capable of driving an antialiasing renderer it no longer makes sense to choose a bias direction for a wide pen since sub-pixel positioning of the pen can be made visible to the user via the blending that occurs along the edges of the traversal of the pen. It is thus, no longer true that a 1-pixel wide pen must choose to fall on pixel N as opposed to pixel N+1; it can now fall partially on both pixels.
When antialiasing is turned off with the ANTIALIAS_OFF hint, the underlying renderer may still need to apply a bias in order to resolve the conflict of which pixel to modify when the pen is exactly straddling a pixel boundary (such as when it is drawn along an integer coordinate in device space). But when antialiasing is enabled, no biasing of the pen needs to occur and so no bias should be explicitly specified by the rendering model.
Thus, there remains the problem of how to define the operation of the legacy rendering operations inherited from the Graphics class to be compatible with existing rendering behavior and to be predictable and unsurprising under all possible settings of the latest rendering attributes.
To provide predictability we will define operations for all of the legacy methods that map onto the more general draw(Shape) and fill(Shape) methods. Such a specification will thus be clear how it extends based on various settings of Stroke and Transform attributes, and rendering hints.
To provide compatibility with previous rendering behavior it is
important to specify a definition that performs identically under
the default attribute settings. In particular, the default Stroke
is a BasicStroke
with a width of 1 and no dashing, and the default
Transform for screen drawing is an Identity transform. Unfortunately,
the default antialiasing rendering hint is ANTIALIAS_DEFAULT which
may be enabled on some implementations and not on others. This
means that the definition of these operations needs to be invariant
under antialiasing.
We now define the following generalizations of the various legacy methods which can be shown to be identical to the previously specified behavior under the default attributes:
fill(gp);
AffineTransform at = new AffineTransform(1f,0f,0f,1f,0.5f,0.5f); draw(at.createTransformedShape(bp));
The existing Graphics class defined two methods for controlling how colors were applied to the destination. The setPaintMode() method will now be implemented as a convenience method to set the default Composite, equivalent to setComposite(new AlphaComposite(SRC_OVER)). The setXORMode(Color xorcolor) method will now be implemented as a convenience method to set a special Composite object which ignores the Alpha components of source colors and sets the destination color to the value:
dstpixel = (PixelOf(srccolor) ^ PixelOf(xorcolor) ^ dstpixel);
Constructor Summary | |
Graphics2D()
Constructs a new Graphics2D object. |
Method Summary | |
abstract void | clip(Shape s)
Intersects the current clip with the interior of the specified Shape and sets the current clip to the resulting intersection. |
abstract void | draw(Shape s)
Strokes the outline of a Shape using the settings of the current graphics state. |
abstract void | drawGlyphVector(GlyphVector g,
float x,
float y)
Draws the text specified by the given GlyphVector using this graphics context's rendering attributes. |
abstract void | drawImage(BufferedImage img,
BufferedImageOp op,
int x,
int y)
Draws a BufferedImage that is filtered with a BufferedImageOp. |
abstract boolean | drawImage(Image img,
AffineTransform xform,
ImageObserver obs)
Draws an image, applying a transform from image space into user space before drawing. |
abstract void | drawRenderableImage(RenderableImage img,
AffineTransform xform)
Draws an RenderableImage, applying a transform from image space into user space before drawing. |
abstract void | drawRenderedImage(RenderedImage img,
AffineTransform xform)
Draws an RenderedImage, applying a transform from image space into user space before drawing. |
abstract void | drawString(AttributedCharacterIterator iterator,
float x,
float y)
Draws the text given by the specified iterator, using this graphics context's current color. |
abstract void | drawString(AttributedCharacterIterator iterator,
int x,
int y)
Draws the text given by the specified iterator, using this graphics context's current color. |
abstract void | drawString(String s,
float x,
float y)
Draws the text given by the specified string, using this graphics context's current font and color. |
abstract void | drawString(String str,
int x,
int y)
Draws the text given by the specified string, using this graphics context's current font and color. |
abstract void | fill(Shape s)
Fills the interior of a Shape using the settings of the current graphics state. |
abstract Color | getBackground()
Returns the background color used for clearing a region. |
abstract Composite | getComposite()
Returns the current Composite in the Graphics2D state. |
abstract GraphicsConfiguration | getDeviceConfiguration()
Returns the device configuration associated with this Graphics2D. |
abstract FontRenderContext | getFontRenderContext()
Get the rendering context of the font within this Graphics2D context. |
abstract Paint | getPaint()
Returns the current Paint in the Graphics2D state. |
abstract Object | getRenderingHint(String hintKey)
Returns the preferences for the rendering algorithms. |
abstract RenderingHints | getRenderingHints()
Gets the preferences for the rendering algorithms. |
abstract Stroke | getStroke()
Returns the current Stroke in the Graphics2D state. |
abstract AffineTransform | getTransform()
Returns the current transform in the Graphics2D state. |
abstract boolean | hit(Rectangle rect,
Shape s,
boolean onStroke)
Checks to see if the outline of a Shape intersects the specified Rectangle in device space. |
abstract void | rotate(double theta,
double x,
double y)
Concatenates the current transform of this Graphics2D with a translated rotation transformation. |
abstract void | rotate(double theta)
Concatenates the current transform of this Graphics2D with a rotation transformation. |
abstract void | scale(double sx,
double sy)
Concatenates the current transform of this Graphics2D with a scaling transformation. |
abstract void | setBackground(Color color)
Sets the background color in this context used for clearing a region. |
abstract void | setComposite(Composite comp)
Sets the Composite in the current graphics state. |
abstract void | setPaint(Paint paint)
Sets the Paint in the current graphics state. |
abstract void | setRenderingHint(String hintKey,
Object hintValue)
Sets the preferences for the rendering algorithms. |
abstract void | setRenderingHints(RenderingHints hints)
Sets the preferences for the rendering algorithms. |
abstract void | setStroke(Stroke s)
Sets the Stroke in the current graphics state. |
abstract void | setTransform(AffineTransform Tx)
Sets the transform in the current graphics state. |
abstract void | shear(double shx,
double shy)
Concatenates the current transform of this Graphics2D with a shearing transformation. |
abstract void | transform(AffineTransform Tx)
Composes an AffineTransform object with the transform in this Graphics2D according to the rule last-specified-first-applied. |
abstract void | translate(double tx,
double ty)
Concatenates the current transform of this Graphics2D with a translation transformation. |
abstract void | translate(int x,
int y)
Translates the origin of the graphics context to the point (x, y) in the current coordinate system. |
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 , fill3DRect , fillArc , fillOval , fillPolygon , fillPolygon , fillRect , fillRoundRect , finalize , getClip , getClipBounds , getClipBounds , getClipRect , getColor , getFont , getFontMetrics , getFontMetrics , hitClip , setClip , setClip , setColor , setFont , setPaintMode , setXORMode , toString |
Methods inherited from class java.lang.Object | |
clone , equals , getClass , hashCode , notify , notifyAll , wait , wait , wait |
Constructor Detail |
protected Graphics2D()
Component.getGraphics()
,
Graphics.create()
Method Detail |
public abstract void draw(Shape s)
s
- The shape to be drawn.setStroke(java.awt.Stroke)
,
setPaint(java.awt.Paint)
,
Graphics.setColor(java.awt.Color)
,
transform(java.awt.geom.AffineTransform)
,
setTransform(java.awt.geom.AffineTransform)
,
clip(java.awt.Shape)
,
Graphics.setClip(int, int, int, int)
,
setComposite(java.awt.Composite)
public abstract boolean drawImage(Image img, AffineTransform xform, ImageObserver obs)
img
- The image to be drawn.
xform
- The transformation from image space into user space.
obs
- The image observer to be notified as more of the image
is converted.transform(java.awt.geom.AffineTransform)
,
setTransform(java.awt.geom.AffineTransform)
,
setComposite(java.awt.Composite)
,
clip(java.awt.Shape)
,
Graphics.setClip(int, int, int, int)
public abstract void drawImage(BufferedImage img, BufferedImageOp op, int x, int y)
img1 = op.filter(img, null); drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);
op
- The filter to be applied to the image before drawing.
img
- The BufferedImage to be drawn.
x,y
- The location in user space where the image should be drawn.transform(java.awt.geom.AffineTransform)
,
setTransform(java.awt.geom.AffineTransform)
,
setComposite(java.awt.Composite)
,
clip(java.awt.Shape)
,
Graphics.setClip(int, int, int, int)
public abstract void drawRenderedImage(RenderedImage img, AffineTransform xform)
img
- The image to be drawn.
xform
- The transformation from image space into user space.transform(java.awt.geom.AffineTransform)
,
setTransform(java.awt.geom.AffineTransform)
,
setComposite(java.awt.Composite)
,
clip(java.awt.Shape)
,
Graphics.setClip(int, int, int, int)
public abstract void drawRenderableImage(RenderableImage img, AffineTransform xform)
Any rendering hints set on the this Graphics2D object may be used in drawing the RenderableImage. If explicit control is required over specific hints recognized by a specific RenderableImage or if knowledge of which hints are used is required, then a RenderedImage should be obtained directly from the RenderableImage and then drawn using drawRenderedImage.
img
- The image to be drawn.
xform
- The transformation from image space into user space.transform(java.awt.geom.AffineTransform)
,
setTransform(java.awt.geom.AffineTransform)
,
setComposite(java.awt.Composite)
,
clip(java.awt.Shape)
,
Graphics.setClip(int, int, int, int)
,
drawRenderedImage(java.awt.image.RenderedImage, java.awt.geom.AffineTransform)
public abstract void drawString(String str, int x, int y)
str
- the string to be drawn.
x
- the x coordinate.
y
- the y coordinate.Graphics.drawBytes(byte[], int, int, int, int)
,
Graphics.drawChars(char[], int, int, int, int)
public abstract void drawString(String s, float x, float y)
s
- The string to be drawn.
x,y
- The coordinates where the string should be drawn.setPaint(java.awt.Paint)
,
Graphics.setColor(java.awt.Color)
,
Graphics.setFont(java.awt.Font)
,
setTransform(java.awt.geom.AffineTransform)
,
setComposite(java.awt.Composite)
,
Graphics.setClip(int, int, int, int)
public abstract void drawString(AttributedCharacterIterator iterator, int x, int y)
iterator
- the iterator whose text is to be drawn
x,y
- the coordinates where the iterator's text should be drawn.setPaint(java.awt.Paint)
,
Graphics.setColor(java.awt.Color)
,
setTransform(java.awt.geom.AffineTransform)
,
setComposite(java.awt.Composite)
,
Graphics.setClip(int, int, int, int)
public abstract void drawString(AttributedCharacterIterator iterator, float x, float y)
iterator
- the iterator whose text is to be drawn
x,y
- the coordinates where the iterator's text should be drawn.setPaint(java.awt.Paint)
,
Graphics.setColor(java.awt.Color)
,
setTransform(java.awt.geom.AffineTransform)
,
setComposite(java.awt.Composite)
,
Graphics.setClip(int, int, int, int)
public abstract void drawGlyphVector(GlyphVector g, float x, float y)
g
- The GlyphVector to be drawn.
x,y
- The coordinates where the glyphs should be drawn.Font.createGlyphVector(java.awt.font.FontRenderContext, java.lang.String)
,
GlyphVector
,
setPaint(java.awt.Paint)
,
Graphics.setColor(java.awt.Color)
,
setTransform(java.awt.geom.AffineTransform)
,
setComposite(java.awt.Composite)
,
Graphics.setClip(int, int, int, int)
public abstract void fill(Shape s)
setPaint(java.awt.Paint)
,
Graphics.setColor(java.awt.Color)
,
transform(java.awt.geom.AffineTransform)
,
setTransform(java.awt.geom.AffineTransform)
,
setComposite(java.awt.Composite)
,
clip(java.awt.Shape)
,
Graphics.setClip(int, int, int, int)
public abstract boolean hit(Rectangle rect, Shape s, boolean onStroke)
rect
- The area in device space to check for a hit.
s
- The shape to check for a hit.
onStroke
- Flag to choose between testing the stroked or
the filled shape.setStroke(java.awt.Stroke)
,
fill(java.awt.Shape)
,
draw(java.awt.Shape)
,
transform(java.awt.geom.AffineTransform)
,
setTransform(java.awt.geom.AffineTransform)
,
clip(java.awt.Shape)
,
Graphics.setClip(int, int, int, int)
public abstract GraphicsConfiguration getDeviceConfiguration()
public abstract void setComposite(Composite comp)
comp
- The Composite object to be used for drawing.Graphics.setXORMode(java.awt.Color)
,
Graphics.setPaintMode()
,
AlphaComposite
public abstract void setPaint(Paint paint)
paint
- The Paint object to be used to generate color in
the rendering process.Graphics.setColor(java.awt.Color)
,
GradientPaint
,
TexturePaint
public abstract void setStroke(Stroke s)
s
- The Stroke object to be used to stroke a Shape in
the rendering process.BasicStroke
public abstract void setRenderingHint(String hintKey, Object hintValue)
hintKey
- The key of hint to be set. The strings are
defined in the RenderingHints class.
hintValue
- The value indicating preferences for the specified
hint category. These objects are defined in the RenderingHints
class.RenderingHints
public abstract Object getRenderingHint(String hintKey)
hintCategory
- The category of hint to be set. The strings
are defined in the RenderingHints class.RenderingHints
public abstract void setRenderingHints(RenderingHints hints)
hints
- The rendering hints to be setRenderingHints
public abstract RenderingHints getRenderingHints()
RenderingHints
public abstract void translate(int x, int y)
x
- the x coordinate.
y
- the y coordinate.public abstract void translate(double tx, double ty)
[ 1 0 tx ] [ 0 1 ty ] [ 0 0 1 ]
public abstract void rotate(double theta)
[ cos(theta) -sin(theta) 0 ] [ sin(theta) cos(theta) 0 ] [ 0 0 1 ]Rotating with a positive angle theta rotates points on the positive x axis toward the positive y axis.
theta
- The angle of rotation in radians.public abstract void rotate(double theta, double x, double y)
translate(x, y); rotate(theta); translate(-x, -y);Rotating with a positive angle theta rotates points on the positive x axis toward the positive y axis.
theta
- The angle of rotation in radians.
x
- The x coordinate of the origin of the rotation
y
- The x coordinate of the origin of the rotationpublic abstract void scale(double sx, double sy)
[ sx 0 0 ] [ 0 sy 0 ] [ 0 0 1 ]
public abstract void shear(double shx, double shy)
[ 1 shx 0 ] [ shy 1 0 ] [ 0 0 1 ]
shx
- The factor by which coordinates are shifted towards the
positive X axis direction according to their Y coordinate
shy
- The factor by which coordinates are shifted towards the
positive Y axis direction according to their X coordinatepublic abstract void transform(AffineTransform Tx)
Tx
- The AffineTransform object to be composed with the current
transform.setTransform(java.awt.geom.AffineTransform)
,
TransformChain
,
AffineTransform
public abstract void setTransform(AffineTransform Tx)
Tx
- The AffineTransform object to be used in the
rendering process.transform(java.awt.geom.AffineTransform)
,
TransformChain
,
AffineTransform
public abstract AffineTransform getTransform()
transform(java.awt.geom.AffineTransform)
,
setTransform(java.awt.geom.AffineTransform)
public abstract Paint getPaint()
setPaint(java.awt.Paint)
,
Graphics.setColor(java.awt.Color)
public abstract Composite getComposite()
setComposite(java.awt.Composite)
public abstract void setBackground(Color color)
color
- The background color that should be used in
subsequent calls to clearRect().getBackground
,
Graphics.clearRect()
public abstract Color getBackground()
setBackground
public abstract Stroke getStroke()
setStroke
public abstract void clip(Shape s)
s
- The Shape to be intersected with the current clip.public abstract FontRenderContext getFontRenderContext()
FontRenderContext
,
Font.createGlyphVector(java.awt.font.FontRenderContext, java.lang.String)
,
TextLayout
|
Java Platform 1.2 Beta 4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |