use of org.eclipse.gef.fx.nodes.Connection in project osate2 by osate.
the class MoveConnectionPointInteraction method onMouseDragged.
@Override
protected Interaction.InteractionState onMouseDragged(final MouseEvent e) {
if (e.getButton() != MouseButton.PRIMARY) {
return super.onMouseDragged(e);
}
final Transform sceneToDiagramTransform = editor.getGefDiagram().getSceneNode().getSceneToLocalTransform();
final Point2D eventInDiagram = sceneToDiagramTransform.transform(e.getSceneX(), e.getSceneY());
final Point2D snappedDiagramPosition = InputEventHandlerUtil.snap(editor, eventInDiagram, false);
if (activeHandle instanceof FlowIndicatorPositionHandle) {
final FlowIndicatorNode c = ((FlowIndicatorPositionHandle) activeHandle).getSceneNode();
final Node positioningReference = c.getPositioningReferenceOrThrow();
// The the position relative to the reference
final Point2D newPoint = getLocalPositionFromDiagram(editor.getGefDiagram(), snappedDiagramPosition, positioningReference);
final Point2D oldPosition = PreferredPosition.get(activeHandle.getSceneNode());
PreferredPosition.set(activeHandle.getSceneNode(), newPoint);
// Adjust positions of control points so that only the ending position of the flow indicator is moved.
if (oldPosition != null) {
final double dx = newPoint.getX() - oldPosition.getX();
final double dy = newPoint.getY() - oldPosition.getY();
c.getInnerConnection().setControlPoints(c.getInnerConnection().getControlPoints().stream().map(p -> new Point(p.x - dx, p.y - dy)).collect(Collectors.toList()));
}
} else if (controlPointIndex != null) {
final BaseConnectionNode c = activeHandle.getSceneNode();
final Connection ic = c.getInnerConnection();
final Point2D newPosition = getLocalPositionFromDiagram(editor.getGefDiagram(), snappedDiagramPosition, ic);
// Get a list of the control points and the start and end points of connection.
final List<Point> allPoints = ic.getPointsUnmodifiable();
final List<org.eclipse.gef.geometry.planar.Point> controlPoints = ic.getControlPoints();
final ArrayList<org.eclipse.gef.geometry.planar.Point> endAndControlPoints = new ArrayList<>(controlPoints.size() + 2);
endAndControlPoints.add(allPoints.get(0));
endAndControlPoints.addAll(controlPoints);
endAndControlPoints.add(allPoints.get(allPoints.size() - 1));
// Determine whether the point should be removed or added
final boolean remove = controlPointExists && distanceToLineSegment(newPosition, endAndControlPoints, controlPointIndex, controlPointIndex + 2) <= REMOVE_POINT_DISTANCE;
final boolean add = !remove && !controlPointExists && distanceToLineSegment(newPosition, endAndControlPoints, controlPointIndex, controlPointIndex + 1) >= ADD_POINT_DISTANCE;
if (remove) {
c.getInnerConnection().removeControlPoint(controlPointIndex);
controlPointExists = false;
} else if (add) {
controlPoints.add(controlPointIndex, FX2Geometry.toPoint(newPosition));
ic.setControlPoints(controlPoints);
controlPointExists = true;
} else if (controlPointExists) {
ic.setControlPoint(controlPointIndex, FX2Geometry.toPoint(newPosition));
}
}
return InteractionState.IN_PROGRESS;
}
use of org.eclipse.gef.fx.nodes.Connection in project osate2 by osate.
the class JavaFXBot method click.
/**
* Clicks a scene graph node.
* If the node is contained in a {@link ScrollPane}, this function will scroll the pane so that it is visible.
* @param node the node to click.
*/
public void click(final Node node) {
ensureRobotCreated();
UiTestUtil.waitUntil(() -> UIThreadRunnable.syncExec(() -> isVisible(node)), "Node " + node + " is not visible");
Display.getDefault().syncExec(() -> {
ensureVisible(node);
final Point2D p;
if (node instanceof BaseConnectionNode) {
final BaseConnectionNode cn = (BaseConnectionNode) node;
final Connection ic = cn.getInnerConnection();
final Point startPoint = ic.getStartPoint();
p = ic.localToScreen(startPoint.x, startPoint.y);
} else {
p = node.localToScreen(4, 4);
}
robot.mouseMove(p.getX(), p.getY());
robot.mousePress(MouseButton.PRIMARY);
robot.mouseRelease(MouseButton.PRIMARY);
});
}
Aggregations