## org.jfree.chart
Class Legend

    java.lang.Object
      org.jfree.chart.Legend

All Implemented Interfaces:
  java.io.Serializable, java.lang.Cloneable

Direct Known Subclasses:
  StandardLegend

    public abstract class Legend

extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

A chart legend shows the names and visual representations of the series that are plotted in a chart.

See Also:
  `StandardLegend`, Serialized Form

Field Summary
`static int` `EAST` Constant anchor value for legend position EAST.
`static int` `EAST_NORTHEAST` Constant anchor value for legend position EAST_NORTHEAST.
`static int` `EAST_SOUTHEAST` Constant anchor value for legend position EAST_SOUTHEAST.
`protected static int` `HORIZONTAL` Internal value indicating the bit holding the value of interest in the anchor value.
`protected static int` `INVERTED` Internal value indicating the bit holding the value of interest in the anchor value.
`static int` `NORTH` Constant anchor value for legend position NORTH.
`static int` `NORTH_NORTHEAST` Constant anchor value for legend position NORTH_NORTHEAST.
`static int` `NORTH_NORTHWEST` Constant anchor value for legend position NORTH_NORTHWEST.
`static int` `SOUTH` Constant anchor value for legend position SOUTH.
`static int` `SOUTH_SOUTHEAST` Constant anchor value for legend position SOUTH_SOUTHEAST.
`static int` `SOUTH_SOUTHWEST` Constant anchor value for legend position SOUTH_SOUTHWEST.
`static int` `WEST` Constant anchor value for legend position WEST.
`static int` `WEST_NORTHWEST` Constant anchor value for legend position WEST_NORTHWEST.
`static int` `WEST_SOUTHWEST` Constant anchor value for legend position WEST_SOUTHWEST.

Constructor Summary
`Legend()` Default constructor.

Method Summary
`void` `addChangeListener(LegendChangeListener listener)` Registers an object for notification of changes to the legend.
`protected java.lang.Object` `clone()` Clones the legend, and takes care of listeners.
`static Legend` `createInstance(JFreeChart chart)` Static factory method that returns a concrete subclass of Legend.
`abstract java.awt.geom.Rectangle2D` `draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D available, ChartRenderingInfo info)` Draws the legend on a Java 2D graphics device (such as the screen or a printer).
`boolean` `equals(java.lang.Object obj)` Tests this legend for equality with another object.
`int` `getAnchor()` Returns the current anchor of this legend.
`JFreeChart` `getChart()` Returns the chart that this legend belongs to.
`protected boolean` `isAnchoredToBottom()` Returns `true` if and only if this legend is anchored to bottom.
`protected boolean` `isAnchoredToCenter()` Returns `true` if and only if this legend is anchored to center.
`protected boolean` `isAnchoredToLeft()` Returns `true` if and only if this legend is anchored to left.
`protected boolean` `isAnchoredToMiddle()` Returns `true` if and only if this legend is anchored to middle.
`protected boolean` `isAnchoredToRight()` Returns `true` if and only if this legend is anchored to right.
`protected boolean` `isAnchoredToTop()` Returns `true` if and only if this legend is anchored to top.
`protected void` `notifyListeners(LegendChangeEvent event)` Notifies all registered listeners that the chart legend has changed in some way.
`protected void` `registerChart(JFreeChart chart)` Internal maintenance method to update the reference to the central JFreeChart object.
`void` `removeChangeListener(LegendChangeListener listener)` Deregisters an object for notification of changes to the legend.
`void` `setAnchor(int anchor)` Sets the current anchor of this legend.

