use of de.cau.cs.kieler.klighd.krendering.KRectangle in project lingua-franca by lf-lang.
the class LinguaFrancaShapeExtensions method addErrorMessage.
/**
* Creates and adds an error message figure
*/
public KRectangle addErrorMessage(KNode node, String title, String message) {
// Create figure for error message
KRectangle figure = _kRenderingExtensions.addRectangle(node);
_kRenderingExtensions.setInvisible(figure, true);
// Add error message box
KRoundedRectangle errMsgBox = _kContainerRenderingExtensions.addRoundedRectangle(figure, 7, 7);
_kContainerRenderingExtensions.setGridPlacement(errMsgBox, 1);
_kRenderingExtensions.setLineWidth(errMsgBox, 2);
_linguaFrancaStyleExtensions.noSelectionStyle(errMsgBox);
if (title != null) {
// Add title to error message box
KText titleText = _kContainerRenderingExtensions.addText(errMsgBox, title);
_kRenderingExtensions.setFontSize(titleText, 12);
_kRenderingExtensions.setFontBold(titleText, true);
_kRenderingExtensions.setForeground(titleText, Colors.RED);
setGridPlacementDataFromPointToPoint(titleText, _kRenderingExtensions.LEFT, 8, 0, _kRenderingExtensions.TOP, 8, 0, _kRenderingExtensions.RIGHT, 8, 0, _kRenderingExtensions.BOTTOM, 4, 0);
DiagramSyntheses.suppressSelectability(titleText);
_linguaFrancaStyleExtensions.noSelectionStyle(titleText);
}
if (message != null) {
// Add message to error message box
KText msgText = _kContainerRenderingExtensions.addText(errMsgBox, message);
if (title != null) {
setGridPlacementDataFromPointToPoint(msgText, _kRenderingExtensions.LEFT, 8, 0, _kRenderingExtensions.TOP, 0, 0, _kRenderingExtensions.RIGHT, 8, 0, _kRenderingExtensions.BOTTOM, 4, 0);
} else {
setGridPlacementDataFromPointToPoint(msgText, _kRenderingExtensions.LEFT, 8, 0, _kRenderingExtensions.TOP, 8, 0, _kRenderingExtensions.RIGHT, 8, 0, _kRenderingExtensions.BOTTOM, 8, 0);
}
_linguaFrancaStyleExtensions.noSelectionStyle(msgText);
}
return figure;
}
use of de.cau.cs.kieler.klighd.krendering.KRectangle in project lingua-franca by lf-lang.
the class LinguaFrancaShapeExtensions method addStopwatchFigure.
/**
* Stopwatch figure for deadlines.
*/
public KRectangle addStopwatchFigure(KContainerRendering parent) {
final int size = 12;
KRectangle container = _kContainerRenderingExtensions.addRectangle(parent);
_kRenderingExtensions.setInvisible(container, true);
_kRenderingExtensions.setPointPlacementData(container, _kRenderingExtensions.LEFT, 0, 0, _kRenderingExtensions.TOP, 0, 0, _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 0, 0, size, size);
KPolyline polyline = _kContainerRenderingExtensions.addPolyline(container, 2, List.of(_kRenderingExtensions.createKPosition(LEFT, 3, 0.5f, TOP, (-2), 0), _kRenderingExtensions.createKPosition(LEFT, (-3), 0.5f, TOP, (-2), 0)));
_kRenderingExtensions.setForeground(polyline, Colors.BROWN);
polyline = _kContainerRenderingExtensions.addPolyline(container, 2, List.of(_kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, (-2), 0), _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 1, 0)));
_kRenderingExtensions.setForeground(polyline, Colors.BROWN);
KEllipse body = _kContainerRenderingExtensions.addEllipse(container);
_kRenderingExtensions.setLineWidth(body, 1);
_kRenderingExtensions.setForeground(body, Colors.BROWN);
_kRenderingExtensions.<KEllipse>setPointPlacementData(body, _kRenderingExtensions.LEFT, 0, 0, _kRenderingExtensions.TOP, 0, 0, _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 0, 0, size, size);
_linguaFrancaStyleExtensions.noSelectionStyle(body);
KArc arc = _kContainerRenderingExtensions.addArc(body);
arc.setStartAngle((-20));
arc.setArcAngle(110);
arc.setArcType(Arc.PIE);
_kRenderingExtensions.setLineWidth(arc, 0);
_kRenderingExtensions.setBackground(arc, Colors.BROWN);
_kRenderingExtensions.setPointPlacementData(arc, _kRenderingExtensions.LEFT, 2, 0, _kRenderingExtensions.TOP, 2, 0, _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 2, 2, size - 4, size - 4);
_linguaFrancaStyleExtensions.noSelectionStyle(arc);
return container;
}
use of de.cau.cs.kieler.klighd.krendering.KRectangle in project lingua-franca by lf-lang.
the class LinguaFrancaShapeExtensions method addReactorFigure.
/**
* Creates the visual representation of a reactor node
*/
public ReactorFigureComponents addReactorFigure(KNode node, ReactorInstance reactorInstance, String text) {
int padding = getBooleanValue(LinguaFrancaSynthesis.SHOW_HYPERLINKS) ? 8 : 6;
Function1<KRoundedRectangle, KRendering> style = r -> {
_kRenderingExtensions.setLineWidth(r, 1);
_kRenderingExtensions.setForeground(r, Colors.GRAY);
_kRenderingExtensions.setBackground(r, Colors.GRAY_95);
return _linguaFrancaStyleExtensions.boldLineSelectionStyle(r);
};
KRoundedRectangle figure = _kRenderingExtensions.addRoundedRectangle(node, 8, 8, 1);
_kContainerRenderingExtensions.setGridPlacement(figure, 1);
style.apply(figure);
figure.setProperty(REACTOR_CONTENT_CONTAINER, true);
// minimal node size is necessary if no text will be added
List<Float> minSize = List.of(2 * figure.getCornerWidth(), 2 * figure.getCornerHeight());
_kNodeExtensions.setMinimalNodeSize(node, minSize.get(0), minSize.get(1));
// Add parent container
KRectangle parentContainer = _kContainerRenderingExtensions.addRectangle(figure);
_kRenderingExtensions.setInvisible(parentContainer, true);
setGridPlacementDataFromPointToPoint(parentContainer, LEFT, padding, 0, TOP, padding, 0, RIGHT, padding, 0, BOTTOM, _utilityExtensions.hasContent(reactorInstance) ? 4 : padding, 0);
// Add centered child container
KRectangle childContainer = _kContainerRenderingExtensions.addRectangle(parentContainer);
_kRenderingExtensions.setInvisible(childContainer, true);
_kRenderingExtensions.setPointPlacementData(childContainer, _kRenderingExtensions.LEFT, 0, 0.5f, _kRenderingExtensions.TOP, 0, 0.5f, _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, 0, 0, 0);
KGridPlacement placement = _kContainerRenderingExtensions.setGridPlacement(childContainer, 1);
KText childText = _kContainerRenderingExtensions.addText(childContainer, text);
DiagramSyntheses.suppressSelectability(childText);
_linguaFrancaStyleExtensions.underlineSelectionStyle(childText);
if (!_utilityExtensions.isRoot(reactorInstance) && reactorInstance.getDefinition().getHost() != null) {
KRendering cloudUploadIcon = _linguaFrancaStyleExtensions.addCloudUploadIcon(childContainer);
setGridPlacementDataFromPointToPoint(cloudUploadIcon, LEFT, 3, 0, TOP, 0, 0, RIGHT, 0, 0, BOTTOM, 0, 0);
placement.setNumColumns(2);
if (getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTOR_HOST)) {
KText reactorHostText = _kContainerRenderingExtensions.addText(childContainer, _utilityExtensions.toText(reactorInstance.getDefinition().getHost()));
DiagramSyntheses.suppressSelectability(reactorHostText);
_linguaFrancaStyleExtensions.underlineSelectionStyle(reactorHostText);
setGridPlacementDataFromPointToPoint(reactorHostText, LEFT, 3, 0, TOP, 0, 0, RIGHT, 0, 0, BOTTOM, 0, 0);
placement.setNumColumns(3);
}
}
if (reactorInstance.isBank()) {
List<KRendering> bank = new ArrayList<>();
KContainerRendering container = _kRenderingExtensions.addInvisibleContainerRendering(node);
// TODO handle unresolved width
KRoundedRectangle banks;
banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1);
style.apply(banks);
setGridPlacementDataFromPointToPoint(banks, LEFT, BANK_FIGURE_X_OFFSET_SUM, 0, TOP, BANK_FIGURE_Y_OFFSET_SUM, 0, RIGHT, 0, 0, BOTTOM, 0, 0);
if (reactorInstance.getWidth() == 3) {
banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1);
style.apply(banks);
setGridPlacementDataFromPointToPoint(banks, LEFT, BANK_FIGURE_X_OFFSET_SUM / 2, 0, TOP, BANK_FIGURE_Y_OFFSET_SUM / 2, 0, RIGHT, BANK_FIGURE_X_OFFSET_SUM / 2, 0, BOTTOM, BANK_FIGURE_Y_OFFSET_SUM / 2, 0);
} else if (reactorInstance.getWidth() != 2 && reactorInstance.getWidth() != 3) {
banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1);
style.apply(banks);
setGridPlacementDataFromPointToPoint(banks, LEFT, 2 * BANK_FIGURE_X_OFFSET_SUM / 3, 0, TOP, 2 * BANK_FIGURE_Y_OFFSET_SUM / 3, 0, RIGHT, BANK_FIGURE_X_OFFSET_SUM / 3, 0, BOTTOM, BANK_FIGURE_Y_OFFSET_SUM / 3, 0);
banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1);
style.apply(banks);
setGridPlacementDataFromPointToPoint(banks, LEFT, BANK_FIGURE_X_OFFSET_SUM / 3, 0, TOP, BANK_FIGURE_Y_OFFSET_SUM / 3, 0, RIGHT, 2 * BANK_FIGURE_X_OFFSET_SUM / 3, 0, BOTTOM, 2 * BANK_FIGURE_Y_OFFSET_SUM / 3, 0);
}
container.getChildren().add(figure);
setGridPlacementDataFromPointToPoint(figure, LEFT, 0, 0, TOP, 0, 0, RIGHT, BANK_FIGURE_X_OFFSET_SUM, 0, BOTTOM, BANK_FIGURE_Y_OFFSET_SUM, 0);
bank.addAll(container.getChildren());
KRectangle widthLabelContainer = _kContainerRenderingExtensions.addRectangle(container);
_kRenderingExtensions.setInvisible(widthLabelContainer, true);
setGridPlacementDataFromPointToPoint(widthLabelContainer, LEFT, 12, 0, BOTTOM, 9, 0, RIGHT, 6, 0, BOTTOM, 0.5f, 0);
// Handle unresolved width.
String widthLabel = reactorInstance.getWidth() >= 0 ? Integer.toString(reactorInstance.getWidth()) : "?";
KText widthLabelText = _kContainerRenderingExtensions.addText(widthLabelContainer, widthLabel);
_kRenderingExtensions.setHorizontalAlignment(widthLabelText, HorizontalAlignment.LEFT);
_kRenderingExtensions.setVerticalAlignment(widthLabelText, VerticalAlignment.BOTTOM);
_kRenderingExtensions.setFontSize(widthLabelText, 6);
_linguaFrancaStyleExtensions.noSelectionStyle(widthLabelText);
associateWith(widthLabelText, reactorInstance.getDefinition().getWidthSpec());
return new ReactorFigureComponents(container, figure, bank);
} else {
return new ReactorFigureComponents(figure, figure, List.of(figure));
}
}
use of de.cau.cs.kieler.klighd.krendering.KRectangle in project lingua-franca by lf-lang.
the class InterfaceDependenciesVisualization method addInterfaceDependencies.
/**
* Adds interface dependencies to the node if this option is active.
* Visibility will be adjusted based on expansion state.
*/
public Spacing addInterfaceDependencies(KNode node, boolean expanded) {
Spacing marginInit = null;
if (getBooleanValue(SHOW_INTERFACE_DEPENDENCIES)) {
List<Pair<KPort, KPort>> deps = getPortDependencies(node);
if (!deps.isEmpty()) {
for (Pair<KPort, KPort> pair : deps) {
createDependencyEdge(pair, expanded);
}
// Fix content (label) of collapsed rendering
KContainerRendering contentContainer = IterableExtensions.findFirst(Iterables.filter(node.getData(), KContainerRendering.class), it -> {
return it.getProperty(KlighdProperties.COLLAPSED_RENDERING);
});
if (contentContainer != null) {
if (!contentContainer.getProperty(LinguaFrancaShapeExtensions.REACTOR_CONTENT_CONTAINER)) {
contentContainer = IteratorExtensions.findFirst(Iterators.filter(contentContainer.eAllContents(), KContainerRendering.class), it -> {
return it.getProperty(LinguaFrancaShapeExtensions.REACTOR_CONTENT_CONTAINER);
});
}
if (contentContainer != null) {
List<KRendering> content = ImmutableList.copyOf(contentContainer.getChildren());
// Put into two new containers such that they are not centered/maximized
KRectangle firstContainer = _kContainerRenderingExtensions.addRectangle(contentContainer);
_kRenderingExtensions.setInvisible(firstContainer, true);
KRectangle secondContainer = _kContainerRenderingExtensions.addRectangle(firstContainer);
_kRenderingExtensions.setInvisible(secondContainer, true);
_kContainerRenderingExtensions.setGridPlacement(secondContainer, 1);
Iterables.addAll(secondContainer.getChildren(), content);
_kRenderingExtensions.setPointPlacementData(secondContainer, _kRenderingExtensions.LEFT, 0, 0.5f, _kRenderingExtensions.TOP, 0, 0, _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_TOP, 0, 0, 0, 0);
// Adjust ports separate dependency edges from label/content
if (content.size() > 0) {
marginInit = _utilityExtensions.getPortMarginsInitIfAbsent(node).add(new ElkMargin((content.size() * 20) - 8, 0, 0, 0));
}
}
}
}
}
return marginInit;
}
use of de.cau.cs.kieler.klighd.krendering.KRectangle in project lingua-franca by lf-lang.
the class LinguaFrancaStyleExtensions method addCloudIcon.
public KContainerRendering addCloudIcon(final KContainerRendering parent) {
KRectangle figure = _kContainerRenderingExtensions.addRectangle(parent);
_kRenderingExtensions.setInvisible(figure, true);
KRoundedRectangle roundRectangle = _kContainerRenderingExtensions.addRoundedRectangle(figure, CLOUD_WIDTH / 7, CLOUD_WIDTH / 7);
_kRenderingExtensions.setBackground(roundRectangle, Colors.GRAY);
_kRenderingExtensions.setForeground(roundRectangle, Colors.GRAY);
_kRenderingExtensions.setPointPlacementData(roundRectangle, _kRenderingExtensions.LEFT, 2, 0, _kRenderingExtensions.TOP, 0, 0.5f, _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 0, 0, CLOUD_WIDTH, CLOUD_WIDTH / 3);
KEllipse childEllipse = _kContainerRenderingExtensions.addEllipse(figure);
_kRenderingExtensions.setBackground(childEllipse, Colors.GRAY);
_kRenderingExtensions.setForeground(childEllipse, Colors.GRAY);
_kRenderingExtensions.setPointPlacementData(childEllipse, _kRenderingExtensions.LEFT, 0, 0f, _kRenderingExtensions.TOP, 0, 0.38f, _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 0, 0, CLOUD_WIDTH / 2.5f, CLOUD_WIDTH / 2.5f);
childEllipse = _kContainerRenderingExtensions.addEllipse(figure);
_kRenderingExtensions.setBackground(childEllipse, Colors.GRAY);
_kRenderingExtensions.setForeground(childEllipse, Colors.GRAY);
_kRenderingExtensions.setPointPlacementData(childEllipse, _kRenderingExtensions.LEFT, 0, 0.5f, _kRenderingExtensions.TOP, 0, 0.25f, _kRenderingExtensions.H_RIGHT, _kRenderingExtensions.V_TOP, 0, 0, CLOUD_WIDTH / 3f, CLOUD_WIDTH / 3f);
childEllipse = _kContainerRenderingExtensions.addEllipse(figure);
_kRenderingExtensions.setBackground(childEllipse, Colors.GRAY);
_kRenderingExtensions.setForeground(childEllipse, Colors.GRAY);
_kRenderingExtensions.setPointPlacementData(childEllipse, _kRenderingExtensions.LEFT, 0, 0.4f, _kRenderingExtensions.TOP, CLOUD_WIDTH / 10, 0, _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, 0, 0, CLOUD_WIDTH / 2, CLOUD_WIDTH / 2);
return figure;
}
Aggregations