Example usage for java.awt.geom Rectangle2D getMinY

List of usage examples for java.awt.geom Rectangle2D getMinY

Introduction

In this page you can find the example usage for java.awt.geom Rectangle2D getMinY.

Prototype

public double getMinY() 

Source Link

Document

Returns the smallest Y coordinate of the framing rectangle of the Shape in double precision.

Usage

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

@Override
protected void drawToolTipFollower(Graphics2D g2, int x, int y) {
    Rectangle2D dataArea = getScreenDataArea();
    if (((int) dataArea.getMinX() <= x) && (x <= (int) dataArea.getMaxX()) && ((int) dataArea.getMinY() <= y)
            && (y <= (int) dataArea.getMaxY())) {
        String text = "";
        if (indexInTooltip) {
            text += "#" + getItemIndex() + ", ";
        }//w w w .  j  a v a  2  s .co m
        text += String.format("(%." + mouseFollowerXPrecision + "f, %." + mouseFollowerYPrecision + "f",
                getChartX(), getChartY());
        boolean isErrorEnabled = false;
        XYItemRenderer renderer = getXYPlot().getRenderer();
        if (renderer instanceof XYErrorRenderer) {
            isErrorEnabled = ((XYErrorRenderer) renderer).getDrawYError();
        }
        if (isErrorEnabled) {
            text += String.format(" \u00B1%." + mouseFollowerYPrecision + "f", getChartError());
        }
        text += ")";
        int xLoc = x + 10;
        int yLoc = y + 20;
        double width = text.length() * 5.5;
        double height = 15;
        if (xLoc + width > dataArea.getMaxX()) {
            xLoc = (int) (x - width);
        }
        if (yLoc + height > dataArea.getMaxY()) {
            yLoc = (int) (y - height);
        }

        Rectangle2D toolTipArea = new Rectangle2D.Double(xLoc, yLoc, width, height);

        g2.setColor(Color.lightGray);
        g2.fill(toolTipArea);
        g2.setColor(Color.black);
        g2.drawString(text, xLoc + 3, yLoc + 11);
    }
}

From source file:org.tsho.dmc2.core.chart.Bifurcation2DRenderer.java

