Example usage for org.jfree.chart.plot Zoomable isDomainZoomable

List of usage examples for org.jfree.chart.plot Zoomable isDomainZoomable

Introduction

In this page you can find the example usage for org.jfree.chart.plot Zoomable isDomainZoomable.

Prototype

public boolean isDomainZoomable();

Source Link

Document

Returns true if the plot's domain is zoomable, and false otherwise.

Usage

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 w w . ja v  a  2 s  . co  m*/
 * 
 * @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;//from www . j  a v a2 s  .c om
    }
    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

/**
 * Sets the chart that is displayed in the panel.
 *
 * @param chart  the chart (<code>null</code> permitted).
 *///from   w  w w. j  a v  a2 s.  c  om
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

/**
 * Sets the chart that is displayed in the panel.
 * /*from   w  w  w  .j  a  v  a2s.  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

/**
 * The idea is to modify the zooming options depending on the type
 * of chart being displayed by the panel.
 * //from   w w  w .j av a  2 s .c  om
 * @param x
 *            horizontal position of the popup.
 * @param y
 *            vertical position of the popup.
 */
protected void displayPopupMenu(int x, int y) {
    if (popup != null && chart != null) {
        // go through each zoom menu item and decide whether or
        // not to
        // enable it...
        Plot plot = chart.getPlot();
        boolean isDomainZoomable = false;
        boolean isRangeZoomable = false;
        if (plot instanceof Zoomable) {
            Zoomable z = (Zoomable) plot;
            isDomainZoomable = z.isDomainZoomable();
            isRangeZoomable = z.isRangeZoomable();
        }
        if (zoomInDomainMenuItem != null) {
            zoomInDomainMenuItem.setEnabled(isDomainZoomable);
        }
        if (zoomOutDomainMenuItem != null) {
            zoomOutDomainMenuItem.setEnabled(isDomainZoomable);
        }
        if (zoomResetDomainMenuItem != null) {
            zoomResetDomainMenuItem.setEnabled(isDomainZoomable);
        }

        if (zoomInRangeMenuItem != null) {
            zoomInRangeMenuItem.setEnabled(isRangeZoomable);
        }
        if (zoomOutRangeMenuItem != null) {
            zoomOutRangeMenuItem.setEnabled(isRangeZoomable);
        }

        if (zoomResetRangeMenuItem != null) {
            zoomResetRangeMenuItem.setEnabled(isRangeZoomable);
        }

        if (zoomInBothMenuItem != null) {
            zoomInBothMenuItem.setEnabled(isDomainZoomable & isRangeZoomable);
        }
        if (zoomOutBothMenuItem != null) {
            zoomOutBothMenuItem.setEnabled(isDomainZoomable & isRangeZoomable);
        }
        if (zoomResetBothMenuItem != null) {
            zoomResetBothMenuItem.setEnabled(isDomainZoomable & isRangeZoomable);
        }

        popup.setLocation(x, y);
        popup.setVisible(true);
    }

}

From source file:de.xirp.ui.widgets.custom.XChartComposite.java

/**
 * @param jfreechart/*from www  .j  a va 2 s. 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:org.jfree.experimental.chart.swt.ChartComposite.java

/**
 * Constructs a JFreeChart panel.//from  ww w.  ja  va  2  s  .co  m
 * 
 * @param comp The parent.
 * @param style The style of the composite.
 * @param jfreechart the chart.
 * @param width the preferred width of the panel.
 * @param height the preferred height of the panel.
 * @param minimumDrawW the minimum drawing width.
 * @param minimumDrawH the minimum drawing height.
 * @param maximumDrawW the maximum drawing width.
 * @param maximumDrawH the maximum drawing height.
 * @param usingBuffer a flag that indicates whether to use the off-screen buffer to improve
 *        performance (at the expense of memory).
 * @param properties a flag indicating whether or not the chart property editor should be
 *        available via the popup menu.
 * @param save a flag indicating whether or not save options should be available via the popup
 *        menu.
 * @param print a flag indicating whether or not the print option should be available via the
 *        popup menu.
 * @param zoom a flag indicating whether or not zoom options should be added to the popup menu.
 * @param tooltips a flag indicating whether or not tooltips should be enabled for the chart.
 */
