org.jfree.pixie.wmf

Class WmfGraphics2D


public class WmfGraphics2D
extends AbstractGraphics2D

Date: Mar 9, 2003 Time: 3:03:51 PM $Id: WmfGraphics2D.java,v 1.5 2004/11/21 16:29:31 taqua Exp $

Method Summary

void
addRenderingHints(Map hints)
Sets the values of an arbitrary number of preferences for the rendering algorithms.
void
clip(Shape s)
Intersects the current Clip with the interior of the specified Shape and sets the Clip to the resulting intersection.
void
copyArea(int x, int y, int width, int height, int dx, int dy)
Copies an area of the component by a distance specified by dx and dy.
Graphics
create()
Creates a new Graphics object that is a copy of this Graphics object.
void
dispose()
Disposes of this graphics context and releases any system resources that it is using.
void
draw(Shape s)
Strokes the outline of a Shape using the settings of the current Graphics2D context.
boolean
drawImage(Image img, AffineTransform xform, ImageObserver obs)
Renders an image, applying a transform from image space into user space before drawing.
void
drawRenderedImage(RenderedImage img, AffineTransform xform)
Renders a RenderedImage, applying a transform from image space into user space before drawing.
void
drawString(String s, float x, float y)
Renders the text specified by the specified String, using the current Font and Paint attributes in the Graphics2D context.
void
fill(Shape s)
Fills the interior of a Shape using the settings of the Graphics2D context.
Color
getBackground()
Returns the background color used for clearing a region.
Shape
getClip()
Gets the current clipping area.
Composite
getComposite()
Returns the current Composite in the Graphics2D context.
GraphicsConfiguration
getDeviceConfiguration()
Returns the device configuration associated with this Graphics2D.
Font
getFont()
Gets the current font.
FontMetrics
getFontMetrics(Font f)
Gets the font metrics for the specified font.
FontRenderContext
getFontRenderContext()
Get the rendering context of the Font within this Graphics2D context.
Paint
getPaint()
Returns the current Paint of the Graphics2D context.
Object
getRenderingHint(RenderingHints.Key hintKey)
Returns the value of a single preference for the rendering algorithms.
RenderingHints
getRenderingHints()
Gets the preferences for the rendering algorithms.
Stroke
getStroke()
Returns the current Stroke in the Graphics2D context.
AffineTransform
getTransform()
Returns a copy of the current Transform in the Graphics2D context.
void
setBackground(Color color)
Sets the background color for the Graphics2D context.
void
setClip(Shape clip)
Sets the current clipping area to an arbitrary clip shape.
void
setComposite(Composite comp)
Sets the Composite for the Graphics2D context.
void
setFont(Font font)
Sets this graphics context's font to the specified font.
void
setPaint(Paint paint)
Sets the Paint attribute for the Graphics2D context.
void
setPaintMode()
Sets the paint mode of this graphics context to overwrite the destination with this graphics context's current color.
void
setRenderingHint(RenderingHints.Key hintKey, Object hintValue)
Sets the value of a single preference for the rendering algorithms.
void
setRenderingHints(Map hints)
Replaces the values of all preferences for the rendering algorithms with the specified hints.
void
setStroke(Stroke s)
Sets the Stroke for the Graphics2D context.
void
setTransform(AffineTransform Tx)
Sets the Transform in the Graphics2D context.
void
setXORMode(Color c1)
Sets the paint mode of this graphics context to alternate between this graphics context's current color and the new specified color.

Methods inherited from class org.jfree.pixie.AbstractGraphics2D

clearRect, clipRect, drawArc, drawGlyphVector, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawLine, drawOval, drawPolygon, drawPolyline, drawRenderableImage, drawRoundRect, drawString, drawString, drawString, fillArc, fillOval, fillPolygon, fillRect, fillRoundRect, getClipBounds, getColor, hit, rotate, rotate, scale, setClip, setColor, shear, transform, translate, translate

Method Details

addRenderingHints

