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,Drawable,PublicCloneable
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 PaintThe background paint (possiblynull).static final FontThe default item font.static final PaintThe default item paint.private ArrangementThe layout for the legend when it is positioned at the top or bottom of the chart.private FontThe item font.private RectangleInsetsThe padding for the item labels.private PaintThe item paint.private BlockContainerA container that holds and displays the legend items.private RectangleAnchorThe anchor point for the legend item graphic.private RectangleEdgeThe edge for the legend item graphic relative to the text.private RectangleAnchorThe legend item graphic location.private RectangleInsetsThe padding for the legend item graphic.private static final longFor serialization.private SortOrderWhether to render legend items in ascending or descending order.private LegendItemSource[]The sources for legend items.private ArrangementThe layout for the legend when it is positioned at the left or right of the chart.private BlockContainerAn 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 voidaddItemBlock(LegendItem item) arrange(Graphics2D g2, RectangleConstraint constraint) Arranges the contents of the block, within the given constraints, and returns the block size.booleanEnsures symmetry between super/subclass implementations of equals.protected BlockCreates a legend item block.voiddraw(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.booleanTests this title for equality with an arbitrary object.protected voidFetches the latest legend items.Returns the background paint.Returns the container that holds the legend items.Returns the item font.Returns the padding used for the items labels.Returns the item paint.Returns the legend item graphic anchor.Returns the location of the shape within each legend item.Returns the legend item graphic location.Returns the padding that will be applied to each item graphic.Gets the order used to display legend items.Returns the legend item sources.Returns the wrapper container, if any.inthashCode()Returns a hashcode for the title.private voidreadObject(ObjectInputStream stream) Provides serialization support.voidsetBackgroundPaint(Paint paint) Sets the background paint for the legend and sends aTitleChangeEventto all registered listeners.voidsetItemFont(Font font) Sets the item font and sends aTitleChangeEventto all registered listeners.voidsetItemLabelPadding(RectangleInsets padding) Sets the padding used for the item labels in the legend.voidsetItemPaint(Paint paint) Sets the item paint.voidSets the anchor point used for the graphic in each legend item.voidSets the location of the shape within each legend item.voidSets the legend item graphic location.voidSets the padding that will be applied to each item graphic in the legend and sends aTitleChangeEventto all registered listeners.voidsetSortOrder(SortOrder order) Sets the order used to display legend items.voidsetSources(LegendItemSource[] sources) Sets the legend item sources and sends aTitleChangeEventto all registered listeners.voidsetWrapper(BlockContainer wrapper) Sets the wrapper container for the legend.private voidwriteObject(ObjectOutputStream stream) Provides serialization support.Methods inherited from class org.jfree.chart.title.Title
addChangeListener, clone, getHorizontalAlignment, getNotify, getPosition, getVerticalAlignment, isVisible, notifyListeners, removeChangeListener, setHorizontalAlignment, setNotify, setPosition, setVerticalAlignment, setVisibleMethods 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, trimToContentWidthMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jfree.chart.block.Block
arrange, getBounds, getID, setBounds, setIDMethods inherited from interface org.jfree.chart.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
The edge for the legend item graphic relative to the text. -
legendItemGraphicAnchor
The anchor point for the legend item graphic. -
legendItemGraphicLocation
The legend item graphic location. -
legendItemGraphicPadding
The padding for the legend item graphic. -
itemFont
The item font. -
itemPaint
The item paint. -
itemLabelPadding
The 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
Whether to render legend items in ascending or descending order.
-
-
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 (nullnot permitted).vLayout- the vertical item arrangement (nullnot permitted).
-
-
Method Details
-
getSources
Returns the legend item sources.- Returns:
- The sources.
-
setSources
Sets the legend item sources and sends aTitleChangeEventto all registered listeners.- Parameters:
sources- the sources (nullnot permitted).
-
getBackgroundPaint
Returns the background paint.- Returns:
- The background paint (possibly
null).
-
setBackgroundPaint
Sets the background paint for the legend and sends aTitleChangeEventto all registered listeners.- Parameters:
paint- the paint (nullpermitted).
-
getLegendItemGraphicEdge
Returns the location of the shape within each legend item.- Returns:
- The location (never
null).
-
setLegendItemGraphicEdge
Sets the location of the shape within each legend item.- Parameters:
edge- the edge (nullnot permitted).
-
getLegendItemGraphicAnchor
Returns the legend item graphic anchor.- Returns:
- The graphic anchor (never
null).
-
setLegendItemGraphicAnchor
Sets the anchor point used for the graphic in each legend item.- Parameters:
anchor- the anchor point (nullnot permitted).
-
getLegendItemGraphicLocation
Returns the legend item graphic location.- Returns:
- The location (never
null).
-
setLegendItemGraphicLocation
Sets the legend item graphic location.- Parameters:
anchor- the anchor (nullnot permitted).
-
getLegendItemGraphicPadding
Returns the padding that will be applied to each item graphic.- Returns:
- The padding (never
null).
-
setLegendItemGraphicPadding
Sets the padding that will be applied to each item graphic in the legend and sends aTitleChangeEventto all registered listeners.- Parameters:
padding- the padding (nullnot permitted).
-
getItemFont
Returns the item font.- Returns:
- The font (never
null).
-
setItemFont
Sets the item font and sends aTitleChangeEventto all registered listeners.- Parameters:
font- the font (nullnot permitted).
-
getItemPaint
Returns the item paint.- Returns:
- The paint (never
null).
-
setItemPaint
Sets the item paint.- Parameters:
paint- the paint (nullnot permitted).
-
getItemLabelPadding
Returns the padding used for the items labels.- Returns:
- The padding (never
null).
-
setItemLabelPadding
Sets the padding used for the item labels in the legend.- Parameters:
padding- the padding (nullnot permitted).
-
getSortOrder
Gets the order used to display legend items.- Returns:
- The order (never
null).
-
setSortOrder
Sets the order used to display legend items.- Parameters:
order- Specifies ascending or descending order (nullnot permitted).
-
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:
arrangein interfaceBlock- Overrides:
arrangein classAbstractBlock- Parameters:
g2- the graphics device.constraint- the constraint (nullnot 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:
drawin interfaceBlock- Parameters:
g2- the graphics device.area- the area.params- ignored (nullpermitted).- Returns:
- An
EntityBlockResultornull.
-
getWrapper
Returns the wrapper container, if any.- Returns:
- The wrapper container (possibly
null).
-
setWrapper
Sets the wrapper container for the legend.- Parameters:
wrapper- the wrapper container.
-
equals
Tests this title for equality with an arbitrary object. -
hashCode
public int hashCode()Description copied from class:TitleReturns a hashcode for the title. -
canEqual
Ensures symmetry between super/subclass implementations of equals. For more detail, see http://jqno.nl/equalsverifier/manual/inheritance. -
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.
-