Example usage for org.jfree.chart.entity EntityCollection getEntity

List of usage examples for org.jfree.chart.entity EntityCollection getEntity

Introduction

In this page you can find the example usage for org.jfree.chart.entity EntityCollection getEntity.

Prototype

public ChartEntity getEntity(double x, double y);

Source Link

Document

Returns an entity whose area contains the specified point.

Usage

From source file:org.rdv.viz.chart.ChartPanel.java

/**
 * Returns the chart entity at a given point.
 * <P>/*  w w  w.  j  ava2  s  .c o m*/
 * This method will return null if there is (a) no entity at the given
 * point, or (b) no entity collection has been generated.
 *
 * @param viewX  the x-coordinate.
 * @param viewY  the y-coordinate.
 *
 * @return The chart entity (possibly <code>null</code>).
 */
public ChartEntity getEntityForPoint(int viewX, int viewY) {

    ChartEntity result = null;
    if (this.info != null) {
        Insets insets = getInsets();
        double x = (viewX - insets.left) / this.scaleX;
        double y = (viewY - insets.top) / this.scaleY;
        EntityCollection entities = this.info.getEntityCollection();
        result = entities != null ? entities.getEntity(x, y) : null;
    }
    return result;

}

From source file:org.rdv.viz.chart.ChartPanel.java

/**
 * Receives notification of mouse clicks on the panel. These are
 * translated and passed on to any registered {@link ChartMouseListener}s.
 *
 * @param event  Information about the mouse event.
 *///from   ww w.j av a 2s.  c  o  m
public void mouseClicked(MouseEvent event) {

    Insets insets = getInsets();
    int x = (int) ((event.getX() - insets.left) / this.scaleX);
    int y = (int) ((event.getY() - insets.top) / this.scaleY);

    this.anchor = new Point2D.Double(x, y);
    if (this.chart == null) {
        return;
    }
    this.chart.setNotify(true); // force a redraw
    // new entity code...
    Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class);
    if (listeners.length == 0) {
        return;
    }

    ChartEntity entity = null;
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            entity = entities.getEntity(x, y);
        }
    }
    ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), event, entity);
    for (int i = listeners.length - 1; i >= 0; i -= 1) {
        ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent);
    }

}

From source file:org.rdv.viz.chart.ChartPanel.java

/**
 * Returns a string for the tooltip.//from www . jav  a 2  s .c  o m
 *
 * @param e  the mouse event.
 *
 * @return A tool tip or <code>null</code> if no tooltip is available.
 */
public String getToolTipText(MouseEvent e) {

    String result = null;
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            Insets insets = getInsets();
            ChartEntity entity = entities.getEntity((int) ((e.getX() - insets.left) / this.scaleX),
                    (int) ((e.getY() - insets.top) / this.scaleY));
            if (entity != null) {
                result = entity.getToolTipText();
            }
        }
    }
    return result;

}

From source file:edu.pitt.dbmi.odie.ui.jfreechart.EnhancedChartComposite.java

/**
 * Finds the chart entity at the given co-ordinates. If the co-ordinates are
 * not within a given entity scrolls down(vertical plot) or left(plot
 * horizontal) until it is within the entity or outside the plot area.
 * /*from  www  .j av a2  s .  c  o m*/
 * @param x
 * @param y
 * @return The entity at the co-ordinates. Returns null if no entity found
 */
private ChartEntity getEntityForLocation(double x, double y) {
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            ChartEntity entity = null;
            Rectangle rect = getScreenDataArea();

            int count = 0;
            // //logger.debug(rect.x + "," + rect.y +"," + rect.width + ","
            // + rect.height);

            Point2D javaPoint = translateScreenToJava2D(new Point(rect.x, rect.y));
            if (this.orientation == PlotOrientation.HORIZONTAL) {
                while (entity == null && x > javaPoint.getX()) {
                    entity = entities.getEntity(x, y);

                    // if(entity!=null)
                    // //logger.debug("found in " + count + " attempts");

                    x--;
                    count++;
                }
            } else {
                while (entity == null && y < (javaPoint.getY() + (rect.height * scaleY))) {
                    entity = entities.getEntity(x, y);

                    // if(entity!=null)
                    // //logger.debug("found in " + count + " attempts");

                    y++;
                    count++;
                }
            }
            return entity;
        }
    }
    return null;
}

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

/**
 * Returns the chart entity at a given point.
 * <P>//from  w  w  w.j  av  a  2  s. c om
 * This method will return null if there is (a) no entity at the given point, or (b) no entity
 * collection has been generated.
 * 
 * @param viewX
 *            the x-coordinate.
 * @param viewY
 *            the y-coordinate.
 * 
 * @return The chart entity (possibly <code>null</code>).
 */

@Override
public ChartEntity getEntityForPoint(int viewX, int viewY) {

    ChartEntity result = null;
    if (this.info != null) {
        Insets insets = getInsets();
        double x = (viewX - insets.left) / this.scaleX;
        double y = (viewY - insets.top) / this.scaleY;
        EntityCollection entities = this.info.getEntityCollection();
        result = entities != null ? entities.getEntity(x, y) : null;
    }
    return result;

}

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

/**
 * Receives notification of mouse clicks on the panel. These are translated and passed on to any
 * registered {@link ChartMouseListener}s.
 * // ww w  . j  av a2  s.c  om
 * @param event
 *            Information about the mouse event.
 */

@Override
public void mouseClicked(MouseEvent event) {

    Insets insets = getInsets();
    int x = (int) ((event.getX() - insets.left) / this.scaleX);
    int y = (int) ((event.getY() - insets.top) / this.scaleY);

    this.anchor = new Point2D.Double(x, y);
    if (this.chart == null) {
        return;
    }
    this.chart.setNotify(true); // force a redraw
    // new entity code...
    Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class);
    if (listeners.length == 0) {
        return;
    }

    ChartEntity entity = null;
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            entity = entities.getEntity(x, y);
        }
    }
    ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), event, entity);
    for (int i = listeners.length - 1; i >= 0; i -= 1) {
        ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent);
    }

}

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

