Search in sources :

Example 1 with FRLayout

use of edu.uci.ics.jung.algorithms.layout.FRLayout in project opennms by OpenNMS.

the class FRLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(final Graph graph) {
    final Layout graphLayout = graph.getLayout();
    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
    Collection<Vertex> vertices = graph.getDisplayVertices();
    for (Vertex v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<Edge> edges = graph.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    FRLayout<VertexRef, EdgeRef> layout = new FRLayout<VertexRef, EdgeRef>(jungGraph);
    // Initialize the vertex positions to the last known positions from the layout
    Dimension size = selectLayoutSize(graph);
    layout.setInitializer(initializer(graphLayout, (int) size.getWidth() / 2, (int) size.getHeight() / 2));
    // Resize the graph to accommodate the number of vertices
    layout.setSize(size);
    while (!layout.done()) {
        layout.step();
    }
    // Store the new positions in the layout
    for (Vertex v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v) - (size.getWidth() / 2), (int) layout.getY(v) - (size.getHeight() / 2)));
    }
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Dimension(java.awt.Dimension) Point(org.opennms.features.topology.api.Point) SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Layout(org.opennms.features.topology.api.Layout) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Example 2 with FRLayout

use of edu.uci.ics.jung.algorithms.layout.FRLayout in project opennms by OpenNMS.

the class RealUltimateLayoutAlgorithm method doFRLayout.

private static void doFRLayout(final Layout graphLayout, SparseGraph<VertexRef, EdgeRef> jungGraph, Dimension size, final int xOffset, final int yOffset) {
    FRLayout<VertexRef, EdgeRef> layout = new FRLayout<VertexRef, EdgeRef>(jungGraph);
    layout.setInitializer(initializer(graphLayout, xOffset, yOffset));
    layout.setSize(size);
    while (!layout.done()) {
        layout.step();
    }
    for (VertexRef v : jungGraph.getVertices()) {
        graphLayout.setLocation(v, new Point(layout.getX(v) + xOffset, layout.getY(v) + yOffset));
    }
}
Also used : FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Aggregations

FRLayout (edu.uci.ics.jung.algorithms.layout.FRLayout)2 Point (org.opennms.features.topology.api.Point)2 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)2 VertexRef (org.opennms.features.topology.api.topo.VertexRef)2 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)1 Dimension (java.awt.Dimension)1 Layout (org.opennms.features.topology.api.Layout)1 Edge (org.opennms.features.topology.api.topo.Edge)1 Vertex (org.opennms.features.topology.api.topo.Vertex)1