org.jfree.chart.renderer
Class AbstractCategoryItemRenderer

java.lang.Object
  extended byorg.jfree.chart.renderer.AbstractRenderer
      extended byorg.jfree.chart.renderer.AbstractCategoryItemRenderer
All Implemented Interfaces:
CategoryItemRenderer, java.lang.Cloneable, java.io.Serializable
Direct Known Subclasses:
AreaRenderer, BarRenderer, BoxAndWhiskerRenderer, LevelRenderer, LineAndShapeRenderer, MinMaxCategoryRenderer

public abstract class AbstractCategoryItemRenderer
extends AbstractRenderer
implements CategoryItemRenderer, java.lang.Cloneable, java.io.Serializable

An abstract base class that you can use to implement a new CategoryItemRenderer.

When you create a new CategoryItemRenderer you are not required to extend this class, but it makes the job easier.

Author:
David Gilbert
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jfree.chart.renderer.AbstractRenderer
DEFAULT_OUTLINE_PAINT, DEFAULT_OUTLINE_STROKE, DEFAULT_PAINT, DEFAULT_SHAPE, DEFAULT_STROKE, DEFAULT_VALUE_LABEL_FONT, DEFAULT_VALUE_LABEL_PAINT, ZERO
 
Constructor Summary
protected AbstractCategoryItemRenderer()
          Creates a new renderer with no tool tip generator and no URL generator.
 
Method Summary
 java.lang.Object clone()
          Returns an independent copy of the renderer.
 void drawBackground(java.awt.Graphics2D g2, CategoryPlot plot, java.awt.geom.Rectangle2D dataArea)
          Draws a background for the data area.
 void drawDomainGridline(java.awt.Graphics2D g2, CategoryPlot plot, java.awt.geom.Rectangle2D dataArea, double value)
          Draws a grid line against the domain axis.
protected  void drawItemLabel(java.awt.Graphics2D g2, PlotOrientation orientation, CategoryDataset dataset, int row, int column, double x, double y, boolean negative)
          Draws an item label.
 void drawOutline(java.awt.Graphics2D g2, CategoryPlot plot, java.awt.geom.Rectangle2D dataArea)
          Draws an outline for the data area.
 void drawRangeGridline(java.awt.Graphics2D g2, CategoryPlot plot, ValueAxis axis, java.awt.geom.Rectangle2D dataArea, double value)
          Draws a grid line against the range axis.
 void drawRangeMarker(java.awt.Graphics2D g2, CategoryPlot plot, ValueAxis axis, Marker marker, java.awt.geom.Rectangle2D dataArea)
          Draws a marker for the range axis.
 boolean equals(java.lang.Object obj)
          Tests this renderer for equality with another object.
 CategoryItemLabelGenerator getBaseItemLabelGenerator()
          Returns the base item label generator.
 CategoryURLGenerator getBaseItemURLGenerator()
          Returns the base item URL generator.
 int getColumnCount()
          Returns the number of columns in the dataset.
protected  CategoryDataset getDataset(CategoryPlot plot, java.lang.Integer index)
          Returns a dataset for a plot.
protected  CategoryAxis getDomainAxis(CategoryPlot plot, java.lang.Integer index)
          Returns a domain axis for a plot.
 DrawingSupplier getDrawingSupplier()
          Returns the drawing supplier from the plot.
 double getItemLabelAnchorOffset()
          Returns the item label anchor offset.
 CategoryItemLabelGenerator getItemLabelGenerator(int row, int column)
          Returns the label generator for a data item.
 CategoryURLGenerator getItemURLGenerator(int row, int column)
          Returns the URL generator for a data item.
 LegendItem getLegendItem(int datasetIndex, int series)
          Returns a legend item for a series.
 CategoryPlot getPlot()
          Returns the plot that the renderer is currently assigned to.