public void addRenderingHints(Map hints)
Sets the values of an arbitrary number of preferences for the rendering algorithms. Only values for the rendering hints that are present in the specified Map object are modified. All other preferences not present in the specified object are left unmodified. Hint categories include controls for rendering quality and overall time/quality trade-off in the rendering process. Refer to the RenderingHints class for definitions of some common keys and values.
Parameters:
hints - the rendering hints to be set
See Also:
RenderingHints

clip

public void clip(Shape s)
Intersects the current Clip with the interior of the specified Shape and sets the Clip to the resulting intersection. The specified Shape is transformed with the current Graphics2D Transform before being intersected with the current Clip. This method is used to make the current Clip smaller. To make the Clip larger, use setClip. The user clip modified by this method is independent of the clipping associated with device bounds and visibility. If no clip has previously been set, or if the clip has been cleared using setClip with a null argument, the specified Shape becomes the new user clip.
Parameters:
s - the Shape to be intersected with the current Clip. If s is null, this method clears the current Clip.

copyArea

public void copyArea(int x,
                     int y,
                     int width,
                     int height,
                     int dx,
                     int dy)
Copies an area of the component by a distance specified by dx and dy. From the point specified by x and y, this method copies downwards and to the right. To copy an area of the component to the left or upwards, specify a negative value for dx or dy. If a portion of the source rectangle lies outside the bounds of the component, or is obscured by another window or component, copyArea will be unable to copy the associated pixels. The area that is omitted can be refreshed by calling the component's paint method.
Parameters:
x - the x coordinate of the source rectangle.
y - the y coordinate of the source rectangle.
width - the width of the source rectangle.
height - the height of the source rectangle.
dx - the horizontal distance to copy the pixels.
dy - the vertical distance to copy the pixels.

create

public Graphics create()
Creates a new Graphics object that is a copy of this Graphics object.
Returns:
a new graphics context that is a copy of this graphics context.

dispose

public void dispose()
Disposes of this graphics context and releases any system resources that it is using. A Graphics object cannot be used after disposehas been called.

When a Java program runs, a large number of Graphics objects can be created within a short time frame. Although the finalization process of the garbage collector also disposes of the same system resources, it is preferable to manually free the associated resources by calling this method rather than to rely on a finalization process which may not run to completion for a long period of time.

Graphics objects which are provided as arguments to the paint and update methods of components are automatically released by the system when those methods return. For efficiency, programmers should call dispose when finished using a Graphics object only if it was created directly from a component or another Graphics object.

See Also:
Graphics.finalize, Component.paint, Component.update, Component.getGraphics, Graphics.create

draw

public void draw(Shape s)
Strokes the outline of a Shape using the settings of the current Graphics2D context. The rendering attributes applied include the Clip, Transform, Paint, Composite and Stroke attributes.
Parameters:
s - the Shape to be rendered

drawImage

public boolean drawImage(Image img,
                         AffineTransform xform,
                         ImageObserver obs)
Renders an image, applying a transform from image space into user space before drawing. The transformation from user space into device space is done with the current Transform in the Graphics2D. The specified transformation is applied to the image before the transform attribute in the Graphics2D context is applied. The rendering attributes applied include the Clip, Transform, and Composite attributes. Note that no rendering is done if the specified transform is noninvertible.
Parameters:
img - the Image to be rendered
xform - the transformation from image space into user space
obs - the ImageObserver to be notified as more of the Image is converted
Returns:
true if the Image is fully loaded and completely rendered; false if the Image is still being loaded.

drawRenderedImage

public void drawRenderedImage(RenderedImage img,
                              AffineTransform xform)
Renders a RenderedImage, applying a transform from image space into user space before drawing. The transformation from user space into device space is done with the current Transform in the Graphics2D. The specified transformation is applied to the image before the transform attribute in the Graphics2D context is applied. The rendering attributes applied include the Clip, Transform, and Composite attributes. Note that no rendering is done if the specified transform is noninvertible.
Parameters:
img - the image to be rendered
xform - the transformation from image space into user space

drawString

public void drawString(String s,
                       float x,
                       float y)
