com.objectplanet.chart.ext
Class PlotterChartRenderer

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

public class PlotterChartRenderer
extends ChartRenderer

This class contains methods to render the plotter chart.

Author:
Philipp Kolibaba.
See Also:
Serialized Form

Field Summary
static int BOTTOM
          Bottom range on.
protected  PlotterChart chart
          The plotter chart object
static int LEFT
          Left range on.
static int RIGHT
          Right range on.
static int TOP
          Top range on.
 
Fields inherited from class com.objectplanet.chart.ChartRenderer
BELOW, BELOW_AND_FLOATING, depth3dPoint, display3dOn, FLOATING, gridRenderer, HORIZONTAL, INSIDE, lastCalculationTime, legend, legendRenderer, OUTSIDE, overlayRenderers, parentRenderer, POINTING, VERTICAL
 
Fields inherited from class com.objectplanet.chart.Renderer
DEFAULT_CURSOR, DOUBLE_CLICK_TIME, GRID_CURSOR_HORZ, GRID_CURSOR_VERT, HAND_CURSOR, RESIZE_CURSOR, RESIZE_HOR_CURSOR
 
Constructor Summary
PlotterChartRenderer(PlotterChart chart)
          Creates a chart renderer for the given plotter chart.
 
Method Summary
protected  void calculateChartData(java.awt.Rectangle gridBounds, java.awt.Rectangle dataBounds)
          Calculates the position and size of each sample in the chart.
protected  void calculateGraphBounds(java.awt.Rectangle gridBounds)
          Calculates the bounding rectangle of the graph itself, based on which features are on and how they are configured.
protected  void checkDataIntegrity()
          Makes sure the plotter chart specific data has the same number of series and samples as the chart data has.
protected  ChartSample checkSelection(java.awt.Point point)
          This method is called when the user releases the mouse and checks if the given point is inside a sample.
protected  java.lang.String constructLabel(int series, int sample, int style)
          Constructs the combination of labels.
protected  java.awt.Rectangle getDataBounds(Grid grid)
          This method returns the bounding box for the data to be drawn in.
protected  java.awt.Point getSampleCenter(int sample, int series)
          Calculates the center point of the sample.
protected  boolean isAnyFloatingLabelsOn(int serie)
          Returns true if any floating labels should be painted for the specified serie.
protected  void paintFloatingLabel(java.awt.Graphics g, java.lang.String label, java.awt.Rectangle gridBounds, int sample, int series, java.awt.Font font, java.awt.FontMetrics fm)
          Paints a floating label.
protected  boolean paintFloatingLabels(java.awt.Graphics g, java.awt.Rectangle bounds)
          Paints floating labels.
protected  void paintGrid(java.awt.Graphics g, Grid grid, java.awt.Rectangle gridBounds)
          Paints the chart gridBounds.
protected  void paintLine(java.awt.Graphics g, int series, java.awt.Color color, java.awt.Rectangle grid)
          Paints lines between the plots for the specified series.
protected  void paintPlotPoint(java.awt.Graphics g, int series, int index, int x, int y, java.awt.Color color)
          Paints a specific plot point.
 void paintSeries(java.awt.Graphics g, java.awt.Rectangle gridBounds)
          Paints the plots.
 void render(java.awt.Graphics g)
          Renders the bar chart according to the current chart attributes and which charts features are turned on or off.
protected  void renderData(java.awt.Graphics g, java.awt.Rectangle gridBounds, java.awt.Rectangle dataBounds)
          Renders the bars and the value labels.
protected  void renderOffScreen(java.awt.Graphics g)
          A subclass should override this method to paint on top of the chart before it is painted to the AWT component.
 void reset()
          Resets the chart state attributes.
 
Methods inherited from class com.objectplanet.chart.ChartRenderer
addOverlayRenderer, calculateOverlayBounds, getLineChartBounds, getOverlayRenderer, isAnyBelowLabelsOn, paintSampleHighlight, removeExternalGraphics, render, setExternalGraphics, setOverlayRenderer
 
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
 

Field Detail

BOTTOM

public static final int BOTTOM
Bottom range on.

See Also:
Constant Field Values

chart

protected PlotterChart chart
The plotter chart object


LEFT

public static final int LEFT
Left range on.

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
Right range on.

See Also:
Constant Field Values

TOP

public static final int TOP
Top range on.

See Also:
Constant Field Values
Constructor Detail

PlotterChartRenderer

public PlotterChartRenderer(PlotterChart chart)
Creates a chart renderer for the given plotter chart.

Parameters:
chart - The bar chart object.
Method Detail

calculateChartData

protected void calculateChartData(java.awt.Rectangle gridBounds,
                                  java.awt.Rectangle dataBounds)
Calculates the position and size of each sample in the chart.

Specified by:
calculateChartData in class ChartRenderer
Parameters:
gridBounds - The chart grid bounds.
dataBounds - The data bounds.

calculateGraphBounds

protected void calculateGraphBounds(java.awt.Rectangle gridBounds)
Calculates the bounding rectangle of the graph itself, based on which features are on and how they are configured.

