Example usage for org.jfree.chart.event ChartChangeEvent getChart

List of usage examples for org.jfree.chart.event ChartChangeEvent getChart

Introduction

In this page you can find the example usage for org.jfree.chart.event ChartChangeEvent getChart.

Prototype

public JFreeChart getChart() 

Source Link

Document

Returns the chart that generated the change event.

Usage

From source file:net.sf.maltcms.chromaui.charts.format.ScaledNumberFormatter.java

/**
 *
 * @param cce// w  w w  .j  a v a 2 s.c o  m
 */
@Override
public void chartChanged(ChartChangeEvent cce) {
    ChartChangeEventType ccet = cce.getType();
    if (ccet == ChartChangeEventType.DATASET_UPDATED || ccet == ChartChangeEventType.NEW_DATASET) {
        if (cce.getSource() != (this)) {
            Plot p = cce.getChart().getPlot();
            if (p instanceof XYPlot) {
                XYPlot xyp = (XYPlot) p;
                Range axisRange = xyp.getRangeAxis().getRange();
                ;
                if (relativeMode) {
                    int cnt = xyp.getDatasetCount();
                    Range r = new Range(0, 1);
                    for (int i = 0; i < cnt; i++) {
                        Dataset d = xyp.getDataset(i);
                        if (d != null && d instanceof XYDataset) {
                            XYDataset xyd = (XYDataset) d;
                            Range dr = DatasetUtilities.findRangeBounds(xyd);
                            if (dr != null) {
                                r = new Range(Math.min(r.getLowerBound(), dr.getLowerBound()),
                                        Math.max(r.getUpperBound(), dr.getUpperBound()));

                            }
                        } else {
                            throw new NotImplementedException(
                                    "No support yet for dataset of type: " + d.getClass());
                        }
                    }
                    this.dataMin = Math.min(0, r.getLowerBound());
                    this.dataMax = r.getUpperBound();
                    cce.getChart().fireChartChanged();
                } else {
                    this.min = axisRange.getLowerBound();
                    this.max = axisRange.getUpperBound();
                    cce.getChart().fireChartChanged();
                }
            }
        }
    }
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.diagnostics.ApproximationSetViewer.java

@Override
public void chartChanged(ChartChangeEvent e) {
    zoomRangeBounds = e.getChart().getXYPlot().getRangeAxis().getRange();
    zoomDomainBounds = e.getChart().getXYPlot().getDomainAxis().getRange();
    useZoomBounds.setSelected(true);//from  w w w .  ja v a  2 s. c  o m
}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

public void chartChanged(ChartChangeEvent event) {
    try {/*from  w  w w .j  a  v a  2  s.c  om*/
        if (event.getChart() == null) {
            return;
        }

        BoundedRangeModel scrollBarModel = this.chartScrollBar.getModel();
        if (scrollBarModel == null) {
            return;
        }

        boolean chartIsZoomed = false;

        Plot plot = event.getChart().getPlot();
        if (plot instanceof XYPlot) {
            XYPlot hvp = (XYPlot) plot;
            ValueAxis xAxis = hvp.getDomainAxis();
            Range xAxisRange = xAxis.getRange();

            // avoid recursion
            scrollBarModel.removeChangeListener(this);

            int low = (int) (xAxisRange.getLowerBound() * scrollFactor);
            scrollBarModel.setValue(low);
            int ext = (int) (xAxisRange.getUpperBound() * scrollFactor - low);
            scrollBarModel.setExtent(ext);

            // restore
            scrollBarModel.addChangeListener(this);

            // check if zoomed horizontally
            //Range hdr = hvp.getHorizontalDataRange(xAxis);
            Range hdr = hvp.getDataRange(xAxis);

            double len = hdr == null ? 0 : hdr.getLength();
            chartIsZoomed |= xAxisRange.getLength() < len;
        }

        if (!chartIsZoomed && plot instanceof XYPlot) {
            // check if zoomed vertically
            XYPlot vvp = (XYPlot) plot;
            ValueAxis yAxis = vvp.getRangeAxis();
            if (yAxis != null) {
                chartIsZoomed = yAxis.getLowerBound() > yMin || yAxis.getUpperBound() < yMax;
            }
        }

        // enable "zoom-out-buttons" if chart is zoomed
        // otherwise disable them
        chartPanButton.setEnabled(chartIsZoomed);
        chartZoomOutButton.setEnabled(chartIsZoomed);
        chartFitButton.setEnabled(chartIsZoomed);
        chartScrollBar.setEnabled(chartIsZoomed);
        if (!chartIsZoomed) {
            setPanMode(false);
            chartZoomButton.setSelected(true);
        }
    } catch (Exception e) {
        MsgBox.error(e.getMessage());
    }
}

From source file:apidemo.PanScrollZoomDemo.java

/**
 * Handles a {@link ChartChangeEvent}.//from w  w  w .  ja  v a  2 s  .  c  om
 * 
 * @param event  the event.
 */
public void chartChanged(final ChartChangeEvent event) {
    try {
        if (event.getChart() == null) {
            return;
        }

        final BoundedRangeModel scrollBarModel = this.scrollBar.getModel();
        if (scrollBarModel == null) {
            return;
        }

        boolean chartIsZoomed = false;

        final Plot plot = event.getChart().getPlot();
        if (plot instanceof XYPlot) {
            final XYPlot hvp = (XYPlot) plot;
            final ValueAxis xAxis = hvp.getDomainAxis();
            final Range xAxisRange = xAxis.getRange();

            // avoid recursion
            scrollBarModel.removeChangeListener(this);

            final int low = (int) (xAxisRange.getLowerBound() * this.scrollFactor);
            scrollBarModel.setValue(low);
            final int ext = (int) (xAxisRange.getUpperBound() * this.scrollFactor - low);
            scrollBarModel.setExtent(ext);

            // restore
            scrollBarModel.addChangeListener(this);

            // check if zoomed horizontally
            //Range hdr = hvp.getHorizontalDataRange(xAxis);
            final Range hdr = hvp.getDataRange(xAxis);

            final double len = hdr == null ? 0 : hdr.getLength();
            chartIsZoomed |= xAxisRange.getLength() < len;
        }

        if (!chartIsZoomed && plot instanceof XYPlot) {
            // check if zoomed vertically
            final XYPlot vvp = (XYPlot) plot;
            ValueAxis yAxis = vvp.getRangeAxis();
            if (yAxis != null) {
                chartIsZoomed = yAxis.getLowerBound() > this.primYMinMax[0]
                        || yAxis.getUpperBound() < this.primYMinMax[1];

                // right y-axis
                if (!chartIsZoomed && plot instanceof XYPlot) {
                    final XYPlot xyPlot = (XYPlot) plot;
                    yAxis = xyPlot.getRangeAxis(1);
                    if (yAxis != null) {
                        chartIsZoomed = yAxis.getLowerBound() > this.secondYMinMax[0]
                                || yAxis.getUpperBound() < this.secondYMinMax[1];
                    }
                }
            }
        }

        // enable "zoom-out-buttons" if chart is zoomed
        // otherwise disable them
        this.panButton.setEnabled(chartIsZoomed);
        this.zoomOutButton.setEnabled(chartIsZoomed);
        this.fitButton.setEnabled(chartIsZoomed);
        this.scrollBar.setEnabled(chartIsZoomed);
        if (!chartIsZoomed) {
            setPanMode(false);
            this.zoomButton.setSelected(true);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}