1
|
/*******************************************************************************
|
2
|
* Copyright 2005, CHISEL Group, University of Victoria, Victoria, BC, Canada.
|
3
|
* All rights reserved. This program and the accompanying materials are made
|
4
|
* available under the terms of the Eclipse Public License v1.0 which
|
5
|
* accompanies this distribution, and is available at
|
6
|
* http://www.eclipse.org/legal/epl-v10.html
|
7
|
*
|
8
|
* Contributors: The Chisel Group, University of Victoria
|
9
|
*******************************************************************************/
|
10
|
package org.eclipse.zest.layouts.algorithms;
|
11
|
|
12
|
import org.eclipse.zest.layouts.LayoutStyles;
|
13
|
import org.eclipse.zest.layouts.dataStructures.InternalNode;
|
14
|
import org.eclipse.zest.layouts.dataStructures.InternalRelationship;
|
15
|
|
16
|
/**
|
17
|
* A simple algorithm to arrange graph nodes in a layered horizontal tree-like layout.
|
18
|
* @see TreeLayoutAlgorithm
|
19
|
*
|
20
|
* @version 1.0
|
21
|
* @author Rob Lintern
|
22
|
*/
|
23
|
public class HorizontalTreeLayoutAlgorithm extends TreeLayoutAlgorithm {
|
24
|
|
25
|
/**
|
26
|
* Creates a horizontal tree layout with no style
|
27
|
*/
|
28
|
public HorizontalTreeLayoutAlgorithm() {
|
29
|
this(LayoutStyles.NONE);
|
30
|
}
|
31
|
|
32
|
/**
|
33
|
*
|
34
|
*/
|
35
|
public HorizontalTreeLayoutAlgorithm(int styles) {
|
36
|
super(styles);
|
37
|
}
|
38
|
|
39
|
protected void preLayoutAlgorithm(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double x, double y, double width, double height) {
|
40
|
// NOTE: width and height are swtiched here when calling super method
|
41
|
super.preLayoutAlgorithm(entitiesToLayout, relationshipsToConsider, x, y, height, width);
|
42
|
}
|
43
|
|
44
|
protected void postLayoutAlgorithm(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider) {
|
45
|
// swap x->y and width->height
|
46
|
for (int i = 0; i < entitiesToLayout.length; i++) {
|
47
|
InternalNode entity = entitiesToLayout[i];
|
48
|
entity.setInternalLocation(entity.getInternalY(), entity.getInternalX());
|
49
|
entity.setInternalSize(entity.getInternalWidth(), entity.getInternalHeight());
|
50
|
}
|
51
|
super.postLayoutAlgorithm(entitiesToLayout, relationshipsToConsider);
|
52
|
}
|
53
|
|
54
|
protected boolean isValidConfiguration(boolean asynchronous, boolean continueous) {
|
55
|
if (asynchronous && continueous)
|
56
|
return false;
|
57
|
else if (asynchronous && !continueous)
|
58
|
return true;
|
59
|
else if (!asynchronous && continueous)
|
60
|
return false;
|
61
|
else if (!asynchronous && !continueous)
|
62
|
return true;
|
63
|
|
64
|
return false;
|
65
|
}
|
66
|
|
67
|
}
|