Package org.jfree.chart.text
Class TextFragment
- java.lang.Object
-
- org.jfree.chart.text.TextFragment
-
- All Implemented Interfaces:
java.io.Serializable
public class TextFragment extends java.lang.Object implements java.io.SerializableA 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 private floatbaselineOffsetThe baseline offset (can be used to simulate subscripts and superscripts).static java.awt.FontDEFAULT_FONTThe default font.static java.awt.PaintDEFAULT_PAINTThe default text color.private java.awt.FontfontThe font.private java.awt.PaintpaintThe text color.private static longserialVersionUIDFor serialization.private java.lang.StringtextThe text.
-
Constructor Summary
Constructors Constructor Description TextFragment(java.lang.String text)Creates a new text fragment.TextFragment(java.lang.String text, java.awt.Font font)Creates a new text fragment.TextFragment(java.lang.String text, java.awt.Font font, java.awt.Paint paint)Creates a new text fragment.TextFragment(java.lang.String text, java.awt.Font font, java.awt.Paint paint, float baselineOffset)Creates a new text fragment.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description floatcalculateBaselineOffset(java.awt.Graphics2D g2, TextAnchor anchor)Calculates the vertical offset between the baseline and the specified text anchor.Size2DcalculateDimensions(java.awt.Graphics2D g2)Calculates the dimensions of the text fragment.voiddraw(java.awt.Graphics2D g2, float anchorX, float anchorY, TextAnchor anchor, float rotateX, float rotateY, double angle)Draws the text fragment.booleanequals(java.lang.Object obj)Tests this instance for equality with an arbitrary object.floatgetBaselineOffset()Returns the baseline offset.java.awt.FontgetFont()Returns the font.java.awt.PaintgetPaint()Returns the text paint.java.lang.StringgetText()Returns the text.inthashCode()Returns a hash code for this object.private voidreadObject(java.io.ObjectInputStream stream)Provides serialization support.private voidwriteObject(java.io.ObjectOutputStream stream)Provides serialization support.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
For serialization.- See Also:
- Constant Field Values
-
DEFAULT_FONT
public static final java.awt.Font DEFAULT_FONT
The default font.
-
DEFAULT_PAINT
public static final java.awt.Paint DEFAULT_PAINT
The default text color.
-
text
private java.lang.String text
The text.
-
font
private java.awt.Font font
The font.
-
paint
private transient java.awt.Paint paint
The text color.
-
baselineOffset
private float baselineOffset
The baseline offset (can be used to simulate subscripts and superscripts).
-
-
Constructor Detail
-
TextFragment
public TextFragment(java.lang.String text)
Creates a new text fragment.- Parameters:
text- the text (nullnot permitted).
-
TextFragment
public TextFragment(java.lang.String text, java.awt.Font font)Creates a new text fragment.- Parameters:
text- the text (nullnot permitted).font- the font (nullnot permitted).
-
TextFragment
public TextFragment(java.lang.String text, java.awt.Font font, java.awt.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(java.lang.String text, java.awt.Font font, java.awt.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
-
getText
public java.lang.String getText()
Returns the text.- Returns:
- The text (possibly
null).
-
getFont
public java.awt.Font getFont()
Returns the font.- Returns:
- The font (never
null).
-
getPaint
public java.awt.Paint 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(java.awt.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 Size2D calculateDimensions(java.awt.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(java.awt.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(java.lang.Object obj)
Tests this instance for equality with an arbitrary object.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to test against (nullpermitted).- Returns:
- A boolean.
-
hashCode
public int hashCode()
Returns a hash code for this object.- Overrides:
hashCodein classjava.lang.Object- Returns:
- A hash code.
-
writeObject
private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOExceptionProvides serialization support.- Parameters:
stream- the output stream.- Throws:
java.io.IOException- if there is an I/O error.
-
readObject
private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, java.lang.ClassNotFoundExceptionProvides serialization support.- Parameters:
stream- the input stream.- Throws:
java.io.IOException- if there is an I/O error.java.lang.ClassNotFoundException- if there is a classpath problem.
-
-