Package org.jfree.chart.plot
Class Plot
java.lang.Object
org.jfree.chart.plot.Plot
- All Implemented Interfaces:
Serializable
,Cloneable
,EventListener
,AnnotationChangeListener
,AxisChangeListener
,MarkerChangeListener
,LegendItemSource
,PublicCloneable
,DatasetChangeListener
- Direct Known Subclasses:
CategoryPlot
,CompassPlot
,DialPlot
,FastScatterPlot
,FlowPlot
,MeterPlot
,MultiplePiePlot
,PiePlot
,PolarPlot
,SpiderWebPlot
,ThermometerPlot
,WaferMapPlot
,XYPlot
public abstract class Plot
extends Object
implements AxisChangeListener, DatasetChangeListener, AnnotationChangeListener, MarkerChangeListener, LegendItemSource, PublicCloneable, Cloneable, 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.- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final float
The default background alpha transparency.static final Paint
The default background color.static final float
The default foreground alpha transparency.static final RectangleInsets
The default insets.static final Shape
A default box shape for legend items.static final Shape
A default circle shape for legend items.static final Paint
The default outline color.static final Stroke
The default outline stroke.static final int
The minimum height at which the plot should be drawn.static final int
The minimum width at which the plot should be drawn.static final Number
Useful constant representing zero. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addChangeListener
(PlotChangeListener listener) Registers an object for notification of changes to the plot.void
Receives notification of a change to anAnnotation
added to this plot.void
axisChanged
(AxisChangeEvent event) Receives notification of a change to one of the plot's axes.boolean
Ensures symmetry between super/subclass implementations of equals.clone()
Creates a clone of the plot.protected void
createAndAddEntity
(Rectangle2D dataArea, PlotRenderingInfo plotState, String toolTip, String urlText) Creates a plot entity that contains a reference to the plot and the data area as shape.void
datasetChanged
(DatasetChangeEvent event) Receives notification of a change to the plot's dataset.abstract void
draw
(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) Draws the plot within the specified area.void
drawBackground
(Graphics2D g2, Rectangle2D area) Draws the plot background (the background color and/or image).void
drawBackgroundImage
(Graphics2D g2, Rectangle2D area) Draws the background image (if there is one) aligned within the specified area.protected void
drawNoDataMessage
(Graphics2D g2, Rectangle2D area) Draws a message to state that there is no data to plot.void
drawOutline
(Graphics2D g2, Rectangle2D area) Draws the plot outline.boolean
Tests this plot for equality with another object.boolean
Fetches the element hinting flag from the chart that this plot is assigned to.protected void
fillBackground
(Graphics2D g2, Rectangle2D area) Fills the specified area with the background paint.protected void
fillBackground
(Graphics2D g2, Rectangle2D area, PlotOrientation orientation) Fills the specified area with the background paint.protected void
Sends aPlotChangeEvent
to all registered listeners.float
Returns the alpha transparency of the plot area background.Returns the background image that is used to fill the plot's background area.int
Returns the background image alignment.float
Returns the alpha transparency used to draw the background image.Returns the background color of the plot area.getChart()
Returns the chart that this plot is assigned to.Returns the dataset group for the plot (not currently used).Returns the drawing supplier for the plot.float
Returns the alpha-transparency for the plot foreground.Returns the insets for the plot area.Returns the legend items for the plot.Returns the string that is displayed when the dataset is empty ornull
.Returns the font used to display the 'no data' message.Returns the paint used to display the 'no data' message.Returns the color used to draw the outline of the plot area.Returns the stroke used to outline the plot area.Returns the parent plot (ornull
if this plot is not part of a combined plot).abstract String
Returns a short string describing the plot type.protected double
getRectX
(double x, double w1, double w2, RectangleEdge edge) Adjusts the supplied x-value.protected double
getRectY
(double y, double h1, double h2, RectangleEdge edge) Adjusts the supplied y-value.Returns the root plot.void
handleClick
(int x, int y, PlotRenderingInfo info) Handles a 'click' on the plot.int
hashCode()
boolean
isNotify()
Returns a flag that controls whether or not change events are sent to registered listeners.boolean
Returns the flag that controls whether or not the plot outline is drawn.boolean
Returnstrue
if this plot is part of a combined plot structure (that is,getParent()
returns a non-null
value), andfalse
otherwise.void
markerChanged
(MarkerChangeEvent event) Receives notification of a change to a marker that is assigned to the plot.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.static RectangleEdge
resolveDomainAxisLocation
(AxisLocation location, PlotOrientation orientation) Resolves a domain axis location for a given plot orientation.static RectangleEdge
resolveRangeAxisLocation
(AxisLocation location, PlotOrientation orientation) Resolves a range axis location for a given plot orientation.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
(Image image) Sets the background image for the plot and sends aPlotChangeEvent
to all registered listeners.void
setBackgroundImageAlignment
(int alignment) Sets the alignment for the background image and sends aPlotChangeEvent
to all registered listeners.void
setBackgroundImageAlpha
(float alpha) Sets the alpha transparency used when drawing the background image.void
setBackgroundPaint
(Paint paint) Sets the background color of the plot area and sends aPlotChangeEvent
to all registered listeners.void
setChart
(JFreeChart chart) Sets the chart that the plot is assigned to.protected void
setDatasetGroup
(DatasetGroup group) Sets the dataset group (not currently used).void
setDrawingSupplier
(DrawingSupplier supplier) Sets the drawing supplier for the plot and sends aPlotChangeEvent
to all registered listeners.void
setDrawingSupplier
(DrawingSupplier supplier, boolean notify) Sets the drawing supplier for the plot and, if requested, sends aPlotChangeEvent
to all registered listeners.void
setForegroundAlpha
(float alpha) Sets the alpha-transparency for the plot and sends aPlotChangeEvent
to all registered listeners.void
setInsets
(RectangleInsets insets) Sets the insets for the plot and sends aPlotChangeEvent
to all registered listeners.void
setInsets
(RectangleInsets insets, boolean notify) Sets the insets for the plot and, if requested, and sends aPlotChangeEvent
to all registered listeners.void
setNoDataMessage
(String message) Sets the message that is displayed when the dataset is empty ornull
, and sends aPlotChangeEvent
to all registered listeners.void
setNoDataMessageFont
(Font font) Sets the font used to display the 'no data' message and sends aPlotChangeEvent
to all registered listeners.void
setNoDataMessagePaint
(Paint paint) Sets the paint used to display the 'no data' message and sends aPlotChangeEvent
to all registered listeners.void
setNotify
(boolean notify) Sets a flag that controls whether or not listeners receivePlotChangeEvent
notifications.void
setOutlinePaint
(Paint paint) Sets the paint used to draw the outline of the plot area and sends aPlotChangeEvent
to all registered listeners.void
setOutlineStroke
(Stroke stroke) Sets the stroke used to outline the plot area and sends aPlotChangeEvent
to all registered listeners.void
setOutlineVisible
(boolean visible) Sets the flag that controls whether or not the plot's outline is drawn, and sends aPlotChangeEvent
to all registered listeners.void
Sets the parent plot.void
zoom
(double percent) Performs a zoom on the plot.
-
Field Details
-
ZERO
Useful constant representing zero. -
DEFAULT_INSETS
The default insets. -
DEFAULT_OUTLINE_STROKE
The default outline stroke. -
DEFAULT_OUTLINE_PAINT
The default outline color. -
DEFAULT_FOREGROUND_ALPHA
The default foreground alpha transparency.- See Also:
-
DEFAULT_BACKGROUND_ALPHA
The default background alpha transparency.- See Also:
-
DEFAULT_BACKGROUND_PAINT
The default background color. -
MINIMUM_WIDTH_TO_DRAW
The minimum width at which the plot should be drawn.- See Also:
-
MINIMUM_HEIGHT_TO_DRAW
The minimum height at which the plot should be drawn.- See Also:
-
DEFAULT_LEGEND_ITEM_BOX
A default box shape for legend items. -
DEFAULT_LEGEND_ITEM_CIRCLE
A default circle shape for legend items.
-
-
Constructor Details
-
Plot
protected Plot()Creates a new plot.
-
-
Method Details
-
getChart
Returns the chart that this plot is assigned to. This method can returnnull
if the plot is not yet assigned to a plot, or if the plot is a subplot of another plot.- Returns:
- The chart (possibly
null
).
-
setChart
Sets the chart that the plot is assigned to. This method is not intended for external use.- Parameters:
chart
- the chart (null
permitted).
-
fetchElementHintingFlag
Fetches the element hinting flag from the chart that this plot is assigned to. If the plot is not assigned (directly or indirectly) to a chart instance, this method will returnfalse
.- Returns:
- A boolean.
-
getDatasetGroup
Returns the dataset group for the plot (not currently used).- Returns:
- The dataset group.
- See Also:
-
setDatasetGroup
Sets the dataset group (not currently used).- Parameters:
group
- the dataset group (null
permitted).- See Also:
-
getNoDataMessage
Returns the string that is displayed when the dataset is empty ornull
.- Returns:
- The 'no data' message (
null
possible). - See Also:
-
setNoDataMessage
Sets the message that is displayed when the dataset is empty ornull
, and sends aPlotChangeEvent
to all registered listeners.- Parameters:
message
- the message (null
permitted).- See Also:
-
getNoDataMessageFont
Returns the font used to display the 'no data' message.- Returns:
- The font (never
null
). - See Also:
-
setNoDataMessageFont
Sets the font used to display the 'no data' message and sends aPlotChangeEvent
to all registered listeners.- Parameters:
font
- the font (null
not permitted).- See Also:
-
getNoDataMessagePaint
Returns the paint used to display the 'no data' message.- Returns:
- The paint (never
null
). - See Also:
-
setNoDataMessagePaint
Sets the paint used to display the 'no data' message and sends aPlotChangeEvent
to all registered listeners.- Parameters:
paint
- the paint (null
not permitted).- See Also:
-
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 (never
null
).
-
getParent
Returns the parent plot (ornull
if this plot is not part of a combined plot).- Returns:
- The parent plot.
- See Also:
-
setParent
Sets the parent plot. This method is intended for internal use, you shouldn't need to call it directly.- Parameters:
parent
- the parent plot (null
permitted).- See Also:
-
getRootPlot
Returns the root plot.- Returns:
- The root plot.
- See Also:
-
isSubplot
Returnstrue
if this plot is part of a combined plot structure (that is,getParent()
returns a non-null
value), andfalse
otherwise.- Returns:
true
if this plot is part of a combined plot structure.- See Also:
-
getInsets
Returns the insets for the plot area.- Returns:
- The insets (never
null
). - See Also:
-
setInsets
Sets the insets for the plot and sends aPlotChangeEvent
to all registered listeners.- Parameters:
insets
- the new insets (null
not permitted).- See Also:
-
setInsets
Sets the insets for the plot and, if requested, and sends aPlotChangeEvent
to all registered listeners.- Parameters:
insets
- the new insets (null
not permitted).notify
- a flag that controls whether the registered listeners are notified.- See Also:
-
getBackgroundPaint
Returns the background color of the plot area.- Returns:
- The paint (possibly
null
). - See Also:
-
setBackgroundPaint
Sets the background color of the plot area and sends aPlotChangeEvent
to all registered listeners.- Parameters:
paint
- the paint (null
permitted).- See Also:
-
getBackgroundAlpha
Returns the alpha transparency of the plot area background.- Returns:
- The alpha transparency.
- See Also:
-
setBackgroundAlpha
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 (in the range 0.0f to 1.0f).- See Also:
-
getDrawingSupplier
Returns the drawing supplier for the plot.- Returns:
- The drawing supplier (possibly
null
). - See Also:
-
setDrawingSupplier
Sets the drawing supplier for the plot and sends aPlotChangeEvent
to all registered listeners. The drawing supplier is responsible for supplying a limitless (possibly repeating) sequence ofPaint
,Stroke
andShape
objects that the plot's renderer(s) can use to populate its (their) tables.- Parameters:
supplier
- the new supplier.- See Also:
-
setDrawingSupplier
Sets the drawing supplier for the plot and, if requested, sends aPlotChangeEvent
to all registered listeners. The drawing supplier is responsible for supplying a limitless (possibly repeating) sequence ofPaint
,Stroke
andShape
objects that the plot's renderer(s) can use to populate its (their) tables.- Parameters:
supplier
- the new supplier.notify
- notify listeners?- See Also:
-
getBackgroundImage
Returns the background image that is used to fill the plot's background area.- Returns:
- The image (possibly
null
). - See Also:
-
setBackgroundImage
Sets the background image for the plot and sends aPlotChangeEvent
to all registered listeners.- Parameters:
image
- the image (null
permitted).- See Also:
-
getBackgroundImageAlignment
Returns the background image alignment. Alignment constants are defined in theAlign
class.- Returns:
- The alignment.
- See Also:
-
setBackgroundImageAlignment
Sets the alignment for the background image and sends aPlotChangeEvent
to all registered listeners. Alignment options are defined by theAlign
class.- Parameters:
alignment
- the alignment.- See Also:
-
getBackgroundImageAlpha
Returns the alpha transparency used to draw the background image. This is a value in the range 0.0f to 1.0f, where 0.0f is fully transparent and 1.0f is fully opaque.- Returns:
- The alpha transparency.
- See Also:
-
setBackgroundImageAlpha
Sets the alpha transparency used when drawing the background image.- Parameters:
alpha
- the alpha transparency (in the range 0.0f to 1.0f, where 0.0f is fully transparent, and 1.0f is fully opaque).- Throws:
IllegalArgumentException
- ifalpha
is not within the specified range.- See Also:
-
isOutlineVisible
Returns the flag that controls whether or not the plot outline is drawn. The default value istrue
. Note that for historical reasons, the plot's outline paint and stroke can take onnull
values, in which case the outline will not be drawn even if this flag is set totrue
.- Returns:
- The outline visibility flag.
- See Also:
-
setOutlineVisible
Sets the flag that controls whether or not the plot's outline is drawn, and sends aPlotChangeEvent
to all registered listeners.- Parameters:
visible
- the new flag value.- See Also:
-
getOutlineStroke
Returns the stroke used to outline the plot area.- Returns:
- The stroke (possibly
null
). - See Also:
-
setOutlineStroke
Sets the stroke used to outline the plot area and sends aPlotChangeEvent
to all registered listeners. If you set this attribute tonull
, no outline will be drawn.- Parameters:
stroke
- the stroke (null
permitted).- See Also:
-
getOutlinePaint
Returns the color used to draw the outline of the plot area.- Returns:
- The color (possibly
null
). - See Also:
-
setOutlinePaint
Sets the paint used to draw the outline of the plot area and sends aPlotChangeEvent
to all registered listeners. If you set this attribute tonull
, no outline will be drawn.- Parameters:
paint
- the paint (null
permitted).- See Also:
-
getForegroundAlpha
Returns the alpha-transparency for the plot foreground.- Returns:
- The alpha-transparency.
- See Also:
-
setForegroundAlpha
Sets the alpha-transparency for the plot and sends aPlotChangeEvent
to all registered listeners.- Parameters:
alpha
- the new alpha transparency.- See Also:
-
getLegendItems
Returns the legend items for the plot. By default, this method returnsnull
. Subclasses should override to return aLegendItemCollection
.- Specified by:
getLegendItems
in interfaceLegendItemSource
- Returns:
- The legend items for the plot (possibly
null
).
-
isNotify
Returns a flag that controls whether or not change events are sent to registered listeners.- Returns:
- A boolean.
- See Also:
-
setNotify
Sets a flag that controls whether or not listeners receivePlotChangeEvent
notifications.- Parameters:
notify
- a boolean.- See Also:
-
addChangeListener
Registers an object for notification of changes to the plot.- Parameters:
listener
- the object to be registered.- See Also:
-
removeChangeListener
Unregisters an object for notification of changes to the plot.- Parameters:
listener
- the object to be unregistered.- See Also:
-
notifyListeners
Notifies all registered listeners that the plot has been modified.- Parameters:
event
- information about the change event.
-
fireChangeEvent
Sends aPlotChangeEvent
to all registered listeners. -
draw
public abstract void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) Draws the plot within the specified area. The anchor is a point on the chart that is specified externally (for instance, it may be the last point of the last mouse click performed by the user) - plots can use or ignore this value as they see fit.
Subclasses need to provide an implementation of this method, obviously.- Parameters:
g2
- the graphics device.area
- the plot area.anchor
- the anchor point (null
permitted).parentState
- the parent state (if any,null
permitted).info
- carries back plot rendering info.
-
drawBackground
Draws the plot background (the background color and/or image).This method will be called during the chart drawing process and is declared public so that it can be accessed by the renderers used by certain subclasses. You shouldn't need to call this method directly.
- Parameters:
g2
- the graphics device.area
- the area within which the plot should be drawn.
-
fillBackground
Fills the specified area with the background paint.- Parameters:
g2
- the graphics device.area
- the area.- See Also:
-
fillBackground
Fills the specified area with the background paint. If the background paint is an instance ofGradientPaint
, the gradient will run in the direction suggested by the plot's orientation.- Parameters:
g2
- the graphics target.area
- the plot area.orientation
- the plot orientation (null
not permitted).
-
drawBackgroundImage
Draws the background image (if there is one) aligned within the specified area.- Parameters:
g2
- the graphics device.area
- the area.- See Also:
-
drawOutline
Draws the plot outline. This method will be called during the chart drawing process and is declared public so that it can be accessed by the renderers used by certain subclasses. You shouldn't need to call this method directly.- Parameters:
g2
- the graphics device.area
- the area within which the plot should be drawn.
-
drawNoDataMessage
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.
-
createAndAddEntity
protected void createAndAddEntity(Rectangle2D dataArea, PlotRenderingInfo plotState, String toolTip, String urlText) Creates a plot entity that contains a reference to the plot and the data area as shape.- Parameters:
dataArea
- the data area used as hot spot for the entity.plotState
- the plot rendering info containing a reference to the EntityCollection.toolTip
- the tool tip (defined in the respective Plot subclass) (null
permitted).urlText
- the url (defined in the respective Plot subclass) (null
permitted).
-
handleClick
Handles a 'click' on the plot. Since the plot does not maintain any information about where it has been drawn, the plot rendering info is supplied as an argument so that the plot dimensions can be determined.- Parameters:
x
- the x coordinate (in Java2D space).y
- the y coordinate (in Java2D space).info
- an object containing information about the dimensions of the plot.
-
zoom
Performs a zoom on the plot. Subclasses should override if zooming is appropriate for the type of plot.- Parameters:
percent
- the zoom percentage.
-
annotationChanged
Receives notification of a change to anAnnotation
added to this plot.- Specified by:
annotationChanged
in interfaceAnnotationChangeListener
- Parameters:
event
- information about the event (not used here).
-
axisChanged
Receives notification of a change to one of the plot's axes.- Specified by:
axisChanged
in interfaceAxisChangeListener
- Parameters:
event
- information about the event (not used here).
-
datasetChanged
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 interfaceDatasetChangeListener
- Parameters:
event
- information about the event (not used here).
-
markerChanged
Receives notification of a change to a marker that is assigned to the plot.- Specified by:
markerChanged
in interfaceMarkerChangeListener
- Parameters:
event
- the event.
-
getRectX
Adjusts the supplied x-value.- Parameters:
x
- the x-value.w1
- width 1.w2
- width 2.edge
- the edge (left or right).- Returns:
- The adjusted x-value.
-
getRectY
Adjusts the supplied y-value.- Parameters:
y
- the x-value.h1
- height 1.h2
- height 2.edge
- the edge (top or bottom).- Returns:
- The adjusted y-value.
-
equals
Tests this plot for equality with another object. -
canEqual
Ensures symmetry between super/subclass implementations of equals. For more detail, see http://jqno.nl/equalsverifier/manual/inheritance.- Parameters:
other
- Object- Returns:
- true ONLY if the parameter is THIS class type
-
hashCode
-
clone
Creates a clone of the plot.- Specified by:
clone
in interfacePublicCloneable
- Overrides:
clone
in classObject
- Returns:
- A clone.
- Throws:
CloneNotSupportedException
- if some component of the plot does not support cloning.
-
resolveDomainAxisLocation
public static RectangleEdge resolveDomainAxisLocation(AxisLocation location, PlotOrientation orientation) Resolves a domain axis location for a given plot orientation.- Parameters:
location
- the location (null
not permitted).orientation
- the orientation (null
not permitted).- Returns:
- The edge (never
null
).
-
resolveRangeAxisLocation
public static RectangleEdge resolveRangeAxisLocation(AxisLocation location, PlotOrientation orientation) Resolves a range axis location for a given plot orientation.- Parameters:
location
- the location (null
not permitted).orientation
- the orientation (null
not permitted).- Returns:
- The edge (never
null
).
-