Example usage for java.awt.geom RectangularShape getCenterX

List of usage examples for java.awt.geom RectangularShape getCenterX

Introduction

In this page you can find the example usage for java.awt.geom RectangularShape getCenterX.

Prototype

public double getCenterX() 

Source Link

Document

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

Usage

From source file:GraphicsUtil.java

public static Point2D getPoint(RectangularShape bounds, Align align) {
    double x = 0.0;
    double y = 0.0;

    switch (align) {
    case North://from  w  w w.j a va 2 s .  com
        x = bounds.getCenterX();
        y = bounds.getMinY();
        break;
    case NorthEast:
        x = bounds.getMaxX();
        y = bounds.getMinY();
        break;
    case East:
        x = bounds.getMaxX();
        y = bounds.getCenterY();
        break;
    case SouthEast:
        x = bounds.getMaxX();
        y = bounds.getMaxY();
        break;
    case South:
        x = bounds.getCenterX();
        y = bounds.getMaxY();
        break;
    case SouthWest:
        x = bounds.getMinX();
        y = bounds.getMaxY();
        break;
    case West:
        x = bounds.getMinX();
        y = bounds.getCenterY();
        break;
    case NorthWest:
        x = bounds.getMinX();
        y = bounds.getMinY();
        break;
    case Center:
        x = bounds.getCenterX();
        y = bounds.getCenterY();
        break;
    }

    return new Point2D.Double(x, y);
}

From source file:com.github.lucapino.sheetmaker.renderer.JavaTemplateRenderer.java

public static Point2D getPoint(RectangularShape bounds, Align align) {
    double x = 0.0;
    double y = 0.0;

    switch (align) {
    case TopCenter:
        x = bounds.getCenterX();
        y = bounds.getMinY();/*w  w w . jav  a  2s.c  o  m*/
        break;
    case TopRight:
        x = bounds.getMaxX();
        y = bounds.getMinY();
        break;
    case MiddleRight:
        x = bounds.getMaxX();
        y = bounds.getCenterY();
        break;
    case BottomRight:
        x = bounds.getMaxX();
        y = bounds.getMaxY();
        break;
    case BottomCenter:
        x = bounds.getCenterX();
        y = bounds.getMaxY();
        break;
    case BottomLeft:
        x = bounds.getMinX();
        y = bounds.getMaxY();
        break;
    case MiddleLeft:
        x = bounds.getMinX();
        y = bounds.getCenterY();
        break;
    case TopLeft:
        x = bounds.getMinX();
        y = bounds.getMinY();
        break;
    case Center:
        x = bounds.getCenterX();
        y = bounds.getCenterY();
        break;
    }

    return new Point2D.Double(x, y);
}

From source file:org.jcurl.demo.tactics.old.MenuView.java

private void zoom(final Point2D center, final double ratio, final int dt) {
    if (getModel() == null)
        return;//from  ww  w. j av  a 2s. co  m
    final RectangularShape src = getModel().getZoom();
    if (log.isDebugEnabled())
        log.debug(src);
    final double w = src.getWidth() * ratio;
    final double h = src.getHeight() * ratio;
    final double cx, cy;
    if (center == null) {
        cx = src.getCenterX();
        cy = src.getCenterY();
    } else {
        cx = center.getX();
        cy = center.getY();
    }
    zoom(new Rectangle2D.Double(cx - w / 2, cy - h / 2, Math.abs(w), Math.abs(h)), dt);
}

From source file:tufts.vue.Actions.java

