com.objectplanet.chart
Class Legend

java.lang.Object
  extended by com.objectplanet.chart.Legend
All Implemented Interfaces:
java.io.Serializable

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

This class represents the chart legend.

Author:
Bjorn J. Kvande., Philipp Kolibaba.
See Also:
Serialized Form

Field Summary
static int BOTTOM
          Bottom legend position.
static int LEFT
          Left legend position.
static int RIGHT
          Right legend position.
static int TOP
          Top legend position.
 
Constructor Summary
Legend()
          Creates a legend.
 
Method Summary
 java.awt.Color getLabelColor(int index)
          Gets the color of the label of the specified series.
 java.awt.Color getLegendColor(int index)
          Gets legend entry's color value by it's index.
 java.awt.Color[] getLegendColors()
          Gets the legend colors.
 int getLegendColumns()
          Gets the number of columns used to display the legend labels.
 java.lang.String getLegendImage(int index)
          Gets a legend entry's image name.
 java.lang.String[] getLegendLabels()
          Gets the legend labels.
 int getLegendPosition()
          Gets the legend position.
 boolean isLegendBoxSizeAsFont()
          Check if the legend box size should be the same as the legend font size.
 boolean isLegendOn()
          Checks if the legend is turned on.
 boolean isLegendReverseOn()
          Returns true if the inverted legend is on.
 void setLabelColor(int index, java.awt.Color color)
          Sets the color of of the label for the specified legend entry.
 void setLegendBoxSizeAsFont(boolean on)
          If set to true the legend box size is set to the same size as the legend font.
 void setLegendColor(int index, java.awt.Color color)
          Sets a legend entry color.
 void setLegendColors(java.awt.Color[] colors)
          Sets the legend colors.
 void setLegendColumns(int columns)
          Sets the number of columns that should be used to display legend labels.
 void setLegendImage(int index, java.lang.String name)
          Sets an image to be used in front of the legend label.
 void setLegendLabels(java.lang.String[] labels)
          Sets the legend labels.
 void setLegendOn(boolean on)
          Turns on or off the label legend.
 void setLegendPosition(int position)
          Sets the legend position.
 void setLegendReverseOn(boolean on)
          Set on or off the inverted legend.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOTTOM

public static final int BOTTOM
Bottom legend position.

See Also:
Constant Field Values

LEFT

public static final int LEFT
Left legend position.

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
Right legend position.

See Also:
Constant Field Values

TOP

public static final int TOP
Top legend position.

See Also:
Constant Field Values
Constructor Detail

Legend

public Legend()
Creates a legend.

Method Detail

getLabelColor

public java.awt.Color getLabelColor(int index)
Gets the color of the label of the specified series.

Parameters:
index - The index of the series (0-based).
Returns:
The color, or null if no color is set.
Throws:
java.lang.IllegalArgumentException - if the series index is invalid.

getLegendColor

public java.awt.Color getLegendColor(int index)
Gets legend entry's color value by it's index.

Parameters:
index - The index of the legend entry to get color from.
Returns:
Color of the given legend entry.

getLegendColors

public java.awt.Color[] getLegendColors()
Gets the legend colors.

Returns:
The array with legend colors.

getLegendColumns

public int getLegendColumns()
Gets the number of columns used to display the legend labels.

Returns:
Number of legend columns.

getLegendImage

public java.lang.String getLegendImage(int index)
Gets a legend entry's image name.

Parameters:
index - The index of the legend entry.
Returns:
The name of the image, or null if the default legend box is used.

getLegendLabels

public java.lang.String[] getLegendLabels()
Gets the legend labels. The array returned is the original, so don't change anything in it if you don't know what you are doing.

Returns:
An array containing the labels.
See Also:
setLegendLabels(java.lang.String[])

getLegendPosition

public int getLegendPosition()
Gets the legend position.

Returns:
TOP, BOTTOM, LEFT, or RIGHT.

isLegendBoxSizeAsFont

public boolean isLegendBoxSizeAsFont()
Check if the legend box size should be the same as the legend font size.

Returns:
True if the legend box size should be the same as the legend font size.

isLegendOn

public boolean isLegendOn()
Checks if the legend is turned on.

Returns:
True for on, false for off.

isLegendReverseOn

public boolean isLegendReverseOn()
Returns true if the inverted legend is on.

Returns:
Number of legend columns.

setLabelColor

public void setLabelColor(int index,
                          java.awt.Color color)
Sets the color of of the label for the specified legend entry.

Parameters:
index - The index of the legend label (0-based).
color - The color to use, null for the default color.
Throws:
java.lang.IllegalArgumentException - if the legend label index is invalid.

setLegendBoxSizeAsFont

public void setLegendBoxSizeAsFont(boolean on)
If set to true the legend box size is set to the same size as the legend font.

Parameters:
on - True or false

setLegendColor

public void setLegendColor(int index,
                           java.awt.Color color)
Sets a legend entry color.

Parameters:
index - The index of the legend entry to set Color for.
color - The color to set for the legend entry.
See Also:
setLegendColors(java.awt.Color[]), setLegendImage(int, java.lang.String)

setLegendColors

public void setLegendColors(java.awt.Color[] colors)
Sets the legend colors. By default the legend colors are taken from the sample colors.

Parameters:
colors - The array with legend colors.
Throws:
java.lang.IllegalArgumentException - if the colors is null.
See Also:
setLegendColors(java.awt.Color[]), setLegendImage(int, java.lang.String)

setLegendColumns

public void setLegendColumns(int columns)
Sets the number of columns that should be used to display legend labels.

Parameters:
columns - Number of columns to display legends on. If columns is set to 0, the default legend rendering is used.

setLegendImage

public void setLegendImage(int index,
                           java.lang.String name)
Sets an image to be used in front of the legend label. The image itself must be added prior to calling this method using the addImage() method.

Parameters:
index - The index of the legend entry to set the image for.
name - The image to use, null for the default legend box.
See Also:
GenericChart.addImage(String, Image)

setLegendLabels

public void setLegendLabels(java.lang.String[] labels)
Sets the legend labels. If the number of series, the default legend labels are the sampleLabels and if the number of series is larger than 1, the legend labels are the series labels. This method overrides the default legend labels. To use the series label when only one series, call setLegendLabels(getSeriesLabels());

Parameters:
labels - The labels to use, null for default behavior.

setLegendOn

public void setLegendOn(boolean on)
Turns on or off the label legend. The label legend displays the label for each of the samples with each sample keyed by its color code. The legend can be displayed on the top, bottom, left, or right of the chart.

Parameters:
on - True if the legend should be displayed.
See Also:
setLegendPosition(int)

setLegendPosition

public void setLegendPosition(int position)
Sets the legend position. The legend can be displayed at the top, bottom, left, or right side of the chart.

Parameters:
position - TOP, BOTTOM, LEFT, or RIGHT.
Throws:
java.lang.IllegalArgumentException - If the position is invalid.

setLegendReverseOn

public void setLegendReverseOn(boolean on)
Set on or off the inverted legend. Default legend entry order is from top to bottom and from left to right.

Parameters:
on - If true the legend entryes are displayed from bottom to top and from right to left.