use of de.cau.cs.kieler.klighd.kgraph.KLabel in project lingua-franca by lf-lang.
the class ModeDiagrams method addTransitionFigure.
private void addTransitionFigure(KEdge edge, Transition transition) {
var spline = _kEdgeExtensions.addSpline(edge);
_kRenderingExtensions.setLineWidth(spline, 1.5f);
_kRenderingExtensions.setForeground(spline, MODE_FG);
_kRenderingExtensions.setBackground(spline, MODE_FG);
_linguaFrancaStyleExtensions.boldLineSelectionStyle(spline);
if (transition.type == ModeTransitionType.HISTORY) {
addHistoryDecorator(spline);
} else {
KRendering arrowDecorator = _kPolylineExtensions.addHeadArrowDecorator(spline);
this._kRenderingExtensions.setForeground(arrowDecorator, MODE_FG);
this._kRenderingExtensions.setBackground(arrowDecorator, MODE_FG);
}
if (getBooleanValue(SHOW_TRANSITION_LABELS)) {
associateWith(spline, transition.getDefinition());
KLabel centerEdgeLabel = _kLabelExtensions.addCenterEdgeLabel(edge, this.toTransitionLabel(transition));
associateWith(centerEdgeLabel, transition.getDefinition());
applyTransitionOnEdgeStyle(centerEdgeLabel);
}
}
use of de.cau.cs.kieler.klighd.kgraph.KLabel in project lingua-franca by lf-lang.
the class LinguaFrancaSynthesis method transformReactorNetwork.
private Collection<KNode> transformReactorNetwork(ReactorInstance reactorInstance, Map<PortInstance, KPort> parentInputPorts, Map<PortInstance, KPort> parentOutputPorts, Map<ReactorInstance, KNode> allReactorNodes) {
List<KNode> nodes = new ArrayList<>();
Table<ReactorInstance, PortInstance, KPort> inputPorts = HashBasedTable.create();
Table<ReactorInstance, PortInstance, KPort> outputPorts = HashBasedTable.create();
Map<ReactionInstance, KNode> reactionNodes = new HashMap<>();
Map<KPort, KNode> directConnectionDummyNodes = new HashMap<>();
Multimap<ActionInstance, KPort> actionDestinations = HashMultimap.create();
Multimap<ActionInstance, KPort> actionSources = HashMultimap.create();
Map<TimerInstance, KNode> timerNodes = new HashMap<>();
KNode startupNode = _kNodeExtensions.createNode();
boolean startupUsed = false;
KNode shutdownNode = _kNodeExtensions.createNode();
boolean shutdownUsed = false;
// Transform instances
int index = 0;
for (ReactorInstance child : ListExtensions.reverseView(reactorInstance.children)) {
Boolean expansionState = MemorizingExpandCollapseAction.getExpansionState(child);
Collection<KNode> rNodes = createReactorNode(child, expansionState != null ? expansionState : false, inputPorts, outputPorts, allReactorNodes);
setLayoutOption(IterableExtensions.<KNode>head(rNodes), CoreOptions.PRIORITY, index);
nodes.addAll(rNodes);
index++;
}
// Create timers
for (TimerInstance timer : reactorInstance.timers) {
KNode node = associateWith(_kNodeExtensions.createNode(), timer.getDefinition());
NamedInstanceUtil.linkInstance(node, timer);
_utilityExtensions.setID(node, timer.uniqueID());
nodes.add(node);
Iterables.addAll(nodes, createUserComments(timer.getDefinition(), node));
timerNodes.put(timer, node);
_linguaFrancaShapeExtensions.addTimerFigure(node, timer);
}
// Create reactions
for (ReactionInstance reaction : ListExtensions.reverseView(reactorInstance.reactions)) {
int idx = reactorInstance.reactions.indexOf(reaction);
KNode node = associateWith(_kNodeExtensions.createNode(), reaction.getDefinition());
NamedInstanceUtil.linkInstance(node, reaction);
_utilityExtensions.setID(node, reaction.uniqueID());
nodes.add(node);
Iterables.addAll(nodes, createUserComments(reaction.getDefinition(), node));
reactionNodes.put(reaction, node);
setLayoutOption(node, CoreOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_SIDE);
// always place with higher priority than reactor nodes
setLayoutOption(node, CoreOptions.PRIORITY, (reactorInstance.reactions.size() - idx) * 10);
// try order reactions vertically if in one layer
setLayoutOption(node, LayeredOptions.POSITION, new KVector(0, idx));
_linguaFrancaShapeExtensions.addReactionFigure(node, reaction);
// connect input
KPort port = null;
for (TriggerInstance<?> trigger : reaction.triggers) {
port = addInvisiblePort(node);
setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.WEST);
int triggersSize = reaction.triggers != null ? reaction.triggers.size() : 0;
int sourcesSize = reaction.sources != null ? reaction.sources.size() : 0;
if (getBooleanValue(REACTIONS_USE_HYPEREDGES) || triggersSize + sourcesSize == 1) {
// manual adjustment disabling automatic one
setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, (double) -LinguaFrancaShapeExtensions.REACTION_POINTINESS);
}
if (trigger.isStartup()) {
connect(createDependencyEdge(((TriggerInstance.BuiltinTriggerVariable) trigger.getDefinition()).definition), startupNode, port);
startupUsed = true;
} else if (trigger.isShutdown()) {
connect(createDelayEdge(((TriggerInstance.BuiltinTriggerVariable) trigger.getDefinition()).definition), shutdownNode, port);
shutdownUsed = true;
} else if (trigger instanceof ActionInstance) {
actionDestinations.put(((ActionInstance) trigger), port);
} else if (trigger instanceof PortInstance) {
KPort src = null;
PortInstance triggerAsPort = (PortInstance) trigger;
if (triggerAsPort.getParent() == reactorInstance) {
src = parentInputPorts.get(trigger);
} else {
src = outputPorts.get(triggerAsPort.getParent(), trigger);
}
if (src != null) {
connect(createDependencyEdge(triggerAsPort.getDefinition()), src, port);
}
} else if (trigger instanceof TimerInstance) {
KNode src = timerNodes.get(trigger);
if (src != null) {
connect(createDependencyEdge(trigger.getDefinition()), src, port);
}
}
}
// port = null // create new ports
for (TriggerInstance<?> dep : reaction.sources) {
if (reaction.triggers.contains(dep))
continue;
if (!(getBooleanValue(REACTIONS_USE_HYPEREDGES) && port != null)) {
port = addInvisiblePort(node);
setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.WEST);
int triggersSize = reaction.triggers != null ? reaction.triggers.size() : 0;
int sourcesSize = reaction.sources != null ? reaction.sources.size() : 0;
if (getBooleanValue(REACTIONS_USE_HYPEREDGES) || triggersSize + sourcesSize == 1) {
// manual adjustment disabling automatic one
setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, (double) -LinguaFrancaShapeExtensions.REACTION_POINTINESS);
}
}
if (dep instanceof PortInstance) {
KPort src = null;
PortInstance depAsPort = (PortInstance) dep;
if (dep.getParent() == reactorInstance) {
src = parentInputPorts.get(dep);
} else {
src = outputPorts.get(depAsPort.getParent(), dep);
}
if (src != null) {
connect(createDependencyEdge(dep.getDefinition()), src, port);
}
}
}
// connect outputs
// create new ports
port = null;
Set<TriggerInstance<?>> iterSet = reaction.effects != null ? reaction.effects : new HashSet<>();
for (TriggerInstance<?> effect : iterSet) {
port = addInvisiblePort(node);
setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.EAST);
if (effect instanceof ActionInstance) {
actionSources.put((ActionInstance) effect, port);
} else if (effect instanceof PortInstance) {
KPort dst = null;
PortInstance effectAsPort = (PortInstance) effect;
if (effectAsPort.isOutput()) {
dst = parentOutputPorts.get(effect);
} else {
dst = inputPorts.get(effectAsPort.getParent(), effect);
}
if (dst != null) {
connect(createDependencyEdge(effect), port, dst);
}
}
}
}
// Connect actions
Set<ActionInstance> actions = new HashSet<>();
actions.addAll(actionSources.keySet());
actions.addAll(actionDestinations.keySet());
for (ActionInstance action : actions) {
KNode node = associateWith(_kNodeExtensions.createNode(), action.getDefinition());
NamedInstanceUtil.linkInstance(node, action);
_utilityExtensions.setID(node, action.uniqueID());
nodes.add(node);
Iterables.addAll(nodes, createUserComments(action.getDefinition(), node));
setLayoutOption(node, CoreOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_SIDE);
Pair<KPort, KPort> ports = _linguaFrancaShapeExtensions.addActionFigureAndPorts(node, action.isPhysical() ? "P" : "L");
// TODO handle variables?
if (action.getMinDelay() != null && action.getMinDelay() != ActionInstance.DEFAULT_MIN_DELAY) {
_kLabelExtensions.addOutsideBottomCenteredNodeLabel(node, String.format("min delay: %s", action.getMinDelay().toString()), 7);
}
// TODO default value?
if (action.getDefinition().getMinSpacing() != null) {
_kLabelExtensions.addOutsideBottomCenteredNodeLabel(node, String.format("min spacing: %s", action.getMinSpacing().toString()), 7);
}
if (!StringExtensions.isNullOrEmpty(action.getDefinition().getPolicy())) {
_kLabelExtensions.addOutsideBottomCenteredNodeLabel(node, String.format("policy: %s", action.getPolicy().toString()), 7);
}
// connect source
for (KPort source : actionSources.get(action)) {
connect(createDelayEdge(action), source, ports.getKey());
}
// connect targets
for (KPort target : actionDestinations.get(action)) {
connect(createDelayEdge(action), ports.getValue(), target);
}
}
// Transform connections.
// First, collect all the source ports.
List<PortInstance> sourcePorts = new LinkedList<>(reactorInstance.inputs);
for (ReactorInstance child : reactorInstance.children) {
sourcePorts.addAll(child.outputs);
}
for (PortInstance leftPort : sourcePorts) {
KPort source = leftPort.getParent() == reactorInstance ? parentInputPorts.get(leftPort) : outputPorts.get(leftPort.getParent(), leftPort);
for (SendRange sendRange : leftPort.getDependentPorts()) {
for (RuntimeRange<PortInstance> rightRange : sendRange.destinations) {
PortInstance rightPort = rightRange.instance;
KPort target = rightPort.getParent() == reactorInstance ? parentOutputPorts.get(rightPort) : inputPorts.get(rightPort.getParent(), rightPort);
// There should be a connection, but skip if not.
Connection connection = sendRange.connection;
if (connection != null) {
KEdge edge = createIODependencyEdge(connection, (leftPort.isMultiport() || rightPort.isMultiport()));
if (connection.getDelay() != null) {
KLabel delayLabel = _kLabelExtensions.addCenterEdgeLabel(edge, ASTUtils.toText(connection.getDelay()));
associateWith(delayLabel, connection.getDelay());
if (connection.isPhysical()) {
_linguaFrancaStyleExtensions.applyOnEdgePysicalDelayStyle(delayLabel, reactorInstance.isMainOrFederated() ? Colors.WHITE : Colors.GRAY_95);
} else {
_linguaFrancaStyleExtensions.applyOnEdgeDelayStyle(delayLabel);
}
} else if (connection.isPhysical()) {
KLabel physicalConnectionLabel = _kLabelExtensions.addCenterEdgeLabel(edge, "---");
_linguaFrancaStyleExtensions.applyOnEdgePysicalStyle(physicalConnectionLabel, reactorInstance.isMainOrFederated() ? Colors.WHITE : Colors.GRAY_95);
}
if (source != null && target != null) {
// check for inside loop (direct in -> out connection with delay)
if (parentInputPorts.values().contains(source) && parentOutputPorts.values().contains(target)) {
// edge.setLayoutOption(CoreOptions.INSIDE_SELF_LOOPS_YO, true) // Does not work as expected
// Introduce dummy node to enable direct connection (that is also hidden when collapsed)
KNode dummy = _kNodeExtensions.createNode();
if (directConnectionDummyNodes.containsKey(target)) {
dummy = directConnectionDummyNodes.get(target);
} else {
nodes.add(dummy);
directConnectionDummyNodes.put(target, dummy);
_kRenderingExtensions.addInvisibleContainerRendering(dummy);
_kNodeExtensions.setNodeSize(dummy, 0, 0);
KEdge extraEdge = createIODependencyEdge(null, (leftPort.isMultiport() || rightPort.isMultiport()));
connect(extraEdge, dummy, target);
}
connect(edge, source, dummy);
} else {
connect(edge, source, target);
}
}
}
}
}
}
// Add startup/shutdown
if (startupUsed) {
_linguaFrancaShapeExtensions.addStartupFigure(startupNode);
nodes.add(0, startupNode);
setLayoutOption(startupNode, LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.FIRST);
if (getBooleanValue(REACTIONS_USE_HYPEREDGES)) {
KPort port = addInvisiblePort(startupNode);
startupNode.getOutgoingEdges().forEach(it -> {
it.setSourcePort(port);
});
}
}
if (shutdownUsed) {
_linguaFrancaShapeExtensions.addShutdownFigure(shutdownNode);
nodes.add(0, shutdownNode);
if (getBooleanValue(REACTIONS_USE_HYPEREDGES)) {
// connect all edges to one port
KPort port = addInvisiblePort(shutdownNode);
shutdownNode.getOutgoingEdges().forEach(it -> {
it.setSourcePort(port);
});
}
}
// Postprocess timer nodes
if (getBooleanValue(REACTIONS_USE_HYPEREDGES)) {
// connect all edges to one port
for (KNode timerNode : timerNodes.values()) {
KPort port = addInvisiblePort(timerNode);
timerNode.getOutgoingEdges().forEach(it -> {
it.setSourcePort(port);
});
}
}
// Add reaction order edges (add last to have them on top of other edges)
if (reactorInstance.reactions.size() > 1) {
KNode prevNode = reactionNodes.get(IterableExtensions.head(reactorInstance.reactions));
Iterable<KNode> iterList = IterableExtensions.map(IterableExtensions.drop(reactorInstance.reactions, 1), reactionNodes::get);
for (KNode node : iterList) {
KEdge edge = createOrderEdge();
edge.setSource(prevNode);
edge.setTarget(node);
edge.setProperty(CoreOptions.NO_LAYOUT, true);
// Do not remove them, as they are needed for cycle detection
KRendering edgeRendering = _kRenderingExtensions.getKRendering(edge);
_kRenderingExtensions.setInvisible(edgeRendering, !getBooleanValue(SHOW_REACTION_ORDER_EDGES));
_kRenderingExtensions.getInvisible(edgeRendering).setPropagateToChildren(true);
// TODO this does not work work with incremental update (https://github.com/kieler/KLighD/issues/37)
// if (!getBooleanValue(SHOW_REACTION_ORDER_EDGES)) edge.initiallyHide()
prevNode = node;
}
}
_modeDiagrams.handleModes(nodes, reactorInstance);
return nodes;
}
use of de.cau.cs.kieler.klighd.kgraph.KLabel in project lingua-franca by lf-lang.
the class LinguaFrancaStyleExtensions method applyOnEdgePysicalDelayStyle.
public void applyOnEdgePysicalDelayStyle(KLabel label, Colors parentBackgroundColor) {
if (_onEdgePysicalDelayLabelConfigurator == null) {
LabelDecorationConfigurator configurator = LabelDecorationConfigurator.create().withInlineLabels(true);
configurator = configurator.withLabelTextRenderingProvider((KContainerRendering container, KLabel klabel) -> {
KText kText = _kRenderingFactory.createKText();
_kRenderingExtensions.setFontSize(kText, 8);
boldTextSelectionStyle(kText);
kText.setProperty(KlighdInternalProperties.MODEL_ELEMEMT, klabel.getProperty(KlighdInternalProperties.MODEL_ELEMEMT));
container.getChildren().add(kText);
return kText;
});
configurator = configurator.addDecoratorRenderingProvider(new IDecoratorRenderingProvider() {
@Override
public ElkPadding createDecoratorRendering(KContainerRendering container, KLabel label, LabelDecorationConfigurator.LayoutMode layoutMode) {
ElkPadding padding = new ElkPadding();
padding.left = 8;
padding.right = 16;
padding.bottom = Math.max(padding.bottom, 1);
KPolygon polygon = _kRenderingFactory.createKPolygon();
_kRenderingExtensions.from(polygon, LEFT, 0, 0, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(polygon, LEFT, 0, 0, TOP, 1, 0.5f);
_kRenderingExtensions.to(polygon, RIGHT, 0, 0, TOP, 1, 0.5f);
_kRenderingExtensions.to(polygon, RIGHT, 0, 0, BOTTOM, 0, 0.5f);
_kRenderingExtensions.setBackground(polygon, label.getProperty(LABEL_PARENT_BACKGROUND));
_kRenderingExtensions.setForeground(polygon, label.getProperty(LABEL_PARENT_BACKGROUND));
container.getChildren().add(polygon);
KSpline kSpline = _kRenderingFactory.createKSpline();
_kRenderingExtensions.from(kSpline, LEFT, -0.66f, 0, BOTTOM, -0.5f, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 1, 0, BOTTOM, -0.5f, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 3, 0, BOTTOM, 8, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 5, 0, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 5.5f, 0, BOTTOM, -1.5f, 0.5f);
container.getChildren().add(kSpline);
kSpline = _kRenderingFactory.createKSpline();
_kRenderingExtensions.from(kSpline, RIGHT, 15f, 0, BOTTOM, 3.5f, 0.5f);
_kRenderingExtensions.to(kSpline, RIGHT, 14f, 0, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(kSpline, RIGHT, 11, 0, BOTTOM, -8, 0.5f);
_kRenderingExtensions.to(kSpline, RIGHT, 9, 0, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(kSpline, RIGHT, 7, 0, BOTTOM, 8, 0.5f);
_kRenderingExtensions.to(kSpline, RIGHT, 4f, 0, BOTTOM, 2, 0.5f);
_kRenderingExtensions.to(kSpline, RIGHT, 1.5f, 0, BOTTOM, 0.5f, 0.5f);
_kRenderingExtensions.to(kSpline, RIGHT, 0.2f, 0, BOTTOM, -0.5f, 0.5f);
_kRenderingExtensions.to(kSpline, RIGHT, -0.7f, 0, BOTTOM, -0.5f, 0.5f);
container.getChildren().add(kSpline);
polygon = _kRenderingFactory.createKPolygon();
_kRenderingExtensions.from(polygon, LEFT, 4, 0, BOTTOM, 0, 0);
_kRenderingExtensions.to(polygon, LEFT, 8, 0, TOP, 0, 0);
_kRenderingExtensions.to(polygon, RIGHT, 12, 0, TOP, 0, 0);
_kRenderingExtensions.to(polygon, RIGHT, 16, 0, BOTTOM, 0, 0);
_kRenderingExtensions.setBackground(polygon, Colors.WHITE);
_kRenderingExtensions.setForeground(polygon, Colors.WHITE);
container.getChildren().add(polygon);
KPolyline polyline = _kRenderingFactory.createKPolyline();
_kRenderingExtensions.from(polyline, LEFT, 4, 0, BOTTOM, 0, 0);
_kRenderingExtensions.to(polyline, LEFT, 8, 0, TOP, 0, 0);
container.getChildren().add(polyline);
polyline = _kRenderingFactory.createKPolyline();
_kRenderingExtensions.from(polyline, RIGHT, 16, 0, BOTTOM, 0, 0);
_kRenderingExtensions.to(polyline, RIGHT, 12, 0, TOP, 0, 0);
container.getChildren().add(polyline);
return padding;
}
});
_onEdgePysicalDelayLabelConfigurator = configurator;
}
label.setProperty(LABEL_PARENT_BACKGROUND, parentBackgroundColor);
_onEdgePysicalDelayLabelConfigurator.applyTo(label);
}
use of de.cau.cs.kieler.klighd.kgraph.KLabel in project lingua-franca by lf-lang.
the class LinguaFrancaStyleExtensions method applyOnEdgePysicalStyle.
public void applyOnEdgePysicalStyle(KLabel label, Colors parentBackgroundColor) {
if (_onEdgePysicalLabelConfigurator == null) {
LabelDecorationConfigurator configurator = LabelDecorationConfigurator.create().withInlineLabels(true);
configurator = configurator.withLabelTextRenderingProvider((KContainerRendering container, KLabel klabel) -> {
KText kText = _kRenderingFactory.createKText();
_kRenderingExtensions.setInvisible(kText, true);
container.getChildren().add(kText);
return kText;
});
configurator = configurator.addDecoratorRenderingProvider(new IDecoratorRenderingProvider() {
@Override
public ElkPadding createDecoratorRendering(final KContainerRendering container, final KLabel label, final LabelDecorationConfigurator.LayoutMode layoutMode) {
ElkPadding padding = new ElkPadding();
padding.left = 3;
padding.right = 3;
padding.bottom = Math.max(padding.bottom, 1);
KPolygon polygon = _kRenderingFactory.createKPolygon();
_kRenderingExtensions.from(polygon, LEFT, 0, 0, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(polygon, LEFT, 0, 0, TOP, 1, 0.5f);
_kRenderingExtensions.to(polygon, RIGHT, 0, 0, TOP, 1, 0.5f);
_kRenderingExtensions.to(polygon, RIGHT, 0, 0, BOTTOM, 0, 0.5f);
_kRenderingExtensions.setBackground(polygon, label.getProperty(LABEL_PARENT_BACKGROUND));
_kRenderingExtensions.setForeground(polygon, label.getProperty(LABEL_PARENT_BACKGROUND));
container.getChildren().add(polygon);
KSpline kSpline = _kRenderingFactory.createKSpline();
_kRenderingExtensions.from(kSpline, LEFT, (-0.66f), 0, BOTTOM, (-0.5f), 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 1, 0, BOTTOM, (-0.5f), 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.1f, BOTTOM, 8, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.2f, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.3f, BOTTOM, (-8), 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.4f, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.45f, BOTTOM, 4f, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.5f, BOTTOM, 8, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.55f, BOTTOM, 4f, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.6f, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.65f, BOTTOM, (-4), 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.7f, BOTTOM, (-8), 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.8f, BOTTOM, (-4), 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0, 0.9f, BOTTOM, 0, 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, (-1), 1, BOTTOM, (-0.5f), 0.5f);
_kRenderingExtensions.to(kSpline, LEFT, 0.66f, 1, BOTTOM, (-0.5f), 0.5f);
container.getChildren().add(kSpline);
return padding;
}
});
_onEdgePysicalLabelConfigurator = configurator;
}
label.setProperty(LABEL_PARENT_BACKGROUND, parentBackgroundColor);
_onEdgePysicalLabelConfigurator.applyTo(label);
}
use of de.cau.cs.kieler.klighd.kgraph.KLabel in project lingua-franca by lf-lang.
the class LinguaFrancaStyleExtensions method applyOnEdgeDelayStyle.
public void applyOnEdgeDelayStyle(KLabel label) {
if (_onEdgeDelayLabelConfigurator == null) {
LabelDecorationConfigurator configurator = LabelDecorationConfigurator.create().withInlineLabels(true);
configurator = configurator.withLabelTextRenderingProvider((KContainerRendering container, KLabel klabel) -> {
KText kText = _kRenderingFactory.createKText();
_kRenderingExtensions.setFontSize(kText, 8);
boldTextSelectionStyle(kText);
kText.setProperty(KlighdInternalProperties.MODEL_ELEMEMT, klabel.getProperty(KlighdInternalProperties.MODEL_ELEMEMT));
container.getChildren().add(kText);
return kText;
});
configurator = configurator.addDecoratorRenderingProvider(new IDecoratorRenderingProvider() {
@Override
public ElkPadding createDecoratorRendering(KContainerRendering container, KLabel label, LabelDecorationConfigurator.LayoutMode layoutMode) {
ElkPadding padding = new ElkPadding();
padding.left = 2;
padding.right = 2;
padding.bottom = Math.max(padding.bottom, 1);
KPolygon polygon = _kRenderingFactory.createKPolygon();
_kRenderingExtensions.from(polygon, LEFT, (-2), 0, BOTTOM, 0, 0);
_kRenderingExtensions.to(polygon, LEFT, 2, 0, TOP, 0, 0);
_kRenderingExtensions.to(polygon, RIGHT, (-2), 0, TOP, 0, 0);
_kRenderingExtensions.to(polygon, RIGHT, 2, 0, BOTTOM, 0, 0);
_kRenderingExtensions.setBackground(polygon, Colors.WHITE);
_kRenderingExtensions.setForeground(polygon, Colors.WHITE);
container.getChildren().add(polygon);
KPolyline polyline = _kRenderingFactory.createKPolyline();
_kRenderingExtensions.from(polyline, LEFT, (-2), 0, BOTTOM, 0, 0);
_kRenderingExtensions.to(polyline, LEFT, 2, 0, TOP, 0, 0);
container.getChildren().add(polyline);
polyline = _kRenderingFactory.createKPolyline();
_kRenderingExtensions.from(polyline, RIGHT, 2, 0, BOTTOM, 0, 0);
_kRenderingExtensions.to(polyline, RIGHT, (-2), 0, TOP, 0, 0);
container.getChildren().add(polyline);
return padding;
}
});
_onEdgeDelayLabelConfigurator = configurator;
}
_onEdgeDelayLabelConfigurator.applyTo(label);
}
Aggregations