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

The following examples show how to use org.netbeans.api.visual.widget.Widget#getLocation() . 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: ReconnectAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean resolveReplacementWidgetCoreDive (Widget[] result, Widget widget, Point parentLocation) {
    if (widget == connectionWidget)
        return false;

    Point widgetLocation = widget.getLocation ();
    Point location = new Point (parentLocation.x - widgetLocation.x, parentLocation.y - widgetLocation.y);

    if (! widget.getBounds ().contains (location))
        return false;

    java.util.List<Widget> children = widget.getChildren ();
    for (int i = children.size () - 1; i >= 0; i --) {
        if (resolveReplacementWidgetCoreDive (result, children.get (i), location))
            return true;
    }

    if (! widget.isHitAt (location))
        return false;

    ConnectorState state = provider.isReplacementWidget (connectionWidget, widget, reconnectingSource);
    if (state == ConnectorState.REJECT)
        return false;
    if (state == ConnectorState.ACCEPT)
        result[0] = widget;
    return true;
}
 
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: ConnectAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean resolveTargetWidgetCoreDive (Widget[] result, Widget widget, Point parentLocation) {
    if (interractionLayer.equals (widget))
        return false;
    Point widgetLocation = widget.getLocation ();
    Point location = new Point (parentLocation.x - widgetLocation.x, parentLocation.y - widgetLocation.y);

    if (! widget.getBounds ().contains (location))
        return false;

    java.util.List<Widget> children = widget.getChildren ();
    for (int i = children.size () - 1; i >= 0; i --) {
        if (resolveTargetWidgetCoreDive (result, children.get (i), location))
            return true;
    }

    if (! widget.isHitAt (location))
        return false;

    ConnectorState state = provider.isTargetWidget (sourceWidget, widget);
    if (state == ConnectorState.REJECT)
        return false;
    if (state == ConnectorState.ACCEPT)
        result[0] = widget;
    return true;
}
 
Example 4
Source File: DependencyGraphScene.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override public void movementFinished(Widget widget) {
    // little hack to call highlightRelated on mouse click while leaving
    // normal move behaviour on real dragging
    Point moveEnd = widget.getLocation();
    if (moveStart.distance(moveEnd) < 5) {
        Object obj = DependencyGraphScene.this.findObject(widget);
        if (obj instanceof GraphNode) {
            DependencyGraphScene.this.highlightRelated((GraphNode)obj);
        }
    }
}
 
Example 5
Source File: PreferredLocationAnimator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void tick (double progress) {
    for (Map.Entry<Widget, Point> entry : targetLocations.entrySet ()) {
        Widget widget = entry.getKey ();
        Point sourceLocation = sourceLocations.get (widget);
        if (sourceLocation == null) {
            sourceLocation = widget.getPreferredLocation ();
            if (sourceLocation == null) {
                sourceLocation = widget.getLocation ();
                if (sourceLocation == null) {
                    sourceLocation = new Point ();
                }
            }
            sourceLocations.put (widget, sourceLocation);
        }
        Point targetLocation = entry.getValue ();
        if (targetLocation == null)
            continue;
        Point point;
        if (progress >= 1.0)
            point = targetLocation;
        else
            point = new Point (
                    (int) (sourceLocation.x + progress * (targetLocation.x - sourceLocation.x)),
                    (int) (sourceLocation.y + progress * (targetLocation.y - sourceLocation.y)));
        widget.setPreferredLocation (point);
    }
    if (progress >= 1.0) {
        sourceLocations.clear ();
        targetLocations.clear ();
    }
}
 
Example 6
Source File: DefaultAnchorShapeResolver.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Rectangle getSourceBounds()
{
    Widget source = connection.getSourceAnchor().getRelatedWidget();
         
    if(source != null)
    {
        Point sourceLocation = source.getLocation();
        Rectangle clientArea = source.getClientArea();
        return new Rectangle(sourceLocation, clientArea.getSize());
    }
    
    return null;
}
 
Example 7
Source File: DefaultAnchorShapeResolver.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Rectangle getTargetBounds()
{
    Widget target = connection.getTargetAnchor().getRelatedWidget();
            
    if(target != null)
    {
        Point targetLocation = target.getLocation();
        Rectangle targetArea = target.getClientArea();
        return new Rectangle(targetLocation, targetArea.getSize());
    }
    
    return null;
}
 
Example 8
Source File: ConnectionWidgetLayout.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Rectangle getSourceBounds(ConnectionWidget connectionWidget) {
    Widget source = connectionWidget.getSourceAnchor().getRelatedWidget();
    if (source == null)
        return null;

    Point sourceLocation = source.getLocation();
    Rectangle clientArea = source.getClientArea();
    return new Rectangle(sourceLocation, clientArea.getSize());
}
 
Example 9
Source File: ConnectionWidgetLayout.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Rectangle getTargetBounds(ConnectionWidget connectionWidget) {
    Widget target = connectionWidget.getTargetAnchor().getRelatedWidget();
    if (target == null)
        return null;

    Point targetLocation = target.getLocation();
    Rectangle targetArea = target.getClientArea();
    return new Rectangle(targetLocation, targetArea.getSize());
}
 
Example 10
Source File: DependencyGraphScene.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override public void movementStarted(Widget widget) {
    widget.bringToFront();
    moveStart = widget.getLocation();
}
 
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));
}