public void render(final Graphics2D g2, final Rectangle2D dataArea, final PlotRenderingInfo info) {

    int numVar = model.getNVar();

    if (model instanceof ODE) {

        boolean pointBeyondPoincareSection;
        ValueAxis domainAxis = plot.getDomainAxis();
        ValueAxis rangeAxis = plot.getRangeAxis();

        int dim = initialValue.length;

        final int colorArrayLen = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length;
        final Paint[] colorArray = new Color[colorArrayLen];
        for (int i = 0; i < colorArrayLen; i++) {
            colorArray[i] = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i];
        }/*w  w w. ja v a 2s. c  o m*/

        double[] fPars = new double[fixedParameters.length];
        System.arraycopy(fixedParameters, 0, fPars, 0, fixedParameters.length);
        double[] initVars = new double[initialValue.length];
        System.arraycopy(initialValue, 0, initVars, 0, initialValue.length);

        double[] result = new double[dim];
        double[][] periodArray = new double[period][dim];

        for (double i = dataArea.getMinX(); i <= dataArea.getMaxX(); i += 1) {

            fPars[firstParameterIdx] = domainAxis.java2DToValue(i, dataArea, RectangleEdge.BOTTOM);

            for (double j = dataArea.getMinY(); j < dataArea.getMaxY(); j += 1) {

                fPars[secondParameterIdx] = rangeAxis.java2DToValue(j, dataArea, RectangleEdge.LEFT);

                stepper.setParameters(fPars);
                stepper.setInitialValue(initVars);
                stepper.initialize();
                stepper.step();
                stepper.getCurrentValue(result);

                int h = 0;
                int transX, transY;

                double[] currentPoint = new double[numVar];
                double[] previousPoint = new double[numVar];
                stepper.getCurrentValue(currentPoint);
                stepper.getCurrentValue(previousPoint);
                pointBeyondPoincareSection = positionWrtPoincareSection(currentPoint);

                Paint color = Color.white;
                double[] cycleStartPoint = new double[numVar];
                int actualPeriod = period + 1;

                for (int jj = 0; jj < time / step; jj++) {
                    stepper.step();
                    stepper.getCurrentValue(currentPoint);

                    if (positionWrtPoincareSection(currentPoint) == pointBeyondPoincareSection) {
                        stepper.getCurrentValue(previousPoint);
                        continue;
                    }

                    pointBeyondPoincareSection = !pointBeyondPoincareSection;
                    double[] pointOnSection = pointOnPoincareSection(previousPoint, currentPoint);
                    stepper.setInitialValue(pointOnSection);
                    stepper.initialize();
                    stepper.getCurrentValue(currentPoint);
                    stepper.getCurrentValue(previousPoint);

                    h++;

                    if (h == transients) {
                        for (int kk = 0; kk < numVar; kk++)
                            cycleStartPoint[kk] = currentPoint[kk];
                    }
                    if (h > transients) {
                        if (distance(currentPoint, cycleStartPoint) < epsilon) {
                            actualPeriod = h - transients;
                            break;
                        }
                        if (h >= transients + period)
                            break;
                    }
                }

                stepper.getCurrentValue(result);

                for (h = 0; h < dim; h++) {
                    if (Math.abs(result[h]) > infinity || Double.isNaN(result[h])) {
                        color = Color.black; // black == infinity
                    }
                }

                if (stopped) {
                    state = STATE_STOPPED;
                    return;
                }

                if (actualPeriod <= period) { // found period
                    color = colorArray[actualPeriod - 1];
                }

                g2.setPaint(color);
                g2.drawRect((int) i, (int) j, 1, 1);

                if (stopped) {
                    state = STATE_STOPPED;
                    return;
                }
            }

        }
        state = STATE_FINISHED;

    } else {
        ValueAxis domainAxis = plot.getDomainAxis();
        ValueAxis rangeAxis = plot.getRangeAxis();

        int dim = initialValue.length;

        final int colorArrayLen = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length;
        final Paint[] colorArray = new Color[colorArrayLen];
        for (int i = 0; i < colorArrayLen; i++) {
            colorArray[i] = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i];
        }

        double[] fPars = new double[fixedParameters.length];
        System.arraycopy(fixedParameters, 0, fPars, 0, fixedParameters.length);
        double[] initVars = new double[initialValue.length];
        System.arraycopy(initialValue, 0, initVars, 0, initialValue.length);

        double[] result = new double[dim];
        double[][] periodArray = new double[period + 1][dim];

        for (double i = dataArea.getMinX(); i <= dataArea.getMaxX(); i += 1) {

            fPars[firstParameterIdx] = domainAxis.java2DToValue(i, dataArea, RectangleEdge.BOTTOM);

            for (double j = dataArea.getMinY(); j < dataArea.getMaxY(); j += 1) {

                fPars[secondParameterIdx] = rangeAxis.java2DToValue(j, dataArea, RectangleEdge.LEFT);

                stepper.setParameters(fPars);
                stepper.setInitialValue(initVars);
                stepper.initialize();
                stepper.step();
                stepper.getCurrentValue(result);

                for (int h = 1; h < transients; h++) {
                    if (stopped) {
                        state = STATE_STOPPED;
                        return;
                    }
                    stepper.step();
                }

                stepper.getCurrentValue(result);

                Paint color = Color.white; // white == longer period
                for (int h = 0; h < dim; h++) {
                    if (Math.abs(result[h]) > infinity || Double.isNaN(result[h])) {
                        color = Color.black; // black == infinity
                        break;
                    }
                }

                if (color != Color.black) {
                    // get maxPeriod next values
                    for (int h = 0; h <= period; h++) {
                        if (stopped) {
                            state = STATE_STOPPED;
                            return;
                        }

                        stepper.step();
                        stepper.getCurrentValue(result);

                        for (int k = 0; k < dim; k++) {
                            periodArray[h][k] = result[k];
                        }
                    }

                    int h, k = -1;
                    for (h = 1; h <= period; h++) {
                        for (k = 0; k < dim; k++) {
                            if (Math.abs(periodArray[0][k] - periodArray[h][k]) >= epsilon) {
                                break;
                            }
                        }
                        if (k == dim) {
                            break;
                        }
                    }

                    if (h <= period) { // found period
                        color = colorArray[h - 1];
                    }
                }
                g2.setPaint(color);
                g2.drawRect((int) i, (int) j, 1, 1);

                if (stopped) {
                    state = STATE_STOPPED;
                    return;
                }
            }
        }
        state = STATE_FINISHED;
    }

}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