public ChartComposite(Composite comp, int style, JFreeChart jfreechart, int width, int height, int minimumDrawW,
        int minimumDrawH, int maximumDrawW, int maximumDrawH, boolean usingBuffer, boolean properties,
        boolean save, boolean print, boolean zoom, boolean tooltips) {
    super(comp, style);
    this.setChart(jfreechart);
    this.chartMouseListeners = new EventListenerList();
    this.setLayout(new FillLayout());
    this.info = new ChartRenderingInfo();
    this.useBuffer = usingBuffer;
    this.refreshBuffer = false;
    this.minimumDrawWidth = minimumDrawW;
    this.minimumDrawHeight = minimumDrawH;
    this.maximumDrawWidth = maximumDrawW;
    this.maximumDrawHeight = maximumDrawH;
    this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE;
    this.setDisplayToolTips(tooltips);
    // create the canvas and add the required listeners
    this.canvas = new Canvas(this, SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND);
    this.canvas.addPaintListener(this);
    this.canvas.addMouseListener(this);
    this.canvas.addMouseMoveListener(this);

    if (this.chart != null) {
        this.chart.addChangeListener(this);
        Plot plot = this.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 (properties || save || print || zoom)
        this.popup = createPopupMenu(properties, save, print, zoom);

    this.enforceFileExtensions = true;
}

From source file:com.munch.exchange.ExchangeChartComposite.java

/**
 * Sets the chart that is displayed in the panel.
 *
 * @param chart  the chart (<code>null</code> permitted).
 *///from ww w .  j  ava2s .co m
public void setChart(JFreeChart chart) {
    // stop listening for changes to the existing chart
    if (this.chart != null) {
        this.chart.removeChangeListener(this);
        this.chart.removeProgressListener(this);
    }

    // add the new chart
    this.chart = chart;
    if (chart != null) {
        this.chart.addChangeListener(this);
        this.chart.addProgressListener(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;
    }
}

From source file:com.munch.exchange.ExchangeChartComposite.java

/**
 * The idea is to modify the zooming options depending on the type of chart
 * being displayed by the panel./*from  ww w .  ja  v a 2 s  . c o  m*/
 *
 * @param x  horizontal position of the popup.
 * @param y  vertical position of the popup.
 */
protected void displayPopupMenu(int x, int y) {
    if (this.popup != null) {
        // go through each zoom menu item and decide whether or not to
        // enable it...
        Plot plot = this.chart.getPlot();
        boolean isDomainZoomable = false;
        boolean isRangeZoomable = false;
        if (plot instanceof Zoomable) {
            Zoomable z = (Zoomable) plot;
            isDomainZoomable = z.isDomainZoomable();
            isRangeZoomable = z.isRangeZoomable();
        }
        if (this.zoomInDomainMenuItem != null) {
            this.zoomInDomainMenuItem.setEnabled(isDomainZoomable);
        }
        if (this.zoomOutDomainMenuItem != null) {
            this.zoomOutDomainMenuItem.setEnabled(isDomainZoomable);
        }
        if (this.zoomResetDomainMenuItem != null) {
            this.zoomResetDomainMenuItem.setEnabled(isDomainZoomable);
        }

        if (this.zoomInRangeMenuItem != null) {
            this.zoomInRangeMenuItem.setEnabled(isRangeZoomable);
        }
        if (this.zoomOutRangeMenuItem != null) {
            this.zoomOutRangeMenuItem.setEnabled(isRangeZoomable);
        }

        if (this.zoomResetRangeMenuItem != null) {
            this.zoomResetRangeMenuItem.setEnabled(isRangeZoomable);
        }

        if (this.zoomInBothMenuItem != null) {
            this.zoomInBothMenuItem.setEnabled(isDomainZoomable & isRangeZoomable);
        }
        if (this.zoomOutBothMenuItem != null) {
            this.zoomOutBothMenuItem.setEnabled(isDomainZoomable & isRangeZoomable);
        }
        if (this.zoomResetBothMenuItem != null) {
            this.zoomResetBothMenuItem.setEnabled(isDomainZoomable & isRangeZoomable);
        }

        this.popup.setLocation(x, y);
        this.popup.setVisible(true);
    }

}

From source file:org.mwc.cmap.grideditor.chart.FixedChartComposite.java

/**
 * Sets the flag that controls whether or not zooming is enable for the domain
 * axis. A check is made to ensure that the current plot supports zooming for
 * the domain values./*from  w ww . j  a v a 2 s .c o m*/
 * 
 * @param flag
 *          <code>true</code> enables zooming if possible.
 */
public void setDomainZoomable(final boolean flag) {
    if (flag) {
        final Plot plot = this.chart.getPlot();
        if (plot instanceof Zoomable) {
            final Zoomable z = (Zoomable) plot;
            this.domainZoomable = flag && (z.isDomainZoomable());
        }
    } else {
        this.domainZoomable = false;
    }
}