Example usage for java.awt.geom GeneralPath getBounds2D

List of usage examples for java.awt.geom GeneralPath getBounds2D

Introduction

In this page you can find the example usage for java.awt.geom GeneralPath getBounds2D.

Prototype

public Rectangle2D getBounds2D();

Source Link

Document

Returns a high precision and more accurate bounding box of the Shape than the getBounds method.

Usage

From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java

private VisualPeakAnnotation generateTriangle(double startX, double startY, double apexX, double apexY,
        double stopX, double stopY) {
    GeneralPath path = new GeneralPath();
    path.moveTo(startX, startY);/*from www  . ja  v a2s.  c  o  m*/
    path.lineTo(apexX, apexY);
    path.lineTo(stopX, stopY);
    path.closePath();
    Rectangle2D r = path.getBounds2D();
    return new VisualPeakAnnotation(path, new Point2D.Double(r.getCenterX(), r.getMaxY()),
            PeakAnnotationType.POINTER);
}

From source file:ro.nextreports.engine.util.chart.CylinderRenderer.java

/**
 * Draws a cylinder to represent one data item.
 * //  w  w  w.  ja v  a  2s .  co  m
 * @param g2 the graphics device.
 * @param state the renderer state.
 * @param dataArea the area for plotting the data.
 * @param plot the plot.
 * @param domainAxis the domain axis.
 * @param rangeAxis the range axis.
 * @param dataset the dataset.
 * @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) {

    // check the value we are plotting...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    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();
    float transL0 = (float) rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
    float transL1 = (float) rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    float barL0 = Math.min(transL0, transL1);
    float barLength = Math.abs(transL1 - transL0);

    // draw the bar...
    GeneralPath bar = new GeneralPath();
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar.moveTo(barL0, (float) barW0);
        bar.lineTo(barL0, (float) (barW0 + state.getBarWidth()));
        bar.lineTo(barL0 + barLength, (float) (barW0 + state.getBarWidth()));
        bar.lineTo(barL0 + barLength, (float) barW0);
        bar.closePath();
    } else {
        bar.moveTo((float) barW0, (float) (barL0 - getYOffset() / 2));
        bar.lineTo((float) barW0, (float) (barL0 + barLength - getYOffset() / 2));
        Arc2D arc = new Arc2D.Double(barW0, (barL0 + barLength - getYOffset()), state.getBarWidth(),
                getYOffset(), 180, 180, Arc2D.OPEN);
        bar.append(arc, true);
        bar.lineTo((float) (barW0 + state.getBarWidth()), (float) (barL0 - getYOffset() / 2));
        arc = new Arc2D.Double(barW0, (barL0 - getYOffset()), state.getBarWidth(), getYOffset(), 0, -180,
                Arc2D.OPEN);
        bar.append(arc, true);
        bar.closePath();
    }
    Paint itemPaint = getItemPaint(row, column);
    if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) itemPaint;
        itemPaint = getGradientPaintTransformer().transform(gp, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    Shape bar3dTop = new Ellipse2D.Double(barW0, barL0 - getYOffset(), state.getBarWidth(), getYOffset());
    if (itemPaint instanceof GradientPaint) {
        g2.setPaint(((GradientPaint) itemPaint).getColor2());
    }
    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 (bar3dTop != null) {
            g2.draw(bar3dTop);
        }
    }

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

    // 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.getBounds2D(), tip, url, dataset,
                    dataset.getRowKey(row), dataset.getColumnKey(column));
            entities.add(entity);
        }
    }

}

From source file:com.bdaum.zoom.report.internal.jfree.custom.CylinderRenderer.java

/**
 * Draws a cylinder to represent one data item.
 *
 * @param g2  the graphics device./*w w  w.j  a va 2  s.  co  m*/
 * @param state  the renderer state.
 * @param dataArea  the area for plotting the data.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @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) {

    // check the value we are plotting...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    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();
    float transL0 = (float) rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
    float transL1 = (float) rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    float barL0 = Math.min(transL0, transL1);
    float barLength = Math.abs(transL1 - transL0);

    // draw the bar...
    GeneralPath bar = new GeneralPath();
    Shape top = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar.moveTo((float) (barL0 + getXOffset() / 2), (float) barW0);
        bar.lineTo((float) (barL0 + barLength + getXOffset() / 2), (float) barW0);
        Arc2D arc = new Arc2D.Double(barL0 + barLength, barW0, getXOffset(), state.getBarWidth(), 90, 180,
                Arc2D.OPEN);
        bar.append(arc, true);
        bar.lineTo((float) (barL0 + getXOffset() / 2), (float) (barW0 + state.getBarWidth()));
        arc = new Arc2D.Double(barL0, barW0, getXOffset(), state.getBarWidth(), 270, -180, Arc2D.OPEN);
        bar.append(arc, true);
        bar.closePath();
        top = new Ellipse2D.Double(barL0 + barLength, barW0, getXOffset(), state.getBarWidth());

    } else {
        bar.moveTo((float) barW0, (float) (barL0 - getYOffset() / 2));
        bar.lineTo((float) barW0, (float) (barL0 + barLength - getYOffset() / 2));
        Arc2D arc = new Arc2D.Double(barW0, (barL0 + barLength - getYOffset()), state.getBarWidth(),
                getYOffset(), 180, 180, Arc2D.OPEN);
        bar.append(arc, true);
        bar.lineTo((float) (barW0 + state.getBarWidth()), (float) (barL0 - getYOffset() / 2));
        arc = new Arc2D.Double(barW0, (barL0 - getYOffset()), state.getBarWidth(), getYOffset(), 0, -180,
                Arc2D.OPEN);
        bar.append(arc, true);
        bar.closePath();

        top = new Ellipse2D.Double(barW0, barL0 - getYOffset(), state.getBarWidth(), getYOffset());
    }
    Paint itemPaint = getItemPaint(row, column);
    if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) itemPaint;
        itemPaint = getGradientPaintTransformer().transform(gp, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    if (itemPaint instanceof GradientPaint) {
        g2.setPaint(((GradientPaint) itemPaint).getColor2());
    } else {
        g2.setPaint(PaintAlpha.darker(itemPaint)); // bd
    }
    if (top != null) {
        g2.fill(top);
    }

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

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

    // 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.getBounds2D(), tip, url, dataset,
                    dataset.getRowKey(row), dataset.getColumnKey(column));
            entities.add(entity);
        }
    }

}

