/** * Creates a new viewer instance. * * @param chart the chart ({@code null} permitted). * @param contextMenuEnabled enable the context menu? */ public ChartViewer(JFreeChart chart, boolean contextMenuEnabled) { this.canvas = new ChartCanvas(chart); this.canvas.setTooltipEnabled(true); this.canvas.addMouseHandler(new ZoomHandlerFX("zoom", this)); setFocusTraversable(true); getChildren().add(this.canvas); this.zoomRectangle = new Rectangle(0, 0, new Color(0, 0, 1, 0.25)); this.zoomRectangle.setManaged(false); this.zoomRectangle.setVisible(false); getChildren().add(this.zoomRectangle); this.contextMenu = createContextMenu(); setOnContextMenuRequested((ContextMenuEvent event) -> { contextMenu.show(ChartViewer.this.getScene().getWindow(), event.getScreenX(), event.getScreenY()); }); this.contextMenu.setOnShowing( e -> ChartViewer.this.getCanvas().setTooltipEnabled(false)); this.contextMenu.setOnHiding( e -> ChartViewer.this.getCanvas().setTooltipEnabled(true)); }
/** * Creates the node representing this control. * * @return The node. */ private BorderPane createNode(ChartViewer control) { BorderPane borderPane = new BorderPane(); borderPane.setPrefSize(800, 500); StackPane sp = new StackPane(); sp.setMinSize(10, 10); sp.setPrefSize(600, 400); this.canvas = new ChartCanvas(getSkinnable().getChart()); this.canvas.setTooltipEnabled(control.isTooltipEnabled()); this.canvas.addChartMouseListener(control); this.canvas.widthProperty().bind(sp.widthProperty()); this.canvas.heightProperty().bind(sp.heightProperty()); this.canvas.addMouseHandler(new ZoomHandlerFX("zoom", control)); sp.getChildren().add(this.canvas); borderPane.setCenter(sp); return borderPane; }