1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package Algorithms;
- import java.util.ArrayList;
- import Algorithms.Animated.BK.ExtremalLayoutCalc.LayoutType;
- import Model.LayeredGraphNode;
- public class InitializeNodePositions {
-
- public static void placeNodes( LayeredGraphNode graph ) {
-
- RandomColorGenerator cGen = new RandomColorGenerator();
- for( LayeredGraphNode n : graph.getContainedNodes() )
- {
- n.setWidth( 40, null );
- n.setHeight( 40, null );
- n.setColor( cGen.generateColor(), null );
- placeNodes( n );
- }
- int curY = 0;
- double maxWidth = 0, maxHeight = 0;
-
- for (LayeredGraphNode node : graph.getContainedNodes()) {
- maxWidth = Math.max(node.getWidth( LayoutType.TOP_BOTTOM_LEFT ), maxWidth);
- maxHeight = Math.max(node.getHeight( LayoutType.TOP_BOTTOM_LEFT ), maxHeight);
- }
-
- ArrayList< ArrayList< LayeredGraphNode > > layers = graph.getContainedLayers();
- for (ArrayList<LayeredGraphNode> layer : layers) {
- maxHeight = 0;
- for (LayeredGraphNode node : layer) {
- maxHeight = Math.max(node.getHeight( LayoutType.TOP_BOTTOM_LEFT ), maxHeight);
- }
- int curX = 0;
- for (LayeredGraphNode node : layer) {
- node.setX( curX + maxWidth / 2 - node.getWidth( LayoutType.TOP_BOTTOM_LEFT ) / 2, false, null );
- node.setY( curY + maxHeight / 2 - node.getHeight( LayoutType.TOP_BOTTOM_LEFT ) / 2, null );
- curX += maxWidth + 25;
- }
- curY += maxHeight + 25;
- }
- }
- }
|