org.jfree.chart
Class Legend

java.lang.Object
  |
  +--org.jfree.chart.Legend
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
StandardLegend

public abstract class Legend
extends java.lang.Object
implements java.io.Serializable

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

Author:
David Gilbert
See Also:
StandardLegend, Serialized Form

Field Summary
static int EAST
          Constant anchor value for legend position EAST.
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 SOUTH
          Constant anchor value for legend position SOUTH.
static int WEST
          Constant anchor value for legend position WEST.
 
Constructor Summary
  Legend()
          Default constructor.
protected Legend(JFreeChart chart)
          Creates a new legend.
 
Method Summary
 void addChangeListener(LegendChangeListener listener)
          Registers an object for notification of changes to the legend.
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)
          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  void notifyListeners(LegendChangeEvent event)
          Notifies all registered listeners that the chart legend has changed in some way.
 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
clone, 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

NORTH

public static final int NORTH
Constant anchor value for legend position NORTH.

See Also:
Constant Field Values

EAST

public static final int EAST
Constant anchor value for legend position EAST.

See Also:
Constant Field Values

SOUTH

public static final int SOUTH
Constant anchor value for legend position SOUTH.

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.


Legend

protected Legend(JFreeChart chart)
Creates a new legend.

Parameters:
chart - the chart that the legend belongs to.
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.

draw

public abstract java.awt.geom.Rectangle2D draw(java.awt.Graphics2D g2,
                                               java.awt.geom.Rectangle2D available)
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.
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.

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.