Search in sources :

Example 1 with LabelLayoutData

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;
}
Also used : LabelLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData) Node(org.eclipse.sirius.components.diagrams.Node) ArrayList(java.util.ArrayList) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)

Example 2 with LabelLayoutData

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;
}
Also used : LabelLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData) Label(org.eclipse.sirius.components.diagrams.Label)

Example 3 with LabelLayoutData

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()));
            }
        }
    }
}
Also used : LabelLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData) MoveEvent(org.eclipse.sirius.components.diagrams.events.MoveEvent) ResizeEvent(org.eclipse.sirius.components.diagrams.events.ResizeEvent)

Example 4 with LabelLayoutData

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));
}
Also used : DiagramLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData) Position(org.eclipse.sirius.components.diagrams.Position) LabelLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData) NodeLabelPositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeLabelPositionProvider) LayoutConfiguratorRegistry(org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData) Test(org.junit.jupiter.api.Test)

Example 5 with LabelLayoutData

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));
}
Also used : DiagramLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData) Position(org.eclipse.sirius.components.diagrams.Position) LabelLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData) NodeLabelPositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeLabelPositionProvider) LayoutConfiguratorRegistry(org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData) Test(org.junit.jupiter.api.Test)

Aggregations

LabelLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData)13 NodeLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)7 Position (org.eclipse.sirius.components.diagrams.Position)3 TextBounds (org.eclipse.sirius.components.diagrams.TextBounds)3 TextBoundsProvider (org.eclipse.sirius.components.diagrams.TextBoundsProvider)3 LayoutConfiguratorRegistry (org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry)3 DiagramLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData)3 Test (org.junit.jupiter.api.Test)3 LabelStyle (org.eclipse.sirius.components.diagrams.LabelStyle)2 NodeLabelPositionProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeLabelPositionProvider)2 ArrayList (java.util.ArrayList)1 Label (org.eclipse.sirius.components.diagrams.Label)1 Node (org.eclipse.sirius.components.diagrams.Node)1 Size (org.eclipse.sirius.components.diagrams.Size)1 IDiagramEvent (org.eclipse.sirius.components.diagrams.events.IDiagramEvent)1 MoveEvent (org.eclipse.sirius.components.diagrams.events.MoveEvent)1 ResizeEvent (org.eclipse.sirius.components.diagrams.events.ResizeEvent)1 SinglePositionEvent (org.eclipse.sirius.components.diagrams.events.SinglePositionEvent)1 ImageSizeProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider)1 NodeSizeProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeSizeProvider)1