Example usage for java.awt.geom Rectangle2D getMinX

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

Introduction

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

Prototype

public double getMinX() 

Source Link

Document

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

Usage

From source file:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Returns a point based on (x, y) but constrained to be within the bounds of the given
 * rectangle. This method could be moved to JCommon.
 * /*from   ww w .j  a v a 2 s . c  om*/
 * @param x
 *            the x-coordinate.
 * @param y
 *            the y-coordinate.
 * @param area
 *            the rectangle (<code>null</code> not permitted).
 * @return A point within the rectangle.
 */
private Point getPointInRectangle(int x, int y, Rectangle2D area) {
    x = (int) Math.max(Math.ceil(area.getMinX()), Math.min(x, Math.floor(area.getMaxX())));
    y = (int) Math.max(Math.ceil(area.getMinY()), Math.min(y, Math.floor(area.getMaxY())));
    return new Point(x, y);
}

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. c o  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:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Draws a vertical line used to trace the mouse position to the horizontal axis.
 * //from   ww w  . ja va2 s .c o  m
 * @param g2
 *            the graphics device.
 * @param x
 *            the x-coordinate of the trace line.
 */
private void drawHorizontalAxisTrace(Graphics2D g2, int x) {
    Rectangle2D dataArea = getScreenDataArea();

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

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

    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}

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

/**
 * Draws a vertical line used to trace the mouse position to the horizontal
 * axis.// ww  w.  j av a  2 s .c o m
 *
 * @param g2 the graphics device.
 * @param x  the x-coordinate of the trace line.
 */
private void drawHorizontalAxisTrace(Graphics2D g2, int x) {

    Rectangle2D dataArea = getScreenDataArea();

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

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

    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}

From source file:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Draws a horizontal line used to trace the mouse position to the vertical axis.
 * /*from   ww  w  .  j  a  va  2s .  c  o m*/
 * @param g2
 *            the graphics device.
 * @param y
 *            the y-coordinate of the trace line.
 */
private void drawVerticalAxisTrace(Graphics2D g2, int y) {
    Rectangle2D dataArea = getScreenDataArea();

    g2.setXORMode(Color.orange);
    if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) {

        if (this.horizontalTraceLine != null) {
            g2.draw(this.horizontalTraceLine);
            this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y);
        } else {
            this.horizontalTraceLine = new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(),
                    y);
        }
        g2.draw(this.horizontalTraceLine);
    }

    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}

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

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

    if (this.zoomingEnabled) {
        // if the popup menu has already been triggered, then ignore dragging...
        if (popup != null && popup.isShowing()) {
            return;
        }

        Graphics2D g2 = (Graphics2D) getGraphics();

        // use XOR to erase the previous zoom rectangle (if any)...
        g2.setXORMode(java.awt.Color.gray);
        if (zoomRectangle != null) {
            if (fillZoomRectangle) {
                g2.fill(zoomRectangle);
            } else {
                g2.draw(zoomRectangle);
            }
        }

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

        if (zoomRectangle != null) {
            // use XOR to draw the new zoom rectangle...
            if (fillZoomRectangle) {
                g2.fill(zoomRectangle);
            } else {
                g2.draw(zoomRectangle);
            }
        }
        g2.dispose();
    }
}

From source file:edu.ucla.stat.SOCR.chart.gui.ExtendedStackedBarRenderer.java