private void drawInternalLegend(Graphics2D g2) {
    //      XYDataset dataset = getXYPlot().getDataset();
    //      int numSeries = dataset.getSeriesCount();
    Rectangle2D screenArea = getScreenDataArea();
    Rectangle2D lengendArea = new Rectangle2D.Double(screenArea.getMaxX() - internalLegendSetup.getMinX(),
            screenArea.getMinY() + internalLegendSetup.getMinY(), internalLegendSetup.getWidth(),
            internalLegendSetup.getHeight());
    LegendTitle legend = new LegendTitle(getXYPlot());
    RectangleConstraint rc = new RectangleConstraint(new Range(0, internalLegendSetup.getWidth()),
            new Range(0, internalLegendSetup.getHeight()));
    Size2D size = legend.arrange(g2, rc);
    getXYPlot().getLegendItems();//from   ww  w.  j a v  a2s .  co m
    legend.draw(g2, lengendArea);
    Rectangle2D titleRect = new Rectangle2D.Double(lengendArea.getMinX(), lengendArea.getMinY(), size.width,
            size.height);
    internalLegendSetup.setRect(internalLegendSetup.getX(), internalLegendSetup.getY(), titleRect.getWidth(),
            titleRect.getHeight());
    if (isInternalLegendSelected) {
        ChartMaskingUtilities.drawMaskBoarder(g2, titleRect);
    } else {
        g2.setColor(Color.GRAY);
        g2.draw(titleRect);
    }
}

From source file:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java

/**
 * Draws the gridlines for the plot, if they are visible.
 *
 * @param g2 the graphics device./*from   ww w .  j av a 2s  .c om*/
 * @param dataArea the data area.
 * @param ticks the ticks.
 */
@Override
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) {

    // draw the domain grid lines, if the flag says they're visible...
    if (isDomainGridlinesVisible()) {
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            ValueTick tick = (ValueTick) iterator.next();
            double v = this.domainAxis.valueToJava2D(tick.getValue(), dataArea, RectangleEdge.BOTTOM);
            Line2D line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());
            g2.setPaint(getDomainGridlinePaint());
            g2.setStroke(getDomainGridlineStroke());
            g2.draw(line);
        }
    }
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

