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 java.lang.reflect.Field;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.Iterator;
|
15
|
import java.util.List;
|
16
|
|
17
|
import org.eclipse.draw2d.geometry.Dimension;
|
18
|
import org.eclipse.draw2d.graph.DirectedGraph;
|
19
|
import org.eclipse.draw2d.graph.DirectedGraphLayout;
|
20
|
import org.eclipse.draw2d.graph.Edge;
|
21
|
import org.eclipse.draw2d.graph.Node;
|
22
|
import org.eclipse.swt.SWT;
|
23
|
import org.eclipse.zest.layouts.dataStructures.InternalNode;
|
24
|
import org.eclipse.zest.layouts.dataStructures.InternalRelationship;
|
25
|
|
26
|
public class DirectedGraphLayoutAlgorithm extends AbstractLayoutAlgorithm {
|
27
|
|
28
|
class ExtendedDirectedGraphLayout extends DirectedGraphLayout {
|
29
|
|
30
|
public void visit(DirectedGraph graph) {
|
31
|
Field field;
|
32
|
try {
|
33
|
field = DirectedGraphLayout.class.getDeclaredField("steps");
|
34
|
field.setAccessible(true);
|
35
|
Object object = field.get(this);
|
36
|
List steps = (List) object;
|
37
|
steps.remove(10);
|
38
|
steps.remove(9);
|
39
|
steps.remove(8);
|
40
|
steps.remove(2);
|
41
|
field.setAccessible(false);
|
42
|
super.visit(graph);
|
43
|
} catch (SecurityException e) {
|
44
|
e.printStackTrace();
|
45
|
} catch (NoSuchFieldException e) {
|
46
|
e.printStackTrace();
|
47
|
} catch (IllegalArgumentException e) {
|
48
|
e.printStackTrace();
|
49
|
} catch (IllegalAccessException e) {
|
50
|
e.printStackTrace();
|
51
|
}
|
52
|
}
|
53
|
|
54
|
}
|
55
|
|
56
|
public DirectedGraphLayoutAlgorithm(int styles) {
|
57
|
super(styles);
|
58
|
}
|
59
|
|
60
|
protected void applyLayoutInternal(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double boundsX, double boundsY, double boundsWidth, double boundsHeight) {
|
61
|
HashMap mapping = new HashMap(entitiesToLayout.length);
|
62
|
DirectedGraph graph = new DirectedGraph();
|
63
|
for (int i = 0; i < entitiesToLayout.length; i++) {
|
64
|
InternalNode internalNode = entitiesToLayout[i];
|
65
|
Node node = new Node(internalNode);
|
66
|
node.setSize(new Dimension(10, 10));
|
67
|
mapping.put(internalNode, node);
|
68
|
graph.nodes.add(node);
|
69
|
}
|
70
|
for (int i = 0; i < relationshipsToConsider.length; i++) {
|
71
|
InternalRelationship relationship = relationshipsToConsider[i];
|
72
|
Node source = (Node) mapping.get(relationship.getSource());
|
73
|
Node dest = (Node) mapping.get(relationship.getDestination());
|
74
|
Edge edge = new Edge(relationship, source, dest);
|
75
|
graph.edges.add(edge);
|
76
|
}
|
77
|
DirectedGraphLayout directedGraphLayout = new ExtendedDirectedGraphLayout();
|
78
|
directedGraphLayout.visit(graph);
|
79
|
|
80
|
for (Iterator iterator = graph.nodes.iterator(); iterator.hasNext();) {
|
81
|
Node node = (Node) iterator.next();
|
82
|
InternalNode internalNode = (InternalNode) node.data;
|
83
|
// For horizontal layout transpose the x and y coordinates
|
84
|
if ((layout_styles & SWT.HORIZONTAL) == SWT.HORIZONTAL) {
|
85
|
internalNode.setInternalLocation(node.y, node.x);
|
86
|
} else {
|
87
|
internalNode.setInternalLocation(node.x, node.y);
|
88
|
}
|
89
|
}
|
90
|
updateLayoutLocations(entitiesToLayout);
|
91
|
}
|
92
|
|
93
|
protected int getCurrentLayoutStep() {
|
94
|
// TODO Auto-generated method stub
|
95
|
return 0;
|
96
|
}
|
97
|
|
98
|
protected int getTotalNumberOfLayoutSteps() {
|
99
|
// TODO Auto-generated method stub
|
100
|
return 0;
|
101
|
}
|
102
|
|
103
|
protected boolean isValidConfiguration(boolean asynchronous, boolean continuous) {
|
104
|
// TODO Auto-generated method stub
|
105
|
return true;
|
106
|
}
|
107
|
|
108
|
protected void postLayoutAlgorithm(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider) {
|
109
|
// TODO Auto-generated method stub
|
110
|
|
111
|
}
|
112
|
|
113
|
protected void preLayoutAlgorithm(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double x, double y, double width, double height) {
|
114
|
// TODO Auto-generated method stub
|
115
|
|
116
|
}
|
117
|
|
118
|
public void setLayoutArea(double x, double y, double width, double height) {
|
119
|
// TODO Auto-generated method stub
|
120
|
|
121
|
}
|
122
|
|
123
|
}
|