private static void projectNodes(final Iterable<LWComponent> toPush, final Collection toExclude,
        final LWComponent pushing, // we want to remove this argument and only rely on pushShape, but we need alot more refactoring for that
        final RectangularShape pushShape, final int distance) {
    if (DEBUG.Enabled)
        Log.debug("projectNodes: " + "\n\t  pushing: " + pushing + "\n\tpushShape: " + pushShape
                + "\n\t   toPush: " + Util.tags(toPush) + "\n\t distance: " + distance);//,new Throwable("HERE"));

    final Point2D.Float groundZero = new Point2D.Float((float) pushShape.getCenterX(),
            (float) pushShape.getCenterY());

    final java.util.List<LWComponent> links = new java.util.ArrayList();
    final java.util.List<LWComponent> nodes = new java.util.ArrayList();

    for (LWComponent node : toPush) {

        if (toExclude.contains(node))
            continue;

        if (node.isManagedLocation())
            continue;

        if (node instanceof LWLink) {
            LWLink link = (LWLink) node;
            if (link.isConnected() || link.isCurved()) // both cases are buggy right now
                continue;
        }/* ww w .  ja v a 2  s .  c  o m*/

        final Line2D.Float connector = new Line2D.Float();
        final boolean overlap = VueUtil.computeConnectorAndCenterHit(pushing, node, connector);
        //VueUtil.computeConnector(pushing, node, connector);

        Point2D newCenter = null;

        float adjust = distance;

        //final boolean intersects = node.intersects(pushingRect); // problems w/slide icons
        final boolean intersects = pushShape.intersects(node.getMapBounds());

        final boolean moveToEdge = overlap || intersects;

        if (false && DEBUG_PUSH) {
            // create a detached link from center of pushing to edge of each pushed to show vectors
            LWLink link = new LWLink();
            link.setHeadPoint(connector.getP1());
            link.setTailPoint(connector.getP2());
            link.setArrowState(LWLink.ARROW_TAIL);
            link.setNotes("head: " + pushing + "\ntail: " + node);
            links.add(link);
        }

        if (moveToEdge) {

            if (distance < 0) // do nothing further if pulling on
                continue;

            // If overlapping, we want to move the node along a line away from the center
            // of the pushing node until it no longer overlaps.  As part of this process,
            // we compute the point at the edge of the pushing node that the overlapping
            // node would be at if all we were going to do was move it to the edge.  This
            // isn't strictly needed to produce the end result (we could start iterating
            // immediately, we don't need to start at the intersect), but it's useful for
            // debugging, and it may be a useful location to know for future tweaks to this
            // code.

            // first, find a point along the line from center of pushing to the center of node
            // that we know is outside of the pushing node
            final Point2D farOut = VueUtil.projectPoint(groundZero, connector, Short.MAX_VALUE);
            // now produce a ray that shoots from that point back to the center of the pushing node
            final Line2D.Float testRay = new Line2D.Float(farOut, groundZero);
            // now find the point at the edge of the pushing node that the ray intersects it
            final Point2D.Float intersect = VueUtil.computeIntersection(testRay, pushing);

            // now project the node along the connector line from the intersect
            // by small increments until the node no longer overlaps the
            // pushing node

            if (Util.isBadPoint(farOut) || Util.isBadPoint(intersect)) {
                Log.warn("bad projection points:" + "\n\tgroundZero: " + Util.fmt(groundZero)
                        + "\n\t connector: " + Util.fmt(connector) + "\n\t    farOut: " + Util.fmt(farOut)
                        + "\n\t   testRay: " + Util.fmt(testRay) + "\n\t intersect: " + Util.fmt(intersect)
                        + "\n\t    pusher: " + pushing + "\n\t    pushee: " + node);
            } else {

                for (int i = 0; i < 1000; i++) {
                    node.setCenterAt(VueUtil.projectPoint(intersect, connector, i * 2f));
                    //                         if (!node.intersects(pushingRect)) // problems w/slide icons
                    //                             break;
                    if (!pushShape.intersects(node.getMapBounds()))
                        break;
                    if (DEBUG_PUSH)
                        Log.debug("PUSH ITER " + i + " on " + node);
                }
            }

            adjust /= 2; // we'll only push half the standard amount from here
        }

        newCenter = VueUtil.projectPoint(node.getMapCenterX(), node.getMapCenterY(), connector, adjust);

        if (Util.isBadPoint(newCenter)) {
            Log.error("bad newCenter: " + newCenter);
            newCenter = null;
        }

        if (DEBUG_PUSH) {
            float dist = (float) connector.getP1().distance(connector.getP2());
            String notes = String.format("distance: %.1f\nadjust: %.1f\n-center: %s\n+center: %s\nconnect: %s",
                    dist, adjust, Util.fmt(node.getMapCenter()), Util.fmt(newCenter), Util.fmt(connector));

            if (intersects)
                notes += "\nINTERSECTS";
            if (overlap)
                notes += "\nOVERLAP";

            final LWComponent n;

            if (false) {
                n = node.duplicate();
                node.setNotes(notes);
                nodes.add(n);
                n.setStrokeWidth(1);
            } else
                n = node;

            if (moveToEdge) {
                n.setTextColor(java.awt.Color.red);
                n.mFontStyle.set(java.awt.Font.BOLD);
            }
            n.setNotes(notes);
            if (newCenter != null)
                n.setCenterAt(newCenter);
        } else {
            if (newCenter != null)
                node.setCenterAt(newCenter);
        }

    }

    if (DEBUG_PUSH) {
        pushing.getMap().sendToBack(pushing);
        pushing.getMap().addChildren(nodes);
        pushing.getMap().addChildren(links);
    }
}