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>");
}
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);
}
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
}
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;
}
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;
}
Aggregations