Search in sources :

Example 1 with BorderNodesOnSide

use of org.eclipse.sirius.components.diagrams.layout.incremental.BorderNodesOnSide in project sirius-components by eclipse-sirius.

the class NodeLabelPositionProvider method getHorizontalPosition.

private double getHorizontalPosition(NodeLayoutData node, LabelLayoutData label, List<BorderNodesOnSide> borderNodesOnSides) {
    double x = 0d;
    EnumSet<NodeLabelPlacement> nodeLabelPlacementSet = this.layoutConfigurator.configureByType(node.getNodeType()).getProperty(CoreOptions.NODE_LABELS_PLACEMENT);
    ElkPadding nodeLabelsPadding = this.layoutConfigurator.configureByType(node.getNodeType()).getProperty(CoreOptions.NODE_LABELS_PADDING);
    boolean outside = this.isOutside(nodeLabelPlacementSet);
    double leftPadding = 0d;
    double rightPadding = 0d;
    if (nodeLabelsPadding == null) {
        nodeLabelsPadding = CoreOptions.NODE_LABELS_PADDING.getDefault();
    }
    leftPadding = nodeLabelsPadding.getLeft();
    rightPadding = nodeLabelsPadding.getRight();
    for (NodeLabelPlacement nodeLabelPlacement : nodeLabelPlacementSet) {
        switch(nodeLabelPlacement) {
            case H_LEFT:
                if (outside) {
                    x = -(label.getTextBounds().getSize().getWidth() + leftPadding);
                } else {
                    x = leftPadding;
                }
                break;
            case H_CENTER:
                // The label is positioned at the center of the node and the front-end will apply a "'text-anchor':
                // 'middle'" property.
                int shiftToEast = 0;
                int shiftToWest = 0;
                for (BorderNodesOnSide borderNodesOnSide : borderNodesOnSides) {
                    if (RectangleSide.WEST.equals(borderNodesOnSide.getSide())) {
                        shiftToEast = 1;
                    } else if (RectangleSide.EAST.equals(borderNodesOnSide.getSide())) {
                        shiftToWest = 1;
                    }
                }
                double portOffset = Optional.ofNullable(this.layoutConfigurator.configureByType(node.getNodeType()).getProperty(CoreOptions.PORT_BORDER_OFFSET)).orElse(0.);
                double offSetAccordingToBorderNodes = -portOffset / 2 * (shiftToEast - shiftToWest);
                x = node.getSize().getWidth() / 2 + offSetAccordingToBorderNodes;
                break;
            case H_RIGHT:
                if (outside) {
                    x = node.getSize().getWidth() + rightPadding;
                } else {
                    x = node.getSize().getWidth() - label.getTextBounds().getSize().getWidth() - rightPadding;
                }
                break;
            default:
                break;
        }
    }
    return x;
}
Also used : BorderNodesOnSide(org.eclipse.sirius.components.diagrams.layout.incremental.BorderNodesOnSide) NodeLabelPlacement(org.eclipse.elk.core.options.NodeLabelPlacement) ElkPadding(org.eclipse.elk.core.math.ElkPadding)

Aggregations

ElkPadding (org.eclipse.elk.core.math.ElkPadding)1 NodeLabelPlacement (org.eclipse.elk.core.options.NodeLabelPlacement)1 BorderNodesOnSide (org.eclipse.sirius.components.diagrams.layout.incremental.BorderNodesOnSide)1