protected  ValueAxis getRangeAxis(CategoryPlot plot, java.lang.Integer index)
          Returns a range axis for a plot.
 RangeType getRangeType()
          Returns the range type for the renderer.
 int getRowCount()
          Returns the number of rows in the dataset.
 CategoryItemLabelGenerator getSeriesItemLabelGenerator(int series)
          Returns the label generator for a series.
 CategoryURLGenerator getSeriesItemURLGenerator(int series)
          Returns the URL generator for a series.
 int hashCode()
          Returns a hash code for the renderer.
 CategoryItemRendererState initialise(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, CategoryPlot plot, java.lang.Integer index, PlotRenderingInfo info)
          Initialises the renderer and returns a state object that will be used for the remainder of the drawing process for a single chart.
 void setBaseItemLabelGenerator(CategoryItemLabelGenerator generator)
          Sets the base item label generator.
 void setBaseItemURLGenerator(CategoryURLGenerator generator)
          Sets the base item URL generator.
 void setItemLabelAnchorOffset(double offset)
          Sets the item label anchor offset.
 void setItemLabelGenerator(CategoryItemLabelGenerator generator)
          Sets the item label generator for ALL series.
 void setItemURLGenerator(CategoryURLGenerator generator)
          Sets the item URL generator for ALL series.
 void setPlot(CategoryPlot plot)
          Sets the plot that the renderer is currently assigned to.
 void setSeriesItemLabelGenerator(int series, CategoryItemLabelGenerator generator)
          Sets the label generator for a series.
 void setSeriesItemURLGenerator(int series, CategoryURLGenerator generator)
          Sets the URL generator for a series.
 
Methods inherited from class org.jfree.chart.renderer.AbstractRenderer
addChangeListener, addPropertyChangeListener, createTransformedShape, firePropertyChanged, getBaseItemLabelAnchor, getBaseItemLabelAngle, getBaseItemLabelFont, getBaseItemLabelPaint, getBaseItemLabelRotationAnchor, getBaseItemLabelsVisible, getBaseItemLabelTextAnchor, getBaseNegativeItemLabelPosition, getBaseOutlinePaint, getBaseOutlineStroke, getBasePaint, getBasePositiveItemLabelPosition, getBaseShape, getBaseStroke, getItemLabelAnchor, getItemLabelAngle, getItemLabelFont, getItemLabelPaint, getItemLabelRotationAnchor, getItemLabelTextAnchor, getItemOutlinePaint, getItemOutlineStroke, getItemPaint, getItemShape, getItemStroke, getNegativeItemLabelPosition, getNegativeItemLabelPosition, getPositiveItemLabelPosition, getPositiveItemLabelPosition, getSeriesItemLabelAnchor, getSeriesItemLabelAngle, getSeriesItemLabelFont, getSeriesItemLabelPaint, getSeriesItemLabelRotationAnchor, getSeriesItemLabelTextAnchor, getSeriesNegativeItemLabelPosition, getSeriesOutlinePaint, getSeriesOutlineStroke, getSeriesPaint, getSeriesPositiveItemLabelPosition, getSeriesShape, getSeriesStroke, isItemLabelVisible, isSeriesItemLabelsVisible, notifyListeners, removeChangeListener, removePropertyChangeListener, setBaseAngle, setBaseItemLabelAnchor, setBaseItemLabelFont, setBaseItemLabelFont, setBaseItemLabelPaint, setBaseItemLabelPaint, setBaseItemLabelRotationAnchor, setBaseItemLabelsVisible, setBaseItemLabelsVisible, setBaseItemLabelTextAnchor, setBaseNegativeItemLabelPosition, setBaseNegativeItemLabelPosition, setBaseOutlinePaint, setBaseOutlinePaint, setBaseOutlineStroke, setBaseOutlineStroke, setBasePaint, setBasePaint, setBasePositiveItemLabelPosition, setBasePositiveItemLabelPosition, setBaseShape, setBaseShape, setBaseStroke, setBaseStroke, setItemLabelAnchor, setItemLabelAngle, setItemLabelFont, setItemLabelFont, setItemLabelPaint, setItemLabelPaint, setItemLabelRotationAnchor, setItemLabelsVisible, setItemLabelsVisible, setItemLabelsVisible, setItemLabelTextAnchor, setNegativeItemLabelPosition, setNegativeItemLabelPosition, setOutlinePaint, setOutlinePaint, setOutlineStroke, setOutlineStroke, setPaint, setPaint, setPositiveItemLabelPosition, setPositiveItemLabelPosition, setSeriesAngle, setSeriesItemLabelAnchor, setSeriesItemLabelFont, setSeriesItemLabelFont, setSeriesItemLabelPaint, setSeriesItemLabelPaint, setSeriesItemLabelRotationAnchor, setSeriesItemLabelsVisible, setSeriesItemLabelsVisible, setSeriesItemLabelTextAnchor, setSeriesNegativeItemLabelPosition, setSeriesNegativeItemLabelPosition, setSeriesOutlinePaint, setSeriesOutlinePaint, setSeriesOutlineStroke, setSeriesOutlineStroke, setSeriesPaint, setSeriesPaint, setSeriesPositiveItemLabelPosition, setSeriesPositiveItemLabelPosition, setSeriesShape, setSeriesShape, setSeriesStroke, setSeriesStroke, setShape, setShape, setStroke, setStroke
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jfree.chart.renderer.CategoryItemRenderer
addChangeListener, drawItem, getBaseItemLabelAnchor, getBaseItemLabelFont, getBaseItemLabelTextAnchor, getBaseOutlinePaint, getBaseOutlineStroke, getBasePaint, getBaseShape, getBaseStroke, getItemLabelAnchor, getItemLabelFont, getItemLabelTextAnchor, getItemOutlinePaint, getItemOutlineStroke, getItemPaint, getItemShape, getItemStroke, getNegativeItemLabelPosition, getPositiveItemLabelPosition, getSeriesItemLabelAnchor, getSeriesItemLabelFont, getSeriesItemLabelTextAnchor, getSeriesOutlinePaint, getSeriesOutlineStroke, getSeriesPaint, getSeriesShape, getSeriesStroke, removeChangeListener, setBaseItemLabelAnchor, setBaseItemLabelFont, setBaseItemLabelTextAnchor, setBaseOutlinePaint, setBaseOutlineStroke, setBasePaint, setBaseShape, setBaseStroke, setItemLabelAnchor, setItemLabelFont, setItemLabelsVisible, setItemLabelsVisible, setItemLabelTextAnchor, setNegativeItemLabelPosition, setOutlinePaint, setOutlineStroke, setPositiveItemLabelPosition, setSeriesItemLabelAnchor, setSeriesItemLabelFont, setSeriesItemLabelTextAnchor, setSeriesOutlinePaint, setSeriesOutlineStroke, setSeriesPaint, setSeriesShape, setSeriesStroke, setStroke
 