From source file:org.jfree.chart.demo.CylinderRenderer.java

public void drawItem(Graphics2D graphics2d, CategoryItemRendererState categoryitemrendererstate,
        Rectangle2D rectangle2d, CategoryPlot categoryplot, CategoryAxis categoryaxis, ValueAxis valueaxis,
        CategoryDataset categorydataset, int i, int j, int k) {
    Number number = categorydataset.getValue(i, j);
    if (number == null)
        return;//from w  w w.  j  a v a2s .  co  m
    double d = number.doubleValue();
    java.awt.geom.Rectangle2D.Double double1 = new java.awt.geom.Rectangle2D.Double(rectangle2d.getX(),
            rectangle2d.getY() + getYOffset(), rectangle2d.getWidth() - getXOffset(),
            rectangle2d.getHeight() - getYOffset());
    PlotOrientation plotorientation = categoryplot.getOrientation();
    double d1 = calculateBarW0(categoryplot, plotorientation, double1, categoryaxis, categoryitemrendererstate,
            i, j);
    double ad[] = calculateBarL0L1(d);
    if (ad == null)
        return;
    RectangleEdge rectangleedge = categoryplot.getRangeAxisEdge();
    float f = (float) valueaxis.valueToJava2D(ad[0], double1, rectangleedge);
    float f1 = (float) valueaxis.valueToJava2D(ad[1], double1, rectangleedge);
    float f2 = Math.min(f, f1);
    float f3 = Math.abs(f1 - f);
    GeneralPath generalpath = new GeneralPath();
    java.awt.geom.Ellipse2D.Double double2 = null;
    if (plotorientation == PlotOrientation.HORIZONTAL) {
        generalpath.moveTo((float) ((double) f2 + getXOffset() / 2D), (float) d1);
        generalpath.lineTo((float) ((double) (f2 + f3) + getXOffset() / 2D), (float) d1);
        java.awt.geom.Arc2D.Double double3 = new java.awt.geom.Arc2D.Double(f2 + f3, d1, getXOffset(),
                categoryitemrendererstate.getBarWidth(), 90D, 180D, 0);
        generalpath.append(double3, true);
        generalpath.lineTo((float) ((double) f2 + getXOffset() / 2D),
                (float) (d1 + categoryitemrendererstate.getBarWidth()));
        double3 = new java.awt.geom.Arc2D.Double(f2, d1, getXOffset(), categoryitemrendererstate.getBarWidth(),
                270D, -180D, 0);
        generalpath.append(double3, true);
        generalpath.closePath();
        double2 = new java.awt.geom.Ellipse2D.Double(f2 + f3, d1, getXOffset(),
                categoryitemrendererstate.getBarWidth());
    } else {
        generalpath.moveTo((float) d1, (float) ((double) f2 - getYOffset() / 2D));
        generalpath.lineTo((float) d1, (float) ((double) (f2 + f3) - getYOffset() / 2D));
        java.awt.geom.Arc2D.Double double4 = new java.awt.geom.Arc2D.Double(d1,
                (double) (f2 + f3) - getYOffset(), categoryitemrendererstate.getBarWidth(), getYOffset(), 180D,
                180D, 0);
        generalpath.append(double4, true);
        generalpath.lineTo((float) (d1 + categoryitemrendererstate.getBarWidth()),
                (float) ((double) f2 - getYOffset() / 2D));
        double4 = new java.awt.geom.Arc2D.Double(d1, (double) f2 - getYOffset(),
                categoryitemrendererstate.getBarWidth(), getYOffset(), 0.0D, -180D, 0);
        generalpath.append(double4, true);
        generalpath.closePath();
        double2 = new java.awt.geom.Ellipse2D.Double(d1, (double) f2 - getYOffset(),
                categoryitemrendererstate.getBarWidth(), getYOffset());
    }
    Object obj = getItemPaint(i, j);
    if (getGradientPaintTransformer() != null && (obj instanceof GradientPaint)) {
        GradientPaint gradientpaint = (GradientPaint) obj;
        obj = getGradientPaintTransformer().transform(gradientpaint, generalpath);
    }
    graphics2d.setPaint(((java.awt.Paint) (obj)));
    graphics2d.fill(generalpath);
    if (obj instanceof GradientPaint) {
        graphics2d.setPaint(((GradientPaint) obj).getColor2());
    }
    if (double2 != null) {
        graphics2d.fill(double2);
    }
    if (isDrawBarOutline() && categoryitemrendererstate.getBarWidth() > 3D) {
        graphics2d.setStroke(getItemOutlineStroke(i, j));
        graphics2d.setPaint(getItemOutlinePaint(i, j));
        graphics2d.draw(generalpath);
        if (double2 != null)
            graphics2d.draw(double2);
    }
    CategoryItemLabelGenerator categoryitemlabelgenerator = getItemLabelGenerator(i, j);
    if (categoryitemlabelgenerator != null && isItemLabelVisible(i, j))
        drawItemLabel(graphics2d, categorydataset, i, j, categoryplot, categoryitemlabelgenerator,
                generalpath.getBounds2D(), d < 0.0D);
    if (categoryitemrendererstate.getInfo() != null) {
        EntityCollection entitycollection = categoryitemrendererstate.getEntityCollection();
        if (entitycollection != null) {
            String s = null;
            CategoryToolTipGenerator categorytooltipgenerator = getToolTipGenerator(i, j);
            if (categorytooltipgenerator != null)
                s = categorytooltipgenerator.generateToolTip(categorydataset, i, j);
            String s1 = null;
            if (getItemURLGenerator(i, j) != null)
                s1 = getItemURLGenerator(i, j).generateURL(categorydataset, i, j);
            CategoryItemEntity categoryitementity = new CategoryItemEntity(generalpath.getBounds2D(), s, s1,
                    categorydataset, categorydataset.getRowKey(i), categorydataset.getColumnKey(j));
            entitycollection.add(categoryitementity);
        }
    }
}

