use of org.eclipse.sirius.components.diagrams.layout.ISiriusWebLayoutConfigurator in project sirius-components by eclipse-sirius.
the class NodeSizeProviderTests method testNodeSizeWithExistingSize.
@Test
public void testNodeSizeWithExistingSize() {
ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
NodeSizeProvider nodeSizeProvider = new NodeSizeProvider(imageSizeProvider);
ISiriusWebLayoutConfigurator layoutConfigurator = new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator();
Size size = nodeSizeProvider.getSize(Optional.empty(), this.createNodeLayoutData(Size.of(WIDTH_80, HEIGHT_50)), layoutConfigurator);
assertThat(size).extracting(Size::getHeight).isEqualTo(Double.valueOf(HEIGHT_50));
assertThat(size).extracting(Size::getWidth).isEqualTo(Double.valueOf(WIDTH_80));
imageSizeProvider.dispose();
}
use of org.eclipse.sirius.components.diagrams.layout.ISiriusWebLayoutConfigurator in project sirius-components by eclipse-sirius.
the class IncrementalLayoutEngine method snapBorderNodes.
/**
* Update the border node by snapping it to the parentRectangle, that is moving it to the closest point of the
* parentRectangle.
*
* @param borderNodesLayoutData
* the border nodes which position is given in the rectangle upper right corner coordinates system
* @return for each side of the given parentRectangle, the list of the updates border node
*/
private List<BorderNodesOnSide> snapBorderNodes(List<NodeLayoutData> borderNodesLayoutData, Size parentRectangle, ISiriusWebLayoutConfigurator layoutConfigurator) {
EnumMap<RectangleSide, List<NodeLayoutData>> borderNodesPerSide = new EnumMap<>(RectangleSide.class);
Geometry geometry = new Geometry();
for (NodeLayoutData borderNodeLayoutData : borderNodesLayoutData) {
double portOffset = layoutConfigurator.configureByType(borderNodeLayoutData.getNodeType()).getProperty(CoreOptions.PORT_BORDER_OFFSET).doubleValue();
Bounds borderNodeRectangle = Bounds.newBounds().position(borderNodeLayoutData.getPosition()).size(borderNodeLayoutData.getSize()).build();
PointOnRectangleInfo borderNodePositionOnSide = geometry.snapBorderNodeOnRectangle(borderNodeRectangle, parentRectangle, portOffset);
// update the border node
borderNodeLayoutData.setPosition(borderNodePositionOnSide.getPosition());
borderNodesPerSide.computeIfAbsent(borderNodePositionOnSide.getSide(), side -> new ArrayList<>());
borderNodesPerSide.get(borderNodePositionOnSide.getSide()).add(borderNodeLayoutData);
}
// @formatter:off
return borderNodesPerSide.entrySet().stream().map(entry -> new BorderNodesOnSide(entry.getKey(), entry.getValue())).collect(Collectors.toList());
// @formatter:on
}
use of org.eclipse.sirius.components.diagrams.layout.ISiriusWebLayoutConfigurator in project sirius-components by eclipse-sirius.
the class NodeSizeProviderTests method testNodeSize.
@Test
public void testNodeSize() {
ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
NodeSizeProvider nodeSizeProvider = new NodeSizeProvider(imageSizeProvider);
ISiriusWebLayoutConfigurator layoutConfigurator = new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator();
Size size = nodeSizeProvider.getSize(Optional.empty(), this.createNodeLayoutData(Size.UNDEFINED), layoutConfigurator);
assertThat(size).extracting(Size::getHeight).isEqualTo(Double.valueOf(HEIGHT_70));
assertThat(size).extracting(Size::getWidth).isEqualTo(Double.valueOf(WIDTH_150));
imageSizeProvider.dispose();
}
use of org.eclipse.sirius.components.diagrams.layout.ISiriusWebLayoutConfigurator in project sirius-components by eclipse-sirius.
the class NodeSizeProviderTests method testResizeNodeEvent.
@Test
public void testResizeNodeEvent() {
Size initialNodeSize = Size.of(200, 100);
NodeLayoutData nodeLayoutData = this.createNodeLayoutData(initialNodeSize);
NodeLayoutData nodeLayoutData2 = this.createNodeLayoutData(initialNodeSize);
Size newSize = Size.of(100, 50);
ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
NodeSizeProvider nodeSizeProvider = new NodeSizeProvider(imageSizeProvider);
Optional<IDiagramEvent> optionalEvent = Optional.of(new ResizeEvent(nodeLayoutData.getId(), Position.UNDEFINED, newSize));
ISiriusWebLayoutConfigurator layoutConfigurator = new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator();
Size newSizeFromProvider = nodeSizeProvider.getSize(optionalEvent, nodeLayoutData, layoutConfigurator);
Size newSizeFromProvider2 = nodeSizeProvider.getSize(optionalEvent, nodeLayoutData2, layoutConfigurator);
assertThat(newSizeFromProvider).isEqualTo(newSize);
assertThat(newSizeFromProvider2).isEqualTo(initialNodeSize);
}
Aggregations