Search in sources :

Example 1 with ZoomHistory

use of net.sf.mzmine.chartbasics.listener.ZoomHistory in project mzmine2 by mzmine.

the class ChartGestureHandler method createHandler.

/**
 * Create preset handlers
 *
 * @param handler
 * @param g
 * @param param Parameters for specific handlers <br>
 * @return
 */
public static ChartGestureHandler createHandler(Handler handler, final ChartGesture g, Object[] param) {
    Consumer<ChartGestureEvent> newHandler = null;
    switch(handler) {
        case DEBUG:
            newHandler = e -> System.out.println(e.toString());
            break;
        case PREVIOUS_ZOOM_HISTORY:
            newHandler = e -> {
                ZoomHistory h = e.getChartWrapper().getZoomHistory();
                if (h != null) {
                    Range[] range = h.setPreviousPoint();
                    if (range != null && range.length > 0 && range[0] != null) {
                        ValueAxis dom = e.getChart().getXYPlot().getDomainAxis();
                        ValueAxis ran = e.getChart().getXYPlot().getRangeAxis();
                        ChartLogics.setZoomAxis(dom, range[0]);
                        ChartLogics.setZoomAxis(ran, range[1]);
                    }
                }
            };
            break;
        case NEXT_ZOOM_HISTORY:
            newHandler = e -> {
                ZoomHistory h = e.getChartWrapper().getZoomHistory();
                if (h != null) {
                    Range[] range = h.setNextPoint();
                    if (range != null && range.length > 0 && range[0] != null) {
                        ValueAxis dom = e.getChart().getXYPlot().getDomainAxis();
                        ValueAxis ran = e.getChart().getXYPlot().getRangeAxis();
                        ChartLogics.setZoomAxis(dom, range[0]);
                        ChartLogics.setZoomAxis(ran, range[1]);
                    }
                }
            };
            break;
        case TITLE_REMOVER:
            newHandler = e -> {
                if (e.getEntity() instanceof TitleEntity) {
                    TitleEntity te = (TitleEntity) e.getEntity();
                    te.getTitle().setVisible(false);
                }
            };
            break;
        case AUTO_ZOOM_AXIS:
            newHandler = e -> {
                ValueAxis a = e.getAxis();
                if (a != null)
                    ChartLogics.autoAxis(a);
            };
            break;
        case AUTO_ZOOM_OPPOSITE_AXIS:
            newHandler = e -> {
                if (e.getGesture().getEntity().equals(Entity.AXIS)) {
                    e.getChartWrapper().autoRangeAxis();
                    e.getChartWrapper().autoDomainAxis();
                } else if (e.getGesture().getEntity().equals(Entity.DOMAIN_AXIS))
                    e.getChartWrapper().autoRangeAxis();
                else
                    e.getChartWrapper().autoDomainAxis();
            };
            break;
        case SCROLL_AXIS:
            newHandler = e -> {
                ValueAxis axis = e.getAxis();
                if (axis != null) {
                    double diff = 0.03;
                    if (e.getMouseEvent().isMouseWheelEvent()) {
                        diff = -0.10 * e.getMouseEvent().getWheelRotation();
                    }
                    ChartLogics.offsetAxis(axis, diff);
                }
            };
            break;
        case SCROLL_AXIS_AND_AUTO_ZOOM:
            newHandler = e -> {
                ValueAxis axis = e.getAxis();
                if (axis != null) {
                    double diff = 0.03;
                    if (e.getMouseEvent().isMouseWheelEvent()) {
                        diff = -0.10 * e.getMouseEvent().getWheelRotation();
                    }
                    ChartLogics.offsetAxis(axis, diff);
                    if (e.getGesture().getEntity().equals(Entity.DOMAIN_AXIS))
                        e.getChartWrapper().autoRangeAxis();
                    else
                        e.getChartWrapper().autoDomainAxis();
                }
            };
            break;
        case ZOOM_AXIS_INCLUDE_ZERO:
            newHandler = e -> {
                ValueAxis axis = e.getAxis();
                if (axis != null) {
                    double diff = 0.05;
                    if (e.getMouseEvent().isMouseWheelEvent()) {
                        diff = -0.10 * e.getMouseEvent().getWheelRotation();
                    }
                    ChartLogics.zoomAxis(axis, diff, true);
                }
            };
            break;
        case ZOOM_AXIS_CENTER:
            newHandler = e -> {
                ValueAxis axis = e.getAxis();
                if (axis != null) {
                    MouseEventWrapper p = e.getMouseEvent();
                    double diff = 0.05;
                    if (e.getMouseEvent().isMouseWheelEvent()) {
                        diff = -0.10 * p.getWheelRotation();
                    }
                    // get data space coordinates
                    Point2D point = e.getCoordinates(p.getX(), p.getY());
                    if (point != null) {
                        // vertical ?
                        Boolean orient = e.isVerticalAxis(axis);
                        if (orient == null)
                            return;
                        else if (orient)
                            ChartLogics.zoomAxis(axis, diff, point.getY());
                        else
                            ChartLogics.zoomAxis(axis, diff, point.getX());
                    }
                }
            };
            break;
        default:
            break;
    }
    if (newHandler == null)
        return null;
    else
        return new ChartGestureHandler(g, newHandler);
}
Also used : ZoomHistory(net.sf.mzmine.chartbasics.listener.ZoomHistory) Point2D(java.awt.geom.Point2D) ValueAxis(org.jfree.chart.axis.ValueAxis) MouseEventWrapper(net.sf.mzmine.chartbasics.gui.wrapper.MouseEventWrapper) TitleEntity(org.jfree.chart.entity.TitleEntity) Range(org.jfree.data.Range)

