use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class TreeLayoutAlgorithm method buildTreeRecursively.
/**
* Builds a tree of the passed in entity.
* The entity will pass a weight value to all of its children recursively.
*/
private void buildTreeRecursively(InternalNode layoutEntity, int i, double weight, InternalNode[] entities, final InternalRelationship[] relationships) {
// No need to do further computation!
if (layoutEntity == null) {
return;
}
// forest, and its weight value needs to be modified.
if (markedArr[i]) {
modifyWeightRecursively(layoutEntity, i, weight, new HashSet(), entities, relationships);
// No need to do further computation.
return;
}
// Mark this entity, set its weight value and create a new tree node.
markedArr[i] = true;
weights[i] = weight;
// collect the children of this entity and put them in order
Collection rels = findRelationships(layoutEntity, AS_SOURCE, relationships);
List children = new ArrayList();
for (Iterator iter = rels.iterator(); iter.hasNext(); ) {
InternalRelationship layoutRel = (InternalRelationship) iter.next();
InternalNode childEntity = layoutRel.getDestination();
children.add(childEntity);
}
if (comparator != null) {
Collections.sort(children, comparator);
} else {
// sort the children by level, then by number of descendents, then by number of children
// TODO: SLOW
Collections.sort(children, new Comparator() {
@Override
public int compare(Object o1, Object o2) {
InternalNode node1 = (InternalNode) o1;
InternalNode node2 = (InternalNode) o2;
int[] numDescendentsAndLevel1 = new int[2];
int[] numDescendentsAndLevel2 = new int[2];
int level1 = numDescendentsAndLevel1[NUM_LEVELS_INDEX];
int level2 = numDescendentsAndLevel2[NUM_LEVELS_INDEX];
if (level1 == level2) {
getNumDescendentsAndLevel(node1, relationships, numDescendentsAndLevel1);
getNumDescendentsAndLevel(node2, relationships, numDescendentsAndLevel2);
int numDescendents1 = numDescendentsAndLevel1[NUM_DESCENDENTS_INDEX];
int numDescendents2 = numDescendentsAndLevel2[NUM_DESCENDENTS_INDEX];
if (numDescendents1 == numDescendents2) {
int numChildren1 = getNumChildren(node1, relationships);
int numChildren2 = getNumChildren(node1, relationships);
return numChildren2 - numChildren1;
} else {
return numDescendents2 - numDescendents1;
}
} else {
return level2 - level1;
}
// return getNumChildren(node2, relationships) - getNumChildren(node1, relationships);
}
});
}
// map children to this parent, and vice versa
for (Iterator iter = children.iterator(); iter.hasNext(); ) {
InternalNode childEntity = (InternalNode) iter.next();
int childEntityIndex = indexOfInternalNode(entities, childEntity);
if (!childrenLists[i].contains(childEntity)) {
childrenLists[i].add(childEntity);
}
if (!parentLists[childEntityIndex].contains(layoutEntity)) {
parentLists[childEntityIndex].add(layoutEntity);
}
}
for (Iterator iter = children.iterator(); iter.hasNext(); ) {
InternalNode childEntity = (InternalNode) iter.next();
int childEntityIndex = indexOfInternalNode(entities, childEntity);
buildTreeRecursively(childEntity, childEntityIndex, weight + 1, entities, relationships);
}
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class TreeLayoutAlgorithm method getLevelRecursive.
private int getLevelRecursive(InternalNode layoutEntity, int i, Set seen, InternalNode[] entities) {
if (seen.contains(layoutEntity)) {
return 0;
}
seen.add(layoutEntity);
List parents = parentLists[i];
int maxParentLevel = 0;
for (Iterator iter = parents.iterator(); iter.hasNext(); ) {
InternalNode parentEntity = (InternalNode) iter.next();
int parentEntityIndex = indexOfInternalNode(entities, parentEntity);
int parentLevel = getLevelRecursive(parentEntity, parentEntityIndex, seen, entities) + 1;
maxParentLevel = Math.max(maxParentLevel, parentLevel);
}
return maxParentLevel;
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class HorizontalShift method applyLayoutInternal.
@Override
protected void applyLayoutInternal(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double boundsX, double boundsY, double boundsWidth, double boundsHeight) {
ArrayList row = new ArrayList();
for (int i = 0; i < entitiesToLayout.length; i++) {
addToRowList(entitiesToLayout[i], row);
}
int heightSoFar = 0;
Collections.sort(row, new Comparator() {
@Override
public int compare(Object arg0, Object arg1) {
// TODO Auto-generated method stub
List a0 = (List) arg0;
List a1 = (List) arg1;
LayoutEntity node0 = ((InternalNode) a0.get(0)).getLayoutEntity();
LayoutEntity node1 = ((InternalNode) a1.get(0)).getLayoutEntity();
return (int) (node0.getYInLayout() - (node1.getYInLayout()));
}
});
Iterator iterator = row.iterator();
while (iterator.hasNext()) {
List currentRow = (List) iterator.next();
Collections.sort(currentRow, new Comparator() {
@Override
public int compare(Object arg0, Object arg1) {
return (int) (((InternalNode) arg1).getLayoutEntity().getYInLayout() - ((InternalNode) arg0).getLayoutEntity().getYInLayout());
}
});
Iterator iterator2 = currentRow.iterator();
int i = 0;
int width = (int) ((boundsWidth / 2) - currentRow.size() * 75);
heightSoFar += ((InternalNode) currentRow.get(0)).getLayoutEntity().getHeightInLayout() + VSPACING * 8;
while (iterator2.hasNext()) {
InternalNode currentNode = (InternalNode) iterator2.next();
double location = width + 10 * ++i;
currentNode.setLocation(location, heightSoFar);
width += currentNode.getLayoutEntity().getWidthInLayout();
}
}
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class HorizontalShift method addToRowList.
private void addToRowList(InternalNode node, ArrayList list) {
double layoutY = node.getLayoutEntity().getYInLayout();
for (int i = 0; i < list.size(); i++) {
List currentRow = (List) list.get(i);
InternalNode currentRowNode = (InternalNode) currentRow.get(0);
double currentRowY = currentRowNode.getLayoutEntity().getYInLayout();
// double currentRowHeight = currentRowNode.getLayoutEntity().getHeightInLayout();
if (layoutY >= (currentRowY - DELTA) && layoutY <= currentRowY + DELTA) {
currentRow.add(node);
// list.add(i, currentRow);
return;
}
}
List newRow = new ArrayList();
newRow.add(node);
list.add(newRow);
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class AbstractLayoutAlgorithm method getLayoutBounds.
/**
* Find the bounds in which the nodes are located. Using the bounds against the real bounds
* of the screen, the nodes can proportionally be placed within the real bounds.
* The bounds can be determined either including the size of the nodes or not. If the size
* is not included, the bounds will only be guaranteed to include the center of each node.
*/
protected DisplayIndependentRectangle getLayoutBounds(InternalNode[] entitiesToLayout, boolean includeNodeSize) {
double rightSide = Double.MIN_VALUE;
double bottomSide = Double.MIN_VALUE;
double leftSide = Double.MAX_VALUE;
double topSide = Double.MAX_VALUE;
for (int i = 0; i < entitiesToLayout.length; i++) {
InternalNode entity = entitiesToLayout[i];
if (entity.hasPreferredLocation()) {
continue;
}
if (includeNodeSize) {
leftSide = Math.min(entity.getInternalX() - entity.getInternalWidth() / 2, leftSide);
topSide = Math.min(entity.getInternalY() - entity.getInternalHeight() / 2, topSide);
rightSide = Math.max(entity.getInternalX() + entity.getInternalWidth() / 2, rightSide);
bottomSide = Math.max(entity.getInternalY() + entity.getInternalHeight() / 2, bottomSide);
} else {
leftSide = Math.min(entity.getInternalX(), leftSide);
topSide = Math.min(entity.getInternalY(), topSide);
rightSide = Math.max(entity.getInternalX(), rightSide);
bottomSide = Math.max(entity.getInternalY(), bottomSide);
}
}
return new DisplayIndependentRectangle(leftSide, topSide, rightSide - leftSide, bottomSide - topSide);
}
Aggregations