com.objectplanet.chart
Class LegendRenderer

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

public class LegendRenderer
extends Renderer

This class contains methods to render the chart legend.

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

Field Summary
 
Fields inherited from class com.objectplanet.chart.Renderer
chart, DEFAULT_CURSOR, DOUBLE_CLICK_TIME, GRID_CURSOR_HORZ, GRID_CURSOR_VERT, HAND_CURSOR, RESIZE_CURSOR, RESIZE_HOR_CURSOR
 
Constructor Summary
LegendRenderer(GenericChart chart)
          Creates a legend renderer.
 
Method Summary
 void calculateGraphBounds(Legend legend, java.awt.Rectangle gridBounds)
          This method adjusts the chart grid for the legend.
 int getSelectedElement(java.awt.Point point, Legend legend)
          This method is called when the user releases the mouse and checks if the given point is inside a sample.
 void handleLegendScrollers(java.awt.AWTEvent event)
          Handles the range adjuster and sample scroller.
protected  void paintLegend(java.awt.Graphics g, Legend legend, java.awt.Rectangle bounds, java.lang.String[] labels)
          Paints the legend.
protected  void paintLegendElement(java.awt.Graphics g, Legend legend, int index, int xpos, int ypos, int height, java.lang.String label, java.awt.FontMetrics fm)
          Paints the particular legend element.
 
Methods inherited from class com.objectplanet.chart.Renderer
clearBackground, fifo_add, fifo_clear, fifo_remove, getAngledLabelCache, getAngledLabelSize, getBrighter, getDarker, getfifo_count, getfifo_queue, getFont, getFontMetrics, getImageSize, getLabel, getLabelAngle, getLabelSize, getSampleCount, getSeriesCount, hashCode, paintBox, paintLabel, setLabelAngleCacheSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LegendRenderer

public LegendRenderer(GenericChart chart)
Creates a legend renderer.

Parameters:
chart - A chart object the legend is set for.
Method Detail

calculateGraphBounds

public void calculateGraphBounds(Legend legend,
                                 java.awt.Rectangle gridBounds)
This method adjusts the chart grid for the legend.

Parameters:
gridBounds - The Rectangle object where the bounds to be stored.

getSelectedElement

public int getSelectedElement(java.awt.Point point,
                              Legend legend)
This method is called when the user releases the mouse and checks if the given point is inside a sample. The default behaviour is to check for selection on the legend if the legend is turned on. If the number of series is 1, the selected label in the legend corresponds to the respective sample in the chart. If the number of series is more than 1, the returned sample will have the series index set, but the sample index will be set to -1. If any subclass wants to add selection behaviour, override this and call super.checkSelection().

Parameters:
point - The point to check for.
legend - The legend to paint.
Returns:
The sample selected, or null if none was selected.

handleLegendScrollers

public void handleLegendScrollers(java.awt.AWTEvent event)
Handles the range adjuster and sample scroller.


paintLegend

protected void paintLegend(java.awt.Graphics g,
                           Legend legend,
                           java.awt.Rectangle bounds,
                           java.lang.String[] labels)
Paints the legend.

Parameters:
g - The graphics context used to paint with.
legend - The legend to paint.
bounds - The chart grid bounds.
labels - The labels of the legend.

paintLegendElement

protected void paintLegendElement(java.awt.Graphics g,
                                  Legend legend,
                                  int index,
                                  int xpos,
                                  int ypos,
                                  int height,
                                  java.lang.String label,
                                  java.awt.FontMetrics fm)
Paints the particular legend element.

Parameters:
g - The graphics context used to paint with.
legend - The legend to paint.
index - The index of element inside the legend.
xpos - The x position if the element.
ypos - The y position if the element.
label - The legend label.
fm - The font metrics used to paint label with.