Example 2 with ZoomHistory

use of net.sf.mzmine.chartbasics.listener.ZoomHistory in project mzmine2 by mzmine.

the class EChartPanel method initChartPanel.

/**
 * Init ChartPanel Mouse Listener For MouseDraggedOverAxis event For scrolling X-Axis und zooming
 * Y-Axis0
 */
private void initChartPanel(boolean stickyZeroForRangeAxis) {
    final EChartPanel chartPanel = this;
    // remove old init
    if (mouseAdapter != null) {
        this.removeMouseListener(mouseAdapter);
        this.removeMouseMotionListener(mouseAdapter);
        this.removeMouseWheelListener(mouseAdapter);
    }
    if (chartPanel.getChart().getPlot() instanceof XYPlot) {
        // set sticky zero
        if (stickyZeroForRangeAxis) {
            ValueAxis rangeAxis = chartPanel.getChart().getXYPlot().getRangeAxis();
            if (rangeAxis instanceof NumberAxis) {
                NumberAxis axis = (NumberAxis) rangeAxis;
                axis.setAutoRangeIncludesZero(true);
                axis.setAutoRange(true);
                axis.setAutoRangeStickyZero(true);
                axis.setRangeType(RangeType.POSITIVE);
            }
        }
        Plot p = getChart().getPlot();
        if (addZoomHistory && (p instanceof XYPlot) && !(p instanceof CombinedDomainXYPlot || p instanceof CombinedRangeXYPlot)) {
            // zoom history
            zoomHistory = new ZoomHistory(this, 20);
            // axis range changed listener for zooming and more
            ValueAxis rangeAxis = this.getChart().getXYPlot().getRangeAxis();
            ValueAxis domainAxis = this.getChart().getXYPlot().getDomainAxis();
            if (rangeAxis != null) {
                rangeAxis.addChangeListener(new AxisRangeChangedListener(new ChartViewWrapper(this)) {

                    @Override
                    public void axisRangeChanged(ChartViewWrapper chart, ValueAxis axis, Range lastR, Range newR) {
                        // notify listeners of changed range
                        if (axesRangeListener != null)
                            for (AxesRangeChangedListener l : axesRangeListener) l.axesRangeChanged(chart, axis, lastR, newR);
                    }
                });
            }
            if (domainAxis != null) {
                domainAxis.addChangeListener(new AxisRangeChangedListener(new ChartViewWrapper(this)) {

                    @Override
                    public void axisRangeChanged(ChartViewWrapper chart, ValueAxis axis, Range lastR, Range newR) {
                        // notify listeners of changed range
                        if (axesRangeListener != null)
                            for (AxesRangeChangedListener l : axesRangeListener) l.axesRangeChanged(chart, axis, lastR, newR);
                    }
                });
            }
        }
        // mouse adapter for scrolling and zooming
        mouseAdapter = new ChartGestureMouseAdapter();
        // mouseAdapter.addDebugHandler();
        this.addMouseListener(mouseAdapter);
        this.addMouseMotionListener(mouseAdapter);
        this.addMouseWheelListener(mouseAdapter);
        // add gestures
        if (standardGestures) {
            addStandardGestures();
        }
    }
}
Also used : ZoomHistory(net.sf.mzmine.chartbasics.listener.ZoomHistory) NumberAxis(org.jfree.chart.axis.NumberAxis) CombinedRangeXYPlot(org.jfree.chart.plot.CombinedRangeXYPlot) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) Plot(org.jfree.chart.plot.Plot) Range(org.jfree.data.Range) ChartViewWrapper(net.sf.mzmine.chartbasics.gui.wrapper.ChartViewWrapper) AxisRangeChangedListener(net.sf.mzmine.chartbasics.listener.AxisRangeChangedListener) CombinedRangeXYPlot(org.jfree.chart.plot.CombinedRangeXYPlot) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) AxesRangeChangedListener(net.sf.mzmine.chartbasics.listener.AxesRangeChangedListener) CombinedRangeXYPlot(org.jfree.chart.plot.CombinedRangeXYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot)

Example 3 with ZoomHistory

