Search in sources :

Example 1 with TextBounds

use of org.eclipse.sirius.components.diagrams.TextBounds in project sirius-components by eclipse-sirius.

the class BorderNodePositionTests method createNodeLayoutData.

private NodeLayoutData createNodeLayoutData(Position position, Size size, IContainerLayoutData parent, String nodeType) {
    NodeLayoutData nodeLayoutData = new NodeLayoutData();
    nodeLayoutData.setId(UUID.randomUUID().toString());
    nodeLayoutData.setParent(parent);
    nodeLayoutData.setPosition(position);
    nodeLayoutData.setSize(size);
    nodeLayoutData.setNodeType(nodeType);
    nodeLayoutData.setChildrenNodes(new ArrayList<>());
    // $NON-NLS-1$
    nodeLayoutData.setLabel(this.createLabelLayoutData(Position.at(0, 0), "inside", new TextBounds(Size.of(0, 0), Position.at(0, 0))));
    return nodeLayoutData;
}
Also used : TextBounds(org.eclipse.sirius.components.diagrams.TextBounds) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)

Example 2 with TextBounds

use of org.eclipse.sirius.components.diagrams.TextBounds in project sirius-components by eclipse-sirius.

the class ELKDiagramConverter method getNodeListItemHeight.

private double getNodeListItemHeight(Node nodeListItem) {
    TextBounds nodeListItemTextBounds = this.textBoundsService.getBounds(nodeListItem.getLabel());
    double nodeListItemHeight = nodeListItemTextBounds.getSize().getHeight() + LayoutOptionValues.NODE_LIST_ELK_NODE_LABELS_PADDING_TOP + LayoutOptionValues.NODE_LIST_ELK_NODE_LABELS_PADDING_BOTTOM;
    return nodeListItemHeight;
}
Also used : TextBounds(org.eclipse.sirius.components.diagrams.TextBounds)

Example 3 with TextBounds

use of org.eclipse.sirius.components.diagrams.TextBounds in project sirius-components by eclipse-sirius.

the class ELKDiagramConverter method getNodeListWidth.

/**
 * Returns the size of the given {@link NodeType#NODE_LIST}, which is the max value between the highest children
 * item width, the node label width and {@link} LayoutOptionValues#MIN_WIDTH_CONSTRAINT}.
 *
 * @param nodeList
 *            The node list we want the width
 * @return the size of the given {@link NodeType#NODE_LIST}
 */
private double getNodeListWidth(Node nodeList) {
    TextBounds nodeListLabelTextBounds = this.textBoundsService.getBounds(nodeList.getLabel());
    double largestNodeListItemWidth = this.getLargestNodeListItemWidth(nodeList.getChildNodes());
    // @formatter:off
    return Arrays.asList(largestNodeListItemWidth, nodeListLabelTextBounds.getSize().getWidth() + LayoutOptionValues.DEFAULT_ELK_NODE_LABELS_PADDING * 2, LayoutOptionValues.MIN_WIDTH_CONSTRAINT).stream().mapToDouble(Number::doubleValue).max().orElse(LayoutOptionValues.MIN_WIDTH_CONSTRAINT);
// @formatter:on
}
Also used : TextBounds(org.eclipse.sirius.components.diagrams.TextBounds)

Example 4 with TextBounds

use of org.eclipse.sirius.components.diagrams.TextBounds in project sirius-components by eclipse-sirius.

the class ELKDiagramConverter method convertBorderNode.

private void convertBorderNode(Node borderNode, ElkNode elkNode, Map<String, ElkConnectableShape> connectableShapeIndex, Map<String, ElkGraphElement> id2ElkGraphElements) {
    ElkPort elkPort = ElkGraphFactory.eINSTANCE.createElkPort();
    elkPort.setIdentifier(borderNode.getId());
    elkPort.setProperty(PROPERTY_TYPE, borderNode.getType());
    TextBounds textBounds = this.textBoundsService.getBounds(borderNode.getLabel());
    double width = borderNode.getSize().getWidth();
    double height = borderNode.getSize().getHeight();
    elkPort.setDimensions(width, height);
    elkPort.setParent(elkNode);
    connectableShapeIndex.put(elkPort.getIdentifier(), elkPort);
    if (borderNode.getStyle() instanceof ImageNodeStyle) {
        Size imageSize = this.imageNodeStyleSizeProvider.getSize((ImageNodeStyle) borderNode.getStyle());
        elkPort.setDimensions(imageSize.getWidth(), imageSize.getHeight());
    }
    this.convertLabel(borderNode.getLabel(), textBounds, elkPort, id2ElkGraphElements, null);
    id2ElkGraphElements.put(borderNode.getId(), elkPort);
}
Also used : ElkPort(org.eclipse.elk.graph.ElkPort) ImageNodeStyle(org.eclipse.sirius.components.diagrams.ImageNodeStyle) Size(org.eclipse.sirius.components.diagrams.Size) TextBounds(org.eclipse.sirius.components.diagrams.TextBounds)

Example 5 with TextBounds

use of org.eclipse.sirius.components.diagrams.TextBounds in project sirius-components by eclipse-sirius.

the class EdgeLabelPositionProviderTests method createLabelLayoutData.

private LabelLayoutData createLabelLayoutData() {
    LabelLayoutData labelLayoutData = new LabelLayoutData();
    labelLayoutData.setId(UUID.randomUUID().toString());
    labelLayoutData.setPosition(Position.UNDEFINED);
    // @formatter:off
    LabelStyle labelStyle = LabelStyle.newLabelStyle().color(LABEL_COLOR).fontSize(FONT_SIZE).iconURL(ICON_URL).build();
    // @formatter:on
    // $NON-NLS-1$
    TextBounds textBounds = new TextBoundsProvider().computeBounds(labelStyle, "labelText");
    labelLayoutData.setTextBounds(textBounds);
    return labelLayoutData;
}
Also used : LabelLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData) TextBounds(org.eclipse.sirius.components.diagrams.TextBounds) LabelStyle(org.eclipse.sirius.components.diagrams.LabelStyle) TextBoundsProvider(org.eclipse.sirius.components.diagrams.TextBoundsProvider)

Aggregations

TextBounds (org.eclipse.sirius.components.diagrams.TextBounds)8 TextBoundsProvider (org.eclipse.sirius.components.diagrams.TextBoundsProvider)3 LabelLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData)3 ImageNodeStyle (org.eclipse.sirius.components.diagrams.ImageNodeStyle)2 LabelStyle (org.eclipse.sirius.components.diagrams.LabelStyle)2 Size (org.eclipse.sirius.components.diagrams.Size)2 ElkNode (org.eclipse.elk.graph.ElkNode)1 ElkPort (org.eclipse.elk.graph.ElkPort)1 NodeLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)1