/**
 * Draws a stacked bar for a specific item.
 *
 * @param g2  the graphics device./* w  w  w. ja va  2 s.com*/
 * @param state  the renderer state.
 * @param dataArea  the plot area.
 * @param plot  the plot.
 * @param domainAxis  the domain (category) axis.
 * @param rangeAxis  the range (value) axis.
 * @param dataset  the data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // nothing is drawn for null values...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    double value = dataValue.doubleValue();

    PlotOrientation orientation = plot.getOrientation();
    double barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge())
            - state.getBarWidth() / 2.0;

    double positiveBase = 0.0;
    double negativeBase = 0.0;

    for (int i = 0; i < row; i++) {
        Number v = dataset.getValue(i, column);
        if (v != null) {
            double d = v.doubleValue();
            if (d > 0) {
                positiveBase = positiveBase + d;
            } else {
                negativeBase = negativeBase + d;
            }
        }
    }

    double translatedBase;
    double translatedValue;
    RectangleEdge location = plot.getRangeAxisEdge();
    if (value > 0.0) {
        translatedBase = rangeAxis.valueToJava2D(positiveBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(positiveBase + value, dataArea, location);
    } else {
        translatedBase = rangeAxis.valueToJava2D(negativeBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(negativeBase + value, dataArea, location);
    }
    double barL0 = Math.min(translatedBase, translatedValue);
    double barLength = Math.max(Math.abs(translatedValue - translatedBase), getMinimumBarLength());

    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 seriesPaint = getItemPaint(row, column);
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
    }

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

    if (value > 0.0) {
        if (this.showPositiveTotal) {
            if (isLastPositiveItem(dataset, row, column)) {
                g2.setPaint(Color.black);
                g2.setFont(this.totalLabelFont);
                double total = calculateSumOfPositiveValuesForCategory(dataset, column);
                if (orientation == PlotOrientation.HORIZONTAL)
                    TextUtilities.drawRotatedString(this.totalFormatter.format(total), g2,
                            (float) (bar.getMaxX() + 5.0), (float) bar.getCenterY(), TextAnchor.CENTER_LEFT,
                            0.0, TextAnchor.CENTER_LEFT);

                else
                    TextUtilities.drawRotatedString(this.totalFormatter.format(total), g2,
                            (float) bar.getCenterX(), (float) (bar.getMinY() - 4.0), TextAnchor.BOTTOM_CENTER,
                            0.0, TextAnchor.BOTTOM_CENTER);
            }
        }
    } else {
        if (this.showNegativeTotal) {
            if (isLastNegativeItem(dataset, row, column)) {
                g2.setPaint(Color.black);
                g2.setFont(this.totalLabelFont);
                double total = calculateSumOfNegativeValuesForCategory(dataset, column);
                if (orientation == PlotOrientation.HORIZONTAL)
                    TextUtilities.drawRotatedString(String.valueOf(total), g2, (float) (bar.getMinX() - 5.0),
                            (float) bar.getCenterY(), TextAnchor.CENTER_RIGHT, 0.0, TextAnchor.CENTER_RIGHT);
                else
                    TextUtilities.drawRotatedString(String.valueOf(total), g2, (float) bar.getCenterX(),
                            (float) (bar.getMaxY() + 4.0), TextAnchor.TOP_CENTER, 0.0, TextAnchor.TOP_CENTER);
            }
        }
    }

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            String tip = null;
            CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
            if (tipster != null) {
                tip = tipster.generateToolTip(dataset, row, column);
            }
            String url = null;
            if (getItemURLGenerator(row, column) != null) {
                url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
            }
            CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, dataset.getRowKey(row),
                    dataset.getColumnKey(column));
            entities.add(entity);
        }
    }

}

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

/**
 * Draws a horizontal line used to trace the mouse position to the vertical
 * axis.//w  w w  . j  ava 2  s.  c  om
 *
 * @param g2 the graphics device.
 * @param y  the y-coordinate of the trace line.
 */
private void drawVerticalAxisTrace(Graphics2D g2, int y) {

    Rectangle2D dataArea = getScreenDataArea();

    g2.setXORMode(Color.orange);
    if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) {

        if (this.horizontalTraceLine != null) {
            g2.draw(this.horizontalTraceLine);
            this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y);
        } else {
            this.horizontalTraceLine = new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(),
                    y);
        }
        g2.draw(this.horizontalTraceLine);
    }

    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}

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

/**
 * Returns a point based on (x, y) but constrained to be within the bounds of the given
 * rectangle. This method could be moved to JCommon.
 * //  w  w w .  ja  v  a2  s. c om
 * @param x
 *            the x-coordinate.
 * @param y
 *            the y-coordinate.
 * @param area
 *            the rectangle (<code>null</code> not permitted).
 * 
 * @return A point within the rectangle.
 */
private Point2D getPointInRectangle(int x, int y, Rectangle2D area) {
    double xx = Math.max(area.getMinX(), Math.min(x, area.getMaxX()));
    double yy = Math.max(area.getMinY(), Math.min(y, area.getMaxY()));
    return new Point2D.Double(xx, yy);
}

From source file:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Zooms in on a selected region.//from ww w.j a va2  s. c  om
 * 
 * @param selection
 *            the selected region.
 */
public void zoom(Rectangle2D selection) {

    // get the origin of the zoom selection in the Java2D space used for
    // drawing the chart (that is, before any scaling to fit the panel)
    Point2D selectOrigin = translateScreenToJava2D(
            new Point((int) Math.ceil(selection.getX()), (int) Math.ceil(selection.getY())));
    PlotRenderingInfo plotInfo = this.info.getPlotInfo();
    Rectangle2D scaledDataArea = getScreenDataArea((int) selection.getCenterX(), (int) selection.getCenterY());
    if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) {

        double hLower = (selection.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        double hUpper = (selection.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        double vLower = (scaledDataArea.getMaxY() - selection.getMaxY()) / scaledDataArea.getHeight();
        double vUpper = (scaledDataArea.getMaxY() - selection.getMinY()) / scaledDataArea.getHeight();

        Plot p = this.chart.getPlot();
        if (p instanceof Zoomable) {
            Zoomable z = (Zoomable) p;
            if (z.getOrientation() == PlotOrientation.HORIZONTAL) {
                z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin);
                z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin);
            } else {
                z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin);
                z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin);
            }
        }
    }
}