Package org.jfree.chart.panel
Class CrosshairOverlay
- java.lang.Object
-
- org.jfree.chart.panel.AbstractOverlay
-
- org.jfree.chart.panel.CrosshairOverlay
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener,java.io.Serializable,java.lang.Cloneable,java.util.EventListener,Overlay,PublicCloneable
public class CrosshairOverlay extends AbstractOverlay implements Overlay, java.beans.PropertyChangeListener, PublicCloneable, java.lang.Cloneable, java.io.Serializable
An overlay for aChartPanelthat draws crosshairs on a chart. If you are using the JavaFX extensions for JFreeChart, then you should use theCrosshairOverlayFXclass.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<Crosshair>xCrosshairsStorage for the crosshairs along the x-axis.private java.util.List<Crosshair>yCrosshairsStorage for the crosshairs along the y-axis.
-
Constructor Summary
Constructors Constructor Description CrosshairOverlay()Creates a new overlay that initially contains no crosshairs.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDomainCrosshair(Crosshair crosshair)Adds a crosshair against the domain axis (x-axis) and sends anOverlayChangeEventto all registered listeners.voidaddRangeCrosshair(Crosshair crosshair)Adds a crosshair against the range axis and sends anOverlayChangeEventto all registered listeners.private java.awt.geom.Point2DcalculateLabelPoint(java.awt.geom.Line2D line, RectangleAnchor anchor, double deltaX, double deltaY)Calculates the anchor point for a label.voidclearDomainCrosshairs()Clears all the domain crosshairs from the overlay and sends anOverlayChangeEventto all registered listeners (unless there were no crosshairs to begin with).voidclearRangeCrosshairs()Clears all the range crosshairs from the overlay and sends anOverlayChangeEventto all registered listeners (unless there were no crosshairs to begin with).java.lang.Objectclone()Returns a clone of this instance.protected voiddrawHorizontalCrosshair(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, double y, Crosshair crosshair)Draws a crosshair horizontally across the plot.protected voiddrawVerticalCrosshair(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, double x, Crosshair crosshair)Draws a crosshair vertically on the plot.booleanequals(java.lang.Object obj)Tests this overlay for equality with an arbitrary object.private RectangleAnchorflipAnchorH(RectangleAnchor anchor)private RectangleAnchorflipAnchorV(RectangleAnchor anchor)java.util.List<Crosshair>getDomainCrosshairs()Returns a new list containing the domain crosshairs for this overlay.java.util.List<Crosshair>getRangeCrosshairs()Returns a new list containing the range crosshairs for this overlay.voidpaintOverlay(java.awt.Graphics2D g2, ChartPanel chartPanel)Renders the crosshairs in the overlay on top of the chart that has just been rendered in the specifiedchartPanel.voidpropertyChange(java.beans.PropertyChangeEvent e)Receives a property change event (typically a change in one of the crosshairs).voidremoveDomainCrosshair(Crosshair crosshair)Removes a domain axis crosshair and sends anOverlayChangeEventto all registered listeners.voidremoveRangeCrosshair(Crosshair crosshair)Removes a range axis crosshair and sends anOverlayChangeEventto all registered listeners.private TextAnchortextAlignPtForLabelAnchorH(RectangleAnchor anchor)Returns the text anchor that is used to align a label to its anchor point.private TextAnchortextAlignPtForLabelAnchorV(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
-
-
-
-
Method Detail
-
addDomainCrosshair
public void addDomainCrosshair(Crosshair crosshair)
Adds a crosshair against the domain axis (x-axis) and sends anOverlayChangeEventto all registered listeners.- Parameters:
crosshair- the crosshair (nullnot permitted).- See Also:
removeDomainCrosshair(org.jfree.chart.plot.Crosshair),addRangeCrosshair(org.jfree.chart.plot.Crosshair)
-
removeDomainCrosshair
public void removeDomainCrosshair(Crosshair crosshair)
Removes a domain axis crosshair and sends anOverlayChangeEventto all registered listeners.- Parameters:
crosshair- the crosshair (nullnot permitted).- See Also:
addDomainCrosshair(org.jfree.chart.plot.Crosshair)
-
clearDomainCrosshairs
public void clearDomainCrosshairs()
Clears all the domain crosshairs from the overlay and sends anOverlayChangeEventto all registered listeners (unless there were no crosshairs to begin with).
-
getDomainCrosshairs
public java.util.List<Crosshair> getDomainCrosshairs()
Returns a new list containing the domain crosshairs for this overlay.- Returns:
- A list of crosshairs.
-
addRangeCrosshair
public void addRangeCrosshair(Crosshair crosshair)
Adds a crosshair against the range axis and sends anOverlayChangeEventto all registered listeners.- Parameters:
crosshair- the crosshair (nullnot permitted).
-
removeRangeCrosshair
public void removeRangeCrosshair(Crosshair crosshair)
Removes a range axis crosshair and sends anOverlayChangeEventto all registered listeners.- Parameters:
crosshair- the crosshair (nullnot permitted).- See Also:
addRangeCrosshair(org.jfree.chart.plot.Crosshair)
-
clearRangeCrosshairs
public void clearRangeCrosshairs()
Clears all the range crosshairs from the overlay and sends anOverlayChangeEventto all registered listeners (unless there were no crosshairs to begin with).
-
getRangeCrosshairs
public java.util.List<Crosshair> getRangeCrosshairs()
Returns a new list containing the range crosshairs for this overlay.- Returns:
- A list of crosshairs.
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent e)
Receives a property change event (typically a change in one of the crosshairs).- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener- Parameters:
e- the event.
-
paintOverlay
public void paintOverlay(java.awt.Graphics2D g2, ChartPanel chartPanel)Renders the crosshairs in the overlay on top of the chart that has just been rendered in the specifiedchartPanel. This method is called by the JFreeChart framework, you won't normally call it from user code.- Specified by:
paintOverlayin interfaceOverlay- Parameters:
g2- the graphics target.chartPanel- the chart panel.
-
drawHorizontalCrosshair
protected void drawHorizontalCrosshair(java.awt.Graphics2D g2, java.awt.geom.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(java.awt.Graphics2D g2, java.awt.geom.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 java.awt.geom.Point2D calculateLabelPoint(java.awt.geom.Line2D line, 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 TextAnchor textAlignPtForLabelAnchorV(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 TextAnchor textAlignPtForLabelAnchorH(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 RectangleAnchor flipAnchorH(RectangleAnchor anchor)
-
flipAnchorV
private RectangleAnchor flipAnchorV(RectangleAnchor anchor)
-
equals
public boolean equals(java.lang.Object obj)
Tests this overlay for equality with an arbitrary object.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object (nullpermitted).- Returns:
- A boolean.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionReturns a clone of this instance.- Specified by:
clonein interfacePublicCloneable- Overrides:
clonein classjava.lang.Object- Returns:
- A clone of this instance.
- Throws:
java.lang.CloneNotSupportedException- if there is some problem with the cloning.
-
-