| Constructor: |
public TextTitle() {
this("");
}
Creates a new title, using default attributes where necessary. |
public TextTitle(String text) {
this(text, TextTitle.DEFAULT_FONT, TextTitle.DEFAULT_TEXT_PAINT,
Title.DEFAULT_POSITION, Title.DEFAULT_HORIZONTAL_ALIGNMENT,
Title.DEFAULT_VERTICAL_ALIGNMENT, Title.DEFAULT_PADDING);
}
Creates a new title, using default attributes where necessary. Parameters:
text - the title text (null not permitted).
|
public TextTitle(String text,
Font font) {
this(text, font, TextTitle.DEFAULT_TEXT_PAINT, Title.DEFAULT_POSITION,
Title.DEFAULT_HORIZONTAL_ALIGNMENT,
Title.DEFAULT_VERTICAL_ALIGNMENT, Title.DEFAULT_PADDING);
}
Creates a new title, using default attributes where necessary. Parameters:
text - the title text (null not permitted).
font - the title font (null not permitted).
|
public TextTitle(String text,
Font font,
Paint paint,
RectangleEdge position,
HorizontalAlignment horizontalAlignment,
VerticalAlignment verticalAlignment,
RectangleInsets padding) {
super(position, horizontalAlignment, verticalAlignment, padding);
if (text == null) {
throw new NullPointerException("Null 'text' argument.");
}
if (font == null) {
throw new NullPointerException("Null 'font' argument.");
}
if (paint == null) {
throw new NullPointerException("Null 'paint' argument.");
}
this.text = text;
this.font = font;
this.paint = paint;
// the textAlignment and the horizontalAlignment are separate things,
// but it makes sense for the default textAlignment to match the
// title's horizontal alignment...
this.textAlignment = horizontalAlignment;
this.backgroundPaint = null;
this.content = null;
this.toolTipText = null;
this.urlText = null;
}
Parameters:
text - the text for the title (null not permitted).
font - the title font (null not permitted).
paint - the title paint (null not permitted).
position - the title position (null not permitted).
horizontalAlignment - the horizontal alignment (null
not permitted).
verticalAlignment - the vertical alignment (null not
permitted).
padding - the space to leave around the outside of the title.
|
| Method from org.jfree.chart.title.TextTitle Detail: |
public Size2D arrange(Graphics2D g2,
RectangleConstraint constraint) {
RectangleConstraint cc = toContentConstraint(constraint);
LengthConstraintType w = cc.getWidthConstraintType();
LengthConstraintType h = cc.getHeightConstraintType();
Size2D contentSize = null;
if (w == LengthConstraintType.NONE) {
if (h == LengthConstraintType.NONE) {
contentSize = arrangeNN(g2);
}
else if (h == LengthConstraintType.RANGE) {
throw new RuntimeException("Not yet implemented.");
}
else if (h == LengthConstraintType.FIXED) {
throw new RuntimeException("Not yet implemented.");
}
}
else if (w == LengthConstraintType.RANGE) {
if (h == LengthConstraintType.NONE) {
contentSize = arrangeRN(g2, cc.getWidthRange());
}
else if (h == LengthConstraintType.RANGE) {
contentSize = arrangeRR(g2, cc.getWidthRange(),
cc.getHeightRange());
}
else if (h == LengthConstraintType.FIXED) {
throw new RuntimeException("Not yet implemented.");
}
}
else if (w == LengthConstraintType.FIXED) {
if (h == LengthConstraintType.NONE) {
contentSize = arrangeFN(g2, cc.getWidth());
}
else if (h == LengthConstraintType.RANGE) {
throw new RuntimeException("Not yet implemented.");
}
else if (h == LengthConstraintType.FIXED) {
throw new RuntimeException("Not yet implemented.");
}
}
return new Size2D(calculateTotalWidth(contentSize.getWidth()),
calculateTotalHeight(contentSize.getHeight()));
}
Arranges the contents of the block, within the given constraints, and
returns the block size. |
protected Size2D arrangeFN(Graphics2D g2,
double w) {
RectangleEdge position = getPosition();
if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) {
float maxWidth = (float) w;
g2.setFont(this.font);
this.content = TextUtilities.createTextBlock(this.text, this.font,
this.paint, maxWidth, this.maximumLinesToDisplay,
new G2TextMeasurer(g2));
this.content.setLineAlignment(this.textAlignment);
Size2D contentSize = this.content.calculateDimensions(g2);
if (this.expandToFitSpace) {
return new Size2D(maxWidth, contentSize.getHeight());
}
else {
return contentSize;
}
}
else if (position == RectangleEdge.LEFT || position
== RectangleEdge.RIGHT) {
float maxWidth = Float.MAX_VALUE;
g2.setFont(this.font);
this.content = TextUtilities.createTextBlock(this.text, this.font,
this.paint, maxWidth, this.maximumLinesToDisplay,
new G2TextMeasurer(g2));
this.content.setLineAlignment(this.textAlignment);
Size2D contentSize = this.content.calculateDimensions(g2);
// transpose the dimensions, because the title is rotated
if (this.expandToFitSpace) {
return new Size2D(contentSize.getHeight(), maxWidth);
}
else {
return new Size2D(contentSize.height, contentSize.width);
}
}
else {
throw new RuntimeException("Unrecognised exception.");
}
}
Arranges the content for this title assuming a fixed width and no bounds
on the height, and returns the required size. This will reflect the
fact that a text title positioned on the left or right of a chart will
be rotated by 90 degrees. |
protected Size2D arrangeNN(Graphics2D g2) {
Range max = new Range(0.0, Float.MAX_VALUE);
return arrangeRR(g2, max, max);
}
Arranges the content for this title assuming no bounds on the width
or the height, and returns the required size. This will reflect the
fact that a text title positioned on the left or right of a chart will
be rotated by 90 degrees. |
protected Size2D arrangeRN(Graphics2D g2,
Range widthRange) {
Size2D s = arrangeNN(g2);
if (widthRange.contains(s.getWidth())) {
return s;
}
double ww = widthRange.constrain(s.getWidth());
return arrangeFN(g2, ww);
}
Arranges the content for this title assuming a range constraint for the
width and no bounds on the height, and returns the required size. This
will reflect the fact that a text title positioned on the left or right
of a chart will be rotated by 90 degrees. |
protected Size2D arrangeRR(Graphics2D g2,
Range widthRange,
Range heightRange) {
RectangleEdge position = getPosition();
if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) {
float maxWidth = (float) widthRange.getUpperBound();
g2.setFont(this.font);
this.content = TextUtilities.createTextBlock(this.text, this.font,
this.paint, maxWidth, this.maximumLinesToDisplay,
new G2TextMeasurer(g2));
this.content.setLineAlignment(this.textAlignment);
Size2D contentSize = this.content.calculateDimensions(g2);
if (this.expandToFitSpace) {
return new Size2D(maxWidth, contentSize.getHeight());
}
else {
return contentSize;
}
}
else if (position == RectangleEdge.LEFT || position
== RectangleEdge.RIGHT) {
float maxWidth = (float) heightRange.getUpperBound();
g2.setFont(this.font);
this.content = TextUtilities.createTextBlock(this.text, this.font,
this.paint, maxWidth, this.maximumLinesToDisplay,
new G2TextMeasurer(g2));
this.content.setLineAlignment(this.textAlignment);
Size2D contentSize = this.content.calculateDimensions(g2);
// transpose the dimensions, because the title is rotated
if (this.expandToFitSpace) {
return new Size2D(contentSize.getHeight(), maxWidth);
}
else {
return new Size2D(contentSize.height, contentSize.width);
}
}
else {
throw new RuntimeException("Unrecognised exception.");
}
}
Returns the content size for the title. This will reflect the fact that
a text title positioned on the left or right of a chart will be rotated
90 degrees. |
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
Returns a clone of this object. |
public void draw(Graphics2D g2,
Rectangle2D area) {
draw(g2, area, null);
}
Draws the title on a Java 2D graphics device (such as the screen or a
printer). |
public Object draw(Graphics2D g2,
Rectangle2D area,
Object params) {
if (this.content == null) {
return null;
}
area = trimMargin(area);
drawBorder(g2, area);
if (this.text.equals("")) {
return null;
}
ChartEntity entity = null;
if (params instanceof EntityBlockParams) {
EntityBlockParams p = (EntityBlockParams) params;
if (p.getGenerateEntities()) {
entity = new ChartEntity(area, this.toolTipText, this.urlText);
}
}
area = trimBorder(area);
if (this.backgroundPaint != null) {
g2.setPaint(this.backgroundPaint);
g2.fill(area);
}
area = trimPadding(area);
RectangleEdge position = getPosition();
if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) {
drawHorizontal(g2, area);
}
else if (position == RectangleEdge.LEFT
|| position == RectangleEdge.RIGHT) {
drawVertical(g2, area);
}
BlockResult result = new BlockResult();
if (entity != null) {
StandardEntityCollection sec = new StandardEntityCollection();
sec.add(entity);
result.setEntityCollection(sec);
}
return result;
}
Draws the block within the specified area. |
protected void drawHorizontal(Graphics2D g2,
Rectangle2D area) {
Rectangle2D titleArea = (Rectangle2D) area.clone();
g2.setFont(this.font);
g2.setPaint(this.paint);
TextBlockAnchor anchor = null;
float x = 0.0f;
HorizontalAlignment horizontalAlignment = getHorizontalAlignment();
if (horizontalAlignment == HorizontalAlignment.LEFT) {
x = (float) titleArea.getX();
anchor = TextBlockAnchor.TOP_LEFT;
}
else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
x = (float) titleArea.getMaxX();
anchor = TextBlockAnchor.TOP_RIGHT;
}
else if (horizontalAlignment == HorizontalAlignment.CENTER) {
x = (float) titleArea.getCenterX();
anchor = TextBlockAnchor.TOP_CENTER;
}
float y = 0.0f;
RectangleEdge position = getPosition();
if (position == RectangleEdge.TOP) {
y = (float) titleArea.getY();
}
else if (position == RectangleEdge.BOTTOM) {
y = (float) titleArea.getMaxY();
if (horizontalAlignment == HorizontalAlignment.LEFT) {
anchor = TextBlockAnchor.BOTTOM_LEFT;
}
else if (horizontalAlignment == HorizontalAlignment.CENTER) {
anchor = TextBlockAnchor.BOTTOM_CENTER;
}
else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
anchor = TextBlockAnchor.BOTTOM_RIGHT;
}
}
this.content.draw(g2, x, y, anchor);
}
Draws a the title horizontally within the specified area. This method
will be called from the draw
method. |
protected void drawVertical(Graphics2D g2,
Rectangle2D area) {
Rectangle2D titleArea = (Rectangle2D) area.clone();
g2.setFont(this.font);
g2.setPaint(this.paint);
TextBlockAnchor anchor = null;
float y = 0.0f;
VerticalAlignment verticalAlignment = getVerticalAlignment();
if (verticalAlignment == VerticalAlignment.TOP) {
y = (float) titleArea.getY();
anchor = TextBlockAnchor.TOP_RIGHT;
}
else if (verticalAlignment == VerticalAlignment.BOTTOM) {
y = (float) titleArea.getMaxY();
anchor = TextBlockAnchor.TOP_LEFT;
}
else if (verticalAlignment == VerticalAlignment.CENTER) {
y = (float) titleArea.getCenterY();
anchor = TextBlockAnchor.TOP_CENTER;
}
float x = 0.0f;
RectangleEdge position = getPosition();
if (position == RectangleEdge.LEFT) {
x = (float) titleArea.getX();
}
else if (position == RectangleEdge.RIGHT) {
x = (float) titleArea.getMaxX();
if (verticalAlignment == VerticalAlignment.TOP) {
anchor = TextBlockAnchor.BOTTOM_RIGHT;
}
else if (verticalAlignment == VerticalAlignment.CENTER) {
anchor = TextBlockAnchor.BOTTOM_CENTER;
}
else if (verticalAlignment == VerticalAlignment.BOTTOM) {
anchor = TextBlockAnchor.BOTTOM_LEFT;
}
}
this.content.draw(g2, x, y, anchor, x, y, -Math.PI / 2.0);
}
Draws a the title vertically within the specified area. This method
will be called from the draw
method. |
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof TextTitle)) {
return false;
}
TextTitle that = (TextTitle) obj;
if (!ObjectUtilities.equal(this.text, that.text)) {
return false;
}
if (!ObjectUtilities.equal(this.font, that.font)) {
return false;
}
if (!PaintUtilities.equal(this.paint, that.paint)) {
return false;
}
if (this.textAlignment != that.textAlignment) {
return false;
}
if (!PaintUtilities.equal(this.backgroundPaint, that.backgroundPaint)) {
return false;
}
if (this.maximumLinesToDisplay != that.maximumLinesToDisplay) {
return false;
}
if (this.expandToFitSpace != that.expandToFitSpace) {
return false;
}
if (!ObjectUtilities.equal(this.toolTipText, that.toolTipText)) {
return false;
}
if (!ObjectUtilities.equal(this.urlText, that.urlText)) {
return false;
}
return super.equals(obj);
}
Tests this title for equality with another object. |
public Paint getBackgroundPaint() {
return this.backgroundPaint;
}
Returns the background paint. |
public boolean getExpandToFitSpace() {
return this.expandToFitSpace;
}
Returns the flag that controls whether or not the title expands to fit
the available space. |
public Font getFont() {
return this.font;
}
Returns the font used to display the title string. |
public int getMaximumLinesToDisplay() {
return this.maximumLinesToDisplay;
}
Returns the maximum number of lines to display. |
public Paint getPaint() {
return this.paint;
}
Returns the paint used to display the title string. |
public String getText() {
return this.text;
}
|
public HorizontalAlignment getTextAlignment() {
return this.textAlignment;
}
Returns the text alignment. This controls how the text is aligned
within the title's bounds, whereas the title's horizontal alignment
controls how the title's bounding rectangle is aligned within the
drawing space. |
public String getToolTipText() {
return this.toolTipText;
}
Returns the tool tip text. |
public String getURLText() {
return this.urlText;
}
|
public int hashCode() {
int result = super.hashCode();
result = 29 * result + (this.text != null ? this.text.hashCode() : 0);
result = 29 * result + (this.font != null ? this.font.hashCode() : 0);
result = 29 * result + (this.paint != null ? this.paint.hashCode() : 0);
result = 29 * result + (this.backgroundPaint != null
? this.backgroundPaint.hashCode() : 0);
return result;
}
|
public void setBackgroundPaint(Paint paint) {
this.backgroundPaint = paint;
notifyListeners(new TitleChangeEvent(this));
}
Sets the background paint and sends a TitleChangeEvent to all
registered listeners. If you set this attribute to null,
no background is painted (which makes the title background transparent). |
public void setExpandToFitSpace(boolean expand) {
this.expandToFitSpace = expand;
notifyListeners(new TitleChangeEvent(this));
}
Sets the flag that controls whether the title expands to fit the
available space, and sends a TitleChangeEvent to all registered
listeners. |
public void setFont(Font font) {
if (font == null) {
throw new IllegalArgumentException("Null 'font' argument.");
}
if (!this.font.equals(font)) {
this.font = font;
notifyListeners(new TitleChangeEvent(this));
}
}
Sets the font used to display the title string. Registered listeners
are notified that the title has been modified. |
public void setMaximumLinesToDisplay(int max) {
this.maximumLinesToDisplay = max;
notifyListeners(new TitleChangeEvent(this));
}
Sets the maximum number of lines to display and sends a
TitleChangeEvent to all registered listeners. |
public void setPaint(Paint paint) {
if (paint == null) {
throw new IllegalArgumentException("Null 'paint' argument.");
}
if (!this.paint.equals(paint)) {
this.paint = paint;
notifyListeners(new TitleChangeEvent(this));
}
}
Sets the paint used to display the title string. Registered listeners
are notified that the title has been modified. |
public void setText(String text) {
if (text == null) {
throw new IllegalArgumentException("Null 'text' argument.");
}
if (!this.text.equals(text)) {
this.text = text;
notifyListeners(new TitleChangeEvent(this));
}
}
Sets the title to the specified text and sends a
TitleChangeEvent to all registered listeners. |
public void setTextAlignment(HorizontalAlignment alignment) {
if (alignment == null) {
throw new IllegalArgumentException("Null 'alignment' argument.");
}
this.textAlignment = alignment;
notifyListeners(new TitleChangeEvent(this));
}
Sets the text alignment and sends a TitleChangeEvent to
all registered listeners. |
public void setToolTipText(String text) {
this.toolTipText = text;
notifyListeners(new TitleChangeEvent(this));
}
Sets the tool tip text to the specified text and sends a
TitleChangeEvent to all registered listeners. |
public void setURLText(String text) {
this.urlText = text;
notifyListeners(new TitleChangeEvent(this));
}
Sets the URL text to the specified text and sends a
TitleChangeEvent to all registered listeners. |