com.objectplanet.chart
Class ChartRenderer

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

public abstract class ChartRenderer
extends Renderer

This class is the abstract superclass of all chart renderers.

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

Field Summary
static int BELOW
          Labels display below the chart grid.
static int BELOW_AND_FLOATING
          Labels display both below the grid and floating over a sample.
protected  java.awt.Point depth3dPoint
           
protected  boolean display3dOn
           
static int FLOATING
          Floating labels display when mouse is over a sample.
protected  GridRenderer gridRenderer
          Used to paint the grid.
static int HORIZONTAL
          Horizontal bar alignment.
static int INSIDE
          Labels display inside each sample.
protected  long lastCalculationTime
           
protected  Legend legend
          This contains the legend data.
protected  LegendRenderer legendRenderer
          Used to paint the legend.
static int OUTSIDE
          Labels display outside pie edge next to each sample.
protected  java.util.Vector overlayRenderers
          This contains any overlayed chart renderers.
protected  ChartRenderer parentRenderer
          The parent of the overlay chart.
static int POINTING
          Lines point to the corresponding slices.
static int VERTICAL
          Vertical bar alignment.
 
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
ChartRenderer()
          Default constructor.
ChartRenderer(GenericChart chart)
          Creates a chart renderer for the given chart.
 
Method Summary
 int addOverlayRenderer(ChartRenderer renderer)
          Adds a new overlay renderer.
protected abstract  void calculateChartData(java.awt.Rectangle gridBounds, java.awt.Rectangle dataBounds)
          Calculates the data used for the chart.
protected abstract  void calculateGraphBounds(java.awt.Rectangle bounds)
          This method returns the bounding box for the chart grid and has to be implemented by the subclass.
protected  void calculateOverlayBounds(ChartRenderer overlay, int index, java.awt.Rectangle gridBounds, java.awt.Rectangle dataBounds)
          Calculates grid bounds and data bounds for the given overlay.
protected abstract  void checkDataIntegrity()
          This method is called each time the sample count or series count changes, and ensures that all the data has the right size.
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.awt.Rectangle getLineChartBounds(java.awt.Rectangle dataBounds)
          Calculates new bounds to be used for line charts.
 ChartRenderer getOverlayRenderer(int index)
          Gets the specified overlay chart.
protected abstract  java.awt.Point getSampleCenter(int sample, int serie)
          Calculates the center point of the sample.
protected  boolean isAnyBelowLabelsOn()
          Returns true if any labels below the grid should be painted.
protected  boolean isAnyFloatingLabelsOn(int serie)
          Returns true if any floating labels should be painted for the specified serie.
protected abstract  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 gridBounds)
          Paints floating labels.
protected  void paintGrid(java.awt.Graphics g, Grid grid, java.awt.Rectangle gridBounds)
          This method is called when the chart grid should be rendered.
protected  void paintSampleHighlight(java.awt.Graphics g, int serie, int sample, int x, int y, java.awt.Color color)
          Paints the sample highlight for a point.
 void removeExternalGraphics()
          Removes external graphics context if there is one.
protected abstract  void render(java.awt.Graphics g)
          This method is called by paint(), and has to be implemented by the subclass to render the chart.
protected  void render(java.awt.Graphics g, boolean offscreenOn)
          Renders the chart according to the set attributes, the current features that are turned on and GUI state values.
protected abstract  void renderData(java.awt.Graphics g, java.awt.Rectangle gridBounds, java.awt.Rectangle dataBounds)
          This method renders the data (bars, lines, pies).
 void reset()
          Resets the chart data and features.
 void setExternalGraphics(java.awt.Graphics g, java.awt.Image image)
          Sets an external graphics context to paint with.
 void setOverlayRenderer(int index, ChartRenderer renderer)
          Sets the specified overlay renderer.
 
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

BELOW

public static final int BELOW
Labels display below the chart grid.

See Also:
Constant Field Values

BELOW_AND_FLOATING

public static final int BELOW_AND_FLOATING
Labels display both below the grid and floating over a sample.

See Also:
Constant Field Values

depth3dPoint

protected java.awt.Point depth3dPoint

display3dOn

protected boolean display3dOn

FLOATING

public static final int FLOATING
Floating labels display when mouse is over a sample.

See Also:
Constant Field Values

gridRenderer

protected GridRenderer gridRenderer
Used to paint the grid.


HORIZONTAL

public static final int HORIZONTAL
Horizontal bar alignment.

See Also:
Constant Field Values

INSIDE

public static final int INSIDE
Labels display inside each sample.

See Also:
Constant Field Values

lastCalculationTime

protected long lastCalculationTime

legend

protected Legend legend
This contains the legend data.


legendRenderer

protected LegendRenderer legendRenderer
Used to paint the legend.


OUTSIDE

public static final int OUTSIDE
Labels display outside pie edge next to each sample.

See Also:
Constant Field Values

overlayRenderers

protected java.util.Vector overlayRenderers
This contains any overlayed chart renderers.


parentRenderer

protected ChartRenderer parentRenderer
The parent of the overlay chart.


POINTING

public static final int POINTING
Lines point to the corresponding slices.

See Also:
Constant Field Values

VERTICAL

public static final int VERTICAL
Vertical bar alignment.

See Also:
Constant Field Values
Constructor Detail

ChartRenderer

public ChartRenderer()
Default constructor.


