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:
java.io.Serializable,java.lang.Cloneable,Block,Drawable,PublicCloneable
public class LegendTitle extends Title implements java.lang.Cloneable, PublicCloneable, java.io.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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.awt.PaintbackgroundPaintThe background paint (possiblynull).static java.awt.FontDEFAULT_ITEM_FONTThe default item font.static java.awt.PaintDEFAULT_ITEM_PAINTThe default item paint.private ArrangementhLayoutThe layout for the legend when it is positioned at the top or bottom of the chart.private java.awt.FontitemFontThe item font.private RectangleInsetsitemLabelPaddingThe padding for the item labels.private java.awt.PaintitemPaintThe item paint.private BlockContaineritemsA container that holds and displays the legend items.private RectangleAnchorlegendItemGraphicAnchorThe anchor point for the legend item graphic.private RectangleEdgelegendItemGraphicEdgeThe edge for the legend item graphic relative to the text.private RectangleAnchorlegendItemGraphicLocationThe legend item graphic location.private RectangleInsetslegendItemGraphicPaddingThe padding for the legend item graphic.private static longserialVersionUIDFor serialization.private SortOrdersortOrderWhether to render legend items in ascending or descending order.private LegendItemSource[]sourcesThe sources for legend items.private ArrangementvLayoutThe layout for the legend when it is positioned at the left or right of the chart.private BlockContainerwrapperAn 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
Constructors Constructor Description LegendTitle(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddItemBlock(LegendItem item)Size2Darrange(java.awt.Graphics2D g2, RectangleConstraint constraint)Arranges the contents of the block, within the given constraints, and returns the block size.booleancanEqual(java.lang.Object other)Ensures symmetry between super/subclass implementations of equals.protected BlockcreateLegendItemBlock(LegendItem item)Creates a legend item block.voiddraw(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.Objectdraw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area, java.lang.Object params)Draws the block within the specified area.booleanequals(java.lang.Object obj)Tests this title for equality with an arbitrary object.protected voidfetchLegendItems()Fetches the latest legend items.java.awt.PaintgetBackgroundPaint()Returns the background paint.BlockContainergetItemContainer()Returns the container that holds the legend items.java.awt.FontgetItemFont()Returns the item font.RectangleInsetsgetItemLabelPadding()Returns the padding used for the items labels.java.awt.PaintgetItemPaint()Returns the item paint.RectangleAnchorgetLegendItemGraphicAnchor()Returns the legend item graphic anchor.RectangleEdgegetLegendItemGraphicEdge()Returns the location of the shape within each legend item.RectangleAnchorgetLegendItemGraphicLocation()Returns the legend item graphic location.RectangleInsetsgetLegendItemGraphicPadding()Returns the padding that will be applied to each item graphic.SortOrdergetSortOrder()Gets the order used to display legend items.LegendItemSource[]getSources()Returns the legend item sources.BlockContainergetWrapper()Returns the wrapper container, if any.inthashCode()Returns a hashcode for the title.private voidreadObject(java.io.ObjectInputStream stream)Provides serialization support.voidsetBackgroundPaint(java.awt.Paint paint)Sets the background paint for the legend and sends aTitleChangeEventto all registered listeners.voidsetItemFont(java.awt.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(java.awt.Paint paint)Sets the item paint.voidsetLegendItemGraphicAnchor(RectangleAnchor anchor)Sets the anchor point used for the graphic in each legend item.voidsetLegendItemGraphicEdge(RectangleEdge edge)Sets the location of the shape within each legend item.voidsetLegendItemGraphicLocation(RectangleAnchor anchor)Sets the legend item graphic location.voidsetLegendItemGraphicPadding(RectangleInsets padding)Sets 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(java.io.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, 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
-
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.chart.util.PublicCloneable
clone
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
For serialization.- See Also:
- Constant Field Values
-
DEFAULT_ITEM_FONT
public static final java.awt.Font DEFAULT_ITEM_FONT
The default item font.
-
DEFAULT_ITEM_PAINT
public static final java.awt.Paint DEFAULT_ITEM_PAINT
The default item paint.
-
sources
private LegendItemSource[] sources
The sources for legend items.
-
backgroundPaint
private transient java.awt.Paint backgroundPaint
The background paint (possiblynull).
-
legendItemGraphicEdge
private RectangleEdge legendItemGraphicEdge
The edge for the legend item graphic relative to the text.
-
legendItemGraphicAnchor
private RectangleAnchor legendItemGraphicAnchor
The anchor point for the legend item graphic.
-
legendItemGraphicLocation
private RectangleAnchor legendItemGraphicLocation
The legend item graphic location.
-
legendItemGraphicPadding
private RectangleInsets legendItemGraphicPadding
The padding for the legend item graphic.
-
itemFont
private java.awt.Font itemFont
The item font.
-
itemPaint
private transient java.awt.Paint itemPaint
The item paint.
-
itemLabelPadding
private RectangleInsets itemLabelPadding
The padding for the item labels.
-
items
private BlockContainer items
A container that holds and displays the legend items.
-
hLayout
private Arrangement hLayout
The layout for the legend when it is positioned at the top or bottom of the chart.
-
vLayout
private Arrangement vLayout
The layout for the legend when it is positioned at the left or right of the chart.
-
wrapper
private BlockContainer wrapper
An optional container for wrapping the legend items (allows for adding a title or other text to the legend).
-
sortOrder
private SortOrder sortOrder
Whether to render legend items in ascending or descending order.
-
-
Constructor Detail
-
LegendTitle
public LegendTitle(LegendItemSource source)
Constructs a new (empty) legend for the specified source.- Parameters:
source- the source.
-
LegendTitle
public LegendTitle(LegendItemSource source, Arrangement hLayout, Arrangement vLayout)
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 Detail
-
getSources
public LegendItemSource[] getSources()
Returns the legend item sources.- Returns:
- The sources.
-
setSources
public void setSources(LegendItemSource[] sources)
Sets the legend item sources and sends aTitleChangeEventto all registered listeners.- Parameters:
sources- the sources (nullnot permitted).
-
getBackgroundPaint
public java.awt.Paint getBackgroundPaint()
Returns the background paint.- Returns:
- The background paint (possibly
null).
-
setBackgroundPaint
public void setBackgroundPaint(java.awt.Paint paint)
Sets the background paint for the legend and sends aTitleChangeEventto all registered listeners.- Parameters:
paint- the paint (nullpermitted).
-
getLegendItemGraphicEdge
public RectangleEdge getLegendItemGraphicEdge()
Returns the location of the shape within each legend item.- Returns:
- The location (never
null).
-
setLegendItemGraphicEdge
public void setLegendItemGraphicEdge(RectangleEdge edge)
Sets the location of the shape within each legend item.- Parameters:
edge- the edge (nullnot permitted).
-
getLegendItemGraphicAnchor
public RectangleAnchor getLegendItemGraphicAnchor()
Returns the legend item graphic anchor.- Returns:
- The graphic anchor (never
null).
-
setLegendItemGraphicAnchor
public void setLegendItemGraphicAnchor(RectangleAnchor anchor)
Sets the anchor point used for the graphic in each legend item.- Parameters:
anchor- the anchor point (nullnot permitted).
-
getLegendItemGraphicLocation
public RectangleAnchor getLegendItemGraphicLocation()
Returns the legend item graphic location.- Returns:
- The location (never
null).
-
setLegendItemGraphicLocation
public void setLegendItemGraphicLocation(RectangleAnchor anchor)
Sets the legend item graphic location.- Parameters:
anchor- the anchor (nullnot permitted).
-
getLegendItemGraphicPadding
public RectangleInsets getLegendItemGraphicPadding()
Returns the padding that will be applied to each item graphic.- Returns:
- The padding (never
null).
-
setLegendItemGraphicPadding
public void setLegendItemGraphicPadding(RectangleInsets padding)
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
public java.awt.Font getItemFont()
Returns the item font.- Returns:
- The font (never
null).
-
setItemFont
public void setItemFont(java.awt.Font font)
Sets the item font and sends aTitleChangeEventto all registered listeners.- Parameters:
font- the font (nullnot permitted).
-
getItemPaint
public java.awt.Paint getItemPaint()
Returns the item paint.- Returns:
- The paint (never
null).
-
setItemPaint
public void setItemPaint(java.awt.Paint paint)
Sets the item paint.- Parameters:
paint- the paint (nullnot permitted).
-
getItemLabelPadding
public RectangleInsets getItemLabelPadding()
Returns the padding used for the items labels.- Returns:
- The padding (never
null).
-
setItemLabelPadding
public void setItemLabelPadding(RectangleInsets padding)
Sets the padding used for the item labels in the legend.- Parameters:
padding- the padding (nullnot permitted).
-
getSortOrder
public SortOrder getSortOrder()
Gets the order used to display legend items.- Returns:
- The order (never
null).
-
setSortOrder
public void setSortOrder(SortOrder order)
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
private void addItemBlock(LegendItem item)
-
createLegendItemBlock
protected Block createLegendItemBlock(LegendItem item)
Creates a legend item block.- Parameters:
item- the legend item.- Returns:
- The block.
-
getItemContainer
public BlockContainer getItemContainer()
Returns the container that holds the legend items.- Returns:
- The container for the legend items.
-
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:
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
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:
drawin interfaceBlock- Parameters:
g2- the graphics device.area- the area.params- ignored (nullpermitted).- Returns:
- An
EntityBlockResultornull.
-
getWrapper
public BlockContainer getWrapper()
Returns the wrapper container, if any.- Returns:
- The wrapper container (possibly
null).
-
setWrapper
public void setWrapper(BlockContainer wrapper)
Sets the wrapper container for the legend.- Parameters:
wrapper- the wrapper container.
-
equals
public boolean equals(java.lang.Object obj)
Tests this title for equality with an arbitrary object.
-
hashCode
public int hashCode()
Description copied from class:TitleReturns a hashcode for the title.
-
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.
-
writeObject
private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOExceptionProvides 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.ClassNotFoundExceptionProvides 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.
-
-