Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ https://github.com/jfree/jfree-fxdemos
History
-------
##### Next release
##### Version 2.0.3-SNAPSHOT (Current)

- Migrated to JFreeChart 2.0 API.
- Introduced JavaFX-native overlay system (`OverlayFX`, `AbstractOverlayFX`).
- Replaced Swing-dependent event listeners with `OverlayChangeListenerFX`.
- Removed internal dependency on `ShapeUtils` in interaction handlers.
- Fixed Javadoc reference errors in `ChartCanvas`.


- requires Java 22 or later

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<groupId>org.jfree</groupId>
<artifactId>org.jfree.chart.fx</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.4-SNAPSHOT</version>
<packaging>jar</packaging>

<organization>
Expand Down Expand Up @@ -64,7 +64,7 @@
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.5.7-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<!-- FXGraphics2D is used for JavaFX support. -->
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
requires javafx.graphics;
requires javafx.controls;
requires org.jfree.fxgraphics2d;
requires org.jfree.jfreechart;
requires org.jfree.chart;
exports org.jfree.chart.fx;
exports org.jfree.chart.fx.interaction;
exports org.jfree.chart.fx.overlay;
Expand Down
47 changes: 24 additions & 23 deletions src/main/java/org/jfree/chart/fx/ChartCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,36 @@
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Tooltip;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent;
import javafx.scene.text.FontSmoothingType;
import org.jfree.chart.ChartMouseEvent;
import java.util.Objects;

import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.event.ChartChangeEvent;
import org.jfree.chart.event.ChartChangeListener;
import org.jfree.chart.event.OverlayChangeEvent;
import org.jfree.chart.event.OverlayChangeListener;
import org.jfree.chart.fx.interaction.AnchorHandlerFX;
import org.jfree.chart.fx.interaction.DispatchHandlerFX;
import org.jfree.chart.fx.interaction.ChartMouseEventFX;
import org.jfree.chart.fx.interaction.ChartMouseListenerFX;
import org.jfree.chart.fx.interaction.TooltipHandlerFX;
import org.jfree.chart.fx.interaction.ScrollHandlerFX;
import org.jfree.chart.fx.interaction.PanHandlerFX;
import org.jfree.chart.fx.interaction.DispatchHandlerFX;
import org.jfree.chart.fx.interaction.MouseHandlerFX;
import org.jfree.chart.fx.interaction.PanHandlerFX;
import org.jfree.chart.fx.interaction.ScrollHandlerFX;
import org.jfree.chart.fx.interaction.TooltipHandlerFX;
import org.jfree.chart.fx.overlay.OverlayChangeEventFX;
import org.jfree.chart.fx.overlay.OverlayChangeListenerFX;
import org.jfree.chart.fx.overlay.OverlayFX;
import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.util.Args;
import org.jfree.fx.FXGraphics2D;
import org.jfree.fx.FXHints;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Tooltip;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent;
import javafx.scene.text.FontSmoothingType;

