org.jfree.chart.plot
Class Plot

java.lang.Object
  |
  +--org.jfree.chart.plot.Plot
All Implemented Interfaces:
AxisChangeListener, AxisConstants, DatasetChangeListener, java.util.EventListener, java.io.Serializable
Direct Known Subclasses:
CategoryPlot, CompassPlot, ContourPlot, FastScatterPlot, MeterPlot, PiePlot, ThermometerPlot, XYPlot

public abstract class Plot
extends java.lang.Object
implements AxisChangeListener, DatasetChangeListener, AxisConstants, java.io.Serializable

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.

Author:
David Gilbert
See Also:
Serialized Form

Field Summary
static float DEFAULT_BACKGROUND_ALPHA
          The default background alpha transparency.
static java.awt.Paint DEFAULT_BACKGROUND_PAINT
          The default background color.
static float DEFAULT_FOREGROUND_ALPHA
          The default foreground alpha transparency.
static java.awt.Insets DEFAULT_INSETS
          The default insets.
static java.awt.Paint DEFAULT_OUTLINE_PAINT
          The default outline color.
static java.awt.Stroke DEFAULT_OUTLINE_STROKE
          The default outline stroke.
static int MINIMUM_HEIGHT_TO_DRAW
          The minimum height at which the plot should be drawn.
static int MINIMUM_WIDTH_TO_DRAW
          The minimum width at which the plot should be drawn.
static java.lang.Number ZERO
          Useful constant representing zero.
 
Fields inherited from interface org.jfree.chart.axis.AxisConstants
BOTTOM, DEFAULT_AXIS_LABEL_FONT, DEFAULT_AXIS_LABEL_INSETS, DEFAULT_AXIS_LABEL_PAINT, DEFAULT_AXIS_VISIBLE, DEFAULT_TICK_LABEL_FONT, DEFAULT_TICK_LABEL_INSETS, DEFAULT_TICK_LABEL_PAINT, DEFAULT_TICK_LABELS_VISIBLE, DEFAULT_TICK_MARK_INSIDE_LENGTH, DEFAULT_TICK_MARK_OUTSIDE_LENGTH, DEFAULT_TICK_MARK_PAINT, DEFAULT_TICK_MARK_STROKE, DEFAULT_TICK_MARKS_VISIBLE, LEFT, RIGHT, TOP
 
Constructor Summary
protected Plot(Dataset data)
          Creates a new plot.
 
