Java Code Examples for org.netbeans.api.visual.widget.Widget#getBounds()

The following examples show how to use org.netbeans.api.visual.widget.Widget#getBounds() . 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: ResizeAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public State mousePressed (Widget widget, WidgetMouseEvent event) {
    if (isLocked ())
        return State.createLocked (widget, this);
    if (event.getButton () == MouseEvent.BUTTON1  &&  event.getClickCount () == 1) {
        insets = widget.getBorder ().getInsets ();
        controlPoint = resolver.resolveControlPoint (widget, event.getPoint ());
        if (controlPoint != null) {
            resizingWidget = widget;
            originalSceneRectangle = null;
            if (widget.isPreferredBoundsSet ())
                originalSceneRectangle = widget.getPreferredBounds ();
            if (originalSceneRectangle == null)
                originalSceneRectangle = widget.getBounds ();
            if (originalSceneRectangle == null)
                originalSceneRectangle = widget.getPreferredBounds ();
            dragSceneLocation = widget.convertLocalToScene (event.getPoint ());
            provider.resizingStarted (widget);
            return State.createLocked (widget, this);
        }
    }
    return State.REJECTED;
}
 
Example 2
Source File: AlignWithMoveStrategyProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Point locationSuggested (Widget widget, Point originalLocation, Point suggestedLocation) {
    Point widgetLocation = widget.getLocation ();
    Rectangle widgetBounds = outerBounds ? widget.getBounds () : widget.getClientArea ();
    Rectangle bounds = widget.convertLocalToScene (widgetBounds);
    bounds.translate (suggestedLocation.x - widgetLocation.x, suggestedLocation.y - widgetLocation.y);
    Insets insets = widget.getBorder ().getInsets ();
    if (! outerBounds) {
        suggestedLocation.x += insets.left;
        suggestedLocation.y += insets.top;
    }
    Point point = super.locationSuggested (widget, bounds, widget.getParentWidget().convertLocalToScene(suggestedLocation), true, true, true, true);
    if (! outerBounds) {
        point.x -= insets.left;
        point.y -= insets.top;
    }
    return widget.getParentWidget ().convertSceneToLocal (point);
}
 