Specified by:
calculateGraphBounds in class ChartRenderer
Parameters:
gridBounds - The Rectangle object where the bounds to be stored.

checkDataIntegrity

protected void checkDataIntegrity()
Makes sure the plotter chart specific data has the same number of series and samples as the chart data has.

Specified by:
checkDataIntegrity in class ChartRenderer

checkSelection

protected ChartSample checkSelection(java.awt.Point point)
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().

Overrides:
checkSelection in class ChartRenderer
Parameters:
point - The point to check for.
Returns:
The sample selected, or null if none was selected.

constructLabel

protected java.lang.String constructLabel(int series,
                                          int sample,
                                          int style)
Constructs the combination of labels.

Parameters:
series - The series index.
sample - The sample index.
style - The style of the label: CENTER, OVER, UNDER, FLOATING
Returns:
The constructed label.

getDataBounds

protected java.awt.Rectangle getDataBounds(Grid grid)
This method returns the bounding box for the data to be drawn in.

Parameters:
grid - The grid to paint.
Returns:
A rectangle with the bounds.
Throws:
java.lang.IllegalArgumentException - if the grid is null.

getSampleCenter

protected java.awt.Point getSampleCenter(int sample,
                                         int series)
Calculates the center point of the sample.

Specified by:
getSampleCenter in class ChartRenderer
Parameters:
sample - Index of the sample.
series - Serie of the sample.
Returns:
The center point of the sample

isAnyFloatingLabelsOn

protected boolean isAnyFloatingLabelsOn(int serie)
Returns true if any floating labels should be painted for the specified serie.

Overrides:
isAnyFloatingLabelsOn in class ChartRenderer
Parameters:
serie - The serie to check floating labels for. Should be set to -1 when checking for all series.

paintFloatingLabel

protected void paintFloatingLabel(java.awt.Graphics g,
                                  java.lang.String label,
                                  java.awt.Rectangle gridBounds,
                                  int sample,
                                  int series,
                                  java.awt.Font font,
                                  java.awt.FontMetrics fm)
Paints a floating label.

Specified by:
paintFloatingLabel in class ChartRenderer
Parameters:
g - The graphics context to paint with.
label - The label to paint.
gridBounds - The chart grid bounds.
sample - The index of the sample.
series - The index of the series.
font - The font to use for painting.
fm - The font metrics, used to calculate label position.

paintFloatingLabels

protected boolean paintFloatingLabels(java.awt.Graphics g,
                                      java.awt.Rectangle bounds)
Paints floating labels. The method should return true if any labels were painted, so that the uppermost chart in an overlay chart paints it's labels on top and the base chart does not paint.

Overrides:
paintFloatingLabels in class ChartRenderer
Parameters:
g - The graphics context used to paint with.
bounds - The chart data bounds.
Returns:
True if painted, false if nothing was painted.

paintGrid

protected void paintGrid(java.awt.Graphics g,
                         Grid grid,
                         java.awt.Rectangle gridBounds)
Paints the chart gridBounds.

Overrides:
paintGrid in class ChartRenderer
Parameters:
g - The graphics context used to paint with.
gridBounds - The chart gridBounds bounds.
grid - The Grid object to be painted.

paintLine

protected void paintLine(java.awt.Graphics g,
                         int series,
                         java.awt.Color color,
                         java.awt.Rectangle grid)
Paints lines between the plots for the specified series.

Parameters:
g - The graphics context used to paint with.
series - The index of the series.
color - The color of the plot.

paintPlotPoint

protected void paintPlotPoint(java.awt.Graphics g,
                              int series,
                              int index,
                              int x,
                              int y,
                              java.awt.Color color)
Paints a specific plot point.

Parameters:
g - The graphics context used to paint with.
series - The index of the series.
index - The index of the plot inside the series.
x - The x-position of the point.
y - The y-position of the point.
color - The color of the plot.

paintSeries

public void paintSeries(java.awt.Graphics g,
                        java.awt.Rectangle gridBounds)
Paints the plots.

Parameters:
g - The graphics context used to paint with.
gridBounds - The chart gridBounds bounds.

render

public void render(java.awt.Graphics g)
Renders the bar chart according to the current chart attributes and which charts features are turned on or off.

Specified by:
render in class ChartRenderer
Parameters:
g - The graphics context used to paint with.
See Also:
GenericChart.paint(java.awt.Graphics)

renderData

protected void renderData(java.awt.Graphics g,
                          java.awt.Rectangle gridBounds,
                          java.awt.Rectangle dataBounds)
Renders the bars and the value labels.

Specified by:
renderData in class ChartRenderer
Parameters:
g - The graphics context used to paint with.
gridBounds - The grid bounds to paint within.
dataBounds - The scrolled data bounds to calculate the bars from.

renderOffScreen

protected void renderOffScreen(java.awt.Graphics g)
A subclass should override this method to paint on top of the chart before it is painted to the AWT component. This is done to avoid flicker of graphics painted by these subclasses.

Parameters:
g - The graphics context used to paint with.

reset

public void reset()
Resets the chart state attributes.

Overrides:
reset in class ChartRenderer