use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class GraphBoundsIndexerImplTest method testGetAreaAt.
@Test
public void testGetAreaAt() {
Point2D position = GraphUtils.getPosition((View) graphInstanceParent.startNode.getContent());
double[] size = GraphUtils.getNodeSize((View) graphInstanceParent.startNode.getContent());
double getAtX = position.getX() + (size[0] / 2);
double getAtY = position.getY() + (size[1] / 2);
Node<View<?>, Edge> node = graphBoundsIndexerImpl.getAt(getAtX, getAtY, size[0], size[1], graphInstanceParent.parentNode);
assertNotNull(node);
Node<View<?>, Edge> nodeFreePosition = graphBoundsIndexerImpl.getAt(getAtX, getAtY + 400, size[0], size[1], graphInstanceParent.parentNode);
assertNull(nodeFreePosition);
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class GraphBoundsIndexerImplTest method testGetAreaAtWithParent.
@Test
public void testGetAreaAtWithParent() {
Point2D position = GraphUtils.getPosition((View) graphInstanceParent.startNode.getContent());
double[] size = GraphUtils.getNodeSize((View) graphInstanceParent.startNode.getContent());
double getAtX = position.getX() + (size[0] / 2);
double getAtY = position.getY() + (size[1] / 2);
Node<View<?>, Edge> node = graphBoundsIndexerImpl.getAt(getAtX, getAtY, size[0], size[1], graphInstanceParent.parentNode);
assertNotNull(node);
Node<View<?>, Edge> nodeAtFreePosition = graphBoundsIndexerImpl.getAt(getAtX, getAtY + 200, size[0], size[1], graphInstanceParent.parentNode);
assertNull(nodeAtFreePosition);
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class LocationControlImpl method handleArrowKeys.
private void handleArrowKeys(final KeyboardEvent.Key... keys) {
final int selectedIDsCount = selectedIDs.size();
if (selectedIDsCount == 0) {
return;
}
double movementDistance = NORMAL_DISTANCE;
if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.CONTROL)) {
movementDistance = LARGE_DISTANCE;
} else if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.SHIFT)) {
movementDistance = SHORT_DISTANCE;
}
double horizontalDistance = 0d;
double verticalDistance = 0d;
if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.ARROW_LEFT)) {
horizontalDistance = -movementDistance;
} else if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.ARROW_RIGHT)) {
horizontalDistance = movementDistance;
}
if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.ARROW_UP)) {
verticalDistance = -movementDistance;
} else if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.ARROW_DOWN)) {
verticalDistance = movementDistance;
}
if (verticalDistance == 0 && horizontalDistance == 0) {
return;
}
List<Element> moveNodes = new ArrayList<>();
List<Point2D> movePositions = new ArrayList<>();
for (String uuid : selectedIDs) {
final Node<View<?>, Edge> node = canvasHandler.getGraphIndex().getNode(uuid);
if (node != null) {
final Point2D nodePosition = GraphUtils.getPosition(node.getContent());
final Point2D movePosition = new Point2D(nodePosition.getX() + horizontalDistance, nodePosition.getY() + verticalDistance);
moveNodes.add(node);
movePositions.add(movePosition);
}
}
move(moveNodes.toArray(new Element[] {}), movePositions.toArray(new Point2D[] {}));
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class ResizeControlImpl method doResize.
@SuppressWarnings("unchecked")
private CommandResult<CanvasViolation> doResize(final Element<? extends View<?>> element, final Double x, final Double y, final double w, final double h) {
// Calculate the new graph element's bounds.
final Point2D current = (null != x && null != y) ? new Point2D(x, y) : GraphUtils.getPosition(element.getContent());
final BoundsImpl newBounds = new BoundsImpl(new BoundImpl(current.getX(), current.getY()), new BoundImpl(current.getX() + w, current.getY() + h));
// Check the new bound values that come from the user's action do not exceed graph ones.
if (!GraphUtils.checkBoundsExceeded(canvasHandler.getDiagram().getGraph(), newBounds)) {
final CanvasViolation cv = CanvasViolationImpl.Builder.build(new BoundsExceededViolation(newBounds).setUUID(canvasHandler.getUuid()));
return new CommandResultImpl<>(CommandResult.Type.ERROR, Collections.singleton(cv));
}
// Execute the update position and update property/ies command/s on the bean instance to achieve the new bounds.
final List<Command<AbstractCanvasHandler, CanvasViolation>> commands = getResizeCommands(element, w, h);
final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>();
if (null != commands) {
if (null != x && null != y) {
commandBuilder.addCommand(canvasCommandFactory.updatePosition((Node<View<?>, Edge>) element, new Point2D(x, y)));
}
commands.forEach(commandBuilder::addCommand);
}
final CommandResult<CanvasViolation> resizeResults = getCommandManager().execute(canvasHandler, commandBuilder.build());
// Update the view bounds on the node content after successful resize.
if (!CommandUtils.isError(resizeResults)) {
element.getContent().setBounds(newBounds);
}
return resizeResults;
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class LocationControlImplTest method testMove.
@Test
@SuppressWarnings("unchecked")
public void testMove() {
tested.enable(canvasHandler);
tested.register(element);
Point2D location = new Point2D(45d, 65.5d);
tested.move(new Element[] { element }, new Point2D[] { location });
ArgumentCaptor<CanvasCommand> commandArgumentCaptor = ArgumentCaptor.forClass(CanvasCommand.class);
verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
ArgumentCaptor<ShapeLocationsChangedEvent> shapeLocationsChangedEventCaptor = ArgumentCaptor.forClass(ShapeLocationsChangedEvent.class);
verify(shapeLocationsChangedEvent, times(1)).fire(shapeLocationsChangedEventCaptor.capture());
assertTrue(shapeLocationsChangedEventCaptor.getValue() instanceof ShapeLocationsChangedEvent);
final UpdateElementPositionCommand command = (UpdateElementPositionCommand) commandArgumentCaptor.getValue();
assertEquals(element, command.getElement());
assertEquals(location, command.getLocation());
}
Aggregations