Constructor Detail

AbstractCategoryItemRenderer

protected AbstractCategoryItemRenderer()
Creates a new renderer with no tool tip generator and no URL generator.

The defaults (no tool tip or URL generators) have been chosen to minimise the processing required to generate a default chart. If you require tool tips or URLs, then you can easily add the required generators.

Method Detail

getPlot

public CategoryPlot getPlot()
Returns the plot that the renderer is currently assigned to.

Specified by:
getPlot in interface CategoryItemRenderer
Returns:
The plot.

setPlot

public void setPlot(CategoryPlot plot)
Sets the plot that the renderer is currently assigned to.

Specified by:
setPlot in interface CategoryItemRenderer
Parameters:
plot - the plot.

getItemLabelGenerator

public CategoryItemLabelGenerator getItemLabelGenerator(int row,
                                                        int column)
Returns the label generator for a data item. This method just calls the getSeriesItemLabelGenerator method, but you can override this behaviour if you want to.

Specified by:
getItemLabelGenerator in interface CategoryItemRenderer
Parameters:
row - the row index (zero based).
column - the column index (zero based).
Returns:
The label generator.

getSeriesItemLabelGenerator

public CategoryItemLabelGenerator getSeriesItemLabelGenerator(int series)
Returns the label generator for a series.

Specified by:
getSeriesItemLabelGenerator in interface CategoryItemRenderer
Parameters:
series - the series index (zero based).
Returns:
The label generator for the series.

setItemLabelGenerator

public void setItemLabelGenerator(CategoryItemLabelGenerator generator)
Sets the item label generator for ALL series.

Specified by:
setItemLabelGenerator in interface CategoryItemRenderer
Parameters:
generator - the generator.

setSeriesItemLabelGenerator

public void setSeriesItemLabelGenerator(int series,
                                        CategoryItemLabelGenerator generator)
Sets the label generator for a series.

Specified by:
setSeriesItemLabelGenerator in interface CategoryItemRenderer
Parameters:
series - the series index (zero based).
generator - the generator.

getBaseItemLabelGenerator

public CategoryItemLabelGenerator getBaseItemLabelGenerator()
Returns the base item label generator.

Specified by:
getBaseItemLabelGenerator in interface CategoryItemRenderer
Returns:
The base item label generator.

setBaseItemLabelGenerator

public void setBaseItemLabelGenerator(CategoryItemLabelGenerator generator)
Sets the base item label generator.

Specified by:
setBaseItemLabelGenerator in interface CategoryItemRenderer
Parameters:
generator - the base item label generator.

