Project

General

Profile

Download (1.4 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
/**
14
 * A base class for visitors which operate on the graphs spanning tree used to
15
 * induce rank assignments.
16
 * 
17
 * @author Randy Hudson
18
 * @since 2.1.2
19
 */
20
abstract class SpanningTreeVisitor extends GraphVisitor {
21

    
22
	Edge getParentEdge(Node node) {
23
		return (Edge) node.workingData[1];
24
	}
25

    
26
	EdgeList getSpanningTreeChildren(Node node) {
27
		return (EdgeList) node.workingData[0];
28
	}
29

    
30
	protected Node getTreeHead(Edge edge) {
31
		if (getParentEdge(edge.source) == edge)
32
			return edge.target;
33
		return edge.source;
34
	}
35

    
36
	Node getTreeParent(Node node) {
37
		Edge e = getParentEdge(node);
38
		if (e == null)
39
			return null;
40
		return e.opposite(node);
41
	}
42

    
43
	protected Node getTreeTail(Edge edge) {
44
		if (getParentEdge(edge.source) == edge)
45
			return edge.source;
46
		return edge.target;
47
	}
48

    
49
	void setParentEdge(Node node, Edge edge) {
50
		node.workingData[1] = edge;
51
	}
52

    
53
}
(40-40/49)