Method Summary
 void addChangeListener(PlotChangeListener listener)
          Registers an object for notification of changes to the plot.
 void axisChanged(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.
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 drawBackground(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)
          Draw the plot background.
protected  void drawNoDataMessage(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)
          Draws a message to state that there is no data to plot.
 void drawOutline(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)
          Draw the plot outline
 boolean equals(java.lang.Object obj)
          Tests this plot for equality with another object.
 float getBackgroundAlpha()
          Returns the alpha transparency of the plot area background.
 java.awt.Image getBackgroundImage()
          Returns the background image that is used to fill the plot's background area.
 int getBackgroundImageAlignment()
          Returns the background image alignment.
 java.awt.Paint getBackgroundPaint()
          Returns the background color of the plot area.
 double getDataAreaRatio()
          Returns the data area ratio.
 Dataset getDataset()
          Returns the primary dataset for the plot.
 DatasetGroup getDatasetGroup()
          Returns the dataset group for the plot.
 float getForegroundAlpha()
          Returns the alpha-transparency for the plot foreground.
 java.awt.Insets getInsets()
          Returns the insets for the plot area.
 LegendItemCollection getLegendItems()
          Returns the legend items for the plot.
 java.lang.String getNoDataMessage()
          Returns the string that is displayed when the dataset is empty or null.
 java.awt.Font getNoDataMessageFont()
          Returns the font used to display the 'no data' message.
 java.awt.Paint getNoDataMessagePaint()
          Returns the paint used to display the 'no data' message.
protected  int getOppositeAxisLocation(int location)
          Returns the location code for the opposite location to the one specified.
 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.
 Plot getParent()
          Returns the parent plot (or null if this plot is not part of a combined plot).
abstract  java.lang.String getPlotType()
          Returns a short string describing the plot type.
protected  double getRectX(double x, double w1, double w2, int location)
          Adjusts the supplied x-value.
protected  double getRectY(double y, double h1, double h2, int location)
          Adjusts the supplied y-value.
 Plot getRootPlot()
          Returns the root plot.
 Dataset getSecondaryDataset()
          Returns the secondary dataset for the plot.
 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.
 void notifyListeners(PlotChangeEvent event)
          Notifies all registered listeners that the plot has been modified.
 void removeChangeListener(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 setBackgroundImageAlignment(int alignment)
          Sets the background alignment.
 void setBackgroundPaint(java.awt.Paint paint)
          Sets the background color of the plot area.
 void setDataAreaRatio(double ratio)
          Sets the data area ratio.
 void setDataset(Dataset data)
          Sets the primary dataset for the chart, replacing any existing dataset.
protected  void setDatasetGroup(DatasetGroup group)
          Sets the dataset group.
 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 setInsets(java.awt.Insets insets, boolean notify)
          Sets the insets for the plot and, if requested, notifies registered listeners that the plot has been modified.
 void setNoDataMessage(java.lang.String message)
          Sets the message that is displayed when the dataset is empty or null.
 void setNoDataMessageFont(java.awt.Font font)
          Sets the font used to display the 'no data' message.
 void setNoDataMessagePaint(java.awt.Paint paint)
          Sets the paint used to display the 'no data' message.
 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 setParent(Plot parent)
          Sets the parent plot.
 void setSecondaryDataset(Dataset dataset)
          Sets the secondary dataset.
 void zoom(double percent)
          Performs a zoom on the plot.
 
Methods inherited from class java.lang.Object
clone, 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

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


DEFAULT_OUTLINE_STROKE

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


DEFAULT_OUTLINE_PAINT

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


DEFAULT_FOREGROUND_ALPHA

public static final float DEFAULT_FOREGROUND_ALPHA
The default foreground alpha transparency.

See Also:
Constant Field Values

DEFAULT_BACKGROUND_ALPHA

public static final float DEFAULT_BACKGROUND_ALPHA
The default background alpha transparency.

See Also:
Constant Field Values

DEFAULT_BACKGROUND_PAINT

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


MINIMUM_WIDTH_TO_DRAW

public static final int MINIMUM_WIDTH_TO_DRAW
The minimum width at which the plot should be drawn.

See Also:
Constant Field Values

MINIMUM_HEIGHT_TO_DRAW

public static final int MINIMUM_HEIGHT_TO_DRAW
The minimum height at which the plot should be drawn.

See Also:
Constant Field Values
Constructor Detail

Plot

protected Plot(Dataset data)
Creates a new plot.

Parameters:
data - the dataset.
Method Detail

getDatasetGroup

public DatasetGroup getDatasetGroup()
Returns the dataset group for the plot.

Returns:
the dataset group.

setDatasetGroup

protected void setDatasetGroup(DatasetGroup group)
Sets the dataset group.

Parameters:
group - the dataset group.

getDataset

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

Returns:
the dataset.

setDataset

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

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

Parameters:
data - the new dataset (null permitted).

getSecondaryDataset

public Dataset getSecondaryDataset()
Returns the secondary dataset for the plot.

Returns:
the secondary dataset.

setSecondaryDataset

public void setSecondaryDataset(Dataset dataset)
Sets the secondary dataset.

Parameters:
dataset - the dataset.

getNoDataMessage

public java.lang.String getNoDataMessage()
Returns the string that is displayed when the dataset is empty or null.

Returns:
The 'no data' message (null possible).

setNoDataMessage

public void setNoDataMessage(java.lang.String message)
Sets the message that is displayed when the dataset is empty or null.

Parameters:
message - the message (null permitted).

getNoDataMessageFont

public java.awt.Font getNoDataMessageFont()
Returns the font used to display the 'no data' message.

Returns:
the font.

setNoDataMessageFont

public void setNoDataMessageFont(java.awt.Font font)
Sets the font used to display the 'no data' message.

Parameters:
font - the font.

getNoDataMessagePaint

public java.awt.Paint getNoDataMessagePaint()
Returns the paint used to display the 'no data' message.

Returns:
the paint.

setNoDataMessagePaint

public void setNoDataMessagePaint(java.awt.Paint paint)
Sets the paint used to display the 'no data' message.

Parameters:
paint - the paint.

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.

getParent

public Plot getParent()
Returns the parent plot (or null if this plot is not part of a combined plot).

Returns:
the parent plot.

setParent

public void setParent(Plot parent)
Sets the parent plot.

Parameters:
parent - the parent plot.

getRootPlot

public Plot getRootPlot()
Returns the root plot.

Returns:
the root plot.

isSubplot

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

Returns:
true if this plot is part of a combined plot structure.

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.

setInsets

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

Parameters:
insets - the new insets.
notify - a flag that controls whether the registered listeners are notified.

getBackgroundPaint

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

Returns:
The paint (possibly null).

setBackgroundPaint

public void setBackgroundPaint(java.awt.Paint paint)
Sets the background color of the plot area. A PlotChangeEvent is forwarded to all registered listeners.

Parameters:
paint - the paint (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.

getBackgroundImage

public java.awt.Image getBackgroundImage()
Returns the background image that is used to fill the plot's background area.

Returns:
The image (possibly null).

setBackgroundImage

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

Parameters:
image - the image (null permitted).

getBackgroundImageAlignment

public int getBackgroundImageAlignment()
Returns the background image alignment. Alignment constants are defined in the com.jrefinery.ui.Align class in the JCommon class library.

Returns:
The alignment.

setBackgroundImageAlignment

public void setBackgroundImageAlignment(int alignment)
Sets the background alignment.

Alignment options are defined by the Align class.

Parameters:
alignment - the alignment.

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.

getLegendItems

public LegendItemCollection getLegendItems()
Returns the legend items for the plot.

By default, this method returns null. Subclasses should override to return a LegendItemCollection.

Returns:
the legend items for the plot.

addChangeListener

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

Parameters:
listener - the object to be registered.

removeChangeListener

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

Parameters:
listener - the object to be unregistered.

notifyListeners

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

Parameters:
event - information about the change event.

draw

public 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.

drawBackground

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

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

drawOutline

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

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

drawNoDataMessage

protected void drawNoDataMessage(java.awt.Graphics2D g2,
                                 java.awt.geom.Rectangle2D area)
Draws a message to state that there is no data to plot.

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.
info - an object for collecting information about the drawing of the chart.

zoom

public void zoom(double percent)
Performs a zoom on the plot. Subclasses should override if zooming is appropriate for the type of plot.

Parameters:
percent - the zoom percentage.

axisChanged

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

Specified by:
axisChanged in interface 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).

getRectX

protected double getRectX(double x,
                          double w1,
                          double w2,
                          int location)
Adjusts the supplied x-value.

Parameters:
x - the x-value.
w1 - width 1.
w2 - width 2.
location - the location (left or right).
Returns:
the adjusted x-value.

getRectY

protected double getRectY(double y,
                          double h1,
                          double h2,
                          int location)
Adjusts the supplied y-value.

Parameters:
y - the x-value.
h1 - height 1.
h2 - height 2.
location - the location (top or bottom).
Returns:
the adjusted y-value.

getOppositeAxisLocation

protected int getOppositeAxisLocation(int location)
Returns the location code for the opposite location to the one specified.

Parameters:
location - the location.
Returns:
The opposite location.

getDataAreaRatio

public double getDataAreaRatio()
Returns the data area ratio.

Returns:
The ratio.

setDataAreaRatio

public void setDataAreaRatio(double ratio)
Sets the data area ratio.

Parameters:
ratio - the ratio.

equals

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

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object.
Returns:
true or false.