objects that form a block of text.
| Method from org.jfree.text.TextBlock Detail: |
public void addLine(TextLine line) {
this.lines.add(line);
}
|
public void addLine(String text,
Font font,
Paint paint) {
addLine(new TextLine(text, font, paint));
}
Adds a line of text that will be displayed using the specified font. |
public Shape calculateBounds(Graphics2D g2,
float anchorX,
float anchorY,
TextBlockAnchor anchor,
float rotateX,
float rotateY,
double angle) {
final Size2D d = calculateDimensions(g2);
final float[] offsets = calculateOffsets(
anchor, d.getWidth(), d.getHeight()
);
final Rectangle2D bounds = new Rectangle2D.Double(
anchorX + offsets[0], anchorY + offsets[1],
d.getWidth(), d.getHeight()
);
final Shape rotatedBounds = ShapeUtilities.rotateShape(
bounds, angle, rotateX, rotateY
);
return rotatedBounds;
}
Returns the bounds of the text block. |
public Size2D calculateDimensions(Graphics2D g2) {
double width = 0.0;
double height = 0.0;
final Iterator iterator = this.lines.iterator();
while (iterator.hasNext()) {
final TextLine line = (TextLine) iterator.next();
final Size2D dimension = line.calculateDimensions(g2);
width = Math.max(width, dimension.getWidth());
height = height + dimension.getHeight();
}
return new Size2D(width, height);
}
Returns the width and height of the text block. |
public void draw(Graphics2D g2,
float x,
float y,
TextBlockAnchor anchor) {
draw(g2, x, y, anchor, 0.0f, 0.0f, 0.0);
}
Draws the text block at a specific location. |
public void draw(Graphics2D g2,
float anchorX,
float anchorY,
TextBlockAnchor anchor,
float rotateX,
float rotateY,
double angle) {
final Size2D d = calculateDimensions(g2);
final float[] offsets = calculateOffsets(anchor, d.getWidth(),
d.getHeight());
final Iterator iterator = this.lines.iterator();
float yCursor = 0.0f;
while (iterator.hasNext()) {
TextLine line = (TextLine) iterator.next();
Size2D dimension = line.calculateDimensions(g2);
float lineOffset = 0.0f;
if (this.lineAlignment == HorizontalAlignment.CENTER) {
lineOffset = (float) (d.getWidth() - dimension.getWidth())
/ 2.0f;
}
else if (this.lineAlignment == HorizontalAlignment.RIGHT) {
lineOffset = (float) (d.getWidth() - dimension.getWidth());
}
line.draw(
g2, anchorX + offsets[0] + lineOffset, anchorY + offsets[1] + yCursor,
TextAnchor.TOP_LEFT, rotateX, rotateY, angle
);
yCursor = yCursor + (float) dimension.getHeight();
}
}
Draws the text block, aligning it with the specified anchor point and
rotating it about the specified rotation point. |
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof TextBlock) {
final TextBlock block = (TextBlock) obj;
return this.lines.equals(block.lines);
}
return false;
}
Tests this object for equality with an arbitrary object. |
public TextLine getLastLine() {
TextLine last = null;
final int index = this.lines.size() - 1;
if (index >= 0) {
last = (TextLine) this.lines.get(index);
}
return last;
}
Returns the last line in the block. |
public HorizontalAlignment getLineAlignment() {
return this.lineAlignment;
}
Returns the alignment of the lines of text within the block. |
public List getLines() {
return Collections.unmodifiableList(this.lines);
}
Returns an unmodifiable list containing the lines for the text block. |
public int hashCode() {
return (this.lines != null ? this.lines.hashCode() : 0);
}
Returns a hash code for this object. |
public void setLineAlignment(HorizontalAlignment alignment) {
if (alignment == null) {
throw new IllegalArgumentException("Null 'alignment' argument.");
}
this.lineAlignment = alignment;
}
Sets the alignment of the lines of text within the block. |