Package org.jfree.chart.text
Class TextBlock
- java.lang.Object
-
- org.jfree.chart.text.TextBlock
-
- All Implemented Interfaces:
java.io.Serializable
public class TextBlock extends java.lang.Object implements java.io.SerializableA list ofTextLineobjects that form a block of text.
-
-
Field Summary
Fields Modifier and Type Field Description private HorizontalAlignmentlineAlignmentThe alignment of the lines.private java.util.ListlinesStorage for the lines of text.private static longserialVersionUIDFor serialization.
-
Constructor Summary
Constructors Constructor Description TextBlock()Creates a new empty text block.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLine(java.lang.String text, java.awt.Font font, java.awt.Paint paint)Adds a line of text that will be displayed using the specified font.voidaddLine(TextLine line)Adds aTextLineto the block.java.awt.ShapecalculateBounds(java.awt.Graphics2D g2, float anchorX, float anchorY, TextBlockAnchor anchor, float rotateX, float rotateY, double angle)Returns the bounds of the text block.Size2DcalculateDimensions(java.awt.Graphics2D g2)Returns the width and height of the text block.private float[]calculateOffsets(TextBlockAnchor anchor, double width, double height)Calculates the x and y offsets required to align the text block with the specified anchor point.voiddraw(java.awt.Graphics2D g2, float x, float y, TextBlockAnchor anchor)Draws the text block at a specific location.voiddraw(java.awt.Graphics2D g2, float anchorX, float anchorY, TextBlockAnchor anchor, float rotateX, float rotateY, double angle)Draws the text block, aligning it with the specified anchor point and rotating it about the specified rotation point.booleanequals(java.lang.Object obj)Tests this object for equality with an arbitrary object.TextLinegetLastLine()Returns the last line in the block.HorizontalAlignmentgetLineAlignment()Returns the alignment of the lines of text within the block.java.util.ListgetLines()Returns an unmodifiable list containing the lines for the text block.inthashCode()Returns a hash code for this object.voidsetLineAlignment(HorizontalAlignment alignment)Sets the alignment of the lines of text within the block.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
For serialization.- See Also:
- Constant Field Values
-
lines
private java.util.List lines
Storage for the lines of text.
-
lineAlignment
private HorizontalAlignment lineAlignment
The alignment of the lines.
-
-
Method Detail
-
getLineAlignment
public HorizontalAlignment getLineAlignment()
Returns the alignment of the lines of text within the block.- Returns:
- The alignment (never
null).
-
setLineAlignment
public void setLineAlignment(HorizontalAlignment alignment)
Sets the alignment of the lines of text within the block.- Parameters:
alignment- the alignment (nullnot permitted).
-
addLine
public void addLine(java.lang.String text, java.awt.Font font, java.awt.Paint paint)Adds a line of text that will be displayed using the specified font.- Parameters:
text- the text.font- the font.paint- the paint.
-
addLine
public void addLine(TextLine line)
Adds aTextLineto the block.- Parameters:
line- the line.
-
getLastLine
public TextLine getLastLine()
Returns the last line in the block.- Returns:
- The last line in the block.
-
getLines
public java.util.List getLines()
Returns an unmodifiable list containing the lines for the text block.- Returns:
- A list of
TextLineobjects.
-
calculateDimensions
public Size2D calculateDimensions(java.awt.Graphics2D g2)
Returns the width and height of the text block.- Parameters:
g2- the graphics device.- Returns:
- The width and height.
-
calculateBounds
public java.awt.Shape calculateBounds(java.awt.Graphics2D g2, float anchorX, float anchorY, TextBlockAnchor anchor, float rotateX, float rotateY, double angle)Returns the bounds of the text block.- Parameters:
g2- the graphics device (nullnot permitted).anchorX- the x-coordinate for the anchor point.anchorY- the y-coordinate for the anchor point.anchor- the text block anchor (nullnot permitted).rotateX- the x-coordinate for the rotation point.rotateY- the y-coordinate for the rotation point.angle- the rotation angle.- Returns:
- The bounds.
-
draw
public void draw(java.awt.Graphics2D g2, float x, float y, TextBlockAnchor anchor)Draws the text block at a specific location.- Parameters:
g2- the graphics device.x- the x-coordinate for the anchor point.y- the y-coordinate for the anchor point.anchor- the anchor point.
-
draw
public void draw(java.awt.Graphics2D g2, float anchorX, float anchorY, TextBlockAnchor anchor, float rotateX, float rotateY, double angle)Draws the text block, aligning it with the specified anchor point and rotating it about the specified rotation point.- Parameters:
g2- the graphics device.anchorX- the x-coordinate for the anchor point.anchorY- the y-coordinate for the anchor point.anchor- the point on the text block that is aligned to the anchor point.rotateX- the x-coordinate for the rotation point.rotateY- the x-coordinate for the rotation point.angle- the rotation (in radians).
-
calculateOffsets
private float[] calculateOffsets(TextBlockAnchor anchor, double width, double height)
Calculates the x and y offsets required to align the text block with the specified anchor point. This assumes that the top left of the text block is at (0.0, 0.0).- Parameters:
anchor- the anchor position.width- the width of the text block.height- the height of the text block.- Returns:
- The offsets (float[0] = x offset, float[1] = y offset).
-
equals
public boolean equals(java.lang.Object obj)
Tests this object 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.
-
-