com.jrefinery.chart
Class Plot

java.lang.Object
  extended by com.jrefinery.chart.Plot
All Implemented Interfaces:
AxisConstants, com.jrefinery.chart.event.AxisChangeListener, DatasetChangeListener
Direct Known Subclasses:
CategoryPlot, CompassPlot, MeterPlot, PiePlot, ThermometerPlot, XYPlot

public abstract class Plot
extends java.lang.Object
implements com.jrefinery.chart.event.AxisChangeListener, DatasetChangeListener, AxisConstants

The base class for all plots in JFreeChart. The JFreeChart class delegates the drawing of axes and data to the plot. This base class provides facilities common to most plot types.


Field Summary
protected  float backgroundAlpha
          The alpha transparency for the background paint.
protected  java.awt.Image backgroundImage
          An optional image for the plot background.
protected  java.awt.Paint backgroundPaint
          An optional color used to fill the plot background.
protected  Dataset dataset
          The data.
protected static float DEFAULT_BACKGROUND_ALPHA
          The default background alpha transparency.
protected static java.awt.Paint DEFAULT_BACKGROUND_PAINT
          The default background color.
protected static float DEFAULT_FOREGROUND_ALPHA
          The default foreground alpha transparency.
protected static java.awt.Insets DEFAULT_INSETS
          The default insets.
protected static java.awt.Paint DEFAULT_OUTLINE_PAINT
          The default outline color.
protected static java.awt.Stroke DEFAULT_OUTLINE_STROKE
          The default outline stroke.
protected  int firstSeriesIndex
          The index of the first series.
protected  float foregroundAlpha
          The alpha-transparency for the plot.
protected  java.awt.Insets insets
          Amount of blank space around the plot area.
protected  java.util.List listeners
          Storage for registered change listeners.
protected static int MINIMUM_HEIGHT_TO_DRAW
          The minimum height for the plot, any less space than this and it should not be drawn (not fully implemented.
protected static int MINIMUM_WIDTH_TO_DRAW
          The minimum width for the plot, any less space than this and it should not be drawn (not fully implemented).
protected  java.awt.Paint outlinePaint
          The Paint used to draw an outline around the plot.
protected  java.awt.Stroke outlineStroke
          The Stroke used to draw an outline around the plot.
protected  java.awt.Paint[] seriesOutlinePaint
          Paint objects used to draw the outline of each series in the chart.
protected  java.awt.Stroke[] seriesOutlineStroke
          Stroke objects used to draw the outline of each series in the chart.
protected  java.awt.Paint[] seriesPaint
          Paint objects used to color each series in the chart.
protected  java.awt.Stroke[] seriesStroke
          Stroke objects used to draw each series in the chart.
protected  ShapeFactory shapeFactory
          Factory for shapes used to represent data points
static java.lang.Number ZERO
          Useful constant representing zero.
 
Fields inherited from interface com.jrefinery.chart.AxisConstants
DEFAULT_AXIS_LABEL_FONT, DEFAULT_AXIS_LABEL_INSETS, DEFAULT_AXIS_LABEL_PAINT, DEFAULT_TICK_LABEL_FONT, DEFAULT_TICK_LABEL_INSETS, DEFAULT_TICK_LABEL_PAINT, DEFAULT_TICK_STROKE
 
Constructor Summary
protected Plot()
          Constructs a new plot with the specified axes.
protected Plot(Dataset data)
           
protected Plot(Dataset data, java.awt.Insets insets, java.awt.Paint backgroundPaint, java.awt.Image backgroundImage, float backgroundAlpha, java.awt.Stroke outlineStroke, java.awt.Paint outlinePaint, float foregroundAlpha)
          Constructs a new plot.
 
Method Summary
 void addChangeListener(com.jrefinery.chart.event.PlotChangeListener listener)
          Registers an object for notification of changes to the plot.
 void axisChanged(com.jrefinery.chart.event.AxisChangeEvent event)
          Receives notification of a change to one of the plot's axes.
 void datasetChanged(DatasetChangeEvent event)
          Receives notification of a change to the plot's dataset.
protected abstract  void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea, ChartRenderingInfo info)
          Draws the plot on a Java 2D graphics device (such as the screen or a printer).
 void drawOutlineAndBackground(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)
          Draw the plot outline and background.
 float getBackgroundAlpha()
          Returns the alpha transparency of the plot area background.
 java.awt.Paint getBackgroundPaint()
          Returns the background color of the plot area.
 Dataset getDataset()
          Returns the dataset for the plot.
 int getFirstSeriesIndex()
          Returns the index of the first series.
 float getForegroundAlpha()
          Returns the alpha-transparency for the plot foreground.
 java.awt.Insets getInsets()
          Returns the insets for the plot area.
