|
33 | 33 | *
|
34 | 34 | * @author Thomas Wuerthinger
|
35 | 35 | */
|
36 |
| -public class HierarchicalLayoutManager extends LayoutManager { |
| 36 | +public class HierarchicalLayoutManager extends LayoutManager implements LayoutMover { |
37 | 37 |
|
38 | 38 | int maxLayerLength;
|
39 | 39 | private LayoutGraph graph;
|
@@ -77,6 +77,62 @@ public void doLayout(LayoutGraph layoutGraph) {
|
77 | 77 | graph = layoutGraph;
|
78 | 78 | }
|
79 | 79 |
|
| 80 | + @Override |
| 81 | + public void moveLink(Point linkPos, int shiftX) { |
| 82 | + int layerNr = graph.findLayer(linkPos.y); |
| 83 | + for (LayoutNode node : graph.getLayer(layerNr)) { |
| 84 | + if (node.isDummy() && linkPos.x == node.getX()) { |
| 85 | + LayoutLayer layer = graph.getLayer(layerNr); |
| 86 | + if (layer.contains(node)) { |
| 87 | + node.setX(linkPos.x + shiftX); |
| 88 | + layer.sortNodesByX(); |
| 89 | + break; |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + writeBack(); |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public void moveVertices(Set<? extends Vertex> movedVertices) { |
| 98 | + for (Vertex vertex : movedVertices) { |
| 99 | + moveVertex(vertex); |
| 100 | + } |
| 101 | + writeBack(); |
| 102 | + } |
| 103 | + |
| 104 | + private void writeBack() { |
| 105 | + graph.optimizeBackEdgeCrossings(); |
| 106 | + graph.updateLayerMinXSpacing(); |
| 107 | + graph.straightenEdges(); |
| 108 | + WriteResult.apply(graph); |
| 109 | + } |
| 110 | + |
| 111 | + @Override |
| 112 | + public void moveVertex(Vertex movedVertex) { |
| 113 | + Point newLoc = movedVertex.getPosition(); |
| 114 | + LayoutNode movedNode = graph.getLayoutNode(movedVertex); |
| 115 | + assert !movedNode.isDummy(); |
| 116 | + |
| 117 | + int layerNr = graph.findLayer(newLoc.y + movedNode.getOuterHeight() / 2); |
| 118 | + if (movedNode.getLayer() == layerNr) { // we move the node in the same layer |
| 119 | + LayoutLayer layer = graph.getLayer(layerNr); |
| 120 | + if (layer.contains(movedNode)) { |
| 121 | + movedNode.setX(newLoc.x); |
| 122 | + layer.sortNodesByX(); |
| 123 | + } |
| 124 | + } else { // only remove edges if we moved the node to a new layer |
| 125 | + if (maxLayerLength > 0) return; // TODO: not implemented |
| 126 | + graph.removeNodeAndEdges(movedNode); |
| 127 | + layerNr = graph.insertNewLayerIfNeeded(movedNode, layerNr); |
| 128 | + graph.addNodeToLayer(movedNode, layerNr); |
| 129 | + movedNode.setX(newLoc.x); |
| 130 | + graph.getLayer(layerNr).sortNodesByX(); |
| 131 | + graph.removeEmptyLayers(); |
| 132 | + graph.addEdges(movedNode, maxLayerLength); |
| 133 | + } |
| 134 | + } |
| 135 | + |
80 | 136 | /**
|
81 | 137 | * Removes self-edges from nodes in the graph. If self-edges are to be included in the layout
|
82 | 138 | * (`layoutSelfEdges` is true), it stores them in the node for later processing and marks the graph
|
|
0 commit comments