Java Code Examples for org.netbeans.api.visual.widget.ConnectionWidget#getControlPoints()
The following examples show how to use
org.netbeans.api.visual.widget.ConnectionWidget#getControlPoints() .
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: AddRemoveControlPointAction.java From netbeans with Apache License 2.0 | 6 votes |
/** * Adds or removes a control point on a specified location * @param widget the connection widget * @param localLocation the local location */ private void addRemoveControlPoint (ConnectionWidget widget, Point localLocation) { ArrayList<Point> list = new ArrayList<Point> (widget.getControlPoints ()); if (!removeControlPoint (localLocation, list, deleteSensitivity)) { Point exPoint = null; int index = 0; for (Point elem : list) { if (exPoint != null) { Line2D l2d = new Line2D.Double (exPoint, elem); if (l2d.ptSegDist (localLocation) < createSensitivity) { list.add (index, localLocation); break; } } exPoint = elem; index++; } } if (routingPolicy != null) widget.setRoutingPolicy (routingPolicy); widget.setControlPoints (list, false); }
Example 2
Source File: FreeRouter.java From netbeans with Apache License 2.0 | 6 votes |
public List<Point> routeConnection(ConnectionWidget widget) { ArrayList<Point> list = new ArrayList<Point> (); Anchor sourceAnchor = widget.getSourceAnchor(); Anchor targetAnchor = widget.getTargetAnchor(); if (sourceAnchor == null || targetAnchor == null) return Collections.emptyList(); list.add(sourceAnchor.compute(widget.getSourceAnchorEntry()).getAnchorSceneLocation()); List<Point> oldControlPoints = widget.getControlPoints (); if(oldControlPoints !=null) { ArrayList<Point> oldList = new ArrayList<Point> (oldControlPoints); oldList.remove(widget.getFirstControlPoint()); oldList.remove(widget.getLastControlPoint()); list.addAll(oldList); } list.add(targetAnchor.compute(widget.getTargetAnchorEntry()).getAnchorSceneLocation()); return list; }
Example 3
Source File: ReconnectAction.java From netbeans with Apache License 2.0 | 5 votes |
public State mousePressed (Widget widget, WidgetMouseEvent event) { if (isLocked ()) return State.createLocked (widget, this); if (event.getButton () == MouseEvent.BUTTON1 && event.getClickCount () == 1) { if (widget instanceof ConnectionWidget) { ConnectionWidget conn = (ConnectionWidget) widget; int index = conn.getControlPointHitAt (event.getPoint ()); List<Point> controlPoints = conn.getControlPoints (); if (index == 0 && provider.isSourceReconnectable (conn)) { reconnectingSource = true; } else if (controlPoints != null && index == controlPoints.size () - 1 && provider.isTargetReconnectable (conn)) { reconnectingSource = false; } else { return State.REJECTED; } floatPoint = new Point (event.getPoint ()); replacementWidget = null; connectionWidget = conn; provider.reconnectingStarted (conn, reconnectingSource); if (reconnectingSource) originalAnchor = connectionWidget.getSourceAnchor (); else originalAnchor = connectionWidget.getTargetAnchor (); return State.createLocked (widget, this); } } return State.REJECTED; }
Example 4
Source File: FreeMoveControlPointProvider.java From netbeans with Apache License 2.0 | 5 votes |
public List<Point> locationSuggested(ConnectionWidget connectionWidget, int index, Point suggestedLocation) { List<Point> controlPoints = connectionWidget.getControlPoints(); int cpSize=controlPoints.size()-1; ArrayList<Point> list = new ArrayList<Point> (controlPoints); if (index <= 0 || index >= cpSize)return null; if(index==1)list.set(0,connectionWidget.getSourceAnchor().compute(connectionWidget.getSourceAnchorEntry()).getAnchorSceneLocation()); if(index==cpSize - 1) list.set(cpSize,connectionWidget.getTargetAnchor().compute(connectionWidget.getTargetAnchorEntry()).getAnchorSceneLocation()); list.set(index, suggestedLocation); return list; }
Example 5
Source File: ConnectionWidgetLayout.java From netbeans with Apache License 2.0 | 4 votes |
public void layout (Widget widget) { ConnectionWidget connectionWidget = (ConnectionWidget) widget; connectionWidget.calculateRouting (); java.util.List<Point> controlPoints = connectionWidget.getControlPoints (); boolean empty = controlPoints == null || controlPoints.size () <= 0; double totalDistance = 0.0; double[] distances = new double[empty ? 0 : controlPoints.size () - 1]; for (int i = 0; i < distances.length; i ++) distances[i] = totalDistance += GeomUtil.distanceSq (controlPoints.get (i), controlPoints.get (i + 1)); ArrayList<Widget> childrenToResolve = new ArrayList<Widget> (widget.getChildren()); for (Map.Entry<Placement,ArrayList<Widget>> entry : reverse.entrySet()) { Placement placement = entry.getKey (); ArrayList<Widget> currentlyResolving = null; for (Widget childWidget : entry.getValue()) { if (childWidget.getParentWidget() == widget && childWidget.isVisible()) { if (currentlyResolving == null) currentlyResolving = new ArrayList<Widget>(); currentlyResolving.add(childWidget); } } if (currentlyResolving == null) continue; Point point; if (empty) { point = new Point(); } else if (placement.isPercentage) { float percentage = placement.placementInPercentage; if (percentage <= 0.0) point = connectionWidget.getFirstControlPoint (); else if (percentage >= 1.0) point = connectionWidget.getLastControlPoint (); else point = getLinePointAtPercentage (distances, (int) (percentage * totalDistance), controlPoints); } else { int distance = placement.placementAtDistance; if (distance < 0) point = getLinePointAtPercentage (distances, distance + (int) totalDistance, controlPoints); else point = getLinePointAtPercentage (distances, distance, controlPoints); } layoutChildrenAt (point, placement.alignment, connectionWidget, currentlyResolving); childrenToResolve.removeAll (currentlyResolving); } if (! childrenToResolve.isEmpty()) layoutChildrenAt (new Point (), null, connectionWidget, childrenToResolve); }