From source file:org.esa.snap.graphbuilder.gpf.ui.worldmap.NestWorldMapPane.java

public void zoomToProduct(Product product) {
    final GeoPos[][] selGeoBoundaries = dataModel.getSelectedGeoBoundaries();
    if ((product == null || product.getSceneGeoCoding() == null) && selGeoBoundaries.length == 0) {
        return;/* www. j a  va  2s  .co  m*/
    }

    //NESTMOD
    final GeneralPath[] generalPaths;
    if (product != null && product.getSceneGeoCoding() != null) {
        generalPaths = getGeoBoundaryPaths(product);
    } else {
        final ArrayList<GeneralPath> pathList = assemblePathList(selGeoBoundaries[0]);
        generalPaths = pathList.toArray(new GeneralPath[pathList.size()]);
    }

    Rectangle2D modelArea = new Rectangle2D.Double();
    final Viewport viewport = layerCanvas.getViewport();
    for (GeneralPath generalPath : generalPaths) {
        final Rectangle2D rectangle2D = generalPath.getBounds2D();
        if (modelArea.isEmpty()) {
            if (!viewport.isModelYAxisDown()) {
                modelArea.setFrame(rectangle2D.getX(), rectangle2D.getMaxY(), rectangle2D.getWidth(),
                        rectangle2D.getHeight());
            }
            modelArea = rectangle2D;
        } else {
            modelArea.add(rectangle2D);
        }
    }
    Rectangle2D modelBounds = modelArea.getBounds2D();
    modelBounds.setFrame(modelBounds.getX() - 2, modelBounds.getY() - 2, modelBounds.getWidth() + 4,
            modelBounds.getHeight() + 4);

    modelBounds = cropToMaxModelBounds(modelBounds);

    viewport.zoom(modelBounds);
}