Example 3
Source File: PopupMenuAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public State keyPressed (Widget widget, WidgetKeyEvent event) {
        if (event.getKeyCode () == KeyEvent.VK_CONTEXT_MENU  ||  ((event.getModifiers () & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK  &&  event.getKeyCode () == KeyEvent.VK_F10)) {
            JPopupMenu popupMenu = provider.getPopupMenu (widget, null);
            if (popupMenu != null) {
                JComponent view = widget.getScene ().getView ();
                if (view != null) {
//                    Rectangle visibleRect = view.getVisibleRect ();
//                    popupMenu.show (view, visibleRect.x + 10, visibleRect.y + 10);
                    Rectangle bounds = widget.getBounds ();
                    Point location = new Point (bounds.x + 5, bounds.y + 5);
                    location = widget.convertLocalToScene (location);
                    location = widget.getScene ().convertSceneToView (location);
                    popupMenu.show (view, location.x, location.y);
                }
            }
            return State.CONSUMED;
        }
        return State.REJECTED;
    }
 
Example 4
Source File: GraphBiLayout.java    From Llunatic with GNU General Public License v3.0 6 votes vote down vote up
private List<GraphLocation> createRelativeLocations(ObjectScene scene, List<GraphNode> nodes, Align align) {
    List<GraphLocation> widgetLocations = new ArrayList<GraphLocation>();
    int startY = 0;
    for (GraphNode node : nodes) {
        Widget widget = scene.findWidget(node);
        if (widget == null) {
            continue;
        }
        Rectangle bounds = widget.getBounds();
        if (bounds == null) {
            continue;
        }
        int startX = 0;
        if ( align == Align.RIGHT){
            startX = -bounds.width;
        }
        widgetLocations.add(new GraphLocation(node, startX, startY,bounds));
        startY += bounds.height + verticalGap;
        
    }
    return widgetLocations;
}
 
Example 5
Source File: DependencyGraphScene.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void performLayout() {
    Rectangle rectangle = null;
    List<? extends Widget> toFit = widgets != null ? widgets : depScene.getChildren();
    if (toFit == null) {
        return;
    }

    for (Widget widget : toFit) {
        Rectangle bounds = widget.getBounds();
        if (bounds == null) {
            continue;
        }
        if (rectangle == null) {
            rectangle = widget.convertLocalToScene(bounds);
        } else {
            rectangle = rectangle.union(widget.convertLocalToScene(bounds));
        }
    }
    // margin around
    if (widgets == null) {
        rectangle.grow(5, 5);
    } else {
        rectangle.grow(25, 25);
    }
    Dimension dim = rectangle.getSize();
    Dimension viewDim = parentScrollPane.getViewportBorderBounds().getSize ();
    double zf = Math.min ((double) viewDim.width / dim.width, (double) viewDim.height / dim.height);
    if (depScene.isAnimated()) {
        if (widgets == null) {
            depScene.getSceneAnimator().animateZoomFactor(zf);
        } else {
            CenteredZoomAnimator cza = new CenteredZoomAnimator(depScene.getSceneAnimator());
            cza.setZoomFactor(zf,
                    new Point((int)rectangle.getCenterX(), (int)rectangle.getCenterY()));
        }
    } else {
        depScene.setMyZoomFactor (zf);
    }
}
 
Example 6
Source File: PreferredBoundsAnimator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void tick (double progress) {
    for (Map.Entry<Widget, Rectangle> entry : targetBounds.entrySet ()) {
        Widget widget = entry.getKey ();
        Rectangle sourceBoundary = sourceBounds.get (widget);
        if (sourceBoundary == null) {
            sourceBoundary = widget.getBounds ();
            if (sourceBoundary == null)
                sourceBoundary = new Rectangle ();
            sourceBounds.put (widget, sourceBoundary);
        }
        Rectangle targetBoundary = entry.getValue ();
        Rectangle boundary;
        if (progress >= 1.0) {
            boundary = nullBounds.get (widget) ? null : targetBoundary;
        } else
            boundary = new Rectangle (
                    (int) (sourceBoundary.x + progress * (targetBoundary.x - sourceBoundary.x)),
                    (int) (sourceBoundary.y + progress * (targetBoundary.y - sourceBoundary.y)),
                    (int) (sourceBoundary.width + progress * (targetBoundary.width - sourceBoundary.width)),
                    (int) (sourceBoundary.height + progress * (targetBoundary.height - sourceBoundary.height)));
        widget.setPreferredBounds (boundary);
    }
    if (progress >= 1.0) {
        sourceBounds.clear ();
        targetBounds.clear ();
        nullBounds.clear ();
    }
}
 
Example 7
Source File: ResizeCornersControlPointResolver.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ResizeProvider.ControlPoint resolveControlPoint (Widget widget, Point point) {
    Rectangle bounds = widget.getBounds ();
    Insets insets = widget.getBorder ().getInsets ();
    Point center = GeomUtil.center (bounds);
    Dimension centerDimension = new Dimension (Math.max (insets.left, insets.right), Math.max (insets.top, insets.bottom));
    if (point.y >= bounds.y + bounds.height - insets.bottom && point.y < bounds.y + bounds.height) {

        if (point.x >= bounds.x + bounds.width - insets.right && point.x < bounds.x + bounds.width)
            return ResizeProvider.ControlPoint.BOTTOM_RIGHT;
        else if (point.x >= bounds.x && point.x < bounds.x + insets.left)
            return ResizeProvider.ControlPoint.BOTTOM_LEFT;
        else
        if (point.x >= center.x - centerDimension.height / 2 && point.x < center.x + centerDimension.height - centerDimension.height / 2)
            return ResizeProvider.ControlPoint.BOTTOM_CENTER;

    } else if (point.y >= bounds.y && point.y < bounds.y + insets.top) {

        if (point.x >= bounds.x + bounds.width - insets.right && point.x < bounds.x + bounds.width)
            return ResizeProvider.ControlPoint.TOP_RIGHT;
        else if (point.x >= bounds.x && point.x < bounds.x + insets.left)
            return ResizeProvider.ControlPoint.TOP_LEFT;
        else
        if (point.x >= center.x - centerDimension.height / 2 && point.x < center.x + centerDimension.height - centerDimension.height / 2)
            return ResizeProvider.ControlPoint.TOP_CENTER;

    } else
    if (point.y >= center.y - centerDimension.width / 2 && point.y < center.y + centerDimension.width - centerDimension.width / 2)
    {

        if (point.x >= bounds.x + bounds.width - insets.right && point.x < bounds.x + bounds.width)
            return ResizeProvider.ControlPoint.CENTER_RIGHT;
        else if (point.x >= bounds.x && point.x < bounds.x + insets.left)
            return ResizeProvider.ControlPoint.CENTER_LEFT;

    }
    // TODO - resolve CENTER points
    return null;
}
 
Example 8
Source File: RectangularAnchor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public List<Point> compute(List<Point> points) {
    ArrayList<Point> bestPoints = new ArrayList<Point> (points) ;
    Point relatedLocation = getRelatedSceneLocation();

    int direction = 1 ;
    int index = 0 ;
    
    //the related location is the center of this anchor. It is possible that
    //the list of points started at the opposite anchor (other end of connection).
    Point endPoint = bestPoints.get(index);
    if (!endPoint.equals(relatedLocation)) {
        index = bestPoints.size() - 1 ;
        endPoint = bestPoints.get(index);
        direction = -1 ;
    }
    
    Widget widget = getRelatedWidget();
    Rectangle bounds = widget.getBounds();
    bounds = widget.convertLocalToScene(bounds);
    
    Point neighbor = bestPoints.get (index+direction) ;
    
    //moving the end point to the end of the anchor from the interior
    while (bounds.contains(neighbor)) {
        bestPoints.remove(index) ;
        endPoint = bestPoints.get (index);
        neighbor = bestPoints.get (index+direction);
    }
    
    Result intersection = this.computeBoundaryIntersectionPoint(endPoint, neighbor);
            
    bestPoints.remove(index) ;
    bestPoints.add(index, intersection.getAnchorSceneLocation());
    
    return bestPoints ;
}
 
Example 9
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 10
Source File: DiagramScene.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void gotoSelection(Set<Object> ids) {

        Rectangle overall = null;
        Set<Integer> hiddenNodes = new HashSet<>(this.getModel().getHiddenNodes());
        hiddenNodes.removeAll(ids);
        this.getModel().showNot(hiddenNodes);

        Set<Object> objects = idSetToObjectSet(ids);
        for (Object o : objects) {

            Widget w = getWidget(o);
            if (w != null) {
                Rectangle r = w.getBounds();
                Point p = w.convertLocalToScene(new Point(0, 0));

                Rectangle r2 = new Rectangle(p.x, p.y, r.width, r.height);

                if (overall == null) {
                    overall = r2;
                } else {
                    overall = overall.union(r2);
                }
            }
        }
        if (overall != null) {
            centerRectangle(overall);
        }

        setSelectedObjects(objects);
    }
 
Example 11
Source File: DiagramScene.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void centerWidget(Widget w) {
    Rectangle r = w.getBounds();
    Point p = w.getLocation();
    centerRectangle(new Rectangle(p.x, p.y, r.width, r.height));
}
 
Example 12
Source File: DirectedGraph.java    From netbeans with Apache License 2.0 3 votes vote down vote up
protected void createGraph() {
    for (E e : edges) {

        N source = uGraph.getEdgeSource(e);
        N target = uGraph.getEdgeTarget(e);

        Vertex sourceVertex = getVertex(source);
        Vertex targetVertex = getVertex(target);

        Edge edge = createEdge(sourceVertex, targetVertex, e);

        sourceVertex.addOutgoingEdge(edge);
        targetVertex.addIncomingEdge(edge);

        sourceVertex.addUpperNeighbor(targetVertex);
        targetVertex.addLowerNeighbor(sourceVertex);

    }

    for (N node : nodes) {
        Vertex vertex = getVertex(node);

        Widget widget = scene.findWidget(node);
        if (widget == null) continue ;  //why is it null
        Rectangle bounds = widget.getBounds();

        Dimension size = new Dimension(bounds.width, bounds.height);

        vertex.setSize(size);
    }


    findRootVertices();
//printGraph();
}