Java Code Examples for org.eclipse.draw2d.PositionConstants#VERTICAL

The following examples show how to use org.eclipse.draw2d.PositionConstants#VERTICAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given the coordinates of the connection anchor point the shape's rectangle and the
 * orientation of the first rectilinear connection segment that comes out from the anchor
 * point the method detemines on which geographic side of the rectangle the anchor point
 * is located on.
 * 
 * @param anchorPoint coordinates of the anchor point
 * @param rectangle the shape's bounding rectangle
 * @param segmentOrientation orinetation of the segment coming out from the anchor point
 * @return geographic position of the anchor point relative to the rectangle
 */
private int getAnchorLocationBasedOnSegmentOrientation(Point anchorPoint, Rectangle rectangle, int segmentOrientation) {
    if (segmentOrientation == PositionConstants.VERTICAL) {
        if (Math.abs(anchorPoint.y - rectangle.y) < Math.abs(anchorPoint.y - rectangle.y - rectangle.height)) {
            return PositionConstants.NORTH;
        } else {
            return PositionConstants.SOUTH;
        }
    } else if (segmentOrientation == PositionConstants.HORIZONTAL) {
        if (Math.abs(anchorPoint.x - rectangle.x) < Math.abs(anchorPoint.x - rectangle.x - rectangle.width)) {
            return PositionConstants.WEST;
        } else {
            return PositionConstants.EAST;
        }
    }
    return PositionConstants.NONE;
}
 
Example 2
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Rectilinear polyline is invalid if:
 * 1. First bend point is within the source
 * 2. Last bend point is within the target
 * 3. First bend point and source anchor are on different sides of the source shape
 * 4. Last bend point and target anchor are on different sides of the target shape
 * 
 * @param conn connection
 * @param line rectilinear polyline
 * @return <code>true</code> if the line is valid
 */
private boolean isValidRectilinearLine(Connection conn, PointList line) {
    if (!(conn.getSourceAnchor().getOwner() instanceof Connection)) {
        Rectangle source = new PrecisionRectangle(
                getAnchorableFigureBounds(conn.getSourceAnchor().getOwner()));
        conn.getSourceAnchor().getOwner().translateToAbsolute(source);
        conn.translateToRelative(source);
        if (source.contains(line.getPoint(1))) {
            return false;
        }
        int firstSegmentOrientation = line.getFirstPoint().x == line.getPoint(1).x ? PositionConstants.VERTICAL
                : PositionConstants.HORIZONTAL;
        if (getOutisePointOffRectanglePosition(line.getPoint(1), source) != getAnchorLocationBasedOnSegmentOrientation(
                line.getFirstPoint(), source, firstSegmentOrientation)) {
            return false;
        }
    }
    if (!(conn.getTargetAnchor().getOwner() instanceof Connection)) {
        Rectangle target = new PrecisionRectangle(
                getAnchorableFigureBounds(conn.getTargetAnchor().getOwner()));
        conn.getTargetAnchor().getOwner().translateToAbsolute(target);
        conn.translateToRelative(target);
        if (target.contains(line.getPoint(line.size() - 2))) {
            return false;
        }
        int lastSegmentOrientation = line.getLastPoint().x == line.getPoint(line.size() - 2).x
                ? PositionConstants.VERTICAL : PositionConstants.HORIZONTAL;
        if (getOutisePointOffRectanglePosition(line.getPoint(line.size() - 2),
                target) != getAnchorLocationBasedOnSegmentOrientation(line.getLastPoint(), target,
                        lastSegmentOrientation)) {
            return false;
        }
    }
    return true;
}
 
Example 3
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines whether the rectilinear line segment coming out of the shape should be
 * horizontal or vertical based on the anchor geographic position relative to the shape
 * 
 * @param anchorRelativeLocation
 * @return
 */
private int getOffShapeDirection(int anchorRelativeLocation) {
    if (anchorRelativeLocation == PositionConstants.EAST || anchorRelativeLocation == PositionConstants.WEST) {
        return PositionConstants.HORIZONTAL;
    } else if (anchorRelativeLocation == PositionConstants.NORTH || anchorRelativeLocation == PositionConstants.SOUTH) {
        return PositionConstants.VERTICAL;
    }
    return PositionConstants.NONE;
}
 
Example 4
Source File: CustomAnchor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Point getOrthogonalLocation(Point orthoReference) {
    PrecisionPoint ownReference = new PrecisionPoint(getReferencePoint());
    //      PrecisionRectangle bounds = new PrecisionRectangle(getBox());
    PrecisionRectangle bounds = new PrecisionRectangle(CustomRectilinearRouter.getAnchorableFigureBounds(getOwner()));
    getOwner().translateToAbsolute(bounds);
    bounds.expand(0.000001, 0.000001);
    PrecisionPoint preciseOrthoReference = new PrecisionPoint(orthoReference);
    int orientation = PositionConstants.NONE;
    if (bounds.contains(preciseOrthoReference)) {
        int side = getClosestSide(ownReference, bounds);
        switch (side) {
            case PositionConstants.LEFT:
            case PositionConstants.RIGHT:
                ownReference.preciseY = preciseOrthoReference.preciseY();
                orientation = PositionConstants.HORIZONTAL;
                break;
            case PositionConstants.TOP:
            case PositionConstants.BOTTOM:
                ownReference.preciseX = preciseOrthoReference.preciseX();
                orientation = PositionConstants.VERTICAL;
                break;
        }
    } else if (preciseOrthoReference.preciseX >= bounds.preciseX
            && preciseOrthoReference.preciseX <= bounds.preciseX + bounds.preciseWidth) {
        ownReference.preciseX = preciseOrthoReference.preciseX;
        orientation = PositionConstants.VERTICAL;
    } else if (preciseOrthoReference.preciseY >= bounds.preciseY
            && preciseOrthoReference.preciseY <= bounds.preciseY + bounds.preciseHeight) {
        ownReference.preciseY = preciseOrthoReference.preciseY;
        orientation = PositionConstants.HORIZONTAL;
    }
    ownReference.updateInts();

    Point location = getLocation(ownReference, preciseOrthoReference);
    if (location == null) {
        location = getLocation(orthoReference);
        orientation = PositionConstants.NONE;
    }

    if (orientation != PositionConstants.NONE) {
        PrecisionPoint loc = new PrecisionPoint(location);
        if (orientation == PositionConstants.VERTICAL) {
            loc.preciseX = preciseOrthoReference.preciseX;
        } else {
            loc.preciseY = preciseOrthoReference.preciseY;
        }
        loc.updateInts();
        location = loc;
    }

    return location;
}