comparison dwtx/draw2d/graph/VerticalPlacement.d @ 98:95307ad235d9

Added Draw2d code, still work in progress
author Frank Benoit <benoit@tionex.de>
date Sun, 03 Aug 2008 00:52:14 +0200
parents
children
comparison
equal deleted inserted replaced
96:b492ba44e44d 98:95307ad235d9
1 /*******************************************************************************
2 * Copyright (c) 2003, 2005 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 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module dwtx.draw2d.graph.VerticalPlacement;
14
15 import dwt.dwthelper.utils;
16
17 import dwtx.draw2d.geometry.Insets;
18 import dwtx.draw2d.graph.GraphVisitor;
19 import dwtx.draw2d.graph.DirectedGraph;
20 import dwtx.draw2d.graph.Rank;
21 import dwtx.draw2d.graph.Node;
22
23 /**
24 * Assigns the Y and Height values to the nodes in the graph. All nodes in the same row
25 * are given the same height.
26 * @author Randy Hudson
27 * @since 2.1.2
28 */
29 class VerticalPlacement : GraphVisitor {
30
31 void visit(DirectedGraph g) {
32 Insets pad;
33 int currentY = g.getMargin().top;
34 int row, rowHeight;
35 g.rankLocations = new int[g.ranks.size() + 1];
36 for (row = 0; row < g.ranks.size(); row++) {
37 g.rankLocations[row] = currentY;
38 Rank rank = g.ranks.getRank(row);
39 rowHeight = 0;
40 rank.topPadding = rank.bottomPadding = 0;
41 for (int n = 0; n < rank.size(); n++) {
42 Node node = rank.getNode(n);
43 pad = g.getPadding(node);
44 rowHeight = Math.max(node.height, rowHeight);
45 rank.topPadding = Math.max(pad.top, rank.topPadding);
46 rank.bottomPadding = Math.max(pad.bottom, rank.bottomPadding);
47 }
48 currentY += rank.topPadding;
49 rank.setDimensions(currentY, rowHeight);
50 currentY += rank.height + rank.bottomPadding;
51 }
52 g.rankLocations[row] = currentY;
53 g.size.height = currentY;
54 }
55
56 }