comparison org.eclipse.draw2d/src/org/eclipse/draw2d/graph/SpanningTreeVisitor.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
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 org.eclipse.draw2d.graph.SpanningTreeVisitor;
14
15 import java.lang.all;
16 import org.eclipse.draw2d.graph.GraphVisitor;
17 import org.eclipse.draw2d.graph.Edge;
18 import org.eclipse.draw2d.graph.Node;
19 import org.eclipse.draw2d.graph.EdgeList;
20
21 /**
22 * A base class for visitors which operate on the graphs spanning tree used to induce rank
23 * assignments.
24 * @author Randy Hudson
25 * @since 2.1.2
26 */
27 abstract class SpanningTreeVisitor : GraphVisitor {
28
29 Edge getParentEdge(Node node) {
30 return cast(Edge)node.workingData[1];
31 }
32
33 EdgeList getSpanningTreeChildren(Node node) {
34 return cast(EdgeList)node.workingData[0];
35 }
36
37 protected Node getTreeHead(Edge edge) {
38 if (getParentEdge(edge.source) is edge)
39 return edge.target;
40 return edge.source;
41 }
42
43 Node getTreeParent(Node node) {
44 Edge e = getParentEdge(node);
45 if (e is null)
46 return null;
47 return e.opposite(node);
48 }
49
50 protected Node getTreeTail(Edge edge) {
51 if (getParentEdge(edge.source) is edge)
52 return edge.source;
53 return edge.target;
54 }
55
56 void setParentEdge(Node node, Edge edge) {
57 node.workingData[1] = edge;
58 }
59
60 }