public class ChartCanvas extends Canvas implements ChartChangeListener
JFreeChart in JavaFX. You can use the
canvas directly to display charts, but usually the ChartViewer
class (which embeds a canvas) is a better option.
The canvas installs several default mouse handlers, if you don't like the behaviour provided by these you can retrieve the handler by ID and disable or remove it (the IDs are "tooltip", "scroll", "anchor", "pan" and "dispatch").
THE API FOR THIS CLASS IS SUBJECT TO CHANGE IN FUTURE RELEASES. This is so that we can incorporate feedback on the (new) JavaFX support in JFreeChart.
| Modifier and Type | Field and Description |
|---|---|
private java.awt.geom.Point2D |
anchor
The anchor point (can be null) is usually updated to reflect the most
recent mouse click and is used during chart rendering to update
crosshairs belonging to the chart.
|
private java.util.List<MouseHandlerFX> |
auxiliaryMouseHandlers
The auxiliary mouse handlers (can be empty but not null).
|
private java.util.List<MouseHandlerFX> |
availableMouseHandlers
The list of available live mouse handlers (can be empty but not null).
|
private JFreeChart |
chart
The chart being displayed in the canvas (never null).
|
private java.util.List<ChartMouseListenerFX> |
chartMouseListeners
Storage for registered chart mouse listeners.
|
private java.awt.Graphics2D |
g2
The graphics drawing context (will be an instance of FXGraphics2D).
|
private ChartRenderingInfo |
info
The chart rendering info from the most recent drawing of the chart.
|
private MouseHandlerFX |
liveHandler
The current live handler (can be null).
|
private Tooltip |
tooltip
The tooltip object for the canvas (can be null).
|
private boolean |
tooltipEnabled
A flag that controls whether or not tooltips will be generated from the
chart as the mouse pointer moves over it.
|
| Constructor and Description |
|---|
ChartCanvas(JFreeChart chart)
Creates a new canvas to display the supplied chart in JavaFX.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addChartMouseListener(ChartMouseListenerFX listener)
Registers a listener to receive
ChartMouseEvent notifications. |
void |
addMouseHandler(MouseHandlerFX handler)
Adds a mouse handler to the list of available handlers (handlers that
are candidates to take the position of live handler).
|
void |
chartChanged(ChartChangeEvent event)
Receives a notification from the chart that it has been changed and
responds by redrawing the chart entirely.
|
void |
clearLiveHandler()
Clears the current live handler.
|
void |
dispatchMouseClickedEvent(java.awt.geom.Point2D point,
MouseEvent e) |
void |
dispatchMouseMovedEvent(java.awt.geom.Point2D point,
MouseEvent e) |
void |
draw()
Draws the content of the canvas and updates the
renderingInfo attribute with the latest rendering
information. |
java.awt.geom.Rectangle2D |
findDataArea(java.awt.geom.Point2D point)
Returns the data area (the area inside the axes) for the plot or subplot.
|
JFreeChart |
getChart()
Returns the chart that is being displayed by this node.
|
MouseHandlerFX |
getMouseHandler(java.lang.String id)
Returns the mouse handler with the specified ID, or
null if
there is no handler with that ID. |
ChartRenderingInfo |
getRenderingInfo()
Returns the rendering info from the most recent drawing of the chart.
|
private void |
handleMouseClicked(MouseEvent e)
Handles a mouse released event by passing it on to the registered
handlers.
|
private void |
handleMouseDragged(MouseEvent e)
Handles a mouse dragged event by passing it on to the registered
handlers.
|
private void |
handleMouseMoved(MouseEvent e)
Handles a mouse moved event by passing it on to the registered handlers.
|
private void |
handleMousePressed(MouseEvent e)
Handles a mouse pressed event by (1) selecting a live handler if one
is not already selected, (2) passing the event to the live handler if
there is one, and (3) passing the event to all enabled auxiliary
handlers.
|
private void |
handleMouseReleased(MouseEvent e)
Handles a mouse released event by passing it on to the registered
handlers.
|
protected void |
handleScroll(ScrollEvent e)
Handles a scroll event by passing it on to the registered handlers.
|
private boolean |
hasUniqueID(MouseHandlerFX handler)
Validates that the specified handler has an ID that uniquely identifies
it amongst the existing handlers for this canvas.
|
boolean |
isResizable()
Return
true to indicate the canvas is resizable. |
boolean |
isTooltipEnabled()
Returns the flag that controls whether or not tooltips are enabled.
|
void |
removeChartMouseListener(ChartMouseListenerFX listener)
Removes a listener from the list of objects listening for chart mouse
events.
|
void |
removeMouseHandler(MouseHandlerFX handler)
Removes a handler from the list of available handlers.
|
void |
setAnchor(java.awt.geom.Point2D anchor)
Set the anchor point and forces a redraw of the chart (the anchor point
is used to determine the position of the crosshairs on the chart, if
they are visible).
|
void |
setChart(JFreeChart chart)
Sets the chart to be displayed by this node.
|
void |
setTooltip(java.lang.String text,
double x,
double y)
Sets the tooltip text, with the (x, y) location being used for the
anchor.
|
void |
setTooltipEnabled(boolean tooltipEnabled)
Sets the flag that controls whether or not tooltips are enabled.
|
private JFreeChart chart
private java.awt.Graphics2D g2
private java.awt.geom.Point2D anchor
private ChartRenderingInfo info
private Tooltip tooltip
private boolean tooltipEnabled
private transient java.util.List<ChartMouseListenerFX> chartMouseListeners
private MouseHandlerFX liveHandler
private java.util.List<MouseHandlerFX> availableMouseHandlers
private java.util.List<MouseHandlerFX> auxiliaryMouseHandlers
public ChartCanvas(JFreeChart chart)
chart - the chart (null not permitted).public JFreeChart getChart()
null).public void setChart(JFreeChart chart)
chart - the chart (null not permitted).public ChartRenderingInfo getRenderingInfo()
null).public boolean isTooltipEnabled()
true. The TooltipHandlerFX
class will only update the tooltip if this flag is set to
true.public void setTooltipEnabled(boolean tooltipEnabled)
tooltipEnabled - the new flag value.public void setAnchor(java.awt.geom.Point2D anchor)
anchor - the anchor (null permitted).public void addChartMouseListener(ChartMouseListenerFX listener)
ChartMouseEvent notifications.listener - the listener (null not permitted).public void removeChartMouseListener(ChartMouseListenerFX listener)
listener - the listener.public MouseHandlerFX getMouseHandler(java.lang.String id)
null if
there is no handler with that ID. This method will look for handlers
in both the regular and auxiliary handler lists.id - the ID (null not permitted).public void addMouseHandler(MouseHandlerFX handler)
handler - the handler (null not permitted).public void removeMouseHandler(MouseHandlerFX handler)
handler - the handler (null not permitted).private boolean hasUniqueID(MouseHandlerFX handler)
handler - the handler (null not permitted).public void clearLiveHandler()
public final void draw()
renderingInfo attribute with the latest rendering
information.public java.awt.geom.Rectangle2D findDataArea(java.awt.geom.Point2D point)
point - the selection point (for subplot selection).public boolean isResizable()
true to indicate the canvas is resizable.true.public void setTooltip(java.lang.String text,
double x,
double y)
null, no tooltip will be displayed.
This method is intended for calling by the TooltipHandlerFX
class, you won't normally call it directly.text - the text (null permitted).x - the x-coordinate of the mouse pointer.y - the y-coordinate of the mouse pointer.private void handleMousePressed(MouseEvent e)
e - the mouse event.private void handleMouseMoved(MouseEvent e)
e - the mouse event.private void handleMouseDragged(MouseEvent e)
e - the mouse event.private void handleMouseReleased(MouseEvent e)
e - the mouse event.private void handleMouseClicked(MouseEvent e)
e - the mouse event.protected void handleScroll(ScrollEvent e)
e - the scroll event.public void chartChanged(ChartChangeEvent event)
chartChanged in interface ChartChangeListenerevent - event information.public void dispatchMouseMovedEvent(java.awt.geom.Point2D point,
MouseEvent e)
public void dispatchMouseClickedEvent(java.awt.geom.Point2D point,
MouseEvent e)