getItemURLGenerator

public CategoryURLGenerator getItemURLGenerator(int row,
                                                int column)
Returns the URL generator for a data item. This method just calls the getSeriesItemURLGenerator method, but you can override this behaviour if you want to.

Specified by:
getItemURLGenerator in interface CategoryItemRenderer
Parameters:
row - the row index (zero based).
column - the column index (zero based).
Returns:
The URL generator.

getSeriesItemURLGenerator

public CategoryURLGenerator getSeriesItemURLGenerator(int series)
Returns the URL generator for a series.

Specified by:
getSeriesItemURLGenerator in interface CategoryItemRenderer
Parameters:
series - the series index (zero based).
Returns:
The URL generator for the series.

setItemURLGenerator

public void setItemURLGenerator(CategoryURLGenerator generator)
Sets the item URL generator for ALL series.

Specified by:
setItemURLGenerator in interface CategoryItemRenderer
Parameters:
generator - the generator.

setSeriesItemURLGenerator

public void setSeriesItemURLGenerator(int series,
                                      CategoryURLGenerator generator)
Sets the URL generator for a series.

Specified by:
setSeriesItemURLGenerator in interface CategoryItemRenderer
Parameters:
series - the series index (zero based).
generator - the generator.

getBaseItemURLGenerator

public CategoryURLGenerator getBaseItemURLGenerator()
Returns the base item URL generator.

Specified by:
getBaseItemURLGenerator in interface CategoryItemRenderer
Returns:
The item URL generator.

setBaseItemURLGenerator

public void setBaseItemURLGenerator(CategoryURLGenerator generator)
Sets the base item URL generator.

Specified by:
setBaseItemURLGenerator in interface CategoryItemRenderer
Parameters:
generator - the item URL generator.

getItemLabelAnchorOffset

public double getItemLabelAnchorOffset()
Returns the item label anchor offset.

Returns:
The offset.

setItemLabelAnchorOffset

public void setItemLabelAnchorOffset(double offset)
Sets the item label anchor offset.

Parameters:
offset - the offset.

getRowCount

public int getRowCount()
Returns the number of rows in the dataset. This value is updated in the initialise(java.awt.Graphics2D, java.awt.geom.Rectangle2D, org.jfree.chart.plot.CategoryPlot, java.lang.Integer, org.jfree.chart.plot.PlotRenderingInfo) method.

Returns:
the row count.

getColumnCount

public int getColumnCount()
Returns the number of columns in the dataset. This value is updated in the initialise(java.awt.Graphics2D, java.awt.geom.Rectangle2D, org.jfree.chart.plot.CategoryPlot, java.lang.Integer, org.jfree.chart.plot.PlotRenderingInfo) method.

Returns:
the column count.

initialise

public CategoryItemRendererState initialise(java.awt.Graphics2D g2,
                                            java.awt.geom.Rectangle2D dataArea,
                                            CategoryPlot plot,
                                            java.lang.Integer index,
                                            PlotRenderingInfo info)
Initialises the renderer and returns a state object that will be used for the remainder of the drawing process for a single chart. The state object allows for the fact that the renderer may be used simultaneously by multiple threads (each thread will work with a separate state object).

Stores a reference to the PlotRenderingInfo object (which might be null), and then sets the useCategoriesPaint flag according to the special case conditions a) there is only one series and b) the categoriesPaint array is not null.

Specified by:
initialise in interface CategoryItemRenderer
Parameters:
g2 - the graphics device.
dataArea - the data area.
plot - the plot.
index - the secondary index (null for primary renderer).
info - an object for returning information about the structure of the plot (null permitted).
Returns:
The renderer state.

getRangeType

public RangeType getRangeType()
Returns the range type for the renderer.

The default implementation returns STANDARD, subclasses may override this behaviour.

The CategoryPlot uses this information when auto-calculating the range for the axis.

Specified by:
getRangeType in interface CategoryItemRenderer
Returns:
the range type.

drawBackground

public void drawBackground(java.awt.Graphics2D g2,
                           CategoryPlot plot,
                           java.awt.geom.Rectangle2D dataArea)
Draws a background for the data area. The default implementation just gets the plot to draw the outline, but some renderers will override this behaviour.

Specified by:
drawBackground in interface CategoryItemRenderer
Parameters:
g2 - the graphics device.
plot - the plot.
dataArea - the data area.

drawOutline

