use of org.eclipse.elk.graph.ElkLabel in project sirius-components by eclipse-sirius.
the class ELKDiagramConverter method convertLabel.
private void convertLabel(Label label, TextBounds textBounds, ElkGraphElement elkGraphElement, Map<String, ElkGraphElement> id2ElkGraphElements, EdgeLabelPlacement placement) {
ElkLabel elkLabel = ElkGraphFactory.eINSTANCE.createElkLabel();
elkLabel.setIdentifier(label.getId());
elkLabel.setProperty(PROPERTY_TYPE, label.getType());
elkLabel.setDimensions(textBounds.getSize().getWidth(), textBounds.getSize().getHeight());
if (label.getText().isEmpty() && !label.getStyle().getIconURL().isEmpty()) {
// $NON-NLS-1$
elkLabel.setText(" ");
} else {
elkLabel.setText(label.getText());
}
elkLabel.setParent(elkGraphElement);
if (placement != null) {
elkLabel.setProperty(CoreOptions.EDGE_LABELS_PLACEMENT, placement);
}
elkLabel.eAdapters().add(new AlignmentHolder(textBounds.getAlignment()));
id2ElkGraphElements.put(label.getId(), elkLabel);
}
use of org.eclipse.elk.graph.ElkLabel in project osate2 by osate.
the class DiagramElementLayoutUtil method setLabelPositionsForEdge.
/**
* @param mapping
* @param m
* @param edge
* @param edgeMidpoint must be relative to the edge's container
*/
private static void setLabelPositionsForEdge(final LayoutMapping mapping, DiagramModification m, final ElkEdge edge, final Point edgeMidpoint) {
// Handle labels
for (final ElkLabel edgeLabel : edge.getLabels()) {
final Object labelValue = mapping.getGraphMap().get(edgeLabel);
if (labelValue instanceof ConnectionLabelReference) {
final ConnectionLabelReference labelRef = (ConnectionLabelReference) labelValue;
if (Boolean.TRUE.equals(edgeLabel.getProperty(CoreOptions.NO_LAYOUT))) {
labelRef.setPosition(m, null);
} else {
final double lx = edgeLabel.getX() - edgeMidpoint.x;
final double ly = edgeLabel.getY() - edgeMidpoint.y;
labelRef.setPosition(m, new Point(lx, ly));
}
}
}
}
use of org.eclipse.elk.graph.ElkLabel in project osate2 by osate.
the class ElkGraphBuilder method createElkLabel.
private static ElkLabel createElkLabel(final ElkGraphElement parentLayoutElement, final String txt, final Dimension labelSize) {
final ElkLabel newLabel = ElkGraphUtil.createLabel(parentLayoutElement);
newLabel.setText(txt);
if (labelSize != null) {
newLabel.setWidth(labelSize.width);
newLabel.setHeight(labelSize.height);
}
return newLabel;
}
use of org.eclipse.elk.graph.ElkLabel in project osate2 by osate.
the class ElkGraphBuilder method createElkLabels.
private void createElkLabels(final DiagramElement parentElement, final ElkGraphElement parentLayoutElement, final LayoutMapping mapping) {
// Don't create labels for ElkPort. The bounds of the port contain their labels.
if (parentLayoutElement instanceof ElkPort) {
return;
}
final boolean isConnection = parentElement.getGraphic() instanceof AgeConnection;
final Style style = styleProvider.getStyle(parentElement);
if (style.getPrimaryLabelVisible()) {
// Create Primary Label
if (parentElement.getLabelName() != null) {
final ElkLabel elkLabel = createElkLabel(parentLayoutElement, parentElement.getLabelName(), layoutInfoProvider.getPrimaryLabelSize(parentElement));
if (isConnection) {
if (!layoutConnectionLabels) {
elkLabel.setProperty(CoreOptions.NO_LAYOUT, true);
}
mapping.getGraphMap().put(elkLabel, new PrimaryConnectionLabelReference(parentElement));
}
}
}
// Create label for annotations which are part of the graphic configuration. These are only supported by non-connections.
if (!isConnection && parentElement.getGraphicalConfiguration().getAnnotation() != null) {
createElkLabel(parentLayoutElement, parentElement.getGraphicalConfiguration().getAnnotation(), layoutInfoProvider.getAnnotationLabelSize(parentElement));
}
// Create Secondary Labels
parentElement.getChildren().stream().filter(c -> c.getGraphic() instanceof Label).forEachOrdered(labelElement -> {
final ElkLabel elkLabel = createElkLabel(parentLayoutElement, labelElement.getLabelName(), layoutInfoProvider.getPrimaryLabelSize(labelElement));
if (isConnection) {
if (!layoutConnectionLabels) {
elkLabel.setProperty(CoreOptions.NO_LAYOUT, true);
}
mapping.getGraphMap().put(elkLabel, new SecondaryConnectionLabelReference(labelElement));
}
});
if (parentLayoutElement instanceof ElkNode) {
parentLayoutElement.setProperty(CoreOptions.NODE_LABELS_PLACEMENT, getNodeLabelPlacement(style));
}
}
use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.
the class GraphRenderer method renderNodeChildren.
/**
* Paints all children of the given parent node that fall into the given dirty area.
*
* @param parent the node whose children to paint
* @param graphics the graphics context used to paint
* @param area dirty area that needs painting
* @param offset offset to be added to relative coordinates
* @param nodeAlpha alpha value for nodes
*/
private void renderNodeChildren(final ElkNode parent, final GC graphics, final Rectangle area, final KVector offset, final int nodeAlpha) {
for (ElkNode childNode : parent.getChildren()) {
PaintRectangle rect = boundsMap.get(childNode);
if (rect == null) {
rect = new PaintRectangle(childNode, offset, scale);
boundsMap.put(childNode, rect);
}
KVector childOffset = new KVector(rect.x, rect.y);
// render the child node and its content
if (!rect.painted && rect.intersects(area)) {
// paint this node
graphics.setAlpha(nodeAlpha);
if (configurator.getNodeFillColor() != null) {
graphics.setBackground(configurator.getNodeFillColor());
graphics.fillRectangle(rect.x, rect.y, rect.width, rect.height);
}
if (configurator.getNodeBorderColor() != null) {
graphics.setForeground(configurator.getNodeBorderColor());
graphics.drawRectangle(rect.x, rect.y, rect.width, rect.height);
}
rect.painted = true;
renderNodeChildren(childNode, graphics, area, childOffset, nodeAlpha);
}
// render node labels
if (configurator.getNodeLabelFont() != null) {
graphics.setFont(configurator.getNodeLabelFont());
for (ElkLabel label : childNode.getLabels()) {
renderLabel(label, graphics, area, childOffset, nodeAlpha);
}
}
// render ports
for (ElkPort port : childNode.getPorts()) {
renderPort(port, graphics, area, childOffset, nodeAlpha);
}
}
// Paint the edges contained in this node
for (ElkEdge childEdge : parent.getContainedEdges()) {
renderEdge(childEdge, graphics, area, offset, nodeAlpha);
}
}
Aggregations