Java Code Examples for org.netbeans.api.visual.anchor.Anchor#Result

The following examples show how to use org.netbeans.api.visual.anchor.Anchor#Result . 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: RectangularAnchor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Result compute(Entry entry) {
    Point relatedLocation = getRelatedSceneLocation();
    Point oppositeLocation = null;

    if (oppositeLocation == null) {
        oppositeLocation = getOppositeSceneLocation(entry);
    }
    
    Result boundaryIntersection =
            computeBoundaryIntersectionPoint(relatedLocation, oppositeLocation);

    if (boundaryIntersection == null) {
        return new Anchor.Result(relatedLocation, Anchor.DIRECTION_ANY);
    }
    
    return boundaryIntersection ;
}
 
Example 2
Source File: DirectionalAnchor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Result compute (Entry entry) {
    Point relatedLocation = getRelatedSceneLocation ();
    Point oppositeLocation = getOppositeSceneLocation (entry);

    Widget widget = getRelatedWidget ();
    Rectangle bounds = widget.convertLocalToScene (widget.getBounds ());
    Point center = GeomUtil.center (bounds);

    switch (kind) {
        case HORIZONTAL:
            if (relatedLocation.x >= oppositeLocation.x)
                return new Anchor.Result (new Point (bounds.x - gap, center.y), Direction.LEFT);
            else
                return new Anchor.Result (new Point (bounds.x + bounds.width + gap, center.y), Direction.RIGHT);
        case VERTICAL:
            if (relatedLocation.y >= oppositeLocation.y)
                return new Anchor.Result (new Point (center.x, bounds.y - gap), Direction.TOP);
            else
                return new Anchor.Result (new Point (center.x, bounds.y + bounds.height + gap), Direction.BOTTOM);
    }
    return null;
}
 
Example 3
Source File: BestPathAnchor.java    From Llunatic with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Result compute(Entry entry) {
    Widget widget = getRelatedWidget();
    Widget otherWidget = entry.getOppositeAnchor().getRelatedWidget();
    Rectangle bounds = widget.convertLocalToScene(widget.getBounds());
    Rectangle otherBounds = otherWidget.convertLocalToScene(otherWidget.getBounds());
    Point center = getCenter(bounds);
    int leftBound = bounds.x;
    int rightBound = bounds.x + bounds.width;
    int oppositeLeftBound = otherBounds.x;
    int oppositeRightBound = otherBounds.x + otherBounds.width;
    if (leftBound >= oppositeRightBound) {
        return new Anchor.Result(new Point(leftBound, center.y), Direction.LEFT);
    } else if (rightBound <= oppositeLeftBound) {
        return new Anchor.Result(new Point(rightBound, center.y), Direction.RIGHT);
    } else {
        int leftDist = Math.abs(leftBound - oppositeLeftBound);
        int rightDist = Math.abs(rightBound - oppositeRightBound);
        if (leftDist <= rightDist) {
            return new Anchor.Result(new Point(leftBound, center.y), Direction.LEFT);
        } else {
            return new Anchor.Result(new Point(rightBound, center.y), Direction.RIGHT);
        }
    }
}
 
Example 4
Source File: RectangularAnchor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Result computeBoundaryIntersectionPoint(Point relatedLocation, Point oppositeLocation) {
    
    Widget widget = getRelatedWidget();
    Rectangle bounds = widget.getBounds();
    if (!includeBorders) {
        Insets insets = widget.getBorder().getInsets();
        bounds.x += insets.left;
        bounds.y += insets.top;
        bounds.width -= insets.left + insets.right;
        bounds.height -= insets.top + insets.bottom;
    }
    bounds = widget.convertLocalToScene(bounds);

    if (bounds.isEmpty() || relatedLocation.equals(oppositeLocation)) {
        return null;
    }
    float dx = oppositeLocation.x - relatedLocation.x;
    float dy = oppositeLocation.y - relatedLocation.y;

    float ddx = Math.abs(dx) / (float) bounds.width;
    float ddy = Math.abs(dy) / (float) bounds.height;

    Anchor.Direction direction;

    if (ddx >= ddy) {
        direction = dx >= 0.0f ? Direction.RIGHT : Direction.LEFT;
    } else {
        direction = dy >= 0.0f ? Direction.BOTTOM : Direction.TOP;
    }

    float scale = 0.5f / Math.max(ddx, ddy);

    Point point = new Point(Math.round(relatedLocation.x + scale * dx), 
            Math.round(relatedLocation.y + scale * dy));
    
    return new Anchor.Result(point, direction);
}
 
Example 5
Source File: CircularAnchor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Result compute (Entry entry) {
    Point relatedLocation = getRelatedSceneLocation ();
    Point oppositeLocation = getOppositeSceneLocation (entry);

    double angle = Math.atan2 (oppositeLocation.y - relatedLocation.y, oppositeLocation.x - relatedLocation.x);

    Point location = new Point (relatedLocation.x + (int) (radius * Math.cos (angle)), relatedLocation.y + (int) (radius * Math.sin (angle)));
    return new Anchor.Result (location, Anchor.DIRECTION_ANY); // TODO - resolve direction
}
 
Example 6
Source File: FixedPathAnchor.java    From Llunatic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Result compute(Entry entry) {
    Widget widget = getRelatedWidget();
    Rectangle bounds = widget.convertLocalToScene(widget.getBounds());
    Point center = getCenter(bounds);
    int leftBound = bounds.x;
    int rightBound = bounds.x + bounds.width;
    if (direction == Direction.LEFT) {
        return new Anchor.Result(new Point(leftBound, center.y), Direction.LEFT);
    } else {
        return new Anchor.Result(new Point(rightBound, center.y), Direction.RIGHT);
    }
}
 
Example 7
Source File: BestPathObjectAnchor.java    From Llunatic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Result compute(Entry entry) {
    Widget widget = getRelatedWidget();
    Widget otherWidget = entry.getOppositeAnchor().getRelatedWidget();
    Rectangle bounds = widget.convertLocalToScene(widget.getBounds());
    Rectangle otherBounds = otherWidget.convertLocalToScene(otherWidget.getBounds());
    Point center = getCenter(bounds);
    Connection minimum = getMin(new Connection(bounds.x, otherBounds.x, Direction.LEFT), new Connection(bounds.x, otherBounds.x + otherBounds.width, Direction.LEFT));
    minimum = getMin(minimum, new Connection(bounds.x + bounds.width, otherBounds.x, Direction.RIGHT));
    minimum = getMin(minimum, new Connection(bounds.x + bounds.width, otherBounds.x + otherBounds.width, Direction.RIGHT));
    return new Anchor.Result(new Point(minimum.getStartX(), center.y), minimum.getDirection());
}
 
Example 8
Source File: ProxyAnchor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Anchor.Result compute (Anchor.Entry entry) {
    return anchors[index].compute (entry);
}