use of org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell in project elk by eclipse.
the class EndLabelPreprocessor method createConfiguredLabelCell.
/**
* Creates label cell for the given port with the given labels, if any. If there are no labels, this method returns
* {@code null}. The label cell will still have to have its alignment set up, but its size is already set to the
* size required to place its labels.
*/
private LabelCell createConfiguredLabelCell(final List<LLabel> labels, final double labelLabelSpacing, final boolean verticalLayout) {
if (labels == null || labels.isEmpty()) {
return null;
}
// Create the new label cell and setup its alignments depending on the port's side
LabelCell labelCell = new LabelCell(labelLabelSpacing, !verticalLayout);
for (LLabel label : labels) {
labelCell.addLabel(LGraphAdapters.adapt(label));
}
// Setup the label cell's size
ElkRectangle labelCellRect = labelCell.getCellRectangle();
labelCellRect.height = labelCell.getMinimumHeight();
labelCellRect.width = labelCell.getMinimumWidth();
return labelCell;
}
use of org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell in project elk by eclipse.
the class EndLabelPreprocessor method processNode.
private void processNode(final LNode node, final double edgeLabelSpacing, final double labelLabelSpacing, final boolean verticalLayout) {
// Iterate over all ports and collect their labels in label cells
int portCount = node.getPorts().size();
LabelCell[] portLabelCells = new LabelCell[portCount];
for (int portIndex = 0; portIndex < portCount; portIndex++) {
LPort port = node.getPorts().get(portIndex);
port.id = portIndex;
portLabelCells[portIndex] = createConfiguredLabelCell(gatherLabels(port), labelLabelSpacing, verticalLayout);
}
// Actually go off and place them labels!
placeLabels(node, portLabelCells, labelLabelSpacing, edgeLabelSpacing, verticalLayout);
// Turn the array into a map and save that in the node
Map<LPort, LabelCell> portToLabelCellMap = new HashMap<>();
for (int index = 0; index < portLabelCells.length; index++) {
if (portLabelCells[index] != null) {
portToLabelCellMap.put(node.getPorts().get(index), portLabelCells[index]);
}
}
if (!portToLabelCellMap.isEmpty()) {
node.setProperty(InternalProperties.END_LABELS, portToLabelCellMap);
// Update the node's margins
updateNodeMargins(node, portLabelCells);
}
}
use of org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell in project elk by eclipse.
the class EndLabelPostprocessor method processNode.
private void processNode(final LNode node) {
assert node.hasProperty(InternalProperties.END_LABELS);
// The node should have a non-empty list of label cells, or something went TERRIBLY WRONG!!!
Map<LPort, LabelCell> endLabelCells = node.getProperty(InternalProperties.END_LABELS);
assert !endLabelCells.isEmpty();
KVector nodePos = node.getPosition();
for (LabelCell labelCell : endLabelCells.values()) {
ElkRectangle labelCellRect = labelCell.getCellRectangle();
labelCellRect.move(nodePos);
labelCell.applyLabelLayout();
}
// Remove label cells
node.setProperty(InternalProperties.END_LABELS, null);
}
use of org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell in project elk by eclipse.
the class EndLabelSorter method processNode.
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Node Processing and Initialization
private void processNode(final LNode node) {
boolean initializeMethodCalled = false;
if (node.hasProperty(InternalProperties.END_LABELS)) {
Map<LPort, LabelCell> labelCellMap = node.getProperty(InternalProperties.END_LABELS);
// Iterate over all ports and check for each port if it requires its labels to be sorted
for (LPort port : node.getPorts()) {
if (needsSorting(port)) {
// Check if we need to initialize
if (!initializeMethodCalled) {
initialize(node.getGraph());
initializeMethodCalled = true;
}
sort(port, labelCellMap.get(port));
}
}
}
}
use of org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell in project elk by eclipse.
the class NodeLabelCellCreator method retrieveNodeLabelCell.
/**
* Retrieves the node label cell for the given location. If it doesn't exist yet, it is created.
*/
private static LabelCell retrieveNodeLabelCell(final NodeContext nodeContext, final NodeLabelLocation nodeLabelLocation, final boolean horizontalLayoutMode) {
LabelCell nodeLabelCell = nodeContext.nodeLabelCells.get(nodeLabelLocation);
if (nodeLabelCell == null) {
// The node label cell doesn't exist yet, so create one and add it to the relevant container
nodeLabelCell = new LabelCell(nodeContext.labelLabelSpacing, nodeLabelLocation, horizontalLayoutMode);
nodeContext.nodeLabelCells.put(nodeLabelLocation, nodeLabelCell);
// Find the correct container and add the cell to it
if (nodeLabelLocation.isInsideLocation()) {
nodeContext.insideNodeLabelContainer.setCell(nodeLabelLocation.getContainerRow(), nodeLabelLocation.getContainerColumn(), nodeLabelCell);
} else {
PortSide outsideSide = nodeLabelLocation.getOutsideSide();
StripContainerCell containerCell = nodeContext.outsideNodeLabelContainers.get(outsideSide);
switch(outsideSide) {
case NORTH:
case SOUTH:
nodeLabelCell.setContributesToMinimumHeight(true);
containerCell.setCell(nodeLabelLocation.getContainerColumn(), nodeLabelCell);
break;
case WEST:
case EAST:
nodeLabelCell.setContributesToMinimumWidth(true);
containerCell.setCell(nodeLabelLocation.getContainerRow(), nodeLabelCell);
break;
}
}
}
return nodeLabelCell;
}
Aggregations