org.jfree.chart.annotations

Class XYTextAnnotation

Implemented Interfaces:
Cloneable, PublicCloneable, Serializable, XYAnnotation
Known Direct Subclasses:
XYPointerAnnotation

public class XYTextAnnotation
extends AbstractXYAnnotation
implements Cloneable, PublicCloneable, Serializable

A text annotation that can be placed at a particular (x, y) location on an XYPlot.

Field Summary

static Font
DEFAULT_FONT
The default font.
static Paint
DEFAULT_PAINT
The default paint.
static TextAnchor
DEFAULT_ROTATION_ANCHOR
The default rotation anchor.
static double
DEFAULT_ROTATION_ANGLE
The default rotation angle.
static TextAnchor
DEFAULT_TEXT_ANCHOR
The default text anchor.

Constructor Summary

XYTextAnnotation(String text, double x, double y)
Creates a new annotation to be displayed at the given coordinates.

Method Summary

Object
clone()
Returns a clone of the annotation.
void
draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info)
Draws the annotation.
boolean
equals(Object obj)
Tests this annotation for equality with an arbitrary object.
Font
getFont()
Returns the font for the annotation.
Paint
getPaint()
Returns the paint for the annotation.
TextAnchor
getRotationAnchor()
Returns the rotation anchor.
double
getRotationAngle()
Returns the rotation angle.
String
getText()
Returns the text for the annotation.
TextAnchor
getTextAnchor()
Returns the text anchor.
double
getX()
Returns the x coordinate for the text anchor point (measured against the domain axis).
double
getY()
Returns the y coordinate for the text anchor point (measured against the range axis).
int
hashCode()
Returns a hash code for the object.
void
setFont(Font font)
Sets the font for the annotation.
void
setPaint(Paint paint)
Sets the paint for the annotation.
void
setRotationAnchor(TextAnchor anchor)
Sets the rotation anchor point.
void
setRotationAngle(double angle)
Sets the rotation angle.
void
setText(String text)
Sets the text for the annotation.
void
setTextAnchor(TextAnchor anchor)
Sets the text anchor (the point on the text bounding rectangle that is aligned to the (x, y) coordinate of the annotation).
void
setX(double x)
Sets the x coordinate for the text anchor point (measured against the domain axis).
void
setY(double y)
Sets the y coordinate for the text anchor point (measured against the range axis).

Methods inherited from class org.jfree.chart.annotations.AbstractXYAnnotation

addEntity, draw, equals, getToolTipText, getURL, hashCode, setToolTipText, setURL

Field Details

DEFAULT_FONT

public static final Font DEFAULT_FONT
The default font.

DEFAULT_PAINT

public static final Paint DEFAULT_PAINT
The default paint.

DEFAULT_ROTATION_ANCHOR

public static final TextAnchor DEFAULT_ROTATION_ANCHOR
The default rotation anchor.

DEFAULT_ROTATION_ANGLE

public static final double DEFAULT_ROTATION_ANGLE
The default rotation angle.
Field Value:
0.0

DEFAULT_TEXT_ANCHOR

public static final TextAnchor DEFAULT_TEXT_ANCHOR
The default text anchor.

Constructor Details

XYTextAnnotation

public XYTextAnnotation(String text,
                        double x,
                        double y)
Creates a new annotation to be displayed at the given coordinates. The coordinates are specified in data space (they will be converted to Java2D space for display).
Parameters:
text - the text (null not permitted).
x - the x-coordinate (in data space).
y - the y-coordinate (in data space).

Method Details

clone

public Object clone()
            throws CloneNotSupportedException
Returns a clone of the annotation.
Returns:
A clone.

draw

public void draw(Graphics2D g2,
                 XYPlot plot,
                 Rectangle2D dataArea,
                 ValueAxis domainAxis,
                 ValueAxis rangeAxis,
                 int rendererIndex,
                 PlotRenderingInfo info)
Draws the annotation.
Specified by:
draw in interface XYAnnotation
Overrides:
draw in interface AbstractXYAnnotation
Parameters:
g2 - the graphics device.
plot - the plot.
dataArea - the data area.
domainAxis - the domain axis.
rangeAxis - the range axis.
rendererIndex - the renderer index.
info - an optional info object that will be populated with entity information.

equals

public boolean equals(Object obj)
Tests this annotation for equality with an arbitrary object.
Overrides:
equals in interface AbstractXYAnnotation
Parameters:
obj - the object (null permitted).
Returns:
A boolean.

getFont

public Font getFont()
Returns the font for the annotation.
Returns:
The font (never null).
See Also:
setFont(Font)

getPaint

public Paint getPaint()
Returns the paint for the annotation.
Returns:
The paint (never null).

getRotationAnchor

public TextAnchor getRotationAnchor()
Returns the rotation anchor.
Returns:
The rotation anchor point (never null).

getRotationAngle

public double getRotationAngle()
Returns the rotation angle.
Returns:
The rotation angle.

getText

public String getText()
Returns the text for the annotation.
Returns:
The text (never null).

getTextAnchor

public TextAnchor getTextAnchor()
Returns the text anchor.
Returns:
The text anchor (never null).

getX

public double getX()
Returns the x coordinate for the text anchor point (measured against the domain axis).
Returns:
The x coordinate (in data space).
See Also:
setX(double)

getY

public double getY()
Returns the y coordinate for the text anchor point (measured against the range axis).
Returns:
The y coordinate (in data space).
See Also:
setY(double)

hashCode

public int hashCode()
Returns a hash code for the object.
Overrides:
hashCode in interface AbstractXYAnnotation
Returns:
A hash code.

setFont

public void setFont(Font font)
Sets the font for the annotation.
Parameters:
font - the font (null not permitted).
See Also:
getFont()

setPaint

public void setPaint(Paint paint)
Sets the paint for the annotation.
Parameters:
paint - the paint (null not permitted).
See Also:
getPaint()

setRotationAnchor

public void setRotationAnchor(TextAnchor anchor)
Sets the rotation anchor point.
Parameters:
anchor - the anchor (null not permitted).

setRotationAngle

public void setRotationAngle(double angle)
Sets the rotation angle. The angle is measured clockwise in radians.
Parameters:
angle - the angle (in radians).

setText

public void setText(String text)
Sets the text for the annotation.
Parameters:
text - the text (null not permitted).
See Also:
getText()

setTextAnchor

public void setTextAnchor(TextAnchor anchor)
Sets the text anchor (the point on the text bounding rectangle that is aligned to the (x, y) coordinate of the annotation).
Parameters:
anchor - the anchor point (null not permitted).

setX

public void setX(double x)
Sets the x coordinate for the text anchor point (measured against the domain axis).
Parameters:
x - the x coordinate (in data space).
See Also:
getX()

setY

public void setY(double y)
Sets the y coordinate for the text anchor point (measured against the range axis).
Parameters:
y - the y coordinate.
See Also:
getY()