Package org.jfree.chart.panel
Class CrosshairOverlay
java.lang.Object
org.jfree.chart.panel.AbstractOverlay
org.jfree.chart.panel.CrosshairOverlay
- All Implemented Interfaces:
PropertyChangeListener
,Serializable
,Cloneable
,EventListener
,Overlay
,org.jfree.util.PublicCloneable
public class CrosshairOverlay
extends AbstractOverlay
implements Overlay, PropertyChangeListener, org.jfree.util.PublicCloneable, Cloneable, Serializable
An overlay for a
ChartPanel
that draws crosshairs on a plot.- Since:
- 1.0.13
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDomainCrosshair
(Crosshair crosshair) Adds a crosshair against the domain axis and sends anOverlayChangeEvent
to all registered listeners.void
addRangeCrosshair
(Crosshair crosshair) Adds a crosshair against the range axis and sends anOverlayChangeEvent
to all registered listeners.private Point2D
calculateLabelPoint
(Line2D line, org.jfree.ui.RectangleAnchor anchor, double deltaX, double deltaY) Calculates the anchor point for a label.void
Clears all the domain crosshairs from the overlay and sends anOverlayChangeEvent
to all registered listeners.void
Clears all the range crosshairs from the overlay and sends anOverlayChangeEvent
to all registered listeners.clone()
Returns a clone of this instance.protected void
drawHorizontalCrosshair
(Graphics2D g2, Rectangle2D dataArea, double y, Crosshair crosshair) Draws a crosshair horizontally across the plot.protected void
drawVerticalCrosshair
(Graphics2D g2, Rectangle2D dataArea, double x, Crosshair crosshair) Draws a crosshair vertically on the plot.boolean
Tests this overlay for equality with an arbitrary object.private org.jfree.ui.RectangleAnchor
flipAnchorH
(org.jfree.ui.RectangleAnchor anchor) private org.jfree.ui.RectangleAnchor
flipAnchorV
(org.jfree.ui.RectangleAnchor anchor) Returns a new list containing the domain crosshairs for this overlay.Returns a new list containing the range crosshairs for this overlay.void
paintOverlay
(Graphics2D g2, ChartPanel chartPanel) Paints the crosshairs in the layer.void
Receives a property change event (typically a change in one of the crosshairs).void
removeDomainCrosshair
(Crosshair crosshair) Removes a domain axis crosshair and sends anOverlayChangeEvent
to all registered listeners.void
removeRangeCrosshair
(Crosshair crosshair) Removes a range axis crosshair and sends anOverlayChangeEvent
to all registered listeners.private org.jfree.ui.TextAnchor
textAlignPtForLabelAnchorH
(org.jfree.ui.RectangleAnchor anchor) Returns the text anchor that is used to align a label to its anchor point.private org.jfree.ui.TextAnchor
textAlignPtForLabelAnchorV
(org.jfree.ui.RectangleAnchor anchor) Returns the text anchor that is used to align a label to its anchor point.Methods inherited from class org.jfree.chart.panel.AbstractOverlay
addChangeListener, fireOverlayChanged, notifyListeners, removeChangeListener
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.jfree.chart.panel.Overlay
addChangeListener, removeChangeListener
-
Field Details
-
xCrosshairs
Storage for the crosshairs along the x-axis. -
yCrosshairs
Storage for the crosshairs along the y-axis.
-
-
Constructor Details
-
CrosshairOverlay
public CrosshairOverlay()Default constructor.
-
-
Method Details
-
addDomainCrosshair
Adds a crosshair against the domain axis and sends anOverlayChangeEvent
to all registered listeners.- Parameters:
crosshair
- the crosshair (null
not permitted).- See Also:
-
removeDomainCrosshair
Removes a domain axis crosshair and sends anOverlayChangeEvent
to all registered listeners.- Parameters:
crosshair
- the crosshair (null
not permitted).- See Also:
-
clearDomainCrosshairs
public void clearDomainCrosshairs()Clears all the domain crosshairs from the overlay and sends anOverlayChangeEvent
to all registered listeners. -
getDomainCrosshairs
Returns a new list containing the domain crosshairs for this overlay.- Returns:
- A list of crosshairs.
-
addRangeCrosshair
Adds a crosshair against the range axis and sends anOverlayChangeEvent
to all registered listeners.- Parameters:
crosshair
- the crosshair (null
not permitted).
-
removeRangeCrosshair
Removes a range axis crosshair and sends anOverlayChangeEvent
to all registered listeners.- Parameters:
crosshair
- the crosshair (null
not permitted).- See Also:
-
clearRangeCrosshairs
public void clearRangeCrosshairs()Clears all the range crosshairs from the overlay and sends anOverlayChangeEvent
to all registered listeners. -
getRangeCrosshairs
Returns a new list containing the range crosshairs for this overlay.- Returns:
- A list of crosshairs.
-
propertyChange
Receives a property change event (typically a change in one of the crosshairs).- Specified by:
propertyChange
in interfacePropertyChangeListener
- Parameters:
e
- the event.
-
paintOverlay
Paints the crosshairs in the layer.- Specified by:
paintOverlay
in interfaceOverlay
- Parameters:
g2
- the graphics target.chartPanel
- the chart panel.
-
drawHorizontalCrosshair
protected void drawHorizontalCrosshair(Graphics2D g2, Rectangle2D dataArea, double y, Crosshair crosshair) Draws a crosshair horizontally across the plot.- Parameters:
g2
- the graphics target.dataArea
- the data area.y
- the y-value in Java2D space.crosshair
- the crosshair.
-
drawVerticalCrosshair
protected void drawVerticalCrosshair(Graphics2D g2, Rectangle2D dataArea, double x, Crosshair crosshair) Draws a crosshair vertically on the plot.- Parameters:
g2
- the graphics target.dataArea
- the data area.x
- the x-value in Java2D space.crosshair
- the crosshair.
-
calculateLabelPoint
private Point2D calculateLabelPoint(Line2D line, org.jfree.ui.RectangleAnchor anchor, double deltaX, double deltaY) Calculates the anchor point for a label.- Parameters:
line
- the line for the crosshair.anchor
- the anchor point.deltaX
- the x-offset.deltaY
- the y-offset.- Returns:
- The anchor point.
-
textAlignPtForLabelAnchorV
private org.jfree.ui.TextAnchor textAlignPtForLabelAnchorV(org.jfree.ui.RectangleAnchor anchor) Returns the text anchor that is used to align a label to its anchor point.- Parameters:
anchor
- the anchor.- Returns:
- The text alignment point.
-
textAlignPtForLabelAnchorH
private org.jfree.ui.TextAnchor textAlignPtForLabelAnchorH(org.jfree.ui.RectangleAnchor anchor) Returns the text anchor that is used to align a label to its anchor point.- Parameters:
anchor
- the anchor.- Returns:
- The text alignment point.
-
flipAnchorH
private org.jfree.ui.RectangleAnchor flipAnchorH(org.jfree.ui.RectangleAnchor anchor) -
flipAnchorV
private org.jfree.ui.RectangleAnchor flipAnchorV(org.jfree.ui.RectangleAnchor anchor) -
equals
Tests this overlay for equality with an arbitrary object. -
clone
Returns a clone of this instance.- Specified by:
clone
in interfaceorg.jfree.util.PublicCloneable
- Overrides:
clone
in classObject
- Returns:
- A clone of this instance.
- Throws:
CloneNotSupportedException
- if there is some problem with the cloning.
-