Search in sources :

Example 1 with DirectedGraphLayout

use of org.eclipse.draw2d.graph.DirectedGraphLayout in project archi by archimatetool.

the class DirectedGraphLayoutAlgorithm method applyLayoutInternal.

@Override
protected void applyLayoutInternal(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double boundsX, double boundsY, double boundsWidth, double boundsHeight) {
    HashMap mapping = new HashMap(entitiesToLayout.length);
    DirectedGraph graph = new DirectedGraph();
    for (int i = 0; i < entitiesToLayout.length; i++) {
        InternalNode internalNode = entitiesToLayout[i];
        Node node = new Node(internalNode);
        node.setSize(new Dimension(10, 10));
        mapping.put(internalNode, node);
        graph.nodes.add(node);
    }
    for (int i = 0; i < relationshipsToConsider.length; i++) {
        InternalRelationship relationship = relationshipsToConsider[i];
        Node source = (Node) mapping.get(relationship.getSource());
        Node dest = (Node) mapping.get(relationship.getDestination());
        Edge edge = new Edge(relationship, source, dest);
        graph.edges.add(edge);
    }
    DirectedGraphLayout directedGraphLayout = new ExtendedDirectedGraphLayout();
    directedGraphLayout.visit(graph);
    for (Iterator iterator = graph.nodes.iterator(); iterator.hasNext(); ) {
        Node node = (Node) iterator.next();
        InternalNode internalNode = (InternalNode) node.data;
        // For horizontal layout transpose the x and y coordinates
        if ((layout_styles & SWT.HORIZONTAL) == SWT.HORIZONTAL) {
            internalNode.setInternalLocation(node.y, node.x);
        } else {
            internalNode.setInternalLocation(node.x, node.y);
        }
    }
    updateLayoutLocations(entitiesToLayout);
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) DirectedGraph(org.eclipse.draw2d.graph.DirectedGraph) DirectedGraphLayout(org.eclipse.draw2d.graph.DirectedGraphLayout) HashMap(java.util.HashMap) Node(org.eclipse.draw2d.graph.Node) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) Iterator(java.util.Iterator) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) Dimension(org.eclipse.draw2d.geometry.Dimension) Edge(org.eclipse.draw2d.graph.Edge)

Aggregations

HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 DirectedGraph (org.eclipse.draw2d.graph.DirectedGraph)1 DirectedGraphLayout (org.eclipse.draw2d.graph.DirectedGraphLayout)1 Edge (org.eclipse.draw2d.graph.Edge)1 Node (org.eclipse.draw2d.graph.Node)1 InternalNode (org.eclipse.zest.layouts.dataStructures.InternalNode)1 InternalRelationship (org.eclipse.zest.layouts.dataStructures.InternalRelationship)1