/* * Created on Mar 9, 2004 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package net.agentis.eclipse.common.draw2d.graph; import org.eclipse.draw2d.geometry.Insets; import org.eclipse.draw2d.graph.*; import org.eclipse.draw2d.internal.graph.GraphVisitor; /** * NOTE: This class is a direct rip off of org.eclipse.draw2d.internal.graph.VerticalPlacement. * I had to copy the class in order to add a flag which determines whether the height of each node * should be set to the largest node in the row. */ public class VerticalPlacement extends GraphVisitor { public boolean resizeHeight; /** * @param resizeHeight if set to true, the heigh of each node will be resized to the height of the largest node in the row */ public VerticalPlacement(boolean resizeHeight) { this.resizeHeight = resizeHeight; } public void visit(DirectedGraph g) { Insets pad; int currentY = 0; for (int row = 0; row < g.ranks.size(); row++) { int rowHeight = 0, rowAscent = 0, rowDescent = 0; Rank rank = g.ranks.getRank(row); for (int n = 0; n < rank.size(); n++) { Node node = rank.getNode(n); pad = g.getPadding(node); rowHeight = Math.max(node.height, rowHeight); rowAscent = Math.max(pad.top, rowAscent); rowDescent = Math.max(pad.bottom, rowDescent); } currentY += rowAscent; for (int n = 0; n < rank.size(); n++) { Node node = rank.getNode(n); node.y = currentY; if (resizeHeight) { node.height = rowHeight; } } currentY += rowHeight + rowDescent; } } }