Package org.jfree.chart.title
Class LegendTitle
java.lang.Object
org.jfree.chart.block.AbstractBlock
org.jfree.chart.title.Title
org.jfree.chart.title.LegendTitle
- All Implemented Interfaces:
Serializable
,Cloneable
,Block
,org.jfree.ui.Drawable
,org.jfree.util.PublicCloneable
public class LegendTitle
extends Title
implements Cloneable, org.jfree.util.PublicCloneable, Serializable
A chart title that displays a legend for the data in the chart.
The title can be populated with legend items manually, or you can assign a reference to the plot, in which case the legend items will be automatically created to match the dataset(s).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Paint
The background paint (possiblynull
).static final Font
The default item font.static final Paint
The default item paint.private Arrangement
The layout for the legend when it is positioned at the top or bottom of the chart.private Font
The item font.private org.jfree.ui.RectangleInsets
The padding for the item labels.private Paint
The item paint.private BlockContainer
A container that holds and displays the legend items.private org.jfree.ui.RectangleAnchor
The anchor point for the legend item graphic.private org.jfree.ui.RectangleEdge
The edge for the legend item graphic relative to the text.private org.jfree.ui.RectangleAnchor
The legend item graphic location.private org.jfree.ui.RectangleInsets
The padding for the legend item graphic.private static final long
For serialization.private org.jfree.util.SortOrder
Whether to render legend items in ascending or descending order.private LegendItemSource[]
The sources for legend items.private Arrangement
The layout for the legend when it is positioned at the left or right of the chart.private BlockContainer
An optional container for wrapping the legend items (allows for adding a title or other text to the legend).Fields inherited from class org.jfree.chart.title.Title
DEFAULT_HORIZONTAL_ALIGNMENT, DEFAULT_PADDING, DEFAULT_POSITION, DEFAULT_VERTICAL_ALIGNMENT, visible
-
Constructor Summary
ConstructorsConstructorDescriptionLegendTitle
(LegendItemSource source) Constructs a new (empty) legend for the specified source.LegendTitle
(LegendItemSource source, Arrangement hLayout, Arrangement vLayout) Creates a new legend title with the specified arrangement. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addItemBlock
(LegendItem item) org.jfree.ui.Size2D
arrange
(Graphics2D g2, RectangleConstraint constraint) Arranges the contents of the block, within the given constraints, and returns the block size.protected Block
Creates a legend item block.void
draw
(Graphics2D g2, Rectangle2D area) Draws the title on a Java 2D graphics device (such as the screen or a printer).draw
(Graphics2D g2, Rectangle2D area, Object params) Draws the block within the specified area.boolean
Tests this title for equality with an arbitrary object.protected void
Fetches the latest legend items.Returns the background paint.Returns the container that holds the legend items.Returns the item font.org.jfree.ui.RectangleInsets
Returns the padding used for the items labels.Returns the item paint.org.jfree.ui.RectangleAnchor
Returns the legend item graphic anchor.org.jfree.ui.RectangleEdge
Returns the location of the shape within each legend item.org.jfree.ui.RectangleAnchor
Returns the legend item graphic location.org.jfree.ui.RectangleInsets
Returns the padding that will be applied to each item graphic.org.jfree.util.SortOrder
Gets the order used to display legend items.Returns the legend item sources.Returns the wrapper container, if any.private void
readObject
(ObjectInputStream stream) Provides serialization support.void
setBackgroundPaint
(Paint paint) Sets the background paint for the legend and sends aTitleChangeEvent
to all registered listeners.void
setItemFont
(Font font) Sets the item font and sends aTitleChangeEvent
to all registered listeners.void
setItemLabelPadding
(org.jfree.ui.RectangleInsets padding) Sets the padding used for the item labels in the legend.void
setItemPaint
(Paint paint) Sets the item paint.void
setLegendItemGraphicAnchor
(org.jfree.ui.RectangleAnchor anchor) Sets the anchor point used for the graphic in each legend item.void
setLegendItemGraphicEdge
(org.jfree.ui.RectangleEdge edge) Sets the location of the shape within each legend item.void
setLegendItemGraphicLocation
(org.jfree.ui.RectangleAnchor anchor) Sets the legend item graphic location.void
setLegendItemGraphicPadding
(org.jfree.ui.RectangleInsets padding) Sets the padding that will be applied to each item graphic in the legend and sends aTitleChangeEvent
to all registered listeners.void
setSortOrder
(org.jfree.util.SortOrder order) Sets the order used to display legend items.void
setSources
(LegendItemSource[] sources) Sets the legend item sources and sends aTitleChangeEvent
to all registered listeners.void
setWrapper
(BlockContainer wrapper) Sets the wrapper container for the legend.private void
writeObject
(ObjectOutputStream stream) Provides serialization support.Methods inherited from class org.jfree.chart.title.Title
addChangeListener, clone, getHorizontalAlignment, getNotify, getPosition, getVerticalAlignment, hashCode, isVisible, notifyListeners, removeChangeListener, setHorizontalAlignment, setNotify, setPosition, setVerticalAlignment, setVisible
Methods inherited from class org.jfree.chart.block.AbstractBlock
arrange, calculateTotalHeight, calculateTotalWidth, drawBorder, getBorder, getBounds, getContentXOffset, getContentYOffset, getFrame, getHeight, getID, getMargin, getPadding, getWidth, setBorder, setBorder, setBounds, setFrame, setHeight, setID, setMargin, setMargin, setPadding, setPadding, setWidth, toContentConstraint, trimBorder, trimMargin, trimPadding, trimToContentHeight, trimToContentWidth
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.jfree.chart.block.Block
arrange, getBounds, getID, setBounds, setID
Methods inherited from interface org.jfree.util.PublicCloneable
clone
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor serialization.- See Also:
-
DEFAULT_ITEM_FONT
The default item font. -
DEFAULT_ITEM_PAINT
The default item paint. -
sources
The sources for legend items. -
backgroundPaint
The background paint (possiblynull
). -
legendItemGraphicEdge
private org.jfree.ui.RectangleEdge legendItemGraphicEdgeThe edge for the legend item graphic relative to the text. -
legendItemGraphicAnchor
private org.jfree.ui.RectangleAnchor legendItemGraphicAnchorThe anchor point for the legend item graphic. -
legendItemGraphicLocation
private org.jfree.ui.RectangleAnchor legendItemGraphicLocationThe legend item graphic location. -
legendItemGraphicPadding
private org.jfree.ui.RectangleInsets legendItemGraphicPaddingThe padding for the legend item graphic. -
itemFont
The item font. -
itemPaint
The item paint. -
itemLabelPadding
private org.jfree.ui.RectangleInsets itemLabelPaddingThe padding for the item labels. -
items
A container that holds and displays the legend items. -
hLayout
The layout for the legend when it is positioned at the top or bottom of the chart. -
vLayout
The layout for the legend when it is positioned at the left or right of the chart. -
wrapper
An optional container for wrapping the legend items (allows for adding a title or other text to the legend). -
sortOrder
private org.jfree.util.SortOrder sortOrderWhether to render legend items in ascending or descending order.- Since:
- 1.0.15
-
-
Constructor Details
-
LegendTitle
Constructs a new (empty) legend for the specified source.- Parameters:
source
- the source.
-
LegendTitle
Creates a new legend title with the specified arrangement.- Parameters:
source
- the source.hLayout
- the horizontal item arrangement (null
not permitted).vLayout
- the vertical item arrangement (null
not permitted).
-
-
Method Details
-
getSources
Returns the legend item sources.- Returns:
- The sources.
-
setSources
Sets the legend item sources and sends aTitleChangeEvent
to all registered listeners.- Parameters:
sources
- the sources (null
not permitted).
-
getBackgroundPaint
Returns the background paint.- Returns:
- The background paint (possibly
null
).
-
setBackgroundPaint
Sets the background paint for the legend and sends aTitleChangeEvent
to all registered listeners.- Parameters:
paint
- the paint (null
permitted).
-
getLegendItemGraphicEdge
public org.jfree.ui.RectangleEdge getLegendItemGraphicEdge()Returns the location of the shape within each legend item.- Returns:
- The location (never
null
).
-
setLegendItemGraphicEdge
public void setLegendItemGraphicEdge(org.jfree.ui.RectangleEdge edge) Sets the location of the shape within each legend item.- Parameters:
edge
- the edge (null
not permitted).
-
getLegendItemGraphicAnchor
public org.jfree.ui.RectangleAnchor getLegendItemGraphicAnchor()Returns the legend item graphic anchor.- Returns:
- The graphic anchor (never
null
).
-
setLegendItemGraphicAnchor
public void setLegendItemGraphicAnchor(org.jfree.ui.RectangleAnchor anchor) Sets the anchor point used for the graphic in each legend item.- Parameters:
anchor
- the anchor point (null
not permitted).
-
getLegendItemGraphicLocation
public org.jfree.ui.RectangleAnchor getLegendItemGraphicLocation()Returns the legend item graphic location.- Returns:
- The location (never
null
).
-
setLegendItemGraphicLocation
public void setLegendItemGraphicLocation(org.jfree.ui.RectangleAnchor anchor) Sets the legend item graphic location.- Parameters:
anchor
- the anchor (null
not permitted).
-
getLegendItemGraphicPadding
public org.jfree.ui.RectangleInsets getLegendItemGraphicPadding()Returns the padding that will be applied to each item graphic.- Returns:
- The padding (never
null
).
-
setLegendItemGraphicPadding
public void setLegendItemGraphicPadding(org.jfree.ui.RectangleInsets padding) Sets the padding that will be applied to each item graphic in the legend and sends aTitleChangeEvent
to all registered listeners.- Parameters:
padding
- the padding (null
not permitted).
-
getItemFont
Returns the item font.- Returns:
- The font (never
null
).
-
setItemFont
Sets the item font and sends aTitleChangeEvent
to all registered listeners.- Parameters:
font
- the font (null
not permitted).
-
getItemPaint
Returns the item paint.- Returns:
- The paint (never
null
).
-
setItemPaint
Sets the item paint.- Parameters:
paint
- the paint (null
not permitted).
-
getItemLabelPadding
public org.jfree.ui.RectangleInsets getItemLabelPadding()Returns the padding used for the items labels.- Returns:
- The padding (never
null
).
-
setItemLabelPadding
public void setItemLabelPadding(org.jfree.ui.RectangleInsets padding) Sets the padding used for the item labels in the legend.- Parameters:
padding
- the padding (null
not permitted).
-
getSortOrder
public org.jfree.util.SortOrder getSortOrder()Gets the order used to display legend items.- Returns:
- The order (never
null
). - Since:
- 1.0.15
-
setSortOrder
public void setSortOrder(org.jfree.util.SortOrder order) Sets the order used to display legend items.- Parameters:
order
- Specifies ascending or descending order (null
not permitted).- Since:
- 1.0.15
-
fetchLegendItems
protected void fetchLegendItems()Fetches the latest legend items. -
addItemBlock
-
createLegendItemBlock
Creates a legend item block.- Parameters:
item
- the legend item.- Returns:
- The block.
-
getItemContainer
Returns the container that holds the legend items.- Returns:
- The container for the legend items.
-
arrange
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
).
-
draw
Draws the title on a Java 2D graphics device (such as the screen or a printer). -
draw
Draws the block within the specified area.- Specified by:
draw
in interfaceBlock
- Parameters:
g2
- the graphics device.area
- the area.params
- ignored (null
permitted).- Returns:
- An
EntityBlockResult
ornull
.
-
getWrapper
Returns the wrapper container, if any.- Returns:
- The wrapper container (possibly
null
). - Since:
- 1.0.11
-
setWrapper
Sets the wrapper container for the legend.- Parameters:
wrapper
- the wrapper container.
-
equals
Tests this title for equality with an arbitrary object. -
writeObject
Provides serialization support.- Parameters:
stream
- the output stream.- Throws:
IOException
- if there is an I/O error.
-
readObject
Provides serialization support.- Parameters:
stream
- the input stream.- Throws:
IOException
- if there is an I/O error.ClassNotFoundException
- if there is a classpath problem.
-