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

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

Introduction

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

Prototype

public double getMaxY() 

Source Link

Document

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

Usage

From source file:Main.java

public static double getMonitorYCoordinateSystem(double x, Rectangle2D.Double rect) {
    return rect.getMaxY() - x;
}

From source file:Main.java

public static boolean isPosible(Rectangle2D.Double r) {
    if ((r.getMaxX() > Integer.MAX_VALUE) || (r.getMaxY() > Integer.MAX_VALUE)
            || (r.getMinX() < Integer.MIN_VALUE) || (r.getMinY() < Integer.MIN_VALUE)
            || (r.getWidth() > Integer.MAX_VALUE) || (r.getHeight() > Integer.MAX_VALUE)) {
        return false;
    }//  w w  w.ja  v  a  2  s  .c  o m

    return true;
}

From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java

/**
 * Method for calculating the minimum bounding rectangle for the given
 * tree layout/*  w  w w . j  a  v  a 2s  .  co  m*/
 * @param treeLayout
 *          the layout to calculate MBR for
 * @param rectangle
 *          the rectangle up to now (should be null initially)
 * @return
 *          the MBR
 */
private Rectangle2D.Double calculateBounds(VisualTreeNode treeLayout, Rectangle2D.Double rectangle) {
    Point2D position = treeLayout.getPosition();
    if (rectangle == null) {
        rectangle = new Rectangle2D.Double(position.getX(), position.getY(), 0.0, 0.0);
    } else {
        if (position.getX() < rectangle.getMinX()) {
            double xDiff = rectangle.getMinX() - position.getX();
            rectangle.x -= xDiff;
            rectangle.width += xDiff;
        } else if (position.getX() > rectangle.getMaxX()) {
            double xDiff = position.getX() - rectangle.getMaxX();
            rectangle.width += xDiff;
        }

        if (position.getY() < rectangle.getMinY()) {
            double yDiff = rectangle.getMinY() - position.getY();
            rectangle.y -= yDiff;
            rectangle.height += yDiff;
        } else if (position.getY() > rectangle.getMaxY()) {
            double yDiff = position.getY() - rectangle.getMaxY();
            rectangle.height += yDiff;
        }
    }

    for (VisualTreeNode childNode : treeLayout.getChildNodes()) {
        rectangle = this.calculateBounds(childNode, rectangle);
    }

    return rectangle;
}

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

/**
 * Internal implementation to add a list of documents to a presentation; either as a single slide or a series of slides.
 * @param imageSource the image source to convert images to data.
 * @param ppt the presentation to add to.
 * @param sl the slide to add to (can be null if pagination is enabled).
 * @param anchor bounding rectangle to draw onto, in PowerPoint coordinates.
 * @param paginate whether to render results as multiple slides if they don't fit on one slide.
 * @param data the documents to render.//from   w  w w . j  a v a  2  s .c  om
 * @param results optional string to render into the top-left corner of the available space.
 *                  Will appear on each page if pagination is enabled.
 * @param sortBy optional string to render into the top-right corner of the available space.
 *                  Will appear on each page if pagination is enabled.
 */