abstract  java.util.List getLegendItemLabels()
           
 java.awt.Paint getOutlinePaint()
          Returns the color used to draw the outline of the plot area.
 java.awt.Stroke getOutlineStroke()
          Returns the pen/brush used to outline the plot area.
abstract  java.lang.String getPlotType()
          Returns a short string describing the plot type.
 java.awt.Paint getSeriesOutlinePaint(int index)
          Returns the Paint used to outline any shapes for the specified series.
 java.awt.Stroke getSeriesOutlineStroke(int index)
          Returns the Stroke used to outline any shapes for the specified series.
 java.awt.Paint getSeriesPaint(int index)
          Returns a Paint object used as the main color for a series.
 java.awt.Stroke getSeriesStroke(int index)
          Returns the Stroke used to draw any shapes for a series.
 java.awt.Shape getShape(int series, int item, double x, double y, double scale)
          Returns a Shape that can be used in plotting data.
 java.awt.Shape getShape(int series, java.lang.Object category, double x, double y, double scale)
          Returns a Shape that can be used in plotting data.
 ShapeFactory getShapeFactory()
          Returns the object used to generate shapes for marking data points
 void handleClick(int x, int y, ChartRenderingInfo info)
          Handles a 'click' on the plot.
 boolean isSubplot()
          Returns true if this plot is part of a combined plot structure, and false otherwise.
 void notifyListeners(com.jrefinery.chart.event.PlotChangeEvent event)
          Notifies all registered listeners that the plot has been modified.
 void removeChangeListener(com.jrefinery.chart.event.PlotChangeListener listener)
          Unregisters an object for notification of changes to the plot.
 void setBackgroundAlpha(float alpha)
          Sets the alpha transparency of the plot area background, and notifies registered listeners that the plot has been modified.
 void setBackgroundImage(java.awt.Image image)
          Sets the background image for the plot.
 void setBackgroundPaint(java.awt.Paint paint)
          Sets the background color of the plot area, and notifies registered listeners that the plot has been modified.
 void setDataset(Dataset data)
          Sets the data for the chart, replacing any existing data.
 void setFirstSeriesIndex(int index)
          Sets the index of the first series.
 void setForegroundAlpha(float alpha)
          Sets the alpha-transparency for the plot.
 void setInsets(java.awt.Insets insets)
          Sets the insets for the plot and notifies registered listeners that the plot has been modified.
 void setOutlinePaint(java.awt.Paint paint)
          Sets the color of the outline of the plot area, and notifies registered listeners that the Plot has been modified.
 void setOutlineStroke(java.awt.Stroke stroke)
          Sets the pen/brush used to outline the plot area, and notifies registered listeners that the plot has been modified.
 void setSeriesOutlinePaint(java.awt.Paint[] paint)
          Sets the paint used to outline any shapes representing series, and notifies registered listeners that the chart has been modified.
 void setSeriesOutlineStroke(int index, java.awt.Stroke stroke)
          Sets the stroke used to draw any shapes representing a specific series, and notifies registered listeners that the chart has been modified.
 void setSeriesOutlineStroke(java.awt.Stroke[] stroke)
          Sets the stroke used to draw any shapes representing series, and notifies registered listeners that the chart has been modified.
 void setSeriesPaint(int index, java.awt.Paint paint)
          Sets the paint used to color any shapes representing a specific series, and notifies registered listeners that the plot has been modified.
 void setSeriesPaint(java.awt.Paint[] paint)
          Sets the paint used to color any shapes representing series, and notifies registered listeners that the plot has been modified.
 void setSeriesStroke(int index, java.awt.Stroke stroke)
          Sets the stroke used to draw any shapes representing a specific series, and notifies registered listeners that the chart has been modified.
 void setSeriesStroke(java.awt.Stroke[] stroke)
          Sets the stroke used to draw any shapes representing series, and notifies registered listeners that the chart has been modified.
 void setShapeFactory(ShapeFactory factory)
          Sets the object used to generate shapes for marking data points
abstract  void zoom(double percent)
          Performs a zoom on the plot.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZERO

public static final java.lang.Number ZERO
Useful constant representing zero.