protected int findCursorOnSelectedItem(int x, int y) {
    if (isInternalLegendEnabled && isInternalLegendSelected) {
        Rectangle2D screenArea = getScreenDataArea();
        Rectangle2D legendArea = new Rectangle2D.Double(screenArea.getMaxX() - internalLegendSetup.getMinX(),
                screenArea.getMinY() + internalLegendSetup.getMinY(), internalLegendSetup.getWidth(),
                internalLegendSetup.getHeight());
        Rectangle2D intersect = screenArea.createIntersection(legendArea);
        Point2D point = new Point2D.Double(x, y);
        double minX = legendArea.getMinX();
        double maxX = legendArea.getMaxX();
        double minY = legendArea.getMinY();
        double width = legendArea.getWidth();
        double height = legendArea.getHeight();
        if (!intersect.isEmpty() && screenArea.contains(point)) {
            if (width > 8) {
                Rectangle2D center = new Rectangle2D.Double(minX + 4, minY, width - 8, height);
                if (screenArea.createIntersection(center).contains(point)) {
                    return Cursor.MOVE_CURSOR;
                }/*  ww w  .  j  a va  2s.  co  m*/
            }
            Rectangle2D west = new Rectangle2D.Double(minX - 4, minY, width < 8 ? width / 2 + 4 : 8, height);
            if (screenArea.createIntersection(west).contains(point)) {
                return Cursor.W_RESIZE_CURSOR;
            }
            Rectangle2D east = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), minY,
                    width < 8 ? width / 2 + 4 : 8, height);
            if (screenArea.createIntersection(east).contains(point)) {
                return Cursor.E_RESIZE_CURSOR;
            }
        }
    } else if (getSelectedMask() != null && !getSelectedMask().isEmpty()) {
        Rectangle2D screenArea = getScreenDataArea();
        Rectangle2D maskArea = ChartMaskingUtilities.getDomainMaskFrame(getSelectedMask(), getScreenDataArea(),
                getChart());
        Rectangle2D intersect = screenArea.createIntersection(maskArea);
        Point2D point = new Point2D.Double(x, y);
        double minX = maskArea.getMinX();
        double maxX = maskArea.getMaxX();
        double minY = maskArea.getMinY();
        double width = maskArea.getWidth();
        double height = maskArea.getHeight();
        if (!intersect.isEmpty() && screenArea.contains(point)) {
            if (width > 8) {
                Rectangle2D center = new Rectangle2D.Double(minX + 4, minY, width - 8, height);
                if (screenArea.createIntersection(center).contains(point)) {
                    return Cursor.MOVE_CURSOR;
                }
            }
            Rectangle2D west = new Rectangle2D.Double(minX - 4, minY, width < 8 ? width / 2 + 4 : 8, height);
            if (screenArea.createIntersection(west).contains(point)) {
                return Cursor.W_RESIZE_CURSOR;
            }
            Rectangle2D east = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), minY,
                    width < 8 ? width / 2 + 4 : 8, height);
            if (screenArea.createIntersection(east).contains(point)) {
                return Cursor.E_RESIZE_CURSOR;
            }
        }
    }
    return Cursor.DEFAULT_CURSOR;
}

From source file:net.sf.fspdfs.chartthemes.spring.EyeCandySixtiesChartTheme.java

public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // check the value we are plotting...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;/*from ww w . j a v a 2 s  .c o m*/
    }

    double value = dataValue.doubleValue();

    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(),
            dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());

    PlotOrientation orientation = plot.getOrientation();

    double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column);
    double[] barL0L1 = calculateBarL0L1(value);
    if (barL0L1 == null) {
        return; // the bar is not visible
    }

    RectangleEdge edge = plot.getRangeAxisEdge();
    double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
    double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    double barL0 = Math.min(transL0, transL1);
    double barLength = Math.abs(transL1 - transL0);

    // draw the bar...
    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);
    }
    Paint itemPaint = getItemPaint(row, column);
    if (itemPaint instanceof GradientPaint) {
        itemPaint = getGradientPaintTransformer().transform((GradientPaint) itemPaint, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    double x0 = bar.getMinX();
    double x1 = x0 + getXOffset();
    double x2 = bar.getMaxX();
    double x3 = x2 + getXOffset();

    double y0 = bar.getMinY() - getYOffset();
    double y1 = bar.getMinY();
    double y2 = bar.getMaxY() - getYOffset();
    double y3 = bar.getMaxY();

    GeneralPath bar3dRight = null;
    GeneralPath bar3dTop = null;
    if (barLength > 0.0) {
        bar3dRight = new GeneralPath();
        bar3dRight.moveTo((float) x2, (float) y3);
        bar3dRight.lineTo((float) x2, (float) y1);
        bar3dRight.lineTo((float) x3, (float) y0);
        bar3dRight.lineTo((float) x3, (float) y2);
        bar3dRight.closePath();

        if (itemPaint instanceof Color) {
            g2.setPaint(((Color) itemPaint).darker());
        } else if (itemPaint instanceof GradientPaint) {
            GradientPaint gp = (GradientPaint) itemPaint;
            g2.setPaint(new StandardGradientPaintTransformer().transform(new GradientPaint(gp.getPoint1(),
                    gp.getColor1().darker(), gp.getPoint2(), gp.getColor2().darker(), gp.isCyclic()),
                    bar3dRight));
        }
        g2.fill(bar3dRight);
    }

    bar3dTop = new GeneralPath();
    bar3dTop.moveTo((float) x0, (float) y1);
    bar3dTop.lineTo((float) x1, (float) y0);
    bar3dTop.lineTo((float) x3, (float) y0);
    bar3dTop.lineTo((float) x2, (float) y1);
    bar3dTop.closePath();
    g2.fill(bar3dTop);

    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemOutlineStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
        if (bar3dRight != null) {
            g2.draw(bar3dRight);
        }
        if (bar3dTop != null) {
            g2.draw(bar3dTop);
        }
    }

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        GeneralPath barOutline = new GeneralPath();
        barOutline.moveTo((float) x0, (float) y3);
        barOutline.lineTo((float) x0, (float) y1);
        barOutline.lineTo((float) x1, (float) y0);
        barOutline.lineTo((float) x3, (float) y0);
        barOutline.lineTo((float) x3, (float) y2);
        barOutline.lineTo((float) x2, (float) y3);
        barOutline.closePath();
        addItemEntity(entities, dataset, row, column, barOutline);
    }
}

