- java.lang.Object
-
- org.jfree.chart.text.TextFragment
-
- All Implemented Interfaces:
Serializable
public class TextFragment extends Object implements Serializable
A text item, with an associated font, that fits on a single line (seeTextLine). Instances of the class are immutable.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static FontDEFAULT_FONTThe default font.static PaintDEFAULT_PAINTThe default text color.
-
Constructor Summary
Constructors Constructor Description TextFragment(String text)Creates a new text fragment.TextFragment(String text, Font font)Creates a new text fragment.TextFragment(String text, Font font, Paint paint)Creates a new text fragment.TextFragment(String text, Font font, Paint paint, float baselineOffset)Creates a new text fragment.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description floatcalculateBaselineOffset(Graphics2D g2, TextAnchor anchor)Calculates the vertical offset between the baseline and the specified text anchor.org.jfree.chart.block.Size2DcalculateDimensions(Graphics2D g2)Calculates the dimensions of the text fragment.voiddraw(Graphics2D g2, float anchorX, float anchorY, TextAnchor anchor, float rotateX, float rotateY, double angle)Draws the text fragment.booleanequals(Object obj)Tests this instance for equality with an arbitrary object.floatgetBaselineOffset()Returns the baseline offset.FontgetFont()Returns the font.PaintgetPaint()Returns the text paint.StringgetText()Returns the text.inthashCode()Returns a hash code for this object.
-
-
-
Field Detail
-
DEFAULT_FONT
public static final Font DEFAULT_FONT
The default font.
-
DEFAULT_PAINT
public static final Paint DEFAULT_PAINT
The default text color.
-
-
Constructor Detail
-
TextFragment
public TextFragment(String text)
Creates a new text fragment.- Parameters:
text- the text (nullnot permitted).
-
TextFragment
public TextFragment(String text, Font font)
Creates a new text fragment.- Parameters:
text- the text (nullnot permitted).font- the font (nullnot permitted).
-
TextFragment
public TextFragment(String text, Font font, Paint paint)
Creates a new text fragment.- Parameters:
text- the text (nullnot permitted).font- the font (nullnot permitted).paint- the text color (nullnot permitted).
-
TextFragment
public TextFragment(String text, Font font, Paint paint, float baselineOffset)
Creates a new text fragment.- Parameters:
text- the text (nullnot permitted).font- the font (nullnot permitted).paint- the text color (nullnot permitted).baselineOffset- the baseline offset.
-
-
Method Detail
-
getBaselineOffset
public float getBaselineOffset()
Returns the baseline offset.- Returns:
- The baseline offset.
-
draw
public void draw(Graphics2D g2, float anchorX, float anchorY, TextAnchor anchor, float rotateX, float rotateY, double angle)
Draws the text fragment.- Parameters:
g2- the graphics device.anchorX- the x-coordinate of the anchor point.anchorY- the y-coordinate of the anchor point.anchor- the location of the text that is aligned to the anchor point.rotateX- the x-coordinate of the rotation point.rotateY- the y-coordinate of the rotation point.angle- the angle.
-
calculateDimensions
public org.jfree.chart.block.Size2D calculateDimensions(Graphics2D g2)
Calculates the dimensions of the text fragment.- Parameters:
g2- the graphics device.- Returns:
- The width and height of the text.
-
calculateBaselineOffset
public float calculateBaselineOffset(Graphics2D g2, TextAnchor anchor)
Calculates the vertical offset between the baseline and the specified text anchor.- Parameters:
g2- the graphics device.anchor- the anchor.- Returns:
- the offset.
-
equals
public boolean equals(Object obj)
Tests this instance for equality with an arbitrary object.
-
-