Example usage for org.jfree.chart ChartPanel zoomInDomain

List of usage examples for org.jfree.chart ChartPanel zoomInDomain

Introduction

In this page you can find the example usage for org.jfree.chart ChartPanel zoomInDomain.

Prototype

public void zoomInDomain(double x, double y) 

Source Link

Document

Decreases the length of the domain axis, centered about the given coordinate on the screen.

Usage

From source file:api3.transform.PlotWave.java

private MouseWheelListener addZoomWheel() {
    return new MouseWheelListener() {
        private void zoomChartAxis(ChartPanel chartP, boolean increase) {
            int width = chartP.getMaximumDrawWidth() - chartP.getMinimumDrawWidth();
            int height = chartP.getMaximumDrawHeight() - chartP.getMinimumDrawWidth();
            if (increase) {
                chartP.zoomInDomain(width / 2, height / 2);
            } else {
                chartP.zoomOutDomain(width / 2, height / 2);
            }/*w  ww . j  a v  a  2  s.  c o m*/
            lastValue = SLIDER_DEFAULT_VALUE;
            slider.setValue(lastValue);

        }

        public synchronized void decreaseZoom(JComponent chart, boolean saveAction) {
            ChartPanel ch = (ChartPanel) chart;
            zoomChartAxis(ch, false);
        }

        public synchronized void increaseZoom(JComponent chart, boolean saveAction) {
            ChartPanel ch = (ChartPanel) chart;
            zoomChartAxis(ch, true);
        }

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getScrollType() != MouseWheelEvent.WHEEL_UNIT_SCROLL) {
                return;
            }
            if (e.getWheelRotation() < 0) {
                increaseZoom((ChartPanel) e.getComponent(), true);
            } else {
                decreaseZoom((ChartPanel) e.getComponent(), true);
            }
        }
    };
}