Search in sources :

Example 1 with LabelStyle

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

the class DiagramElementExportService method exportLabel.

public StringBuilder exportLabel(Label label) {
    StringBuilder labelExport = new StringBuilder();
    Position position = label.getPosition();
    Position alignment = label.getAlignment();
    LabelStyle style = label.getStyle();
    // $NON-NLS-1$
    labelExport.append("<g ");
    // $NON-NLS-1$
    labelExport.append("transform=\"");
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    labelExport.append("translate(" + position.getX() + ", " + position.getY() + ") ");
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    labelExport.append("translate(" + alignment.getX() + ", " + alignment.getY() + ")\"");
    // $NON-NLS-1$
    labelExport.append(">");
    if (!(style.getIconURL().isEmpty())) {
        labelExport.append(this.exportImageElement(style.getIconURL(), -20, -12, Optional.empty()));
    }
    labelExport.append(this.exportTextElement(label.getText(), label.getType(), style));
    // $NON-NLS-1$
    return labelExport.append("</g>");
}
Also used : Position(org.eclipse.sirius.components.diagrams.Position) LabelStyle(org.eclipse.sirius.components.diagrams.LabelStyle)

Example 2 with LabelStyle

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

the class DiagramRendererNodeTests method testSimpleNodeRendering.

/**
 * Creates a diagram with a single node.
 */
@Test
public void testSimpleNodeRendering() {
    Function<VariableManager, INodeStyle> styleProvider = variableManager -> {
        // @formatter:off
        return RectangularNodeStyle.newRectangularNodeStyle().color(// $NON-NLS-1$
        "").borderColor(// $NON-NLS-1$
        "").borderSize(0).borderStyle(LineStyle.Solid).build();
    // @formatter:on
    };
    Diagram diagram = this.createDiagram(styleProvider, variableManager -> NODE_RECTANGULAR, VariableManager -> Size.UNDEFINED, Optional.empty());
    assertThat(diagram).isNotNull();
    assertThat(diagram.getId()).asString().isNotBlank();
    assertThat(diagram.getLabel()).isEqualTo(DIAGRAM_LABEL);
    assertThat(diagram.getTargetObjectId()).isNotBlank();
    assertThat(diagram.getNodes()).hasSize(1);
    assertThat(diagram.getNodes()).extracting(Node::getTargetObjectId).noneMatch(String::isBlank);
    assertThat(diagram.getNodes()).extracting(Node::getDescriptionId).noneMatch(t -> t.toString().isBlank());
    assertThat(diagram.getNodes()).extracting(Node::getType).noneMatch(String::isBlank);
    assertThat(diagram.getNodes()).extracting(Node::getType).allMatch(t -> NODE_RECTANGULAR.equals(t));
    assertThat(diagram.getNodes()).extracting(Node::getBorderNodes).allMatch(List::isEmpty);
    assertThat(diagram.getNodes()).extracting(Node::getStyle).allMatch(s -> s instanceof RectangularNodeStyle);
    assertThat(diagram.getNodes()).extracting(Node::getSize).allMatch(s -> s.getHeight() == -1 && s.getWidth() == -1);
    assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getId).allMatch(id -> UUID.nameUUIDFromBytes(LABEL_ID.getBytes()).toString().equals(id));
    assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getText).allMatch(text -> LABEL_TEXT.equals(text));
    assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::getColor).allMatch(color -> LABEL_COLOR.equals(color));
    assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::getFontSize).allMatch(size -> LABEL_FONT_SIZE == size);
    assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::isBold).allMatch(bold -> bold);
    assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::isItalic).allMatch(italic -> italic);
    assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::isUnderline).allMatch(underline -> underline);
    assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::isStrikeThrough).allMatch(strikeThrough -> strikeThrough);
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) Node(org.eclipse.sirius.components.diagrams.Node) Size(org.eclipse.sirius.components.diagrams.Size) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) Function(java.util.function.Function) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) ArrayList(java.util.ArrayList) RectangularNodeStyle(org.eclipse.sirius.components.diagrams.RectangularNodeStyle) Diagram(org.eclipse.sirius.components.diagrams.Diagram) LineStyle(org.eclipse.sirius.components.diagrams.LineStyle) Label(org.eclipse.sirius.components.diagrams.Label) LabelStyle(org.eclipse.sirius.components.diagrams.LabelStyle) Failure(org.eclipse.sirius.components.representations.Failure) ImageNodeStyle(org.eclipse.sirius.components.diagrams.ImageNodeStyle) Success(org.eclipse.sirius.components.representations.Success) Set(java.util.Set) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) UUID(java.util.UUID) CustomizableProperties(org.eclipse.sirius.components.diagrams.CustomizableProperties) Element(org.eclipse.sirius.components.representations.Element) Test(org.junit.jupiter.api.Test) List(java.util.List) DiagramComponentProps(org.eclipse.sirius.components.diagrams.components.DiagramComponentProps) Optional(java.util.Optional) DiagramComponent(org.eclipse.sirius.components.diagrams.components.DiagramComponent) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Node(org.eclipse.sirius.components.diagrams.Node) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) Label(org.eclipse.sirius.components.diagrams.Label) RectangularNodeStyle(org.eclipse.sirius.components.diagrams.RectangularNodeStyle) ArrayList(java.util.ArrayList) List(java.util.List) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Example 3 with LabelStyle

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

