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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/target/
/target/

#Idea project files
.idea
*.iml
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.5.3</version>
<version>2.0.0-SNAPSHOT</version>
</dependency>

<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
21 changes: 10 additions & 11 deletions src/main/java/org/jfree/chart/fx/ChartCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -371,7 +370,7 @@ public List<ChartMouseListenerFX> 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);
}

Expand Down
15 changes: 7 additions & 8 deletions src/main/java/org/jfree/chart/fx/ChartViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -86,7 +86,7 @@ public ChartMouseEventFX(JFreeChart chart, MouseEvent trigger,
* @return The chart (never {@code null}).
*/
public JFreeChart getChart() {
return this.chart;
return chart;
}

/**
Expand All @@ -95,7 +95,7 @@ public JFreeChart getChart() {
* @return The event (never {@code null}).
*/
public MouseEvent getTrigger() {
return this.trigger;
return trigger;
}

/**
Expand All @@ -104,7 +104,7 @@ public MouseEvent getTrigger() {
* @return The chart entity (possibly {@code null}).
*/
public ChartEntity getEntity() {
return this.entity;
return entity;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -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();
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/org/jfree/chart/fx/interaction/PanHandlerFX.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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;
Expand All @@ -132,37 +132,37 @@ 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);
}

@Override
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();
}

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 All @@ -62,16 +62,15 @@ 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).
*
* @return The zoom factor.
*/
public double getZoomFactor() {
return this.zoomFactor;
return zoomFactor;
}

/**
Expand All @@ -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());
}
}
Expand All @@ -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;
}
Expand Down
Loading