Example usage for java.awt.geom Rectangle2D.Double setRect

List of usage examples for java.awt.geom Rectangle2D.Double setRect

Introduction

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

Prototype

public abstract void setRect(double x, double y, double w, double h);

Source Link

Document

Sets the location and size of this Rectangle2D to the specified double values.

Usage

From source file:Main.java

public static Rectangle2D.Double toSheetRect(Rectangle2D r, AffineTransform at) {
    Point2D.Double pSheet = toSheetPoint(new Point2D.Double(r.getX(), r.getY()), at);
    Point2D.Double pSheetX = toSheetPoint(new Point2D.Double(r.getMaxX(), r.getMinY()), at);
    Point2D.Double pSheetY = toSheetPoint(new Point2D.Double(r.getMinX(), r.getMaxY()), at);
    Rectangle2D.Double res = new Rectangle2D.Double();
    res.setRect(pSheet.getX(), pSheet.getY(), pSheet.distance(pSheetX), pSheet.distance(pSheetY));

    return res;//from www .j av  a  2s.  co  m
}

From source file:Main.java

public static Rectangle2D.Double fromSheetRect(Rectangle2D r, AffineTransform at) {
    Point2D.Double pSheet = new Point2D.Double(r.getX(), r.getY());
    Point2D.Double pSX = new Point2D.Double(r.getMaxX(), r.getMinY());
    Point2D.Double pSY = new Point2D.Double(r.getMinX(), r.getMaxY());
    Point2D.Double pScreen = new Point2D.Double();
    Point2D.Double pScreenX = new Point2D.Double();
    Point2D.Double pScreenY = new Point2D.Double();

    try {//from   www .  ja  v a 2 s  .com
        at.transform(pSheet, pScreen);
        at.transform(pSX, pScreenX);
        at.transform(pSY, pScreenY);
    } catch (Exception e) {
        System.err.print(e.getMessage());
    }

    Rectangle2D.Double res = new Rectangle2D.Double();
    res.setRect(pScreen.getX(), pScreen.getY(), pScreen.distance(pScreenX), pScreen.distance(pScreenY));

    return res;
}

From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java

@Override
public XMLSlideShow report(final ReportData report, final boolean slidePerVisualizer)
        throws TemplateLoadException {
    final SlideShowTemplate template = loadTemplate();
    final XMLSlideShow ppt = template.getSlideShow();

    final Rectangle2D.Double pageAnchor = createPageAnchor(ppt);
    double width = pageAnchor.getWidth();
    double height = pageAnchor.getHeight();

    if (!slidePerVisualizer) {
        // If drawing multiple visualizations on a single slide, we need to render the charts first since adding
        //   chart objects directly via XML after calling slide.getShapes() or createShape() etc. will break things.
        Arrays.sort(report.getChildren(), Comparator.comparingInt(PowerPointServiceImpl::prioritizeCharts));
    }/*from  w  w  w .  j  a  va  2s .c  o  m*/

    // As above, we need to have a separate slide to place our sizing textbox for calculations.
    XSLFSlide sizingSlide = ppt.createSlide();
    // This is the slide to draw on.
    XSLFSlide slide = ppt.createSlide();

    int shapeId = 1;
    boolean first = true;

    for (final ReportData.Child child : report.getChildren()) {
        if (slidePerVisualizer && !first) {
            sizingSlide = ppt.createSlide();
            slide = ppt.createSlide();
        }

        first = false;

        final ComposableElement data = child.getData();
        final Rectangle2D.Double anchor = new Rectangle2D.Double(pageAnchor.getMinX() + width * child.getX(),
                pageAnchor.getMinY() + height * child.getY(), width * child.getWidth(),
                height * child.getHeight());

        if (child.getMargin() >= 0) {
            final double margin = child.getMargin();
            final double marginX2 = margin * 2;
            final double textMargin = child.getTextMargin();

            if (anchor.getWidth() > marginX2) {
                double xCursor = anchor.getMinX() + margin, xWidthAvail = anchor.getWidth() - marginX2,
                        yCursor = anchor.getMinY() + margin, yHeightAvail = anchor.getHeight() - marginX2;
                XSLFTextBox sizingBox = null;

                final String title = child.getTitle();
                if (StringUtils.isNotEmpty(title) && yHeightAvail > 0) {
                    sizingBox = sizingSlide.createTextBox();
                    final Rectangle2D.Double sizingAnchor = new Rectangle2D.Double(xCursor, yCursor,
                            xWidthAvail, yHeightAvail);
                    sizingBox.setAnchor(sizingAnchor);
                    sizingBox.clearText();
                    addTextRun(sizingBox.addNewTextParagraph(), title, child.getFontSize(), Color.BLACK)
                            .setFontFamily(child.getFontFamily());

                    final double textHeight = sizingBox.getTextHeight() + textMargin;
                    yCursor += textHeight;
                    yHeightAvail -= textHeight;
                }

                if (yHeightAvail > 0) {
                    anchor.setRect(xCursor, yCursor, xWidthAvail, yHeightAvail);
                } else if (sizingBox != null) {
                    sizingSlide.removeShape(sizingBox);
                }
            }
        }

        if (data instanceof DategraphData) {
            addDategraph(template, slide, anchor, (DategraphData) data, shapeId, "relId" + shapeId);
            shapeId++;
        } else if (data instanceof ListData) {
            final ListData listData = (ListData) data;
            addList(imageSource, ppt, slide, anchor, false, listData, null, null);
        } else if (data instanceof MapData) {
            final MapData mapData = (MapData) data;
            addMap(slide, anchor, addPictureData(imageSource, ppt, mapData.getImage()), mapData.getMarkers(),
                    mapData.getPolygons());
        } else if (data instanceof SunburstData) {
            addSunburst(template, slide, anchor, (SunburstData) data, shapeId, "relId" + shapeId);
            shapeId++;
        } else if (data instanceof TableData) {
            final TableData tableData = (TableData) data;
            addTable(slide, anchor, tableData.getRows(), tableData.getCols(), tableData.getCells(), true);
        } else if (data instanceof TopicMapData) {
            addTopicMap(slide, anchor, (TopicMapData) data);
        } else if (data instanceof TextData) {
            addTextData(slide, anchor, (TextData) data);
        }

        if (slidePerVisualizer) {
            transferSizedTextboxes(ppt, slide, sizingSlide);
        }
    }

    if (!slidePerVisualizer) {
        transferSizedTextboxes(ppt, slide, sizingSlide);
    }

    return ppt;
}