From source file:KIDLYRenderer.java

/**
 * Calculates the item label anchor point.
 *
 * @param anchor  the anchor.//from  w ww .  j a  v  a2 s.c o m
 * @param bar  the bar.
 * @param orientation  the plot orientation.
 *
 * @return The anchor point.
 */
private Point2D calculateLabelAnchorPoint(ItemLabelAnchor anchor, Rectangle2D bar,
        PlotOrientation orientation) {

    Point2D result = null;
    double offset = getItemLabelAnchorOffset();
    double x0 = bar.getX() - offset;
    double x1 = bar.getX();
    double x2 = bar.getX() + offset;
    double x3 = bar.getCenterX();
    double x4 = bar.getMaxX() - offset;
    double x5 = bar.getMaxX();
    double x6 = bar.getMaxX() + offset;

    double y0 = bar.getMaxY() + offset;
    double y1 = bar.getMaxY();
    double y2 = bar.getMaxY() - offset;
    double y3 = bar.getCenterY();
    double y4 = bar.getMinY() + offset;
    double y5 = bar.getMinY();
    double y6 = bar.getMinY() - offset;

    if (anchor == ItemLabelAnchor.CENTER) {
        result = new Point2D.Double(x3, y3);
    } else if (anchor == ItemLabelAnchor.INSIDE1) {
        result = new Point2D.Double(x4, y4);
    } else if (anchor == ItemLabelAnchor.INSIDE2) {
        result = new Point2D.Double(x4, y4);
    } else if (anchor == ItemLabelAnchor.INSIDE3) {
        result = new Point2D.Double(x4, y3);
    } else if (anchor == ItemLabelAnchor.INSIDE4) {
        result = new Point2D.Double(x4, y2);
    } else if (anchor == ItemLabelAnchor.INSIDE5) {
        result = new Point2D.Double(x4, y2);
    } else if (anchor == ItemLabelAnchor.INSIDE6) {
        result = new Point2D.Double(x3, y2);
    } else if (anchor == ItemLabelAnchor.INSIDE7) {
        result = new Point2D.Double(x2, y2);
    } else if (anchor == ItemLabelAnchor.INSIDE8) {
        result = new Point2D.Double(x2, y2);
    } else if (anchor == ItemLabelAnchor.INSIDE9) {
        result = new Point2D.Double(x2, y3);
    } else if (anchor == ItemLabelAnchor.INSIDE10) {
        result = new Point2D.Double(x2, y4);
    } else if (anchor == ItemLabelAnchor.INSIDE11) {
        result = new Point2D.Double(x2, y4);
    } else if (anchor == ItemLabelAnchor.INSIDE12) {
        result = new Point2D.Double(x3, y4);
    } else if (anchor == ItemLabelAnchor.OUTSIDE1) {
        result = new Point2D.Double(x5, y6);
    } else if (anchor == ItemLabelAnchor.OUTSIDE2) {
        result = new Point2D.Double(x6, y5);
    } else if (anchor == ItemLabelAnchor.OUTSIDE3) {
        result = new Point2D.Double(x6, y3);
    } else if (anchor == ItemLabelAnchor.OUTSIDE4) {
        result = new Point2D.Double(x6, y1);
    } else if (anchor == ItemLabelAnchor.OUTSIDE5) {
        result = new Point2D.Double(x5, y0);
    } else if (anchor == ItemLabelAnchor.OUTSIDE6) {
        result = new Point2D.Double(x3, y0);
    } else if (anchor == ItemLabelAnchor.OUTSIDE7) {
        result = new Point2D.Double(x1, y0);
    } else if (anchor == ItemLabelAnchor.OUTSIDE8) {
        result = new Point2D.Double(x0, y1);
    } else if (anchor == ItemLabelAnchor.OUTSIDE9) {
        result = new Point2D.Double(x0, y3);
    } else if (anchor == ItemLabelAnchor.OUTSIDE10) {
        result = new Point2D.Double(x0, y5);
    } else if (anchor == ItemLabelAnchor.OUTSIDE11) {
        result = new Point2D.Double(x1, y6);
    } else if (anchor == ItemLabelAnchor.OUTSIDE12) {
        result = new Point2D.Double(x3, y6);
    }

    return result;

}

