Package org.jfree.chart.title
Class TextTitle
- java.lang.Object
-
- org.jfree.chart.block.AbstractBlock
-
- org.jfree.chart.title.Title
-
- org.jfree.chart.title.TextTitle
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,Block
,Drawable
,PublicCloneable
- Direct Known Subclasses:
DateTitle
,ShortTextTitle
public class TextTitle extends Title implements java.io.Serializable, java.lang.Cloneable, PublicCloneable
A chart title that displays a text string with automatic wrapping as required.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.awt.Paint
backgroundPaint
The background paint.private TextBlock
content
The content.static java.awt.Font
DEFAULT_FONT
The default font.static java.awt.Paint
DEFAULT_TEXT_PAINT
The default text color.private boolean
expandToFitSpace
A flag that controls whether the title expands to fit the available space..private java.awt.Font
font
The font used to display the title.private int
maximumLinesToDisplay
The maximum number of lines to display.private java.awt.Paint
paint
The paint used to display the title text.private static long
serialVersionUID
For serialization.private java.lang.String
text
The title text.private HorizontalAlignment
textAlignment
The text alignment.private java.lang.String
toolTipText
The tool tip text (can benull
).private java.lang.String
urlText
The URL text (can benull
).-
Fields inherited from class org.jfree.chart.title.Title
DEFAULT_HORIZONTAL_ALIGNMENT, DEFAULT_PADDING, DEFAULT_POSITION, DEFAULT_VERTICAL_ALIGNMENT, visible
-
-
Constructor Summary
Constructors Constructor Description TextTitle()
Creates a new title, using default attributes where necessary.TextTitle(java.lang.String text)
Creates a new title, using default attributes where necessary.TextTitle(java.lang.String text, java.awt.Font font)
Creates a new title, using default attributes where necessary.TextTitle(java.lang.String text, java.awt.Font font, java.awt.Paint paint, RectangleEdge position, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, RectangleInsets padding)
Creates a new title.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Size2D
arrange(java.awt.Graphics2D g2, RectangleConstraint constraint)
Arranges the contents of the block, within the given constraints, and returns the block size.protected Size2D
arrangeFN(java.awt.Graphics2D g2, double w)
Arranges the content for this title assuming a fixed width and no bounds on the height, and returns the required size.protected Size2D
arrangeNN(java.awt.Graphics2D g2)
Arranges the content for this title assuming no bounds on the width or the height, and returns the required size.protected Size2D
arrangeRN(java.awt.Graphics2D g2, Range widthRange)
Arranges the content for this title assuming a range constraint for the width and no bounds on the height, and returns the required size.protected Size2D
arrangeRR(java.awt.Graphics2D g2, Range widthRange, Range heightRange)
Returns the content size for the title.boolean
canEqual(java.lang.Object other)
Ensures symmetry between super/subclass implementations of equals.java.lang.Object
clone()
Returns a clone of this object.void
draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)
Draws the title on a Java 2D graphics device (such as the screen or a printer).java.lang.Object
draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area, java.lang.Object params)
Draws the block within the specified area.protected void
drawHorizontal(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)
Draws a the title horizontally within the specified area.protected void
drawVertical(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)
Draws a the title vertically within the specified area.boolean
equals(java.lang.Object obj)
Tests this title for equality with another object.java.awt.Paint
getBackgroundPaint()
Returns the background paint.boolean
getExpandToFitSpace()
Returns the flag that controls whether or not the title expands to fit the available space.java.awt.Font
getFont()
Returns the font used to display the title string.int
getMaximumLinesToDisplay()
Returns the maximum number of lines to display.java.awt.Paint
getPaint()
Returns the paint used to display the title string.java.lang.String
getText()
Returns the title text.HorizontalAlignment
getTextAlignment()
Returns the text alignment.java.lang.String
getToolTipText()
Returns the tool tip text.java.lang.String
getURLText()
Returns the URL text.int
hashCode()
Returns a hash code.private void
readObject(java.io.ObjectInputStream stream)
Provides serialization support.void
setBackgroundPaint(java.awt.Paint paint)
Sets the background paint and sends aTitleChangeEvent
to all registered listeners.void
setExpandToFitSpace(boolean expand)
Sets the flag that controls whether the title expands to fit the available space, and sends aTitleChangeEvent
to all registered listeners.void
setFont(java.awt.Font font)
Sets the font used to display the title string.void
setMaximumLinesToDisplay(int max)
Sets the maximum number of lines to display and sends aTitleChangeEvent
to all registered listeners.void
setPaint(java.awt.Paint paint)
Sets the paint used to display the title string.void
setText(java.lang.String text)
Sets the title to the specified text and sends aTitleChangeEvent
to all registered listeners.void
setTextAlignment(HorizontalAlignment alignment)
Sets the text alignment and sends aTitleChangeEvent
to all registered listeners.void
setToolTipText(java.lang.String text)
Sets the tool tip text to the specified text and sends aTitleChangeEvent
to all registered listeners.void
setURLText(java.lang.String text)
Sets the URL text to the specified text and sends aTitleChangeEvent
to all registered listeners.private void
writeObject(java.io.ObjectOutputStream stream)
Provides serialization support.-
Methods inherited from class org.jfree.chart.title.Title
addChangeListener, getHorizontalAlignment, getNotify, getPosition, getVerticalAlignment, isVisible, notifyListeners, removeChangeListener, setHorizontalAlignment, setNotify, setPosition, setVerticalAlignment, setVisible
-
Methods inherited from class org.jfree.chart.block.AbstractBlock
arrange, calculateTotalHeight, calculateTotalWidth, drawBorder, getBounds, getContentXOffset, getContentYOffset, getFrame, getHeight, getID, getMargin, getPadding, getWidth, setBorder, setBounds, setFrame, setHeight, setID, setMargin, setMargin, setPadding, setPadding, setWidth, toContentConstraint, trimBorder, trimMargin, trimPadding, trimToContentHeight, trimToContentWidth
-
-
-
-
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_TEXT_PAINT
public static final java.awt.Paint DEFAULT_TEXT_PAINT
The default text color.
-
text
private java.lang.String text
The title text.
-
font
private java.awt.Font font
The font used to display the title.
-
textAlignment
private HorizontalAlignment textAlignment
The text alignment.
-
paint
private transient java.awt.Paint paint
The paint used to display the title text.
-
backgroundPaint
private transient java.awt.Paint backgroundPaint
The background paint.
-
toolTipText
private java.lang.String toolTipText
The tool tip text (can benull
).
-
urlText
private java.lang.String urlText
The URL text (can benull
).
-
content
private TextBlock content
The content.
-
expandToFitSpace
private boolean expandToFitSpace
A flag that controls whether the title expands to fit the available space..
-
maximumLinesToDisplay
private int maximumLinesToDisplay
The maximum number of lines to display.
-
-
Constructor Detail
-
TextTitle
public TextTitle()
Creates a new title, using default attributes where necessary.
-
TextTitle
public TextTitle(java.lang.String text)
Creates a new title, using default attributes where necessary.- Parameters:
text
- the title text (null
not permitted).
-
TextTitle
public TextTitle(java.lang.String text, java.awt.Font font)
Creates a new title, using default attributes where necessary.- Parameters:
text
- the title text (null
not permitted).font
- the title font (null
not permitted).
-
TextTitle
public TextTitle(java.lang.String text, java.awt.Font font, java.awt.Paint paint, RectangleEdge position, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, RectangleInsets padding)
Creates a new title.- 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 Detail
-
getText
public java.lang.String getText()
Returns the title text.- Returns:
- The text (never
null
). - See Also:
setText(String)
-
setText
public void setText(java.lang.String text)
Sets the title to the specified text and sends aTitleChangeEvent
to all registered listeners.- Parameters:
text
- the text (null
not permitted).
-
getTextAlignment
public HorizontalAlignment getTextAlignment()
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.- Returns:
- The text alignment.
-
setTextAlignment
public void setTextAlignment(HorizontalAlignment alignment)
Sets the text alignment and sends aTitleChangeEvent
to all registered listeners.- Parameters:
alignment
- the alignment (null
not permitted).
-
getFont
public java.awt.Font getFont()
Returns the font used to display the title string.- Returns:
- The font (never
null
). - See Also:
setFont(Font)
-
setFont
public void setFont(java.awt.Font font)
Sets the font used to display the title string. Registered listeners are notified that the title has been modified.- Parameters:
font
- the new font (null
not permitted).- See Also:
getFont()
-
getPaint
public java.awt.Paint getPaint()
Returns the paint used to display the title string.- Returns:
- The paint (never
null
). - See Also:
setPaint(Paint)
-
setPaint
public void setPaint(java.awt.Paint paint)
Sets the paint used to display the title string. Registered listeners are notified that the title has been modified.- Parameters:
paint
- the new paint (null
not permitted).- See Also:
getPaint()
-
getBackgroundPaint
public java.awt.Paint getBackgroundPaint()
Returns the background paint.- Returns:
- The paint (possibly
null
).
-
setBackgroundPaint
public void setBackgroundPaint(java.awt.Paint paint)
Sets the background paint and sends aTitleChangeEvent
to all registered listeners. If you set this attribute tonull
, no background is painted (which makes the title background transparent).- Parameters:
paint
- the background paint (null
permitted).
-
getToolTipText
public java.lang.String getToolTipText()
Returns the tool tip text.- Returns:
- The tool tip text (possibly
null
).
-
setToolTipText
public void setToolTipText(java.lang.String text)
Sets the tool tip text to the specified text and sends aTitleChangeEvent
to all registered listeners.- Parameters:
text
- the text (null
permitted).
-
getURLText
public java.lang.String getURLText()
Returns the URL text.- Returns:
- The URL text (possibly
null
).
-
setURLText
public void setURLText(java.lang.String text)
Sets the URL text to the specified text and sends aTitleChangeEvent
to all registered listeners.- Parameters:
text
- the text (null
permitted).
-
getExpandToFitSpace
public boolean getExpandToFitSpace()
Returns the flag that controls whether or not the title expands to fit the available space.- Returns:
- The flag.
-
setExpandToFitSpace
public void setExpandToFitSpace(boolean expand)
Sets the flag that controls whether the title expands to fit the available space, and sends aTitleChangeEvent
to all registered listeners.- Parameters:
expand
- the flag.
-
getMaximumLinesToDisplay
public int getMaximumLinesToDisplay()
Returns the maximum number of lines to display.- Returns:
- The maximum.
- See Also:
setMaximumLinesToDisplay(int)
-
setMaximumLinesToDisplay
public void setMaximumLinesToDisplay(int max)
Sets the maximum number of lines to display and sends aTitleChangeEvent
to all registered listeners.- Parameters:
max
- the maximum.- See Also:
getMaximumLinesToDisplay()
-
arrange
public Size2D arrange(java.awt.Graphics2D g2, RectangleConstraint constraint)
Arranges the contents of the block, within the given constraints, and returns the block size.- Specified by:
arrange
in interfaceBlock
- Overrides:
arrange
in classAbstractBlock
- Parameters:
g2
- the graphics device.constraint
- the constraint (null
not permitted).- Returns:
- The block size (in Java2D units, never
null
).
-
arrangeNN
protected Size2D arrangeNN(java.awt.Graphics2D g2)
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.- Parameters:
g2
- the graphics target.- Returns:
- The content size.
-
arrangeFN
protected Size2D arrangeFN(java.awt.Graphics2D g2, double w)
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.- Parameters:
g2
- the graphics target.w
- the width.- Returns:
- The content size.
-
arrangeRN
protected Size2D arrangeRN(java.awt.Graphics2D g2, Range widthRange)
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.- Parameters:
g2
- the graphics target.widthRange
- the range for the width.- Returns:
- The content size.
-
arrangeRR
protected Size2D arrangeRR(java.awt.Graphics2D g2, Range widthRange, Range heightRange)
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.- Parameters:
g2
- the graphics device.widthRange
- the width range.heightRange
- the height range.- Returns:
- The content size.
-
draw
public void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)
Draws the title on a Java 2D graphics device (such as the screen or a printer).
-
draw
public java.lang.Object draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area, java.lang.Object params)
Draws the block within the specified area.- Specified by:
draw
in interfaceBlock
- Parameters:
g2
- the graphics device.area
- the area.params
- if this is an instance ofEntityBlockParams
it is used to determine whether or not anEntityCollection
is returned by this method.- Returns:
- An
EntityCollection
containing a chart entity for the title, ornull
.
-
drawHorizontal
protected void drawHorizontal(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)
Draws a the title horizontally within the specified area. This method will be called from thedraw
method.- Parameters:
g2
- the graphics device.area
- the area for the title.
-
drawVertical
protected void drawVertical(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)
Draws a the title vertically within the specified area. This method will be called from thedraw
method.- Parameters:
g2
- the graphics device.area
- the area for the title.
-
equals
public boolean equals(java.lang.Object obj)
Tests this title for equality with another object.
-
canEqual
public boolean canEqual(java.lang.Object other)
Ensures symmetry between super/subclass implementations of equals. For more detail, see http://jqno.nl/equalsverifier/manual/inheritance.
-
hashCode
public int hashCode()
Returns a hash code.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
Returns a clone of this object.- Specified by:
clone
in interfacePublicCloneable
- Overrides:
clone
in classTitle
- Returns:
- A clone.
- Throws:
java.lang.CloneNotSupportedException
- never.
-
writeObject
private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException
Provides 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.ClassNotFoundException
Provides 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.
-
-