Package org.jfree.chart.text
Class TextFragment
java.lang.Object
org.jfree.chart.text.TextFragment
- All Implemented Interfaces:
Serializable
A text item, with an associated font, that fits on a single line (see
TextLine). Instances of the class are immutable.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate floatThe baseline offset (can be used to simulate subscripts and superscripts).static final FontThe default font.static final PaintThe default text color.private FontThe font.private PaintThe text color.private static final longFor serialization.private StringThe text. -
Constructor Summary
ConstructorsConstructorDescriptionTextFragment(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
Modifier and TypeMethodDescriptionfloatcalculateBaselineOffset(Graphics2D g2, TextAnchor anchor) Calculates the vertical offset between the baseline and the specified text anchor.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.booleanTests this instance for equality with an arbitrary object.floatReturns the baseline offset.getFont()Returns the font.getPaint()Returns the text paint.getText()Returns the text.inthashCode()Returns a hash code for this object.private voidreadObject(ObjectInputStream stream) Provides serialization support.private voidwriteObject(ObjectOutputStream stream) Provides serialization support.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor serialization.- See Also:
-
DEFAULT_FONT
The default font. -
DEFAULT_PAINT
The default text color. -
text
The text. -
font
The font. -
paint
The text color. -
baselineOffset
private float baselineOffsetThe baseline offset (can be used to simulate subscripts and superscripts).
-
-
Constructor Details
-
TextFragment
Creates a new text fragment.- Parameters:
text- the text (nullnot permitted).
-
TextFragment
Creates a new text fragment.- Parameters:
text- the text (nullnot permitted).font- the font (nullnot permitted).
-
TextFragment
Creates a new text fragment.- Parameters:
text- the text (nullnot permitted).font- the font (nullnot permitted).paint- the text color (nullnot permitted).
-
TextFragment
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 Details
-
getText
Returns the text.- Returns:
- The text (possibly
null).
-
getFont
Returns the font.- Returns:
- The font (never
null).
-
getPaint
Returns the text paint.- Returns:
- The text paint (never
null).
-
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
Calculates the dimensions of the text fragment.- Parameters:
g2- the graphics device.- Returns:
- The width and height of the text.
-
calculateBaselineOffset
Calculates the vertical offset between the baseline and the specified text anchor.- Parameters:
g2- the graphics device.anchor- the anchor.- Returns:
- the offset.
-
equals
Tests this instance for equality with an arbitrary object. -
hashCode
public int hashCode()Returns a hash code for this object. -
writeObject
Provides serialization support.- Parameters:
stream- the output stream.- Throws:
IOException- if there is an I/O error.
-
readObject
Provides serialization support.- Parameters:
stream- the input stream.- Throws:
IOException- if there is an I/O error.ClassNotFoundException- if there is a classpath problem.
-