private static void addList(final ImageSource imageSource, final XMLSlideShow ppt, XSLFSlide sl,
        final Rectangle2D.Double anchor, final boolean paginate, final ListData data, final String results,
        final String sortBy) {
    final double
    // How much space to leave at the left and right edge of the slide
    xMargin = 20,
            // How much space to leave at the top
            yMargin = 5,
            // Size of the icon
            iconWidth = 20, iconHeight = 24,
            // Find's thumbnail height is 97px by 55px, hardcoded in the CSS in .document-thumbnail
            thumbScale = 0.8, thumbW = 97 * thumbScale, thumbH = 55 * thumbScale,
            // Margin around the thumbnail
            thumbMargin = 4.,
            // Space between list items
            listItemMargin = 5.;

    final Pattern highlightPattern = Pattern
            .compile("<HavenSearch-QueryText-Placeholder>(.*?)</HavenSearch-QueryText-Placeholder>");

    double yCursor = yMargin + anchor.getMinY(), xCursor = xMargin + anchor.getMinX();

    int docsOnPage = 0;

    final Document[] docs = data.getDocs();
    for (int docIdx = 0; docIdx < docs.length; ++docIdx) {
        final Document doc = docs[docIdx];

        if (sl == null) {
            sl = ppt.createSlide();
            yCursor = yMargin + anchor.getMinY();
            xCursor = xMargin + anchor.getMinX();
            docsOnPage = 0;

            double yStep = 0;

            if (StringUtils.isNotBlank(results)) {
                final XSLFTextBox textBox = sl.createTextBox();
                textBox.clearText();
                final Rectangle2D.Double textBounds = new Rectangle2D.Double(xCursor, yCursor,
                        Math.max(0, anchor.getMaxX() - xCursor - xMargin), 20);
                textBox.setAnchor(textBounds);

                addTextRun(textBox.addNewTextParagraph(), results, 12., Color.LIGHT_GRAY);

                yStep = textBox.getTextHeight();
            }

            if (StringUtils.isNotBlank(sortBy)) {
                final XSLFTextBox sortByEl = sl.createTextBox();
                sortByEl.clearText();
                final XSLFTextParagraph sortByText = sortByEl.addNewTextParagraph();
                sortByText.setTextAlign(TextParagraph.TextAlign.RIGHT);

                addTextRun(sortByText, sortBy, 12., Color.LIGHT_GRAY);

                sortByEl.setAnchor(new Rectangle2D.Double(xCursor, yCursor,
                        Math.max(0, anchor.getMaxX() - xCursor - xMargin), 20));

                yStep = Math.max(sortByEl.getTextHeight(), yStep);
            }

            if (yStep > 0) {
                yCursor += listItemMargin + yStep;
            }
        }

        XSLFAutoShape icon = null;
        if (data.isDrawIcons()) {
            icon = sl.createAutoShape();
            icon.setShapeType(ShapeType.SNIP_1_RECT);
            icon.setAnchor(new Rectangle2D.Double(xCursor, yCursor + listItemMargin, iconWidth, iconHeight));
            icon.setLineColor(Color.decode("#888888"));
            icon.setLineWidth(2.0);

            xCursor += iconWidth;
        }

        final XSLFTextBox listEl = sl.createTextBox();
        listEl.clearText();
        listEl.setAnchor(new Rectangle2D.Double(xCursor, yCursor,
                Math.max(0, anchor.getMaxX() - xCursor - xMargin), Math.max(0, anchor.getMaxY() - yCursor)));

        final XSLFTextParagraph titlePara = listEl.addNewTextParagraph();
        addTextRun(titlePara, doc.getTitle(), data.getTitleFontSize(), Color.BLACK).setBold(true);

        if (StringUtils.isNotBlank(doc.getDate())) {
            final XSLFTextParagraph datePara = listEl.addNewTextParagraph();
            datePara.setLeftMargin(5.);
            addTextRun(datePara, doc.getDate(), data.getDateFontSize(), Color.GRAY).setItalic(true);
        }

        if (StringUtils.isNotBlank(doc.getRef())) {
            addTextRun(listEl.addNewTextParagraph(), doc.getRef(), data.getRefFontSize(), Color.GRAY);
        }

        final double thumbnailOffset = listEl.getTextHeight();

        final XSLFTextParagraph contentPara = listEl.addNewTextParagraph();

        Rectangle2D.Double pictureAnchor = null;
        XSLFPictureData pictureData = null;

        if (StringUtils.isNotBlank(doc.getThumbnail())) {
            try {
                // Picture reuse is automatic
                pictureData = addPictureData(imageSource, ppt, doc.getThumbnail());
                // We reserve space for the picture, but we don't actually add it yet.
                // The reason is we may have to remove it later if it doesn't fit; but due to a quirk of OpenOffice,
                //   deleting the picture shape removes the pictureData as well; which is a problem since the
                //   pictureData can be shared between multiple pictures.
                pictureAnchor = new Rectangle2D.Double(xCursor, yCursor + thumbnailOffset + thumbMargin, thumbW,
                        thumbH);

                // If there is enough horizontal space, put the text summary to the right of the thumbnail image,
                //    otherwise put it under the thumbnail,
                if (listEl.getAnchor().getWidth() > 2.5 * thumbW) {
                    contentPara.setLeftMargin(thumbW);
                } else {
                    contentPara.addLineBreak().setFontSize(thumbH);
                }

            } catch (RuntimeException e) {
                // if there's any errors, we'll just ignore the image
            }
        }

        final String rawSummary = doc.getSummary();
        if (StringUtils.isNotBlank(rawSummary)) {
            // HTML treats newlines and multiple whitespace as a single whitespace.
            final String summary = rawSummary.replaceAll("\\s+", " ");
            final Matcher matcher = highlightPattern.matcher(summary);
            int idx = 0;

            while (matcher.find()) {
                final int start = matcher.start();

                if (idx < start) {
                    addTextRun(contentPara, summary.substring(idx, start), data.getSummaryFontSize(),
                            Color.DARK_GRAY);
                }

                addTextRun(contentPara, matcher.group(1), data.getSummaryFontSize(), Color.DARK_GRAY)
                        .setBold(true);
                idx = matcher.end();
            }

            if (idx < summary.length()) {
                addTextRun(contentPara, summary.substring(idx), data.getSummaryFontSize(), Color.DARK_GRAY);
            }
        }

        double elHeight = Math.max(listEl.getTextHeight(), iconHeight);
        if (pictureAnchor != null) {
            elHeight = Math.max(elHeight, pictureAnchor.getMaxY() - yCursor);
        }

        yCursor += elHeight;
        xCursor = xMargin + anchor.getMinX();

        docsOnPage++;

        if (yCursor > anchor.getMaxY()) {
            if (docsOnPage > 1) {
                // If we drew more than one list element on this page; and we exceeded the available space,
                //   delete the last element's shapes and redraw it on the next page.
                // We don't have to remove the picture since we never added it.
                sl.removeShape(listEl);
                if (icon != null) {
                    sl.removeShape(icon);
                }

                --docIdx;
            } else if (pictureAnchor != null) {
                // We've confirmed we need the picture, add it.
                sl.createPicture(pictureData).setAnchor(pictureAnchor);
            }

            sl = null;

            if (!paginate) {
                break;
            }
        } else {
            yCursor += listItemMargin;

            if (pictureAnchor != null) {
                // We've confirmed we need the picture, add it.
                sl.createPicture(pictureData).setAnchor(pictureAnchor);
            }
        }
    }
}

