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