the class TestDiagramBuilder method getNode.

public Node getNode(String id) {
    // @formatter:off
    LabelStyle labelStyle = LabelStyle.newLabelStyle().color(// $NON-NLS-1$
    "#000000").fontSize(16).iconURL(// $NON-NLS-1$
    "").build();
    Label label = Label.newLabel(UUID.randomUUID().toString()).type(// $NON-NLS-1$
    "labelType").text(// $NON-NLS-1$
    "text").position(Position.UNDEFINED).size(Size.UNDEFINED).alignment(Position.UNDEFINED).style(labelStyle).build();
    return Node.newNode(id).type(NodeType.NODE_RECTANGLE).targetObjectId(// $NON-NLS-1$
    "nodeTargetObjectId").targetObjectKind(// $NON-NLS-1$
    "").targetObjectLabel(// $NON-NLS-1$
    "").descriptionId(UUID.randomUUID()).label(label).style(this.getRectangularNodeStyle()).position(Position.UNDEFINED).size(Size.UNDEFINED).borderNodes(List.of()).childNodes(List.of()).build();
// @formatter:on
}
Also used : Label(org.eclipse.sirius.components.diagrams.Label) LabelStyle(org.eclipse.sirius.components.diagrams.LabelStyle)

Example 4 with LabelStyle

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

the class LabelStyleIconURLDataFetcher method get.

@Override
public String get(DataFetchingEnvironment environment) throws Exception {
    LabelStyle style = environment.getSource();
    String result = style.getIconURL();
    if (result != null && !result.isBlank()) {
        result = URLConstants.IMAGE_BASE_PATH + result;
    }
    return result;
}
Also used : LabelStyle(org.eclipse.sirius.components.diagrams.LabelStyle)

Example 5 with LabelStyle

use of org.eclipse.sirius.components.diagrams.LabelStyle 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

LabelStyle (org.eclipse.sirius.components.diagrams.LabelStyle)7 Label (org.eclipse.sirius.components.diagrams.Label)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 UUID (java.util.UUID)2 Function (java.util.function.Function)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 CustomizableProperties (org.eclipse.sirius.components.diagrams.CustomizableProperties)2 Diagram (org.eclipse.sirius.components.diagrams.Diagram)2 INodeStyle (org.eclipse.sirius.components.diagrams.INodeStyle)2 ImageNodeStyle (org.eclipse.sirius.components.diagrams.ImageNodeStyle)2 LineStyle (org.eclipse.sirius.components.diagrams.LineStyle)2 Node (org.eclipse.sirius.components.diagrams.Node)2 RectangularNodeStyle (org.eclipse.sirius.components.diagrams.RectangularNodeStyle)2 Size (org.eclipse.sirius.components.diagrams.Size)2 TextBounds (org.eclipse.sirius.components.diagrams.TextBounds)2 TextBoundsProvider (org.eclipse.sirius.components.diagrams.TextBoundsProvider)2 DiagramComponent (org.eclipse.sirius.components.diagrams.components.DiagramComponent)2