use of org.eclipse.elk.core.util.Triple in project elk by eclipse.
the class Issue682Test method testGraph.
public Triple<ElkNode, ElkNode, ElkLabel> testGraph() {
ElkNode graph = ElkGraphUtil.createGraph();
graph.setProperty(CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID);
graph.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.ORTHOGONAL);
graph.setProperty(LayeredOptions.DIRECTION, layoutDirection);
graph.setProperty(LayeredOptions.NODE_LABELS_PADDING, new ElkPadding(21, 32, 43, 54));
ElkNode parent = ElkGraphUtil.createNode(graph);
parent.setProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS, EnumSet.of(SizeConstraint.NODE_LABELS));
parent.setProperty(LayeredOptions.NODE_LABELS_PLACEMENT, NodeLabelPlacement.insideTopCenter());
ElkLabel label = ElkGraphUtil.createLabel("foobar", parent);
// Arbitrary
label.setWidth(23);
label.setHeight(22);
return new Triple<>(graph, parent, label);
}
use of org.eclipse.elk.core.util.Triple in project elk by eclipse.
the class DisCoGraphRenderer method renderPolyominoes.
// added by mic
/**
* Paints all polyominoes that fall into the given dirty area.
*
* @param polys
* the polyominoes 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
* @param fillingAlpha
* alpha value for node fillings
*/
private void renderPolyominoes(final ElkNode parent, final List<DCPolyomino> polys, final GC graphics, final Rectangle area, final KVector offset, final int nodeAlpha, final int fillingAlpha, final int levelNumber) {
for (DCPolyomino poly : polys) {
KVector polyCorner = poly.getMinCornerOnCanvas();
double topLeftCornerX = polyCorner.x;
double topLeftCornerY = polyCorner.y;
double cellSizeX = poly.getCellSizeX();
double cellSizeY = poly.getCellSizeY();
double bottomRightCornerX = topLeftCornerX + cellSizeX * poly.getWidth();
double bottomRightCornerY = topLeftCornerY + cellSizeY * poly.getHeight();
for (int x = 0; x < poly.getWidth(); x++) {
for (int y = 0; y < poly.getHeight(); y++) {
Triple<Polyomino, Integer, Integer> polyoCell = new Triple<Polyomino, Integer, Integer>(poly, x, y);
PaintRectangle rect = polyominoMap.get(polyoCell);
if (rect == null) {
rect = new PaintRectangle(topLeftCornerX, topLeftCornerY, cellSizeX, cellSizeY, x, y, offset, getScale());
polyominoMap.put(polyoCell, rect);
}
if (!rect.painted && rect.intersects(area)) {
// paint this node
graphics.setAlpha(fillingAlpha);
if (configurator.getPolyominoFillColor() != null && poly.isBlocked(x, y)) {
graphics.setBackground(configurator.getPolyominoFillColor());
graphics.fillRectangle(rect.x, rect.y, rect.width, rect.height);
if (configurator.getNodeLabelFont() != null) {
graphics.setFont(configurator.getNodeLabelFont());
}
graphics.setAlpha(nodeAlpha);
graphics.setForeground(configurator.getPolyominoBorderTextColor());
if (state.drawLabels()) {
String levelprefix = levelNumber + "_";
if (state.removeLvl()) {
levelprefix = "";
}
graphics.drawString(levelprefix + Integer.toString(poly.getId()), rect.x, rect.y, true);
}
}
if (configurator.getPolyominoFillColor() != null && poly.isWeaklyBlocked(x, y)) {
// CHECKSTYLEOFF MagicNumber
graphics.setBackgroundPattern(patterns.getPolyominoExtensionPattern(state.makeSolid() ? 255 : fillingAlpha));
// CHECKSTYLEON MagicNumber
graphics.fillRectangle(rect.x, rect.y, rect.width, rect.height);
graphics.setAlpha(nodeAlpha);
graphics.setForeground(configurator.getPolyominoWeaklyBlockedBorderTextColor());
graphics.drawRectangle(rect.x, rect.y, rect.width, rect.height);
if (configurator.getNodeLabelFont() != null) {
graphics.setFont(configurator.getNodeLabelFont());
}
graphics.setAlpha(nodeAlpha);
if (state.drawLabels()) {
String levelprefix = levelNumber + "_";
if (state.removeLvl()) {
levelprefix = "";
}
graphics.drawString(levelprefix + Integer.toString(poly.getId()), rect.x, rect.y, true);
}
}
graphics.setAlpha(nodeAlpha);
if (configurator.getPolyominoBorderTextColor() != null && !poly.isWeaklyBlocked(x, y)) {
graphics.setForeground(configurator.getPolyominoBorderTextColor());
if (state.drawPolyLinesBlack()) {
graphics.setForeground(configurator.getBlack());
}
graphics.drawRectangle(rect.x, rect.y, rect.width, rect.height);
}
rect.painted = true;
}
}
}
if (state.markTheCenter()) {
int x = poly.getCenterX();
int y = poly.getCenterY();
PaintRectangle centerRect = polyominoCenterMap.get(poly);
if (centerRect == null) {
centerRect = new PaintRectangle(topLeftCornerX, topLeftCornerY, cellSizeX, cellSizeY, x, y, offset, getScale());
polyominoCenterMap.put(poly, centerRect);
}
if (configurator.getPolyominoFillColor() != null) {
// CHECKSTYLEOFF MagicNumber
graphics.setBackgroundPattern(patterns.getPolyominoCenterPattern(state.makeSolid() ? 255 : fillingAlpha));
// CHECKSTYLEON MagicNumber
graphics.fillRectangle(centerRect.x, centerRect.y, centerRect.width, centerRect.height);
graphics.setAlpha(nodeAlpha);
}
}
for (UniqueTriple<Direction, Integer, Integer> ext : poly.getPolyominoExtensions()) {
PaintRectangle rect = polyominoExtensionMap.get(ext);
if (rect == null) {
Direction dir = ext.getFirst();
int extStart = ext.getSecond();
int extEnd = ext.getThird();
switch(dir) {
case NORTH:
rect = new PaintRectangle(topLeftCornerX + extStart * cellSizeX, 0, (extEnd - extStart + 1) * cellSizeX, topLeftCornerY, offset, getScale());
break;
case SOUTH:
rect = new PaintRectangle(topLeftCornerX + extStart * cellSizeX, bottomRightCornerY, (extEnd - extStart + 1) * cellSizeX, parent.getHeight() - bottomRightCornerY, offset, getScale());
break;
case WEST:
rect = new PaintRectangle(0, topLeftCornerY + extStart * cellSizeY, topLeftCornerX, (extEnd - extStart + 1) * cellSizeY, offset, getScale());
break;
default:
// EAST
rect = new PaintRectangle(bottomRightCornerX, topLeftCornerY + extStart * cellSizeY, parent.getWidth() - bottomRightCornerX, (extEnd - extStart + 1) * cellSizeY, offset, getScale());
break;
}
// Maybe not unique in extreme cases where extensions
// are very close to each other, but it doesn't matter
// for the drawing
polyominoExtensionMap.put(ext, rect);
}
graphics.setAlpha(fillingAlpha);
// CHECKSTYLEOFF MagicNumber
graphics.setBackgroundPattern(patterns.getPolyominoExtensionPattern(state.makeSolid() ? 255 : fillingAlpha));
// CHECKSTYLEON MagicNumber
graphics.fillRectangle(rect.x, rect.y, rect.width, rect.height);
graphics.setAlpha(nodeAlpha);
graphics.setForeground(configurator.getPolyominoWeaklyBlockedBorderTextColor());
graphics.drawRectangle(rect.x, rect.y, rect.width, rect.height);
if (configurator.getNodeLabelFont() != null) {
graphics.setFont(configurator.getNodeLabelFont());
}
graphics.setAlpha(nodeAlpha);
if (state.drawLabels()) {
String levelprefix = levelNumber + "_";
if (state.removeLvl()) {
levelprefix = "";
}
graphics.drawString(levelprefix + Integer.toString(poly.getId()), rect.x, rect.y, true);
}
}
}
}
use of org.eclipse.elk.core.util.Triple in project elk by eclipse.
the class Issue680Test method testGraph.
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests
public Triple<ElkNode, ElkNode, ElkNode> testGraph() {
ElkNode graph = ElkGraphUtil.createGraph();
graph.setProperty(CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID);
graph.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.ORTHOGONAL);
graph.setProperty(LayeredOptions.DIRECTION, Direction.DOWN);
ElkNode parent = ElkGraphUtil.createNode(graph);
parent.setProperty(CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID);
parent.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.ORTHOGONAL);
parent.setProperty(LayeredOptions.DIRECTION, Direction.DOWN);
ElkPort p1 = ElkGraphUtil.createPort(parent);
p1.setWidth(15);
p1.setHeight(165);
p1.setProperty(LayeredOptions.PORT_BORDER_OFFSET, -20.0);
ElkPort p2 = ElkGraphUtil.createPort(parent);
p2.setWidth(15);
p2.setHeight(166);
p2.setProperty(LayeredOptions.PORT_BORDER_OFFSET, -22.0);
ElkNode child = ElkGraphUtil.createNode(parent);
child.setWidth(40.265625);
child.setHeight(75.5);
ElkPort childP1 = ElkGraphUtil.createPort(child);
childP1.setWidth(15);
childP1.setHeight(33);
childP1.setProperty(LayeredOptions.PORT_BORDER_OFFSET, -8.0);
ElkPort childP2 = ElkGraphUtil.createPort(child);
childP2.setWidth(15);
childP2.setHeight(34);
childP2.setProperty(LayeredOptions.PORT_BORDER_OFFSET, -8.0);
ElkGraphUtil.createSimpleEdge(p1, childP1);
ElkGraphUtil.createSimpleEdge(childP2, p2);
return new Triple<>(graph, parent, child);
}
Aggregations