Renders the text specified by the specified String, using the current Font and Paint attributes in the Graphics2D context. The baseline of the first character is at position (xy) in the User Space. The rendering attributes applied include the Clip, Transform, Paint, Font and Composite attributes. For characters in script systems such as Hebrew and Arabic, the glyphs can be rendered from right to left, in which case the coordinate supplied is the location of the leftmost character on the baseline.
Parameters:
s - the String to be rendered
x - the x-coordinates where the String should be rendered
y - the y-coordinates where the String should be rendered

fill

public void fill(Shape s)
Fills the interior of a Shape using the settings of the Graphics2D context. The rendering attributes applied include the Clip, Transform, Paint, and Composite.
Parameters:
s - the Shape to be filled

getBackground

public Color getBackground()
Returns the background color used for clearing a region.
Returns:
the current Graphics2D Color, which defines the background color.

getClip

public Shape getClip()
Gets the current clipping area. This method returns the user clip, which is independent of the clipping associated with device bounds and window visibility. If no clip has previously been set, or if the clip has been cleared using setClip(null), this method returns null.
Returns:
a Shape object representing the current clipping area, or null if no clip is set.
Since:
JDK1.1
See Also:
Graphics.getClipBounds, Graphics.clipRect, Graphics.setClip(int, int, int, int), Graphics.setClip(Shape)

getComposite

public Composite getComposite()
Returns the current Composite in the Graphics2D context.
Returns:
the current Graphics2D Composite, which defines a compositing style.

getDeviceConfiguration

public GraphicsConfiguration getDeviceConfiguration()
Returns the device configuration associated with this Graphics2D.

getFont

public Font getFont()
Gets the current font.
Returns:
this graphics context's current font.
See Also:
Font, Graphics.setFont

getFontMetrics

public FontMetrics getFontMetrics(Font f)
Gets the font metrics for the specified font.
Parameters:
f - the specified font
Returns:
the font metrics for the specified font.
See Also:
Graphics.getFont, FontMetrics, Graphics.getFontMetrics()

getFontRenderContext

public FontRenderContext getFontRenderContext()
Get the rendering context of the Font within this Graphics2D context. The FontRenderContext encapsulates application hints such as anti-aliasing and fractional metrics, as well as target device specific information such as dots-per-inch. This information should be provided by the application when using objects that perform typographical formatting, such as Font and TextLayout. This information should also be provided by applications that perform their own layout and need accurate measurements of various characteristics of glyphs such as advance and line height when various rendering hints have been applied to the text rendering.
Returns:
a reference to an instance of FontRenderContext.
Since:
1.2
See Also:
FontRenderContext, Font.createGlyphVector, TextLayout

getPaint

public Paint getPaint()
Returns the current Paint of the Graphics2D context.
Returns:
the current Graphics2D Paint, which defines a color or pattern.
See Also:
setPaint(Paint), Graphics.setColor

getRenderingHint

public Object getRenderingHint(RenderingHints.Key hintKey)
Returns the value of a single preference for the rendering algorithms. Hint categories include controls for rendering quality and overall time/quality trade-off in the rendering process. Refer to the RenderingHints class for definitions of some common keys and values.
Parameters:
hintKey - the key corresponding to the hint to get.
Returns:
an object representing the value for the specified hint key. Some of the keys and their associated values are defined in the RenderingHints class.
See Also:
RenderingHints

getRenderingHints

public RenderingHints getRenderingHints()
Gets the preferences for the rendering algorithms. Hint categories include controls for rendering quality and overall time/quality trade-off in the rendering process. Returns all of the hint key/value pairs that were ever specified in one operation. Refer to the RenderingHints class for definitions of some common keys and values.
Returns:
a reference to an instance of RenderingHints that contains the current preferences.
See Also:
RenderingHints

getStroke

public Stroke getStroke()
Returns the current Stroke in the Graphics2D context.
Returns:
the current Graphics2D Stroke, which defines the line style.

getTransform

public AffineTransform getTransform()
Returns a copy of the current Transform in the Graphics2D context.
Returns:
the current AffineTransform in the Graphics2D context.

setBackground

public void setBackground(Color color)
Sets the background color for the Graphics2D context. The background color is used for clearing a region. When a Graphics2D is constructed for a Component, the background color is inherited from the Component. Setting the background color in the Graphics2D context only affects the subsequent clearRect calls and not the background color of the Component. To change the background of the Component, use appropriate methods of the Component.
Parameters:
color - the background color that isused in subsequent calls to clearRect
See Also:
getBackground(), Graphics.clearRect