Methods inherited from class java.lang.Object
`finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### WEST

    public static final int WEST

  Constant anchor value for legend position WEST.

  See Also:
    Constant Field Values

### WEST_NORTHWEST

    public static final int WEST_NORTHWEST

  Constant anchor value for legend position WEST_NORTHWEST.

  See Also:
    Constant Field Values

### WEST_SOUTHWEST

    public static final int WEST_SOUTHWEST

  Constant anchor value for legend position WEST_SOUTHWEST.

  See Also:
    Constant Field Values

### NORTH

    public static final int NORTH

  Constant anchor value for legend position NORTH.

  See Also:
    Constant Field Values

### NORTH_NORTHWEST

    public static final int NORTH_NORTHWEST

  Constant anchor value for legend position NORTH_NORTHWEST.

  See Also:
    Constant Field Values

### NORTH_NORTHEAST

    public static final int NORTH_NORTHEAST

  Constant anchor value for legend position NORTH_NORTHEAST.

  See Also:
    Constant Field Values

### EAST

    public static final int EAST

  Constant anchor value for legend position EAST.

  See Also:
    Constant Field Values

### EAST_NORTHEAST

    public static final int EAST_NORTHEAST

  Constant anchor value for legend position EAST_NORTHEAST.

  See Also:
    Constant Field Values

### EAST_SOUTHEAST

    public static final int EAST_SOUTHEAST

  Constant anchor value for legend position EAST_SOUTHEAST.

  See Also:
    Constant Field Values

### SOUTH

    public static final int SOUTH

  Constant anchor value for legend position SOUTH.

  See Also:
    Constant Field Values

### SOUTH_SOUTHWEST

    public static final int SOUTH_SOUTHWEST

  Constant anchor value for legend position SOUTH_SOUTHWEST.

  See Also:
    Constant Field Values

### SOUTH_SOUTHEAST

    public static final int SOUTH_SOUTHEAST

  Constant anchor value for legend position SOUTH_SOUTHEAST.

  See Also:
    Constant Field Values

### INVERTED

    protected static final int INVERTED

  Internal value indicating the bit holding the value of interest in the anchor value.

  See Also:
    Constant Field Values

### HORIZONTAL

    protected static final int HORIZONTAL

  Internal value indicating the bit holding the value of interest in the anchor value.

  See Also:
    Constant Field Values

Constructor Detail

### Legend

    public Legend()

  Default constructor.

Method Detail

### createInstance

    public static Legend createInstance(JFreeChart chart)

  Static factory method that returns a concrete subclass of Legend.

  Parameters:
    `chart` - the chart that the legend belongs to.
  Returns:
    a StandardLegend.

### getChart

    public JFreeChart getChart()

  Returns the chart that this legend belongs to.

  Returns:
    the chart.

### registerChart

    protected void registerChart(JFreeChart chart)

  Internal maintenance method to update the reference to the central JFreeChart object.

  Parameters:
    `chart` - the chart, may be null, if the legend gets removed from the chart.

### draw

    public abstract java.awt.geom.Rectangle2D draw(java.awt.Graphics2D g2,
                                                   java.awt.geom.Rectangle2D available,
                                                   ChartRenderingInfo info)

  Draws the legend on a Java 2D graphics device (such as the screen or a printer).

  Parameters:
    `g2` - the graphics device.
    `available` - the area within which the legend (and plot) should be drawn.
    `info` - a carrier for returning information about the entities in the legend.
  Returns:
    the area remaining after the legend has drawn itself.

### addChangeListener

    public void addChangeListener(LegendChangeListener listener)

  Registers an object for notification of changes to the legend.

  Parameters:
    `listener` - the object that is being registered.

### removeChangeListener

    public void removeChangeListener(LegendChangeListener listener)

  Deregisters an object for notification of changes to the legend.

  Parameters:
    `listener` - the object that is being deregistered.

### notifyListeners

    protected void notifyListeners(LegendChangeEvent event)

  Notifies all registered listeners that the chart legend has changed in some way.

  Parameters:
    `event` - information about the change to the legend.

### getAnchor

    public int getAnchor()

  Returns the current anchor of this legend.

  The default anchor for this legend is `SOUTH`.

  Returns:
    the current anchor.

### setAnchor

    public void setAnchor(int anchor)

  Sets the current anchor of this legend.

  The anchor can be one of: `NORTH`, `SOUTH`, `EAST`, `WEST`. If a valid anchor value is provided, the current anchor is set and an update event is triggered. Otherwise, no change is made.

  Parameters:
    `anchor` - the new anchor value.

### isAnchoredToTop

    protected boolean isAnchoredToTop()

  Returns `true` if and only if this legend is anchored to top.

  Returns:
    `true` if and only if this legend is anchored to top.

### isAnchoredToMiddle

    protected boolean isAnchoredToMiddle()

  Returns `true` if and only if this legend is anchored to middle.

  Returns:
    `true` if and only if this legend is anchored to middle.

### isAnchoredToBottom

    protected boolean isAnchoredToBottom()

  Returns `true` if and only if this legend is anchored to bottom.

  Returns:
    `true` if and only if this legend is anchored to bottom.

### isAnchoredToLeft

    protected boolean isAnchoredToLeft()

  Returns `true` if and only if this legend is anchored to left.

  Returns:
    `true` if and only if this legend is anchored to left.

### isAnchoredToRight

    protected boolean isAnchoredToRight()

  Returns `true` if and only if this legend is anchored to right.

  Returns:
    `true` if and only if this legend is anchored to right.

### isAnchoredToCenter

    protected boolean isAnchoredToCenter()

  Returns `true` if and only if this legend is anchored to center.

  Returns:
    `true` if and only if this legend is anchored to center.

### equals

    public boolean equals(java.lang.Object obj)

  Tests this legend for equality with another object.

  Overrides:
    `equals` in class `java.lang.Object`
  Parameters:
    `obj` - the object.
  Returns:
    `true` or `false`.

### clone

    protected java.lang.Object clone()
                              throws java.lang.CloneNotSupportedException

  Clones the legend, and takes care of listeners. Note: the cloned legend refer to the same chart as the original one. JFreeChart clone() takes care of setting the references correctly.

  Overrides:
    `clone` in class `java.lang.Object`
  Returns:
    A clone.
  Throws:
    `java.lang.CloneNotSupportedException` - if the object cannot be cloned.