From source file:uk.ac.ebi.cysbgn.methods.SegmentMethods.java

/**
 * IMPORTANT: the y axis is inverted since the origin of the axis in Cytoscape
 * is located in the top left corner of the screen.
 * // w  w w .  ja v a 2  s . c o m
 * @param nodeRectangle
 * @param arcLine
 * @return
 */
public static Vector2D nodeArcIntersectionPoint(Rectangle2D.Double nodeRectangle, Line arcLine) {

    Line topLine = new Line(new Vector2D(nodeRectangle.getMinX(), nodeRectangle.getMinY()),
            new Vector2D(nodeRectangle.getMaxX(), nodeRectangle.getMinY()));

    Line bottomLine = new Line(new Vector2D(nodeRectangle.getMinX(), nodeRectangle.getMaxY()),
            new Vector2D(nodeRectangle.getMaxX(), nodeRectangle.getMaxY()));

    Line leftLine = new Line(new Vector2D(nodeRectangle.getMinX(), nodeRectangle.getMinY()),
            new Vector2D(nodeRectangle.getMinX(), nodeRectangle.getMaxY()));

    Line rightLine = new Line(new Vector2D(nodeRectangle.getMaxX(), nodeRectangle.getMinY()),
            new Vector2D(nodeRectangle.getMaxX(), nodeRectangle.getMaxY()));

    Vector2D topLineIntersection = topLine.intersection(arcLine);
    if (topLineIntersection != null)
        return topLineIntersection;

    Vector2D bottomLineIntersection = bottomLine.intersection(arcLine);
    if (bottomLineIntersection != null)
        return bottomLineIntersection;

    Vector2D leftLineIntersection = leftLine.intersection(arcLine);
    if (leftLineIntersection != null)
        return leftLineIntersection;

    Vector2D rightLineIntersection = rightLine.intersection(arcLine);
    if (rightLineIntersection != null)
        return rightLineIntersection;

    return null;
}