Project

General

Profile

Download (1.62 KB) Statistics
| Branch: | Tag: | Revision:
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.draw2d.graph;
12

    
13
import org.eclipse.draw2d.geometry.Insets;
14

    
15
/**
16
 * Assigns the Y and Height values to the nodes in the graph. All nodes in the
17
 * same row are given the same height.
18
 * 
19
 * @author Randy Hudson
20
 * @since 2.1.2
21
 */
22
class VerticalPlacement extends GraphVisitor {
23

    
24
	void visit(DirectedGraph g) {
25
		Insets pad;
26
		int currentY = g.getMargin().top;
27
		int row, rowHeight;
28
		g.rankLocations = new int[g.ranks.size() + 1];
29
		for (row = 0; row < g.ranks.size(); row++) {
30
			g.rankLocations[row] = currentY;
31
			Rank rank = g.ranks.getRank(row);
32
			rowHeight = 0;
33
			rank.topPadding = rank.bottomPadding = 0;
34
			for (int n = 0; n < rank.size(); n++) {
35
				Node node = rank.getNode(n);
36
				pad = g.getPadding(node);
37
				rowHeight = Math.max(node.height, rowHeight);
38
				rank.topPadding = Math.max(pad.top, rank.topPadding);
39
				rank.bottomPadding = Math.max(pad.bottom, rank.bottomPadding);
40
			}
41
			currentY += rank.topPadding;
42
			rank.setDimensions(currentY, rowHeight);
43
			currentY += rank.height + rank.bottomPadding;
44
		}
45
		g.rankLocations[row] = currentY;
46
		g.size.height = currentY;
47
	}
48

    
49
}
(46-46/49)