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.dataStructures.DisplayIndependentRectangle;
|
13
|
import org.eclipse.zest.layouts.dataStructures.InternalNode;
|
14
|
import org.eclipse.zest.layouts.dataStructures.InternalRelationship;
|
15
|
|
16
|
/**
|
17
|
*
|
18
|
* @author Ian Bull
|
19
|
*
|
20
|
* Used to represent algorithms that can continuously run.
|
21
|
*
|
22
|
*/
|
23
|
public abstract class ContinuousLayoutAlgorithm extends AbstractLayoutAlgorithm {
|
24
|
|
25
|
double x, y, widht, height;
|
26
|
|
27
|
public ContinuousLayoutAlgorithm(int styles) {
|
28
|
super(styles);
|
29
|
}
|
30
|
|
31
|
/**
|
32
|
* The logic to determine if a layout should continue running or not
|
33
|
*/
|
34
|
protected abstract boolean performAnotherNonContinuousIteration();
|
35
|
|
36
|
/**
|
37
|
* Computes a single iteration of the layout algorithm
|
38
|
* @return
|
39
|
*/
|
40
|
protected abstract void computeOneIteration(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double x, double y, double width, double height);
|
41
|
|
42
|
private boolean continueRunning() {
|
43
|
if (layoutStopped) {
|
44
|
return false;
|
45
|
} else if (this.internalContinuous && !layoutStopped) {
|
46
|
return true;
|
47
|
} else if (performAnotherNonContinuousIteration()) {
|
48
|
return true;
|
49
|
} else {
|
50
|
return false;
|
51
|
}
|
52
|
}
|
53
|
|
54
|
public void setLayoutArea(double x, double y, double width, double height) {
|
55
|
this.setBounds(x, y, width, height);
|
56
|
|
57
|
}
|
58
|
|
59
|
public synchronized DisplayIndependentRectangle getBounds() {
|
60
|
return new DisplayIndependentRectangle(this.x, this.y, this.widht, this.height);
|
61
|
}
|
62
|
|
63
|
public synchronized void setBounds(double x, double y, double width, double height) {
|
64
|
this.x = x;
|
65
|
this.y = y;
|
66
|
this.widht = width;
|
67
|
this.height = height;
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* Calculates and applies the positions of the given entities based on a
|
72
|
* spring layout using the given relationships.
|
73
|
*/
|
74
|
protected void applyLayoutInternal(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double x, double y, double width, double height) {
|
75
|
|
76
|
this.setBounds(x, y, width, height);
|
77
|
|
78
|
while (continueRunning()) {
|
79
|
// check for entities and relationships to add or remove
|
80
|
entitiesToLayout = updateEntities(entitiesToLayout);
|
81
|
relationshipsToConsider = updateRelationships(relationshipsToConsider);
|
82
|
DisplayIndependentRectangle bounds = this.getBounds();
|
83
|
double localX = bounds.x;
|
84
|
double localY = bounds.y;
|
85
|
double localWidth = bounds.width;
|
86
|
double localHeight = bounds.height;
|
87
|
|
88
|
computeOneIteration(entitiesToLayout, relationshipsToConsider, localX, localY, localWidth, localHeight);
|
89
|
|
90
|
updateLayoutLocations(entitiesToLayout);
|
91
|
|
92
|
if (this.internalContinuous) {
|
93
|
fireProgressEvent(1, 1);
|
94
|
} else {
|
95
|
fireProgressEvent(getCurrentLayoutStep(), getTotalNumberOfLayoutSteps());
|
96
|
}
|
97
|
|
98
|
}
|
99
|
}
|
100
|
|
101
|
}
|