/**
* A canvas for displaying a {@link JFreeChart} in JavaFX. You can use the
* canvas directly to display charts, but usually the {@link ChartViewer}
Expand All @@ -89,7 +91,7 @@
*
*/
public class ChartCanvas extends Canvas implements ChartChangeListener,
OverlayChangeListener {
OverlayChangeListenerFX {

/** The chart being displayed in the canvas. */
private JFreeChart chart;
Expand Down Expand Up @@ -325,7 +327,7 @@ public void setAnchor(Point2D anchor) {
* @param overlay the overlay ({@code null} not permitted).
*/
public void addOverlay(OverlayFX overlay) {
Args.nullNotPermitted(overlay, "overlay");
Objects.requireNonNull(overlay, "overlay");
this.overlays.add(overlay);
overlay.addChangeListener(this);
draw();
Expand All @@ -337,7 +339,7 @@ public void addOverlay(OverlayFX overlay) {
* @param overlay the overlay to remove ({@code null} not permitted).
*/
public void removeOverlay(OverlayFX overlay) {
Args.nullNotPermitted(overlay, "overlay");
Objects.requireNonNull(overlay, "overlay");
boolean removed = this.overlays.remove(overlay);
if (removed) {
overlay.removeChangeListener(this);
Expand All @@ -351,7 +353,7 @@ public void removeOverlay(OverlayFX overlay) {
* @param event the event.
*/
@Override
public void overlayChanged(OverlayChangeEvent event) {
public void overlayChanged(OverlayChangeEventFX event) {
draw();
}

Expand All @@ -366,12 +368,12 @@ public List<ChartMouseListenerFX> getChartMouseListeners() {
}

/**
* Registers a listener to receive {@link ChartMouseEvent} notifications.
* Registers a listener to receive {@link ChartMouseEventFX} notifications.
*
* @param listener the listener ({@code null} not permitted).
*/
public void addChartMouseListener(ChartMouseListenerFX listener) {
Args.nullNotPermitted(listener, "listener");
Objects.requireNonNull(listener, "listener");
this.chartMouseListeners.add(listener);
}

Expand Down Expand Up @@ -703,4 +705,3 @@ public void chartChanged(ChartChangeEvent event) {
}

}

24 changes: 13 additions & 11 deletions src/main/java/org/jfree/chart/fx/ChartViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@

import java.io.File;
import java.io.IOException;
import java.util.Objects;

import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.fx.interaction.ChartMouseEventFX;
import org.jfree.chart.fx.interaction.ChartMouseListenerFX;
import org.jfree.chart.fx.interaction.ZoomHandlerFX;
import org.jfree.chart.util.ExportUtils;

import javafx.scene.control.ContextMenu;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
Expand All @@ -47,13 +56,6 @@
import javafx.scene.paint.Paint;
import javafx.scene.shape.Rectangle;
import javafx.stage.FileChooser;
import org.jfree.chart.ChartMouseEvent;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.fx.interaction.ChartMouseListenerFX;
import org.jfree.chart.fx.interaction.ZoomHandlerFX;
import org.jfree.chart.util.ExportUtils;
import org.jfree.chart.util.Args;

/**
* A control for displaying a {@link JFreeChart} in JavaFX (embeds a
Expand Down Expand Up @@ -135,7 +137,7 @@ public JFreeChart getChart() {
* @param chart the chart ({@code null} not permitted).
*/
public void setChart(JFreeChart chart) {
Args.nullNotPermitted(chart, "chart");
Objects.requireNonNull(chart, "chart");
this.canvas.setChart(chart);
}

Expand Down Expand Up @@ -194,13 +196,13 @@ protected void layoutChildren() {
}

/**
* Registers a listener to receive {@link ChartMouseEvent} notifications
* Registers a listener to receive {@link ChartMouseEventFX} notifications
* from the canvas embedded in this viewer.
*
* @param listener the listener ({@code null} not permitted).
*/
public void addChartMouseListener(ChartMouseListenerFX listener) {
Args.nullNotPermitted(listener, "listener");
Objects.requireNonNull(listener, "listener");
this.canvas.addChartMouseListener(listener);
}

Expand All @@ -211,7 +213,7 @@ public void addChartMouseListener(ChartMouseListenerFX listener) {
* @param listener the listener.
*/
public void removeChartMouseListener(ChartMouseListenerFX listener) {
Args.nullNotPermitted(listener, "listener");
Objects.requireNonNull(listener, "listener");
this.canvas.removeChartMouseListener(listener);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@

package org.jfree.chart.fx.interaction;

import java.util.Objects;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent;
import org.jfree.chart.fx.ChartCanvas;
import org.jfree.chart.util.Args;

/**
* A base class that can be used to implement the {@link MouseHandlerFX}
Expand Down Expand Up @@ -81,7 +81,7 @@ public class AbstractMouseHandlerFX implements MouseHandlerFX {
*/
public AbstractMouseHandlerFX(String id, boolean altKey, boolean ctrlKey,
boolean metaKey, boolean shiftKey) {
Args.nullNotPermitted(id, "id");
Objects.requireNonNull(id, "id");
this.id = id;
this.enabled = true;
this.altKey = altKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@

package org.jfree.chart.fx.interaction;

import org.jfree.chart.ChartMouseListener;
import org.jfree.chart.fx.ChartViewer;

/**
* A mouse listener that can receive event notifications from a (JavaFX)
* {@link ChartViewer} instance. This interface is equivalent to the
* {@link ChartMouseListener} interface used for charts in Swing.
* ChartMouseListener interface used for charts in Swing.
*/
public interface ChartMouseListenerFX {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.fx.ChartCanvas;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.pie.PiePlot;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.plot.Zoomable;
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/jfree/chart/fx/interaction/ZoomHandlerFX.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@

import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import javafx.scene.input.MouseEvent;

import org.jfree.chart.fx.ChartCanvas;
import org.jfree.chart.fx.ChartViewer;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.plot.Zoomable;
import org.jfree.chart.util.ShapeUtils;

import javafx.scene.input.MouseEvent;

/**
* Handles drag zooming of charts on a {@link ChartCanvas}. This
Expand Down Expand Up @@ -103,8 +104,9 @@ public void handleMousePressed(ChartCanvas canvas, MouseEvent e) {
Point2D pt = new Point2D.Double(e.getX(), e.getY());
Rectangle2D dataArea = canvas.findDataArea(pt);
if (dataArea != null) {
this.startPoint = ShapeUtils.getPointInRectangle(e.getX(),
e.getY(), dataArea);
double x = Math.max(dataArea.getMinX(), Math.min(e.getX(), dataArea.getMaxX()));
double y = Math.max(dataArea.getMinY(), Math.min(e.getY(), dataArea.getMaxY()));
this.startPoint = new Point2D.Double(x, y);
} else {
this.startPoint = null;
canvas.clearLiveHandler();
Expand Down
99 changes: 99 additions & 0 deletions src/main/java/org/jfree/chart/fx/overlay/AbstractOverlayFX.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/* ================================================
* JFreeChart-FX : JavaFX extensions for JFreeChart
* ================================================
*
* (C) Copyright 2017-present, by David Gilbert and Contributors.
*
* Project Info: https://github.com/jfree/jfreechart-fx
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
* Other names may be trademarks of their respective owners.]
*
* ----------------------
* AbstractOverlayFX.java
* ----------------------
* (C) Copyright 2024-present, by David Gilbert and Contributors.
*
* Original Author: David Gilbert;
* Contributor(s): -;
*
*/

package org.jfree.chart.fx.overlay;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList;

/**
* A base class for implementing overlays for the {@link org.jfree.chart.fx.ChartCanvas}.
*/
public abstract class AbstractOverlayFX implements OverlayFX {

/** Storage for registered change listeners. */
private final transient List<OverlayChangeListenerFX> changeListeners = new CopyOnWriteArrayList<>();

/**
* Default constructor.
*/
public AbstractOverlayFX() {
}

/**
* Registers a listener to receive notification of changes to the overlay.
*
* @param listener the listener ({@code null} not permitted).
*/
@Override
public void addChangeListener(OverlayChangeListenerFX listener) {
Objects.requireNonNull(listener, "listener");
this.changeListeners.add(listener);
}

/**
* Deregisters a listener so that it no longer receives notification of
* changes to the overlay.
*
* @param listener the listener ({@code null} not permitted).
*/
@Override
public void removeChangeListener(OverlayChangeListenerFX listener) {
Objects.requireNonNull(listener, "listener");
this.changeListeners.remove(listener);
}

/**
* Sends a {@link OverlayChangeEventFX} to all registered listeners.
*/
public void fireOverlayChanged() {
OverlayChangeEventFX event = new OverlayChangeEventFX(this);
notifyListeners(event);
}

/**
* Notifies all registered listeners that the overlay has changed.
*
* @param event the event.
*/
protected void notifyListeners(OverlayChangeEventFX event) {
for (OverlayChangeListenerFX listener : this.changeListeners) {
listener.overlayChanged(event);
}
}

}
Loading