/**
 * Implementation of the MouseMotionListener's method.
 * //from  w ww . j  a  va  2 s . c  o  m
 * @param e
 *            the event.
 */

@Override
public void mouseMoved(MouseEvent e) {
    Graphics2D g2 = (Graphics2D) getGraphics();
    if (this.horizontalAxisTrace) {
        drawHorizontalAxisTrace(g2, e.getX());
    }
    if (this.verticalAxisTrace) {
        drawVerticalAxisTrace(g2, e.getY());
    }
    g2.dispose();

    Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class);
    if (listeners.length == 0) {
        return;
    }
    Insets insets = getInsets();
    int x = (int) ((e.getX() - insets.left) / this.scaleX);
    int y = (int) ((e.getY() - insets.top) / this.scaleY);

    ChartEntity entity = null;
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            entity = entities.getEntity(x, y);
        }
    }

    // we can only generate events if the panel's chart is not null
    // (see bug report 1556951)
    if (this.chart != null) {
        ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity);
        for (int i = listeners.length - 1; i >= 0; i -= 1) {
            ((ChartMouseListener) listeners[i]).chartMouseMoved(event);
        }
    }

}

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

/**
 * Returns a string for the tooltip./*from   w  ww  .j  ava2s . c  o  m*/
 * 
 * @param e
 *            the mouse event.
 * 
 * @return A tool tip or <code>null</code> if no tooltip is available.
 */

@Override
public String getToolTipText(MouseEvent e) {

    String result = null;
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            Insets insets = getInsets();
            ChartEntity entity = entities.getEntity((int) ((e.getX() - insets.left) / this.scaleX),
                    (int) ((e.getY() - insets.top) / this.scaleY));
            if (entity != null) {
                result = entity.getToolTipText();
            }
        }
    }
    return result;

}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

private void makeNewMask(MouseEvent e, EntityCollection entities) {
    if (this.maskPoint == null) {
        return;/*  w  w  w  .j a  v a  2 s. c  o  m*/
    }
    Graphics2D g2 = (Graphics2D) getGraphics();

    // erase the previous zoom rectangle (if any).  We only need to do
    // this is we are using XOR mode, which we do when we're not using
    // the buffer (if there is a buffer, then at the end of this method we
    // just trigger a repaint)
    if (!isDoubleBuffered()) {
        //          drawZoomRectangle(g2, true);
        ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), getMaskMap(), getSelectedMask(), getChart());
    }

    //       boolean hZoom = false;
    //       boolean vZoom = false;
    //       if (this.orientation == PlotOrientation.HORIZONTAL) {
    //          hZoom = this.rangeZoomable;
    //          vZoom = this.domainZoomable;
    //       }
    //       else {
    //          hZoom = this.domainZoomable;
    //          vZoom = this.rangeZoomable;
    //       }
    Rectangle2D scaledDataArea = getScreenDataArea((int) this.maskPoint.getX(), (int) this.maskPoint.getY());
    // Working on the current mask. Only create one new mask per drag-drawing.
    if (currentMaskRectangle == null) {
        boolean isInclusive = (e.getModifiers() & maskingExclusiveMask) == 0;
        boolean isEllipse = (e.getModifiers() & MouseEvent.BUTTON3_MASK) != 0;
        if (isEllipse) {
            currentMaskRectangle = new EllipseMask(isInclusive);
        } else {
            currentMaskRectangle = new RectangleMask(isInclusive);
        }
        //           currentMaskRectangle.setFillColor(getNextMaskColor(isInclusive));
        //           getMasks().add(currentMaskRectangle);
        addMask(currentMaskRectangle);
    }
    // selected rectangle shouldn't extend outside the data area...
    double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
    double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
    // Update the current mask.
    ChartEntity startEntity = null;
    ChartEntity endEntity = null;
    boolean isMaskUpdated = false;
    if (entities != null) {
        //            EntityCollection entities = this.info.getEntityCollection();
        //            if (entities != null) {
        Insets insets = getInsets();
        double screenX = (maskPoint.getX() - insets.left) / getScaleX();
        double screenY = (maskPoint.getY() - insets.top) / getScaleY();
        startEntity = entities.getEntity(screenX, screenY);

        screenX = (xmax - insets.left) / getScaleX();
        screenY = (ymax - insets.top) / getScaleY();
        if (screenX >= scaledDataArea.getMaxX()) {
            screenX = scaledDataArea.getMaxX() - 0.001;
        }
        if (screenY >= scaledDataArea.getMaxY()) {
            screenY = scaledDataArea.getMaxY() - 0.001;
        }
        endEntity = entities.getEntity(screenX, screenY);
        //           System.out.println("Try to update mask");
        if (startEntity instanceof XYItemEntity && endEntity instanceof XYItemEntity) {
            isMaskUpdated = updateCurrentMaskRectangle((XYItemEntity) startEntity, (XYItemEntity) endEntity);
        }
        //            }
    }
    if (!isMaskUpdated) {
        currentMaskRectangle.setRectangleFrame(new Rectangle2D.Double(maskPoint.getX(), this.maskPoint.getY(),
                xmax - this.maskPoint.getX(), ymax - this.maskPoint.getY()));
    }
    // Draw the new zoom rectangle...
    if (isDoubleBuffered()) {
        repaint();
    } else {
        // with no buffer, we use XOR to draw the rectangle "over" the
        // chart...
        ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), getMaskMap(), getSelectedMask(), getChart());
    }
    g2.dispose();
}