From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java

/**
 * Handles a 'mouse dragged' event.// ww w .  j  av a  2 s  .  c om
 *
 * @param e  the mouse event.
 */
public void mouseDragged(MouseEvent e) {

    // if the popup menu has already been triggered, then ignore dragging...
    if (this.popup != null && this.popup.isShowing()) {
        return;
    }
    // if no initial zoom point was set, ignore dragging...
    if (this.zoomPoint == null) {
        return;
    }
    Graphics2D g2 = (Graphics2D) getGraphics();

    // Erase the previous zoom rectangle (if any)...
    drawRectangle(g2);

    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.zoomPoint.getX(), (int) this.zoomPoint.getY());
    if (hZoom && vZoom) {
        // 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());
        this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), this.zoomPoint.getY(),
                xmax - this.zoomPoint.getX(), ymax - this.zoomPoint.getY());
    } else if (hZoom) {
        double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
        this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), scaledDataArea.getMinY(),
                xmax - this.zoomPoint.getX(), scaledDataArea.getHeight());
    } else if (vZoom) {
        double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
        this.zoomRectangle = new Rectangle2D.Double(scaledDataArea.getMinX(), this.zoomPoint.getY(),
                scaledDataArea.getWidth(), ymax - this.zoomPoint.getY());
    }

    // Draw the new zoom rectangle...
    drawRectangle(g2);
    g2.dispose();
}

From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java

/**
 * Draws a vertical line used to trace the mouse position to the horizontal axis.
 *
 * @param x  the x-coordinate of the trace line.
 *///from   w  w w  .j a va2s.  c om