use of net.sf.mzmine.chartbasics.listener.ZoomHistory in project mzmine2 by mzmine.

the class EChartViewer method initChartPanel.

/**
 * Init ChartPanel Mouse Listener For MouseDraggedOverAxis event For scrolling X-Axis und zooming
 * Y-Axis0
 */
private void initChartPanel() {
    final EChartViewer chartPanel = this;
    // remove old init
    if (mouseAdapter != null) {
        this.getCanvas().removeMouseHandler(mouseAdapter);
    }
    if (chartPanel.getChart().getPlot() instanceof XYPlot) {
        // set sticky zero
        if (stickyZeroForRangeAxis) {
            ValueAxis rangeAxis = chartPanel.getChart().getXYPlot().getRangeAxis();
            if (rangeAxis instanceof NumberAxis) {
                NumberAxis axis = (NumberAxis) rangeAxis;
                axis.setAutoRangeIncludesZero(true);
                axis.setAutoRange(true);
                axis.setAutoRangeStickyZero(true);
                axis.setRangeType(RangeType.POSITIVE);
            }
        }
        Plot p = getChart().getPlot();
        if (addZoomHistory && p instanceof XYPlot && !(p instanceof CombinedDomainXYPlot || p instanceof CombinedRangeXYPlot)) {
            // zoom history
            zoomHistory = new ZoomHistory(this, 20);
            // axis range changed listener for zooming and more
            ValueAxis rangeAxis = this.getChart().getXYPlot().getRangeAxis();
            ValueAxis domainAxis = this.getChart().getXYPlot().getDomainAxis();
            if (rangeAxis != null) {
                rangeAxis.addChangeListener(new AxisRangeChangedListener(new ChartViewWrapper(this)) {

                    @Override
                    public void axisRangeChanged(ChartViewWrapper chart, ValueAxis axis, Range lastR, Range newR) {
                        // notify listeners of changed range
                        if (axesRangeListener != null)
                            for (AxesRangeChangedListener l : axesRangeListener) l.axesRangeChanged(chart, axis, lastR, newR);
                    }
                });
            }
            if (domainAxis != null) {
                domainAxis.addChangeListener(new AxisRangeChangedListener(new ChartViewWrapper(this)) {

                    @Override
                    public void axisRangeChanged(ChartViewWrapper chart, ValueAxis axis, Range lastR, Range newR) {
                        // notify listeners of changed range
                        if (axesRangeListener != null)
                            for (AxesRangeChangedListener l : axesRangeListener) l.axesRangeChanged(chart, axis, lastR, newR);
                    }
                });
            }
        }
        // mouse adapter for scrolling and zooming
        mouseAdapter = new ChartGestureMouseAdapterFX("gestures", this);
        addMouseHandler(mouseAdapter);
        // add gestures
        if (standardGestures) {
            addStandardGestures();
        }
    // mouseAdapter.addDebugHandler();
    }
}
Also used : ZoomHistory(net.sf.mzmine.chartbasics.listener.ZoomHistory) NumberAxis(org.jfree.chart.axis.NumberAxis) CombinedRangeXYPlot(org.jfree.chart.plot.CombinedRangeXYPlot) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) Plot(org.jfree.chart.plot.Plot) Range(org.jfree.data.Range) ChartViewWrapper(net.sf.mzmine.chartbasics.gui.wrapper.ChartViewWrapper) AxisRangeChangedListener(net.sf.mzmine.chartbasics.listener.AxisRangeChangedListener) CombinedRangeXYPlot(org.jfree.chart.plot.CombinedRangeXYPlot) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) AxesRangeChangedListener(net.sf.mzmine.chartbasics.listener.AxesRangeChangedListener) CombinedRangeXYPlot(org.jfree.chart.plot.CombinedRangeXYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot)

Aggregations

ZoomHistory (net.sf.mzmine.chartbasics.listener.ZoomHistory)3 ValueAxis (org.jfree.chart.axis.ValueAxis)3 Range (org.jfree.data.Range)3 ChartViewWrapper (net.sf.mzmine.chartbasics.gui.wrapper.ChartViewWrapper)2 AxesRangeChangedListener (net.sf.mzmine.chartbasics.listener.AxesRangeChangedListener)2 AxisRangeChangedListener (net.sf.mzmine.chartbasics.listener.AxisRangeChangedListener)2 NumberAxis (org.jfree.chart.axis.NumberAxis)2 CombinedDomainXYPlot (org.jfree.chart.plot.CombinedDomainXYPlot)2 CombinedRangeXYPlot (org.jfree.chart.plot.CombinedRangeXYPlot)2 Plot (org.jfree.chart.plot.Plot)2 XYPlot (org.jfree.chart.plot.XYPlot)2 Point2D (java.awt.geom.Point2D)1 MouseEventWrapper (net.sf.mzmine.chartbasics.gui.wrapper.MouseEventWrapper)1 TitleEntity (org.jfree.chart.entity.TitleEntity)1