Class LegendTitle

All Implemented Interfaces:
Serializable, Cloneable, Block, Drawable, PublicCloneable

public class LegendTitle extends Title implements Cloneable, 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 Details

    • serialVersionUID

      private static final long serialVersionUID
      For serialization.
      See Also:
    • DEFAULT_ITEM_FONT

      public static final Font DEFAULT_ITEM_FONT
      The default item font.
    • DEFAULT_ITEM_PAINT

      public static final Paint DEFAULT_ITEM_PAINT
      The default item paint.
    • sources

      private LegendItemSource[] sources
      The sources for legend items.
    • backgroundPaint

      private transient Paint backgroundPaint
      The background paint (possibly null).
    • 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 Font itemFont
      The item font.
    • itemPaint

      private transient 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 Details

    • 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 (null not permitted).
      vLayout - the vertical item arrangement (null not permitted).
  • Method Details

    • 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 a TitleChangeEvent to all registered listeners.
      Parameters:
      sources - the sources (null not permitted).
    • getBackgroundPaint

      public Paint getBackgroundPaint()
      Returns the background paint.
      Returns:
      The background paint (possibly null).
    • setBackgroundPaint

      public void setBackgroundPaint(Paint paint)
      Sets the background paint for the legend and sends a TitleChangeEvent to all registered listeners.
      Parameters:
      paint - the paint (null permitted).
    • 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 (null not 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 (null not 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 (null not 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 a TitleChangeEvent to all registered listeners.
      Parameters:
      padding - the padding (null not permitted).
    • getItemFont

      public Font getItemFont()
      Returns the item font.
      Returns:
      The font (never null).
    • setItemFont

      public void setItemFont(Font font)
      Sets the item font and sends a TitleChangeEvent to all registered listeners.
      Parameters:
      font - the font (null not permitted).
    • getItemPaint

      public Paint getItemPaint()
      Returns the item paint.
      Returns:
      The paint (never null).
    • setItemPaint

      public void setItemPaint(Paint paint)
      Sets the item paint.
      Parameters:
      paint - the paint (null not 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 (null not 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 (null not 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(Graphics2D g2, RectangleConstraint constraint)
      Arranges the contents of the block, within the given constraints, and returns the block size.
      Specified by:
      arrange in interface Block
      Overrides:
      arrange in class AbstractBlock
      Parameters:
      g2 - the graphics device.
      constraint - the constraint (null not permitted).
      Returns:
      The block size (in Java2D units, never null).
    • draw

      public void draw(Graphics2D g2, Rectangle2D area)
      Draws the title on a Java 2D graphics device (such as the screen or a printer).
      Specified by:
      draw in interface Drawable
      Specified by:
      draw in class Title
      Parameters:
      g2 - the graphics device.
      area - the available area for the title.
    • draw

      public Object draw(Graphics2D g2, Rectangle2D area, Object params)
      Draws the block within the specified area.
      Specified by:
      draw in interface Block
      Parameters:
      g2 - the graphics device.
      area - the area.
      params - ignored (null permitted).
      Returns:
      An EntityBlockResult or null.
    • 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(Object obj)
      Tests this title for equality with an arbitrary object.
      Overrides:
      equals in class Title
      Parameters:
      obj - the object (null permitted).
      Returns:
      A boolean.
    • hashCode

      public int hashCode()
      Description copied from class: Title
      Returns a hashcode for the title.
      Overrides:
      hashCode in class Title
      Returns:
      The hashcode.
    • canEqual

      public boolean canEqual(Object other)
      Ensures symmetry between super/subclass implementations of equals. For more detail, see http://jqno.nl/equalsverifier/manual/inheritance.
      Overrides:
      canEqual in class Title
      Parameters:
      other - Object
      Returns:
      true ONLY if the parameter is THIS class type
    • writeObject

      private void writeObject(ObjectOutputStream stream) throws IOException
      Provides serialization support.
      Parameters:
      stream - the output stream.
      Throws:
      IOException - if there is an I/O error.
    • readObject

      private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
      Provides serialization support.
      Parameters:
      stream - the input stream.
      Throws:
      IOException - if there is an I/O error.
      ClassNotFoundException - if there is a classpath problem.