use of org.eclipse.zest.layouts.LayoutEntity in project archi by archimatetool.
the class SimpleSwingExample method createTreeGraphRecursive.
private void createTreeGraphRecursive(LayoutEntity currentParentNode, int minChildren, int maxChildren, int minLevel, int maxLevel, int level, boolean randomNumChildren, boolean randomLevels, boolean addNonTreeRels) {
if (level > maxLevel) {
return;
}
if (randomLevels) {
if (level > minLevel) {
double zeroToOne = Math.random();
if (zeroToOne < 0.75) {
return;
}
}
}
int numChildren = randomNumChildren ? Math.max(minChildren, (int) (Math.random() * maxChildren + 1)) : maxChildren;
for (int i = 0; i < numChildren; i++) {
LayoutEntity newNode = createSimpleNode(getNextID());
entities.add(newNode);
if (addNonTreeRels && entities.size() % 5 == 0) {
int index = (int) (Math.random() * entities.size());
LayoutRelationship rel = new SimpleRelationship((LayoutEntity) entities.get(index), newNode, false);
relationships.add(rel);
}
LayoutRelationship rel = new SimpleRelationship(currentParentNode, newNode, false);
relationships.add(rel);
createTreeGraphRecursive(newNode, minChildren, maxChildren, minLevel, maxLevel, level + 1, randomNumChildren, randomLevels, addNonTreeRels);
}
}
Aggregations