diff --git a/.gitignore b/.gitignore
index f2d840b..6b66486 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,4 +10,8 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
-/target/
\ No newline at end of file
+/target/
+
+#Idea project files
+.idea
+*.iml
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 2535b8e..22bad6c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -53,7 +53,7 @@
org.jfree
jfreechart
- 1.5.3
+ 2.0.0-SNAPSHOT
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index f08acb2..2e37678 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -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;
diff --git a/src/main/java/org/jfree/chart/fx/ChartCanvas.java b/src/main/java/org/jfree/chart/fx/ChartCanvas.java
index b7348fd..c99fbe1 100644
--- a/src/main/java/org/jfree/chart/fx/ChartCanvas.java
+++ b/src/main/java/org/jfree/chart/fx/ChartCanvas.java
@@ -51,23 +51,22 @@
import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent;
import javafx.scene.text.FontSmoothingType;
-import org.jfree.chart.ChartMouseEvent;
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.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.OverlayFX;
import org.jfree.chart.plot.PlotRenderingInfo;
-import org.jfree.chart.util.Args;
+import org.jfree.chart.swing.ChartMouseEvent;
+import org.jfree.chart.swing.OverlayChangeEvent;
+import org.jfree.chart.swing.OverlayChangeListener;
import org.jfree.fx.FXGraphics2D;
import org.jfree.fx.FXHints;
@@ -325,7 +324,7 @@ public void setAnchor(Point2D anchor) {
* @param overlay the overlay ({@code null} not permitted).
*/
public void addOverlay(OverlayFX overlay) {
- Args.nullNotPermitted(overlay, "overlay");
+ if (overlay == null) throw new IllegalArgumentException("overlay must not be null");
this.overlays.add(overlay);
overlay.addChangeListener(this);
draw();
@@ -337,7 +336,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");
+ if (overlay == null) throw new IllegalArgumentException("overlay must not be null");
boolean removed = this.overlays.remove(overlay);
if (removed) {
overlay.removeChangeListener(this);
@@ -371,7 +370,7 @@ public List getChartMouseListeners() {
* @param listener the listener ({@code null} not permitted).
*/
public void addChartMouseListener(ChartMouseListenerFX listener) {
- Args.nullNotPermitted(listener, "listener");
+ if (listener == null) throw new IllegalArgumentException("listener must not be null");
this.chartMouseListeners.add(listener);
}
diff --git a/src/main/java/org/jfree/chart/fx/ChartViewer.java b/src/main/java/org/jfree/chart/fx/ChartViewer.java
index 06e1725..3ef0de7 100644
--- a/src/main/java/org/jfree/chart/fx/ChartViewer.java
+++ b/src/main/java/org/jfree/chart/fx/ChartViewer.java
@@ -47,13 +47,12 @@
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.swing.ChartMouseEvent;
import org.jfree.chart.util.ExportUtils;
-import org.jfree.chart.util.Args;
/**
* A control for displaying a {@link JFreeChart} in JavaFX (embeds a
@@ -63,17 +62,17 @@
*/
public class ChartViewer extends Region {
- private ChartCanvas canvas;
+ private final ChartCanvas canvas;
/**
* The zoom rectangle is used to display the zooming region when
* doing a drag-zoom with the mouse. Most of the time this rectangle
* is not visible.
*/
- private Rectangle zoomRectangle;
+ private final Rectangle zoomRectangle;
/** The context menu for the chart viewer. */
- private ContextMenu contextMenu;
+ private final ContextMenu contextMenu;
/**
* Creates a new instance, initially with no chart to display. This
@@ -137,7 +136,7 @@ public JFreeChart getChart() {
* @param chart the chart ({@code null} not permitted).
*/
public void setChart(JFreeChart chart) {
- Args.nullNotPermitted(chart, "chart");
+ if (chart == null) throw new IllegalArgumentException("chart must not be null");
this.canvas.setChart(chart);
}
@@ -202,7 +201,7 @@ protected void layoutChildren() {
* @param listener the listener ({@code null} not permitted).
*/
public void addChartMouseListener(ChartMouseListenerFX listener) {
- Args.nullNotPermitted(listener, "listener");
+ if (listener == null) throw new IllegalArgumentException("listener must not be null");
this.canvas.addChartMouseListener(listener);
}
@@ -213,7 +212,7 @@ public void addChartMouseListener(ChartMouseListenerFX listener) {
* @param listener the listener.
*/
public void removeChartMouseListener(ChartMouseListenerFX listener) {
- Args.nullNotPermitted(listener, "listener");
+ if (listener == null) throw new IllegalArgumentException("listener must not be null");
this.canvas.removeChartMouseListener(listener);
}
diff --git a/src/main/java/org/jfree/chart/fx/interaction/AbstractMouseHandlerFX.java b/src/main/java/org/jfree/chart/fx/interaction/AbstractMouseHandlerFX.java
index fbd25c7..7842444 100644
--- a/src/main/java/org/jfree/chart/fx/interaction/AbstractMouseHandlerFX.java
+++ b/src/main/java/org/jfree/chart/fx/interaction/AbstractMouseHandlerFX.java
@@ -39,7 +39,6 @@
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}
@@ -81,7 +80,7 @@ public class AbstractMouseHandlerFX implements MouseHandlerFX {
*/
public AbstractMouseHandlerFX(String id, boolean altKey, boolean ctrlKey,
boolean metaKey, boolean shiftKey) {
- Args.nullNotPermitted(id, "id");
+ if (id == null) throw new IllegalArgumentException("id must not be null");
this.id = id;
this.enabled = true;
this.altKey = altKey;
diff --git a/src/main/java/org/jfree/chart/fx/interaction/ChartMouseEventFX.java b/src/main/java/org/jfree/chart/fx/interaction/ChartMouseEventFX.java
index 71b4530..4ad5791 100644
--- a/src/main/java/org/jfree/chart/fx/interaction/ChartMouseEventFX.java
+++ b/src/main/java/org/jfree/chart/fx/interaction/ChartMouseEventFX.java
@@ -55,13 +55,13 @@ public class ChartMouseEventFX extends EventObject implements Serializable {
private static final long serialVersionUID = -682393837314562149L;
/** The chart that the mouse event relates to. */
- private JFreeChart chart;
+ private final JFreeChart chart;
/** The Java mouse event that triggered this event. */
- private MouseEvent trigger;
+ private final MouseEvent trigger;
/** The chart entity (if any). */
- private ChartEntity entity;
+ private final ChartEntity entity;
/**
* Constructs a new event.
@@ -86,7 +86,7 @@ public ChartMouseEventFX(JFreeChart chart, MouseEvent trigger,
* @return The chart (never {@code null}).
*/
public JFreeChart getChart() {
- return this.chart;
+ return chart;
}
/**
@@ -95,7 +95,7 @@ public JFreeChart getChart() {
* @return The event (never {@code null}).
*/
public MouseEvent getTrigger() {
- return this.trigger;
+ return trigger;
}
/**
@@ -104,7 +104,7 @@ public MouseEvent getTrigger() {
* @return The chart entity (possibly {@code null}).
*/
public ChartEntity getEntity() {
- return this.entity;
+ return entity;
}
}
diff --git a/src/main/java/org/jfree/chart/fx/interaction/ChartMouseListenerFX.java b/src/main/java/org/jfree/chart/fx/interaction/ChartMouseListenerFX.java
index 89c66a0..92756f9 100644
--- a/src/main/java/org/jfree/chart/fx/interaction/ChartMouseListenerFX.java
+++ b/src/main/java/org/jfree/chart/fx/interaction/ChartMouseListenerFX.java
@@ -36,7 +36,7 @@
package org.jfree.chart.fx.interaction;
-import org.jfree.chart.ChartMouseListener;
+import org.jfree.chart.swing.ChartMouseListener;
import org.jfree.chart.fx.ChartViewer;
/**
diff --git a/src/main/java/org/jfree/chart/fx/interaction/DispatchHandlerFX.java b/src/main/java/org/jfree/chart/fx/interaction/DispatchHandlerFX.java
index 427a9ad..6cfed57 100644
--- a/src/main/java/org/jfree/chart/fx/interaction/DispatchHandlerFX.java
+++ b/src/main/java/org/jfree/chart/fx/interaction/DispatchHandlerFX.java
@@ -72,7 +72,7 @@ public DispatchHandlerFX(String id) {
*/
@Override
public void handleMousePressed(ChartCanvas canvas, MouseEvent e) {
- this.mousePressedPoint = new Point2D.Double(e.getX(), e.getY());
+ mousePressedPoint = new Point2D.Double(e.getX(), e.getY());
}
/**
@@ -106,7 +106,7 @@ public void handleMouseMoved(ChartCanvas canvas, MouseEvent e) {
*/
@Override
public void handleMouseClicked(ChartCanvas canvas, MouseEvent e) {
- if (this.mousePressedPoint == null || canvas.getChart() == null) {
+ if (mousePressedPoint == null || canvas.getChart() == null) {
return;
}
double x = e.getX();
diff --git a/src/main/java/org/jfree/chart/fx/interaction/PanHandlerFX.java b/src/main/java/org/jfree/chart/fx/interaction/PanHandlerFX.java
index a75435c..0f5cc87 100644
--- a/src/main/java/org/jfree/chart/fx/interaction/PanHandlerFX.java
+++ b/src/main/java/org/jfree/chart/fx/interaction/PanHandlerFX.java
@@ -104,9 +104,9 @@ public void handleMousePressed(ChartCanvas canvas, MouseEvent e) {
Point2D point = new Point2D.Double(e.getX(), e.getY());
Rectangle2D dataArea = canvas.findDataArea(point);
if (dataArea != null && dataArea.contains(point)) {
- this.panW = dataArea.getWidth();
- this.panH = dataArea.getHeight();
- this.panLast = point;
+ panW = dataArea.getWidth();
+ panH = dataArea.getHeight();
+ panLast = point;
canvas.setCursor(javafx.scene.Cursor.MOVE);
}
}
@@ -122,7 +122,7 @@ public void handleMousePressed(ChartCanvas canvas, MouseEvent e) {
*/
@Override
public void handleMouseDragged(ChartCanvas canvas, MouseEvent e) {
- if (this.panLast == null) {
+ if (panLast == null) {
//handle panning if we have a start point else unregister
canvas.clearLiveHandler();
return;
@@ -132,26 +132,26 @@ public void handleMouseDragged(ChartCanvas canvas, MouseEvent e) {
if (chart == null) {
return;
}
- double dx = e.getX() - this.panLast.getX();
- double dy = e.getY() - this.panLast.getY();
+ double dx = e.getX() - panLast.getX();
+ double dy = e.getY() - panLast.getY();
if (dx == 0.0 && dy == 0.0) {
return;
}
- double wPercent = -dx / this.panW;
- double hPercent = dy / this.panH;
+ double wPercent = -dx / panW;
+ double hPercent = dy / panH;
boolean old = chart.getPlot().isNotify();
chart.getPlot().setNotify(false);
Pannable p = (Pannable) chart.getPlot();
PlotRenderingInfo info = canvas.getRenderingInfo().getPlotInfo();
if (p.getOrientation().isVertical()) {
- p.panDomainAxes(wPercent, info, this.panLast);
- p.panRangeAxes(hPercent, info, this.panLast);
+ p.panDomainAxes(wPercent, info, panLast);
+ p.panRangeAxes(hPercent, info, panLast);
}
else {
- p.panDomainAxes(hPercent, info, this.panLast);
- p.panRangeAxes(wPercent, info, this.panLast);
+ p.panDomainAxes(hPercent, info, panLast);
+ p.panRangeAxes(wPercent, info, panLast);
}
- this.panLast = new Point2D.Double(e.getX(), e.getY());
+ panLast = new Point2D.Double(e.getX(), e.getY());
chart.getPlot().setNotify(old);
}
@@ -159,10 +159,10 @@ public void handleMouseDragged(ChartCanvas canvas, MouseEvent e) {
public void handleMouseReleased(ChartCanvas canvas, MouseEvent e) {
//if we have been panning reset the cursor
//unregister in any case
- if (this.panLast != null) {
+ if (panLast != null) {
canvas.setCursor(javafx.scene.Cursor.DEFAULT);
}
- this.panLast = null;
+ panLast = null;
canvas.clearLiveHandler();
}
diff --git a/src/main/java/org/jfree/chart/fx/interaction/ScrollHandlerFX.java b/src/main/java/org/jfree/chart/fx/interaction/ScrollHandlerFX.java
index 8b1e828..a506af9 100644
--- a/src/main/java/org/jfree/chart/fx/interaction/ScrollHandlerFX.java
+++ b/src/main/java/org/jfree/chart/fx/interaction/ScrollHandlerFX.java
@@ -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;
@@ -62,8 +62,7 @@ public class ScrollHandlerFX extends AbstractMouseHandlerFX
*/
public ScrollHandlerFX(String id) {
super(id, false, false, false, false);
- this.zoomFactor = 0.1;
- };
+ }
/**
* Returns the zoom factor. The default value is 0.10 (ten percent).
@@ -71,7 +70,7 @@ public ScrollHandlerFX(String id) {
* @return The zoom factor.
*/
public double getZoomFactor() {
- return this.zoomFactor;
+ return zoomFactor;
}
/**
@@ -96,7 +95,7 @@ public void handleScroll(ChartCanvas canvas, ScrollEvent e) {
handleZoomable(canvas, zoomable, e);
}
else if (plot instanceof PiePlot) {
- PiePlot pp = (PiePlot) plot;
+ PiePlot> pp = (PiePlot>) plot;
pp.handleMouseWheelRotation((int) e.getDeltaY());
}
}
@@ -123,7 +122,7 @@ private void handleZoomable(ChartCanvas canvas, Zoomable zoomable,
boolean notifyState = plot.isNotify();
plot.setNotify(false);
int clicks = (int) e.getDeltaY();
- double zf = 1.0 + this.zoomFactor;
+ double zf = 1.0 + zoomFactor;
if (clicks < 0) {
zf = 1.0 / zf;
}
diff --git a/src/main/java/org/jfree/chart/fx/interaction/ZoomHandlerFX.java b/src/main/java/org/jfree/chart/fx/interaction/ZoomHandlerFX.java
index 2f27f9b..432adff 100644
--- a/src/main/java/org/jfree/chart/fx/interaction/ZoomHandlerFX.java
+++ b/src/main/java/org/jfree/chart/fx/interaction/ZoomHandlerFX.java
@@ -44,7 +44,6 @@
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.plot.Zoomable;
-import org.jfree.chart.util.ShapeUtils;
/**
* Handles drag zooming of charts on a {@link ChartCanvas}. This
@@ -56,7 +55,7 @@
public class ZoomHandlerFX extends AbstractMouseHandlerFX {
/** The viewer is used to overlay the zoom rectangle. */
- private ChartViewer viewer;
+ private final ChartViewer viewer;
/** The starting point for the zoom. */
private Point2D startPoint;
@@ -103,8 +102,7 @@ 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);
+ this.startPoint = getPointInRectangle(e.getX(), e.getY(), dataArea);
} else {
this.startPoint = null;
canvas.clearLiveHandler();
@@ -262,4 +260,23 @@ private double percentW(double x, Rectangle2D r) {
private double percentH(double y, Rectangle2D r) {
return (y - r.getMinY()) / r.getHeight();
}
+
+ /**
+ * Returns a point based on (x, y) but constrained to be within the bounds
+ * of a given rectangle.
+ *
+ * @param x the x-coordinate.
+ * @param y the y-coordinate.
+ * @param area the constraining rectangle ({@code null} not permitted).
+ *
+ * @return A point within the rectangle.
+ *
+ * @throws NullPointerException if {@code area} is {@code null}.
+ */
+ private static Point2D getPointInRectangle(double x, double y,
+ Rectangle2D area) {
+ x = Math.max(area.getMinX(), Math.min(x, area.getMaxX()));
+ y = Math.max(area.getMinY(), Math.min(y, area.getMaxY()));
+ return new Point2D.Double(x, y);
+ }
}
diff --git a/src/main/java/org/jfree/chart/fx/overlay/CrosshairOverlayFX.java b/src/main/java/org/jfree/chart/fx/overlay/CrosshairOverlayFX.java
index c67704d..d8eb9da 100644
--- a/src/main/java/org/jfree/chart/fx/overlay/CrosshairOverlayFX.java
+++ b/src/main/java/org/jfree/chart/fx/overlay/CrosshairOverlayFX.java
@@ -41,14 +41,14 @@
import java.awt.geom.Rectangle2D;
import java.util.Iterator;
import org.jfree.chart.JFreeChart;
+import org.jfree.chart.api.RectangleEdge;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.fx.ChartCanvas;
import org.jfree.chart.fx.ChartViewer;
-import org.jfree.chart.panel.CrosshairOverlay;
import org.jfree.chart.plot.Crosshair;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
-import org.jfree.chart.ui.RectangleEdge;
+import org.jfree.chart.swing.CrosshairOverlay;
/**
* An overlay for a {@link ChartViewer} that draws crosshairs on a plot.
@@ -64,12 +64,12 @@ public void paintOverlay(Graphics2D g2, ChartCanvas chartCanvas) {
Rectangle2D dataArea = chartCanvas.getRenderingInfo().getPlotInfo().getDataArea();
g2.clip(dataArea);
JFreeChart chart = chartCanvas.getChart();
- XYPlot plot = (XYPlot) chart.getPlot();
+ XYPlot> plot = (XYPlot>) chart.getPlot();
ValueAxis xAxis = plot.getDomainAxis();
RectangleEdge xAxisEdge = plot.getDomainAxisEdge();
- Iterator iterator = getDomainCrosshairs().iterator();
+ Iterator iterator = getDomainCrosshairs().iterator();
while (iterator.hasNext()) {
- Crosshair ch = (Crosshair) iterator.next();
+ Crosshair ch = iterator.next();
if (ch.isVisible()) {
double x = ch.getValue();
double xx = xAxis.valueToJava2D(x, dataArea, xAxisEdge);
@@ -84,7 +84,7 @@ public void paintOverlay(Graphics2D g2, ChartCanvas chartCanvas) {
RectangleEdge yAxisEdge = plot.getRangeAxisEdge();
iterator = getRangeCrosshairs().iterator();
while (iterator.hasNext()) {
- Crosshair ch = (Crosshair) iterator.next();
+ Crosshair ch = iterator.next();
if (ch.isVisible()) {
double y = ch.getValue();
double yy = yAxis.valueToJava2D(y, dataArea, yAxisEdge);
diff --git a/src/main/java/org/jfree/chart/fx/overlay/OverlayFX.java b/src/main/java/org/jfree/chart/fx/overlay/OverlayFX.java
index 1b687bf..b7650f7 100644
--- a/src/main/java/org/jfree/chart/fx/overlay/OverlayFX.java
+++ b/src/main/java/org/jfree/chart/fx/overlay/OverlayFX.java
@@ -38,7 +38,7 @@
import java.awt.Graphics2D;
import org.jfree.chart.fx.ChartCanvas;
-import org.jfree.chart.panel.Overlay;
+import org.jfree.chart.swing.Overlay;
/**
* An overlay that can be added to a {@link ChartCanvas}.
@@ -51,6 +51,5 @@ public interface OverlayFX extends Overlay {
* @param g2 the graphics target ({@code null} not permitted).
* @param chartCanvas the chart canvas ({@code null} not permitted).
*/
- public void paintOverlay(Graphics2D g2, ChartCanvas chartCanvas);
-
+ void paintOverlay(Graphics2D g2, ChartCanvas chartCanvas);
}