DEFAULT_INSETS

protected static final java.awt.Insets DEFAULT_INSETS
The default insets.


DEFAULT_OUTLINE_STROKE

protected static final java.awt.Stroke DEFAULT_OUTLINE_STROKE
The default outline stroke.


DEFAULT_OUTLINE_PAINT

protected static final java.awt.Paint DEFAULT_OUTLINE_PAINT
The default outline color.


DEFAULT_FOREGROUND_ALPHA

protected static final float DEFAULT_FOREGROUND_ALPHA
The default foreground alpha transparency.

See Also:
Constant Field Values

DEFAULT_BACKGROUND_ALPHA

protected static final float DEFAULT_BACKGROUND_ALPHA
The default background alpha transparency.

See Also:
Constant Field Values

DEFAULT_BACKGROUND_PAINT

protected static final java.awt.Paint DEFAULT_BACKGROUND_PAINT
The default background color.


MINIMUM_WIDTH_TO_DRAW

protected static final int MINIMUM_WIDTH_TO_DRAW
The minimum width for the plot, any less space than this and it should not be drawn (not fully implemented).

See Also:
Constant Field Values

MINIMUM_HEIGHT_TO_DRAW

protected static final int MINIMUM_HEIGHT_TO_DRAW
The minimum height for the plot, any less space than this and it should not be drawn (not fully implemented.

See Also:
Constant Field Values

dataset

protected Dataset dataset
The data.


firstSeriesIndex

protected int firstSeriesIndex
The index of the first series. This defaults to zero...when you combine plots you might want to set this to a higher index to ensure that series colors are different.


insets

protected java.awt.Insets insets
Amount of blank space around the plot area.


outlineStroke

protected java.awt.Stroke outlineStroke
The Stroke used to draw an outline around the plot.


outlinePaint

protected java.awt.Paint outlinePaint
The Paint used to draw an outline around the plot.


backgroundPaint

protected java.awt.Paint backgroundPaint
An optional color used to fill the plot background.


backgroundImage

protected java.awt.Image backgroundImage
An optional image for the plot background.


foregroundAlpha

protected float foregroundAlpha
The alpha-transparency for the plot.


backgroundAlpha

protected float backgroundAlpha
The alpha transparency for the background paint.


seriesPaint

protected java.awt.Paint[] seriesPaint
Paint objects used to color each series in the chart.


seriesStroke

protected java.awt.Stroke[] seriesStroke
Stroke objects used to draw each series in the chart.


seriesOutlinePaint

protected java.awt.Paint[] seriesOutlinePaint
Paint objects used to draw the outline of each series in the chart.


seriesOutlineStroke

protected java.awt.Stroke[] seriesOutlineStroke
Stroke objects used to draw the outline of each series in the chart.


listeners

protected java.util.List listeners
Storage for registered change listeners.


shapeFactory

protected ShapeFactory shapeFactory
Factory for shapes used to represent data points

Constructor Detail

Plot

protected Plot()
Constructs a new plot with the specified axes.

Parameters:
data - The dataset.
horizontalAxis - The horizontal axis.
verticalAxis - The vertical axis.

Plot

protected Plot(Dataset data)

Plot

protected Plot(Dataset data,
               java.awt.Insets insets,
               java.awt.Paint backgroundPaint,
               java.awt.Image backgroundImage,
               float backgroundAlpha,
               java.awt.Stroke outlineStroke,
               java.awt.Paint outlinePaint,
               float foregroundAlpha)
Constructs a new plot.

Parameters:
data - The dataset.
insets - Amount of blank space around the plot area.
backgroundPaint - An optional color for the plot's background.
backgroundImage - An optional image for the plot's background.
backgroundAlpha - Alpha-transparency for the plot's background.
outlineStroke - The Stroke used to draw an outline around the plot.
outlinePaint - The color used to draw an outline around the plot.
foregroundAlpha - The alpha-transparency for the plot foreground.
Method Detail

getPlotType

public abstract java.lang.String getPlotType()
Returns a short string describing the plot type.

Note: this gets used in the chart property editing user interface, but there needs to be a better mechanism for identifying the plot type.

Returns:
A short string describing the plot type.

getDataset

public Dataset getDataset()
Returns the dataset for the plot.

Returns:
The dataset.

setDataset

public void setDataset(Dataset data)
Sets the data for the chart, replacing any existing data. Registered listeners are notified that the data has been modified.

The plot is automatically registered with the new dataset, to listen for any changes.

Parameters:
data - The new dataset.

isSubplot

public boolean isSubplot()
Returns true if this plot is part of a combined plot structure, and false otherwise.

Returns:
A flag indicating if this plot is a subplot.

getFirstSeriesIndex

public int getFirstSeriesIndex()
Returns the index of the first series.

Returns:
The index.

setFirstSeriesIndex

public void setFirstSeriesIndex(int index)
Sets the index of the first series. For a single plot, this defaults to zero, but when you combine plots this will be set to a higher value to ensure that all series have a unique index (and therefore color).

Parameters:
index - The new index.

getInsets

public java.awt.Insets getInsets()
Returns the insets for the plot area.

Returns:
The insets.

setInsets

public void setInsets(java.awt.Insets insets)
Sets the insets for the plot and notifies registered listeners that the plot has been modified.

Parameters:
insets - The new insets.

getBackgroundPaint

public java.awt.Paint getBackgroundPaint()
Returns the background color of the plot area.

Returns:
The background color (null possible).

setBackgroundPaint

public void setBackgroundPaint(java.awt.Paint paint)
Sets the background color of the plot area, and notifies registered listeners that the plot has been modified.

Parameters:
paint - The new background color (null permitted).

getBackgroundAlpha

public float getBackgroundAlpha()
Returns the alpha transparency of the plot area background.

Returns:
The alpha transparency.

setBackgroundAlpha

public void setBackgroundAlpha(float alpha)
Sets the alpha transparency of the plot area background, and notifies registered listeners that the plot has been modified.

Parameters:
alpha - The new alpha value.

setBackgroundImage

public void setBackgroundImage(java.awt.Image image)
Sets the background image for the plot.

Parameters:
image - The background image.

getOutlineStroke

public java.awt.Stroke getOutlineStroke()
Returns the pen/brush used to outline the plot area.

Returns:
The outline stroke (possibly null).

setOutlineStroke

public void setOutlineStroke(java.awt.Stroke stroke)
Sets the pen/brush used to outline the plot area, and notifies registered listeners that the plot has been modified.

Parameters:
stroke - The new outline pen/brush (null permitted).

getOutlinePaint

public java.awt.Paint getOutlinePaint()
Returns the color used to draw the outline of the plot area.

Returns:
The color (possibly null).

setOutlinePaint

public void setOutlinePaint(java.awt.Paint paint)
Sets the color of the outline of the plot area, and notifies registered listeners that the Plot has been modified.

Parameters:
paint - The new outline paint (null permitted).

getForegroundAlpha

public float getForegroundAlpha()
Returns the alpha-transparency for the plot foreground.

Returns:
The alpha-transparency.

setForegroundAlpha

public void setForegroundAlpha(float alpha)
Sets the alpha-transparency for the plot.

Parameters:
alpha - The new alpha transparency.

getLegendItemLabels

public abstract java.util.List getLegendItemLabels()

getSeriesPaint

public java.awt.Paint getSeriesPaint(int index)
Returns a Paint object used as the main color for a series.

Parameters:
index - The series index (zero-based).

setSeriesPaint

public void setSeriesPaint(java.awt.Paint[] paint)
Sets the paint used to color any shapes representing series, and notifies registered listeners that the plot has been modified.

Parameters:
paint - An array of Paint objects used to color series.

setSeriesPaint

public void setSeriesPaint(int index,
                           java.awt.Paint paint)
Sets the paint used to color any shapes representing a specific series, and notifies registered listeners that the plot has been modified.

Parameters:
index - The series index (zero-based)
paint - An array of Paint objects used to color series.

getSeriesStroke

public java.awt.Stroke getSeriesStroke(int index)
Returns the Stroke used to draw any shapes for a series.

Parameters:
index - The series (zero-based index).

setSeriesStroke

public void setSeriesStroke(java.awt.Stroke[] stroke)
Sets the stroke used to draw any shapes representing series, and notifies registered listeners that the chart has been modified.

Parameters:
stroke - An array of Stroke objects used to draw series.

setSeriesStroke

public void setSeriesStroke(int index,
                            java.awt.Stroke stroke)
Sets the stroke used to draw any shapes representing a specific series, and notifies registered listeners that the chart has been modified.

Parameters:
index - The series index (zero-based)
stroke - An array of Stroke objects used to draw series.

getSeriesOutlinePaint

public java.awt.Paint getSeriesOutlinePaint(int index)
Returns the Paint used to outline any shapes for the specified series.

Parameters:
index - The index of the series of interest (zero-based);

setSeriesOutlinePaint

public void setSeriesOutlinePaint(java.awt.Paint[] paint)
Sets the paint used to outline any shapes representing series, and notifies registered listeners that the chart has been modified.

Parameters:
paint - An array of Paint objects for drawing the outline of series shapes;

getSeriesOutlineStroke

public java.awt.Stroke getSeriesOutlineStroke(int index)
Returns the Stroke used to outline any shapes for the specified series.

Parameters:
index - The index of the series of interest (zero-based);

setSeriesOutlineStroke

public void setSeriesOutlineStroke(java.awt.Stroke[] stroke)
Sets the stroke used to draw any shapes representing series, and notifies registered listeners that the chart has been modified.

Parameters:
stroke - An array of Stroke objects;

setSeriesOutlineStroke

public void setSeriesOutlineStroke(int index,
                                   java.awt.Stroke stroke)
Sets the stroke used to draw any shapes representing a specific series, and notifies registered listeners that the chart has been modified.

Parameters:
index - The series index (zero-based)
stroke - An array of Stroke objects;

getShapeFactory

public ShapeFactory getShapeFactory()
Returns the object used to generate shapes for marking data points


setShapeFactory

public void setShapeFactory(ShapeFactory factory)
Sets the object used to generate shapes for marking data points

Parameters:
factory - The new shape factory.

getShape

public java.awt.Shape getShape(int series,
                               int item,
                               double x,
                               double y,
                               double scale)
Returns a Shape that can be used in plotting data. Used in XYPlots.


getShape

public java.awt.Shape getShape(int series,
                               java.lang.Object category,
                               double x,
                               double y,
                               double scale)
Returns a Shape that can be used in plotting data. Should allow a plug-in object to determine the shape...


notifyListeners

public void notifyListeners(com.jrefinery.chart.event.PlotChangeEvent event)
Notifies all registered listeners that the plot has been modified.

Parameters:
event - Information about the change event.

addChangeListener

public void addChangeListener(com.jrefinery.chart.event.PlotChangeListener listener)
Registers an object for notification of changes to the plot.

Parameters:
listener - The object to be registered.

removeChangeListener

public void removeChangeListener(com.jrefinery.chart.event.PlotChangeListener listener)
Unregisters an object for notification of changes to the plot.

Parameters:
listener - The object to be unregistered.

draw

protected abstract void draw(java.awt.Graphics2D g2,
                             java.awt.geom.Rectangle2D plotArea,
                             ChartRenderingInfo info)
Draws the plot on a Java 2D graphics device (such as the screen or a printer).

This class does not store any information about where the individual items that make up the plot are actually drawn. If you want to collect this information, pass in a ChartRenderingInfo object. After the drawing is complete, the info object will contain lots of information about the chart. If you don't want the information, pass in null. *

Parameters:
g2 - The graphics device.
plotArea - The area within which the plot should be drawn.
info - An object for collecting information about the drawing of the chart.

drawOutlineAndBackground

public void drawOutlineAndBackground(java.awt.Graphics2D g2,
                                     java.awt.geom.Rectangle2D area)
Draw the plot outline and background.

Parameters:
g2 - The graphics device.
area - The area within which the plot should be drawn.

handleClick

public void handleClick(int x,
                        int y,
                        ChartRenderingInfo info)
Handles a 'click' on the plot. Since the plot does not maintain any information about where it has been drawn, the plot area is supplied as an argument.

Parameters:
x - The x coordinate.
y - The y coordinate.
plotArea - The area in which the plot is assumed to be drawn.

zoom

public abstract void zoom(double percent)
Performs a zoom on the plot. Subclasses will implement a behaviour that is appropriate to the type of plot.

Parameters:
The - zoom percentage.

axisChanged

public void axisChanged(com.jrefinery.chart.event.AxisChangeEvent event)
Receives notification of a change to one of the plot's axes.

Specified by:
axisChanged in interface com.jrefinery.chart.event.AxisChangeListener
Parameters:
event - Information about the event (not used here).

datasetChanged

public void datasetChanged(DatasetChangeEvent event)
Receives notification of a change to the plot's dataset.

The plot reacts by passing on a plot change event to all registered listeners.

Specified by:
datasetChanged in interface DatasetChangeListener
Parameters:
event - Information about the event (not used here).


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.