List of usage examples for org.jfree.chart.plot Zoomable getOrientation
public PlotOrientation getOrientation();
From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.ZoomHandlerFX.java
/** * Handles a mouse dragged event by updating the zoom rectangle displayed * in the ChartViewer.//from w ww. j a v a 2 s .c om * * @param canvas the JavaFX canvas (<code>null</code> not permitted). * @param e the mouse event (<code>null</code> not permitted). */ @Override public void handleMouseDragged(ChartCanvas canvas, MouseEvent e) { if (this.startPoint == null) { //no initial zoom rectangle exists but the handler is set //as life handler unregister canvas.clearLiveHandler(); return; } boolean hZoom, vZoom; Plot p = canvas.getChart().getPlot(); if (!(p instanceof Zoomable)) { return; } Zoomable z = (Zoomable) p; if (z.getOrientation().isHorizontal()) { hZoom = z.isRangeZoomable(); vZoom = z.isDomainZoomable(); } else { hZoom = z.isDomainZoomable(); vZoom = z.isRangeZoomable(); } Rectangle2D dataArea = canvas.findDataArea(this.startPoint); double x = this.startPoint.getX(); double y = this.startPoint.getY(); double w = 0; double h = 0; if (hZoom && vZoom) { // selected rectangle shouldn't extend outside the data area... double xmax = Math.min(e.getX(), dataArea.getMaxX()); double ymax = Math.min(e.getY(), dataArea.getMaxY()); w = xmax - this.startPoint.getX(); h = ymax - this.startPoint.getY(); } else if (hZoom) { double xmax = Math.min(e.getX(), dataArea.getMaxX()); y = dataArea.getMinY(); w = xmax - this.startPoint.getX(); h = dataArea.getHeight(); } else if (vZoom) { double ymax = Math.min(e.getY(), dataArea.getMaxY()); x = dataArea.getMinX(); w = dataArea.getWidth(); h = ymax - this.startPoint.getY(); } viewer.showZoomRectangle(x, y, w, h); }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.ZoomHandlerFX.java
@Override public void handleMouseReleased(ChartCanvas canvas, MouseEvent e) { Plot p = canvas.getChart().getPlot(); if (!(p instanceof Zoomable)) { return;// ww w .j a v a2s . co m } boolean hZoom, vZoom; Zoomable z = (Zoomable) p; if (z.getOrientation().isHorizontal()) { hZoom = z.isRangeZoomable(); vZoom = z.isDomainZoomable(); } else { hZoom = z.isDomainZoomable(); vZoom = z.isRangeZoomable(); } boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.startPoint.getX()) >= 10; boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.startPoint.getY()) >= 10; if (zoomTrigger1 || zoomTrigger2) { Point2D endPoint = new Point2D.Double(e.getX(), e.getY()); PlotRenderingInfo pri = canvas.getRenderingInfo().getPlotInfo(); if ((hZoom && (e.getX() < this.startPoint.getX())) || (vZoom && (e.getY() < this.startPoint.getY()))) { boolean saved = p.isNotify(); p.setNotify(false); z.zoomDomainAxes(0, pri, endPoint); z.zoomRangeAxes(0, pri, endPoint); p.setNotify(saved); } else { double x = this.startPoint.getX(); double y = this.startPoint.getY(); double w = e.getX() - x; double h = e.getY() - y; Rectangle2D dataArea = canvas.findDataArea(this.startPoint); double maxX = dataArea.getMaxX(); double maxY = dataArea.getMaxY(); // for mouseReleased event, (horizontalZoom || verticalZoom) // will be true, so we can just test for either being false; // otherwise both are true if (!vZoom) { y = dataArea.getMinY(); w = Math.min(w, maxX - this.startPoint.getX()); h = dataArea.getHeight(); } else if (!hZoom) { x = dataArea.getMinX(); w = dataArea.getWidth(); h = Math.min(h, maxY - this.startPoint.getY()); } else { w = Math.min(w, maxX - this.startPoint.getX()); h = Math.min(h, maxY - this.startPoint.getY()); } Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h); boolean saved = p.isNotify(); p.setNotify(false); double pw0 = percentW(x, dataArea); double pw1 = percentW(x + w, dataArea); double ph0 = percentH(y, dataArea); double ph1 = percentH(y + h, dataArea); PlotRenderingInfo info = this.viewer.getRenderingInfo().getPlotInfo(); if (z.getOrientation().isVertical()) { z.zoomDomainAxes(pw0, pw1, info, endPoint); z.zoomRangeAxes(1 - ph1, 1 - ph0, info, endPoint); } else { z.zoomRangeAxes(pw0, pw1, info, endPoint); z.zoomDomainAxes(1 - ph1, 1 - ph0, info, endPoint); } p.setNotify(saved); } } viewer.hideZoomRectangle(); this.startPoint = null; canvas.clearLiveHandler(); }
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * Receives notification of changes to the chart, and redraws the chart. *//from w w w . jav a2 s . c om * @param event details of the chart change event. */ public void chartChanged(ChartChangeEvent event) { this.refreshBuffer = true; Plot plot = this.chart.getPlot(); if (plot instanceof Zoomable) { Zoomable z = (Zoomable) plot; this.orientation = z.getOrientation(); } repaint(); }
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * Sets the chart that is displayed in the panel. * * @param chart the chart (<code>null</code> permitted). *//*ww w .j av a 2 s . c o m*/ public void setChart(JFreeChart chart) { if (this.chart != null) { this.chart.removeChangeListener(this); } this.chart = chart; if (chart != null) { this.chart.addChangeListener(this); Plot plot = chart.getPlot(); this.domainZoomable = false; this.rangeZoomable = false; if (plot instanceof Zoomable) { Zoomable z = (Zoomable) plot; this.domainZoomable = z.isDomainZoomable(); this.rangeZoomable = z.isRangeZoomable(); this.orientation = z.getOrientation(); } } else { this.domainZoomable = false; this.rangeZoomable = false; } if (this.useBuffer) { this.refreshBuffer = true; } repaint(); }
From source file:de.xirp.ui.widgets.custom.XChartComposite.java
/** * Receives notification of changes to the chart, and redraws the * chart.//w ww.j a va2 s . c o m * * @param event * details of the chart change event. */ public void chartChanged(ChartChangeEvent event) { this.refreshBuffer = true; Plot plot = chart.getPlot(); if (plot instanceof Zoomable) { Zoomable z = (Zoomable) plot; this.orientation = z.getOrientation(); } forceRedraw(); }
From source file:de.xirp.ui.widgets.custom.XChartComposite.java
/** * Zooms in on a selected region.//w ww . j av a 2s. com * * @param selection * the selected region. */ @SuppressWarnings("cast") public void zoom(Rectangle selection) { // get the origin of the zoom selection in the Java2D space // used for // drawing the chart (that is, before any scaling to fit the // panel) Point2D selectOrigin = translateScreenToJava2D(new Point(selection.x, selection.y)); PlotRenderingInfo plotInfo = this.info.getPlotInfo(); Rectangle scaledDataArea = getScreenDataArea((int) (selection.x + selection.width) / 2, (int) (selection.y + selection.height) / 2); if ((selection.height > 0) && (selection.width > 0)) { double hLower = (selection.x - scaledDataArea.x) / (double) scaledDataArea.width; double hUpper = (selection.x + selection.width - scaledDataArea.x) / (double) scaledDataArea.width; double vLower = (scaledDataArea.y + scaledDataArea.height - selection.y - selection.height) / (double) scaledDataArea.height; double vUpper = (scaledDataArea.y + scaledDataArea.height - selection.y) / (double) scaledDataArea.height; Plot p = this.chart.getPlot(); if (p instanceof Zoomable) { Zoomable z = (Zoomable) p; if (z.getOrientation() == PlotOrientation.HORIZONTAL) { z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin); z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin); } else { z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin); z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin); } } } }
From source file:de.xirp.ui.widgets.custom.XChartComposite.java
/** * Sets the chart that is displayed in the panel. * /*from w ww .ja va2s . c o m*/ * @param chart * the chart (<code>null</code> permitted). */ public void setChartAndRobotName(JFreeChart chart, String robotName) { // stop listening for changes to the existing chart if (this.chart != null) { this.chart.removeChangeListener(this); } // add the new chart this.chart = chart; if (chart != null) { this.chart.addChangeListener(this); Plot plot = chart.getPlot(); this.domainZoomable = false; this.rangeZoomable = false; if (plot instanceof Zoomable) { Zoomable z = (Zoomable) plot; this.domainZoomable = z.isDomainZoomable(); this.rangeZoomable = z.isRangeZoomable(); this.orientation = z.getOrientation(); } this.chart.setBackgroundPaint(SWTUtils.toAwtColor((getBackground()))); } else { this.domainZoomable = false; this.rangeZoomable = false; } if (this.useBuffer) { this.refreshBuffer = true; } this.robotName = robotName; forceRedraw(); }
From source file:de.xirp.ui.widgets.custom.XChartComposite.java
/** * @param jfreechart/* w w w. j a v a2s . c o m*/ * @param minimumDrawWidth * @param minimumDrawHeight * @param maximumDrawWidth * @param maximumDrawHeight * @param useBuffer * @param zoom * @param tooltips * @param export * @param robotName */ private void init(JFreeChart jfreechart, int minimumDrawWidth, int minimumDrawHeight, int maximumDrawWidth, int maximumDrawHeight, boolean useBuffer, boolean zoom, boolean tooltips, boolean export, String robotName) { setChartAndRobotName(jfreechart, robotName); addControlListener(this); chartMouseListeners = new EventListenerList(); setLayout(new FillLayout()); info = new ChartRenderingInfo(); this.useBuffer = useBuffer; this.refreshBuffer = false; this.minimumDrawWidth = minimumDrawWidth; this.minimumDrawHeight = minimumDrawHeight; this.maximumDrawWidth = maximumDrawWidth; this.maximumDrawHeight = maximumDrawHeight; this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE; setDisplayToolTips(tooltips); canvas = new XCanvas(this, SWT.DOUBLE_BUFFERED | SWT.BACKGROUND); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { if (chart != null) { paintChart(e); } } }); if (chart != null) { chart.addChangeListener(this); Plot plot = chart.getPlot(); this.domainZoomable = false; this.rangeZoomable = false; if (plot instanceof Zoomable) { Zoomable z = (Zoomable) plot; this.domainZoomable = z.isDomainZoomable(); this.rangeZoomable = z.isRangeZoomable(); this.orientation = z.getOrientation(); } } // set up popup menu... this.popup = null; if (zoom) { this.popup = createPopupMenu(zoom, export); } Listener listener = new Listener() { public void handleEvent(Event event) { if (XChartComposite.this.chart != null) { handleMouseEvents(event); } } }; canvas.addListener(SWT.MouseDown, listener); canvas.addListener(SWT.MouseMove, listener); canvas.addListener(SWT.MouseUp, listener); this.enforceFileExtensions = true; }
From source file:com.munch.exchange.ExchangeChartComposite.java
/** * Receives notification of changes to the chart, and redraws the chart. * * @param event details of the chart change event. *//* w w w . j a v a2s. com*/ public void chartChanged(ChartChangeEvent event) { this.refreshBuffer = true; Plot plot = this.chart.getPlot(); if (plot instanceof Zoomable) { Zoomable z = (Zoomable) plot; this.orientation = z.getOrientation(); } this.canvas.redraw(); }
From source file:com.munch.exchange.ExchangeChartComposite.java
/** * Zooms in on a selected region./*ww w .java 2s .c o m*/ * * @param selection the selected region. */ public void zoom(Rectangle selection) { // get the origin of the zoom selection in the Java2D space used for // drawing the chart (that is, before any scaling to fit the panel) Point2D selectOrigin = translateScreenToJava2D(new Point(selection.x, selection.y)); PlotRenderingInfo plotInfo = this.info.getPlotInfo(); Rectangle scaledDataArea = getScreenDataArea((selection.x + selection.width / 2), (selection.y + selection.height / 2)); if ((selection.height > 0) && (selection.width > 0)) { double hLower = (selection.x - scaledDataArea.x) / (double) scaledDataArea.width; double hUpper = (selection.x + selection.width - scaledDataArea.x) / (double) scaledDataArea.width; double vLower = (scaledDataArea.y + scaledDataArea.height - selection.y - selection.height) / (double) scaledDataArea.height; double vUpper = (scaledDataArea.y + scaledDataArea.height - selection.y) / (double) scaledDataArea.height; Plot p = this.chart.getPlot(); if (p instanceof Zoomable) { Zoomable z = (Zoomable) p; if (z.getOrientation() == PlotOrientation.HORIZONTAL) { z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin); z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin); } else { z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin); z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin); } } } }