public void drawOutline(java.awt.Graphics2D g2,
                        CategoryPlot plot,
                        java.awt.geom.Rectangle2D dataArea)
Draws an outline for the data area. The default implementation just gets the plot to draw the outline, but some renderers will override this behaviour.

Specified by:
drawOutline in interface CategoryItemRenderer
Parameters:
g2 - the graphics device.
plot - the plot.
dataArea - the data area.

drawDomainGridline

public void drawDomainGridline(java.awt.Graphics2D g2,
                               CategoryPlot plot,
                               java.awt.geom.Rectangle2D dataArea,
                               double value)
Draws a grid line against the domain axis.

Note that this default implementation assumes that the horizontal axis is the domain axis. If this is not the case, you will need to override this method.

Specified by:
drawDomainGridline in interface CategoryItemRenderer
Parameters:
g2 - the graphics device.
plot - the plot.
dataArea - the area for plotting data (not yet adjusted for any 3D effect).
value - the Java2D value at which the grid line should be drawn.

drawRangeGridline

public void drawRangeGridline(java.awt.Graphics2D g2,
                              CategoryPlot plot,
                              ValueAxis axis,
                              java.awt.geom.Rectangle2D dataArea,
                              double value)
Draws a grid line against the range axis.

Specified by:
drawRangeGridline in interface CategoryItemRenderer
Parameters:
g2 - the graphics device.
plot - the plot.
axis - the value axis.
dataArea - the area for plotting data (not yet adjusted for any 3D effect).
value - the value at which the grid line should be drawn.

drawRangeMarker

public void drawRangeMarker(java.awt.Graphics2D g2,
                            CategoryPlot plot,
                            ValueAxis axis,
                            Marker marker,
                            java.awt.geom.Rectangle2D dataArea)
Draws a marker for the range axis.

A marker is a constant value, usually represented by a line.

Specified by:
drawRangeMarker in interface CategoryItemRenderer
Parameters:
g2 - the graphics device.
plot - the plot.
axis - the range axis.
marker - the marker to be drawn.
dataArea - the area inside the axes.

getLegendItem

public LegendItem getLegendItem(int datasetIndex,
                                int series)
Returns a legend item for a series.

Specified by:
getLegendItem in interface CategoryItemRenderer
Parameters:
datasetIndex - the dataset index (zero-based).
series - the series index (zero-based).
Returns:
the legend item.

equals

public boolean equals(java.lang.Object obj)
Tests this renderer for equality with another object.

Overrides:
equals in class AbstractRenderer
Parameters:
obj - the object.
Returns:
true or false.

hashCode

public int hashCode()
Returns a hash code for the renderer.

Overrides:
hashCode in class AbstractRenderer
Returns:
The hash code.

getDrawingSupplier

public DrawingSupplier getDrawingSupplier()
Returns the drawing supplier from the plot.

Specified by:
getDrawingSupplier in class AbstractRenderer
Returns:
The drawing supplier (possibly null).

drawItemLabel

protected void drawItemLabel(java.awt.Graphics2D g2,
                             PlotOrientation orientation,
                             CategoryDataset dataset,
                             int row,
                             int column,
                             double x,
                             double y,
                             boolean negative)
Draws an item label.

Parameters:
g2 - the graphics device.
orientation - the orientation.
dataset - the dataset.
row - the row.
column - the column.
x - the x coordinate.
y - the y coordinate.
negative - indicates a negative value (which affects the item label position).

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Returns an independent copy of the renderer.

The plot reference is shallow copied.

Overrides:
clone in class AbstractRenderer
Returns:
A clone.
Throws:
java.lang.CloneNotSupportedException - should not happen.

getDomainAxis

protected CategoryAxis getDomainAxis(CategoryPlot plot,
                                     java.lang.Integer index)
Returns a domain axis for a plot.

Parameters:
plot - the plot.
index - the axis index (null for the primary axis).
Returns:
A domain axis.

getRangeAxis

protected ValueAxis getRangeAxis(CategoryPlot plot,
                                 java.lang.Integer index)
Returns a range axis for a plot.

Parameters:
plot - the plot.
index - the axis index (null for the primary axis).
Returns:
A range axis.

getDataset

protected CategoryDataset getDataset(CategoryPlot plot,
                                     java.lang.Integer index)
Returns a dataset for a plot.

Parameters:
plot - the plot.
index - the dataset index (null for the primary dataset).
Returns:
A dataset.