use of org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData in project sirius-components by eclipse-sirius.
the class IncrementalLayoutDiagramConverter method convertNode.
private NodeLayoutData convertNode(Node node, IContainerLayoutData parent, Map<String, ILayoutData> id2LayoutData) {
NodeLayoutData layoutData = new NodeLayoutData();
String id = node.getId();
layoutData.setId(id);
id2LayoutData.put(id, layoutData);
layoutData.setParent(parent);
layoutData.setNodeType(node.getType());
layoutData.setStyle(node.getStyle());
layoutData.setPosition(node.getPosition());
layoutData.setSize(node.getSize());
List<NodeLayoutData> borderNodes = new ArrayList<>();
for (Node borderNode : node.getBorderNodes()) {
borderNodes.add(this.convertNode(borderNode, layoutData, id2LayoutData));
}
layoutData.setBorderNodes(borderNodes);
List<NodeLayoutData> childNodes = new ArrayList<>();
for (Node childNode : node.getChildNodes()) {
childNodes.add(this.convertNode(childNode, layoutData, id2LayoutData));
}
layoutData.setChildrenNodes(childNodes);
LabelLayoutData labelLayoutData = this.convertLabel(node.getLabel(), id2LayoutData);
layoutData.setLabel(labelLayoutData);
layoutData.setResizedByUser(node.getCustomizedProperties().contains(CustomizableProperties.Size));
layoutData.setBorderNode(node.isBorderNode());
return layoutData;
}
use of org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData in project sirius-components by eclipse-sirius.
the class IncrementalLayoutedDiagramProvider method getLayoutedLabel.
private Label getLayoutedLabel(Label label, Map<String, ILayoutData> id2LayoutData) {
Label layoutedLabel = label;
var optionalLabelLayoutData = Optional.of(id2LayoutData.get(label.getId())).filter(LabelLayoutData.class::isInstance).map(LabelLayoutData.class::cast);
if (optionalLabelLayoutData.isPresent()) {
LabelLayoutData labelLayoutData = optionalLabelLayoutData.get();
// @formatter:off
layoutedLabel = Label.newLabel(label).size(labelLayoutData.getTextBounds().getSize()).position(labelLayoutData.getPosition()).alignment(labelLayoutData.getTextBounds().getAlignment()).build();
// @formatter:on
}
return layoutedLabel;
}
use of org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData in project sirius-components by eclipse-sirius.
the class BorderNodeLabelPositionProvider method updateLabelPosition.
public void updateLabelPosition(Optional<IDiagramEvent> optionalDiagramElementEvent, RectangleSide side, NodeLayoutData borderNodeLayoutData) {
LabelLayoutData label = borderNodeLayoutData.getLabel();
if (label != null) {
// @formatter:off
boolean isBorderNodeMoved = optionalDiagramElementEvent.filter(MoveEvent.class::isInstance).map(MoveEvent.class::cast).map(MoveEvent::getNodeId).filter(borderNodeLayoutData.getId()::equals).isPresent();
boolean isBorderNodeResized = optionalDiagramElementEvent.filter(ResizeEvent.class::isInstance).map(ResizeEvent.class::cast).map(ResizeEvent::getNodeId).filter(borderNodeLayoutData.getId()::equals).isPresent();
if (borderNodeLayoutData.getLabel().getPosition().getX() == -1 || isBorderNodeMoved || isBorderNodeResized) {
if (RectangleSide.NORTH.equals(side)) {
label.setPosition(Position.at(-label.getTextBounds().getSize().getWidth(), -label.getTextBounds().getSize().getHeight()));
} else if (RectangleSide.EAST.equals(side)) {
label.setPosition(Position.at(borderNodeLayoutData.getSize().getWidth(), borderNodeLayoutData.getSize().getHeight()));
} else {
label.setPosition(Position.at(-label.getTextBounds().getSize().getWidth(), borderNodeLayoutData.getSize().getHeight()));
}
}
}
}
use of org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData in project sirius-components by eclipse-sirius.
the class NodeLabelPositionProviderTests method testNodeRectangleLabelBoundsPosition.
@Test
public void testNodeRectangleLabelBoundsPosition() {
DiagramLayoutData createDiagramLayoutData = this.createDiagramLayoutData();
NodeLayoutData nodeLayoutData = this.createNodeLayoutData(Position.at(0, 0), DEFAULT_NODE_SIZE, createDiagramLayoutData, NodeType.NODE_RECTANGLE);
NodeLabelPositionProvider labelBoundsProvider = new NodeLabelPositionProvider(new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator());
LabelLayoutData labelLayoutData = this.createLabelLayoutData();
Position position = labelBoundsProvider.getPosition(nodeLayoutData, labelLayoutData, new ArrayList<>());
assertThat(position).extracting(Position::getX).isEqualTo(Double.valueOf(DEFAULT_NODE_SIZE.getWidth() / 2));
assertThat(position).extracting(Position::getY).isEqualTo(Double.valueOf(5));
}
use of org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData in project sirius-components by eclipse-sirius.
the class NodeLabelPositionProviderTests method testNodeImageLabelBoundsPosition.
@Test
public void testNodeImageLabelBoundsPosition() {
DiagramLayoutData createDiagramLayoutData = this.createDiagramLayoutData();
NodeLayoutData nodeLayoutData = this.createNodeLayoutData(Position.at(0, 0), DEFAULT_NODE_SIZE, createDiagramLayoutData, NodeType.NODE_IMAGE);
NodeLabelPositionProvider labelBoundsProvider = new NodeLabelPositionProvider(new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator());
LabelLayoutData labelLayoutData = this.createLabelLayoutData();
Position position = labelBoundsProvider.getPosition(nodeLayoutData, labelLayoutData, new ArrayList<>());
assertThat(position).extracting(Position::getX).isEqualTo(Double.valueOf(DEFAULT_NODE_SIZE.getWidth() / 2));
assertThat(position).extracting(Position::getY).isEqualTo(Double.valueOf(-23.3984375));
}
Aggregations