private void drawHorizontalAxisTrace(int x) {

    Graphics2D g2 = (Graphics2D) getGraphics();
    Rectangle2D dataArea = getScaledDataArea();

    g2.setXORMode(java.awt.Color.orange);
    if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) {

        if (verticalTraceLine != null) {
            g2.draw(verticalTraceLine);
            verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
        } else {
            verticalTraceLine = new Line2D.Float(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
        }
        g2.draw(verticalTraceLine);
    } else {
        if (horizontalTraceLine != null) {
            g2.draw(horizontalTraceLine);
            horizontalTraceLine = null;
        }
        if (verticalTraceLine != null) {
            g2.draw(verticalTraceLine);
            verticalTraceLine = null;
        }

    }
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.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.
 *//* w w w .  ja  v a  2 s  .c om*/
@Override
public void mouseClicked(MouseEvent event) {

    Insets insets = getInsets();
    int x = (int) ((event.getX() - insets.left) / getScaleX());
    int y = (int) ((event.getY() - insets.top) / getScaleY());

    setAnchor(new Point2D.Double(x, y));
    if (getChart() == null) {
        return;
    }
    //        getChart().setNotify(true);  // force a redraw
    // new entity code...
    //        if (listeners.length == 0) {
    //            return;
    //        }

    //        if ((event.getModifiers() & maskingSelectionMask) != 0) {
    if (isInternalLegendEnabled) {
        Rectangle2D screenArea = getScreenDataArea();
        Rectangle2D legendArea = new Rectangle2D.Double(screenArea.getMaxX() - internalLegendSetup.getMinX(),
                screenArea.getMinY() + internalLegendSetup.getMinY(), internalLegendSetup.getWidth(),
                internalLegendSetup.getHeight());
        if (legendArea.contains(event.getPoint())) {
            selectInternalLegend(true);
            selectMask(Double.NaN, Double.NaN);
            repaint();
            return;
        } else {
            selectInternalLegend(false);
        }
    }
    if (!isTextInputEnabled() && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
        selectMask(ChartMaskingUtilities.translateScreenX(x, getScreenDataArea(), getChart()), Double.NaN);
        repaint();
    }
    if ((event.getModifiers() & seriesSelectionEventMask) == 0) {
        if (getSelectedMask() != null && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0
                && !getSelectedMask().getRange()
                        .contains(ChartMaskingUtilities.translateScreenX(x, getScreenDataArea(), getChart()))) {
            selectMask(Double.NaN, Double.NaN);
        }
        repaint();
    } else if (!isTextInputEnabled()) {
        selectMask(ChartMaskingUtilities.translateScreenX(x, getScreenDataArea(), getChart()), Double.NaN);
        repaint();
    }

    ChartEntity entity = null;
    if (getChartRenderingInfo() != null) {
        EntityCollection entities = getChartRenderingInfo().getEntityCollection();
        if (entities != null) {
            entity = entities.getEntity(x, y);
            if (entity instanceof XYItemEntity) {
                XYItemEntity xyEntity = (XYItemEntity) entity;
                //                   XYDataset dataset = xyEntity.getDataset();
                //                   int item = ((XYItemEntity) entity).getItem();
                //                   chartX = dataset.getXValue(xyEntity.getSeriesIndex(), item);
                //                   chartY = dataset.getYValue(xyEntity.getSeriesIndex(), item);
                //                   Point2D screenPoint = ChartMaskingUtilities.translateChartPoint(
                //                         new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart());
                //                   if (getHorizontalAxisTrace()) {
                //                      horizontalTraceLocation = (int) screenPoint.getX();
                //                   }
                //                   if (getVerticalAxisTrace()) {
                //                      verticalTraceLocation = (int) screenPoint.getY();
                //                   }
                if ((event.getModifiers() & seriesSelectionEventMask) != 0
                        && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
                    selectSeries(xyEntity.getSeriesIndex());
                    return;
                } else if ((event.getModifiers() & maskingSelectionMask) == 0
                        && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
                    if (selectedSeriesIndex != xyEntity.getSeriesIndex()) {
                        selectSeries(-1);
                        return;
                    }
                }
            } else {
                if (selectedSeriesIndex >= 0) {
                    if ((event.getModifiers() & seriesSelectionEventMask) != 0
                            && (event.getModifiers() & maskingSelectionMask) == 0
                            && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
                        selectSeries(-1);
                        return;
                    }
                }
            }
        }
    }
    XYChartMouseEvent chartEvent = new XYChartMouseEvent(getChart(), event, entity);
    chartEvent.setXY(getChartX(), getChartY());
    Object[] listeners = getListeners(ChartMouseListener.class);
    for (int i = listeners.length - 1; i >= 0; i -= 1) {
        ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent);
    }
    super.mouseClicked(event);
}