setClip

public void setClip(Shape clip)
Sets the current clipping area to an arbitrary clip shape. Not all objects that implement the Shape interface can be used to set the clip. The only Shape objects that are guaranteed to be supported are Shape objects that are obtained via the getClip method and via Rectangle objects. This method sets the user clip, which is independent of the clipping associated with device bounds and window visibility.
Parameters:
clip - the Shape to use to set the clip
Since:
JDK1.1
See Also:
Graphics.getClip(), Graphics.clipRect, Graphics.setClip(int, int, int, int)

setComposite

public void setComposite(Composite comp)
Sets the Composite for the Graphics2D context. The Composite is used in all drawing methods such as drawImage, drawString, draw, and fill. It specifies how new pixels are to be combined with the existing pixels on the graphics device during the rendering process.

If this Graphics2D context is drawing to a Component on the display screen and the Composite is a custom object rather than an instance of the AlphaComposite class, and if there is a security manager, its checkPermission method is called with an AWTPermission("readDisplayPixels") permission.

Parameters:
comp - the Composite object to be used for rendering
See Also:
Graphics.setXORMode, Graphics.setPaintMode, AlphaComposite, SecurityManager.checkPermission, AWTPermission

setFont

public void setFont(Font font)
Sets this graphics context's font to the specified font. All subsequent text operations using this graphics context use this font.
Parameters:
font - the font.
See Also:
Graphics.getFont, Graphics.drawString(String, int, int), Graphics.drawBytes(byte[], int, int, int, int), Graphics.drawChars(char[], int, int, int, int)

setPaint

public void setPaint(Paint paint)
Sets the Paint attribute for the Graphics2D context. Calling this method with a null Paint object does not have any effect on the current Paint attribute of this Graphics2D.
Parameters:
paint - the Paint object to be used to generate color during the rendering process, or null
See Also:
Graphics.setColor, GradientPaint, TexturePaint

setPaintMode

public void setPaintMode()
Sets the paint mode of this graphics context to overwrite the destination with this graphics context's current color. This sets the logical pixel operation function to the paint or overwrite mode. All subsequent rendering operations will overwrite the destination with the current color.

setRenderingHint

public void setRenderingHint(RenderingHints.Key hintKey,
                             Object hintValue)
Sets the value of a single preference for the rendering algorithms. Hint categories include controls for rendering quality and overall time/quality trade-off in the rendering process. Refer to the RenderingHints class for definitions of some common keys and values.
Parameters:
hintKey - the key of the hint to be set.
hintValue - the value indicating preferences for the specified hint category.
See Also:
RenderingHints

setRenderingHints

public void setRenderingHints(Map hints)
Replaces the values of all preferences for the rendering algorithms with the specified hints. The existing values for all rendering hints are discarded and the new set of known hints and values are initialized from the specified Map object. Hint categories include controls for rendering quality and overall time/quality trade-off in the rendering process. Refer to the RenderingHints class for definitions of some common keys and values.
Parameters:
hints - the rendering hints to be set
See Also:
RenderingHints

setStroke

public void setStroke(Stroke s)
Sets the Stroke for the Graphics2D context.
Parameters:
s - the Stroke object to be used to stroke a Shape during the rendering process
See Also:
BasicStroke

setTransform

public void setTransform(AffineTransform Tx)
Sets the Transform in the Graphics2D context.
Parameters:
Tx - the AffineTransform object to be used in the rendering process
See Also:
WmfGraphics2D, AffineTransform

setXORMode

public void setXORMode(Color c1)
Sets the paint mode of this graphics context to alternate between this graphics context's current color and the new specified color. This specifies that logical pixel operations are performed in the XOR mode, which alternates pixels between the current color and a specified XOR color.

When drawing operations are performed, pixels which are the current color are changed to the specified color, and vice versa.

Pixels that are of colors other than those two colors are changed in an unpredictable but reversible manner; if the same figure is drawn twice, then all pixels are restored to their original values.

Parameters:
c1 - the XOR alternation color