Search in sources :

Example 1 with TitleEntity

use of org.jfree.chart.entity.TitleEntity 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 TitleEntity

use of org.jfree.chart.entity.TitleEntity in project SIMVA-SoS by SESoS.

the class TextTitle method draw.

/**
 * Draws the block within the specified area.
 *
 * @param g2  the graphics device.
 * @param area  the area.
 * @param params  if this is an instance of {@link EntityBlockParams} it
 *                is used to determine whether or not an
 *                {@link EntityCollection} is returned by this method.
 *
 * @return An {@link EntityCollection} containing a chart entity for the
 *         title, or <code>null</code>.
 */
@Override
public Object draw(Graphics2D g2, Rectangle2D area, Object params) {
    if (this.content == null) {
        return null;
    }
    area = trimMargin(area);
    drawBorder(g2, area);
    if (this.text.equals("")) {
        return null;
    }
    ChartEntity entity = null;
    if (params instanceof EntityBlockParams) {
        EntityBlockParams p = (EntityBlockParams) params;
        if (p.getGenerateEntities()) {
            entity = new TitleEntity(area, this, this.toolTipText, this.urlText);
        }
    }
    area = trimBorder(area);
    if (this.backgroundPaint != null) {
        g2.setPaint(this.backgroundPaint);
        g2.fill(area);
    }
    area = trimPadding(area);
    RectangleEdge position = getPosition();
    if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) {
        drawHorizontal(g2, area);
    } else if (position == RectangleEdge.LEFT || position == RectangleEdge.RIGHT) {
        drawVertical(g2, area);
    }
    BlockResult result = new BlockResult();
    if (entity != null) {
        StandardEntityCollection sec = new StandardEntityCollection();
        sec.add(entity);
        result.setEntityCollection(sec);
    }
    return result;
}
Also used : StandardEntityCollection(org.jfree.chart.entity.StandardEntityCollection) BlockResult(org.jfree.chart.block.BlockResult) TitleEntity(org.jfree.chart.entity.TitleEntity) ChartEntity(org.jfree.chart.entity.ChartEntity) EntityBlockParams(org.jfree.chart.block.EntityBlockParams) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 3 with TitleEntity

use of org.jfree.chart.entity.TitleEntity in project SIMVA-SoS by SESoS.

the class LegendTitle method draw.

/**
 * Draws the block within the specified area.
 *
 * @param g2  the graphics device.
 * @param area  the area.
 * @param params  ignored (<code>null</code> permitted).
 *
 * @return An {@link org.jfree.chart.block.EntityBlockResult} or
 *         <code>null</code>.
 */
@Override
public Object draw(Graphics2D g2, Rectangle2D area, Object params) {
    Rectangle2D target = (Rectangle2D) area.clone();
    Rectangle2D hotspot = (Rectangle2D) area.clone();
    StandardEntityCollection sec = null;
    if (params instanceof EntityBlockParams && ((EntityBlockParams) params).getGenerateEntities()) {
        sec = new StandardEntityCollection();
        sec.add(new TitleEntity(hotspot, this));
    }
    target = trimMargin(target);
    if (this.backgroundPaint != null) {
        g2.setPaint(this.backgroundPaint);
        g2.fill(target);
    }
    BlockFrame border = getFrame();
    border.draw(g2, target);
    border.getInsets().trim(target);
    BlockContainer container = this.wrapper;
    if (container == null) {
        container = this.items;
    }
    target = trimPadding(target);
    Object val = container.draw(g2, target, params);
    if (val instanceof BlockResult) {
        EntityCollection ec = ((BlockResult) val).getEntityCollection();
        if (ec != null && sec != null) {
            sec.addAll(ec);
            ((BlockResult) val).setEntityCollection(sec);
        }
    }
    return val;
}
Also used : StandardEntityCollection(org.jfree.chart.entity.StandardEntityCollection) BlockResult(org.jfree.chart.block.BlockResult) StandardEntityCollection(org.jfree.chart.entity.StandardEntityCollection) EntityCollection(org.jfree.chart.entity.EntityCollection) BlockContainer(org.jfree.chart.block.BlockContainer) Rectangle2D(java.awt.geom.Rectangle2D) TitleEntity(org.jfree.chart.entity.TitleEntity) EntityBlockParams(org.jfree.chart.block.EntityBlockParams) BlockFrame(org.jfree.chart.block.BlockFrame)

Aggregations

TitleEntity (org.jfree.chart.entity.TitleEntity)3 BlockResult (org.jfree.chart.block.BlockResult)2 EntityBlockParams (org.jfree.chart.block.EntityBlockParams)2 StandardEntityCollection (org.jfree.chart.entity.StandardEntityCollection)2 Point2D (java.awt.geom.Point2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 MouseEventWrapper (net.sf.mzmine.chartbasics.gui.wrapper.MouseEventWrapper)1 ZoomHistory (net.sf.mzmine.chartbasics.listener.ZoomHistory)1 ValueAxis (org.jfree.chart.axis.ValueAxis)1 BlockContainer (org.jfree.chart.block.BlockContainer)1 BlockFrame (org.jfree.chart.block.BlockFrame)1 ChartEntity (org.jfree.chart.entity.ChartEntity)1 EntityCollection (org.jfree.chart.entity.EntityCollection)1 Range (org.jfree.data.Range)1 RectangleEdge (org.jfree.ui.RectangleEdge)1