ChartRenderer

public ChartRenderer(GenericChart chart)
Creates a chart renderer for the given chart.

Parameters:
chart - The chart object.
Method Detail

addOverlayRenderer

public int addOverlayRenderer(ChartRenderer renderer)
Adds a new overlay renderer.

Parameters:
renderer - The renderer the chart that will be layed over the chart this renderer is attached to.
Returns:
The index of this overlay renderer, the first one has index 0.

calculateChartData

protected abstract void calculateChartData(java.awt.Rectangle gridBounds,
                                           java.awt.Rectangle dataBounds)
Calculates the data used for the chart.

Parameters:
gridBounds - The chart grid bounds to paint data within.
dataBounds - The scrolled bounds to calculate the data within.

calculateGraphBounds

protected abstract void calculateGraphBounds(java.awt.Rectangle bounds)
This method returns the bounding box for the chart grid and has to be implemented by the subclass.


calculateOverlayBounds

protected void calculateOverlayBounds(ChartRenderer overlay,
                                      int index,
                                      java.awt.Rectangle gridBounds,
                                      java.awt.Rectangle dataBounds)
Calculates grid bounds and data bounds for the given overlay. Takes in account 3D effect. References to the grid bounds and data bounds rectangles should be provided.

Parameters:
overlay - The overlay chart renderer to calculate bounds for.
index - Index of the overlay chart.
gridBounds - Original grid bounds from the base chart.
dataBounds - Original data bounds from the base chart.

checkDataIntegrity

protected abstract void checkDataIntegrity()
This method is called each time the sample count or series count changes, and ensures that all the data has the right size. Any class that overrides this method must remember to call super.checkDataIntegrity().


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().

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

getLineChartBounds

protected java.awt.Rectangle getLineChartBounds(java.awt.Rectangle dataBounds)
Calculates new bounds to be used for line charts. Should be overrided by BarChartRenderer in order to calculate bounds for the overlayed LineChartRenderer.

Parameters:
dataBounds - The original data bounds.

getOverlayRenderer

public ChartRenderer getOverlayRenderer(int index)
Gets the specified overlay chart.

Parameters:
index - The index of the overlay chart.
Returns:
The chart, or null if not found.

getSampleCenter

protected abstract java.awt.Point getSampleCenter(int sample,
                                                  int serie)
Calculates the center point of the sample. Must be implemented by subclasses.

Parameters:
sample - Index of the sample.
serie - Serie of the sample.
Returns:
The center point of the sample

isAnyBelowLabelsOn

protected boolean isAnyBelowLabelsOn()
Returns true if any labels below the grid should be painted.


isAnyFloatingLabelsOn

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

Parameters:
serie - The serie to check floating labels for. Should be set to -1 when checking for all series.

paintFloatingLabel

protected abstract 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.

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 gridBounds)
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.

Parameters:
g - The graphics context used to paint with.
gridBounds - The chart grid bounds.
Returns:
True if painted, false if nothing was painted.

paintGrid

protected void paintGrid(java.awt.Graphics g,
                         Grid grid,
                         java.awt.Rectangle gridBounds)
This method is called when the chart grid should be rendered. It does no paint the grid itself but provides this possibility to the subclasses. The charts with grid should override this method and paint the grid by themselves.

Parameters:
g - The graphic context used to paint with.
grid - The Grid object to be painted.
gridBounds - The given bounding rectangle.

paintSampleHighlight

protected void paintSampleHighlight(java.awt.Graphics g,
                                    int serie,
                                    int sample,
                                    int x,
                                    int y,
                                    java.awt.Color color)
Paints the sample highlight for a point.

Parameters:
g - The graphics context used to paint with.
serie - The index of the serie.
x - The x-position of the sample.
y - The y-position of the sample.
color - The color of the sample highlight.

removeExternalGraphics

public void removeExternalGraphics()
Removes external graphics context if there is one.

See Also:
setExternalGraphics(java.awt.Graphics, java.awt.Image)

render

protected abstract void render(java.awt.Graphics g)
This method is called by paint(), and has to be implemented by the subclass to render the chart.

Parameters:
g - The graphics context used to paint with.
See Also:
GenericChart.paint(java.awt.Graphics)

render

protected void render(java.awt.Graphics g,
                      boolean offscreenOn)
Renders the chart according to the set attributes, the current features that are turned on and GUI state values.


renderData

protected abstract void renderData(java.awt.Graphics g,
                                   java.awt.Rectangle gridBounds,
                                   java.awt.Rectangle dataBounds)
This method renders the data (bars, lines, pies).

Parameters:
g - The graphics context used to paint with.
gridBounds - The chart grid bounds to paint data within.
dataBounds - The scrolled bounds to calculate the data within.

reset

public void reset()
Resets the chart data and features.


setExternalGraphics

public void setExternalGraphics(java.awt.Graphics g,
                                java.awt.Image image)
Sets an external graphics context to paint with. The size of the image must at least as large as the largest chart that will be displayed.

Parameters:
g - The graphics context used for painting.
image - The image to which graphics context belongs. See here for an example.

setOverlayRenderer

public void setOverlayRenderer(int index,
                               ChartRenderer renderer)
Sets the specified overlay renderer.

Parameters:
renderer - The renderer to set for this overlay position.
Throws:
java.lang.IllegalArgumentException - If the index is invalid.