Search in sources :

Example 11 with LayoutRelationship

use of org.eclipse.zest.layouts.LayoutRelationship 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);
    }
}
Also used : LayoutEntity(org.eclipse.zest.layouts.LayoutEntity) Point(java.awt.Point) LayoutBendPoint(org.eclipse.zest.layouts.LayoutBendPoint) SimpleRelationship(org.eclipse.zest.layouts.exampleStructures.SimpleRelationship) LayoutRelationship(org.eclipse.zest.layouts.LayoutRelationship)

Aggregations

LayoutRelationship (org.eclipse.zest.layouts.LayoutRelationship)11 LayoutEntity (org.eclipse.zest.layouts.LayoutEntity)6 InvalidLayoutConfiguration (org.eclipse.zest.layouts.InvalidLayoutConfiguration)4 BasicEntityConstraint (org.eclipse.zest.layouts.constraints.BasicEntityConstraint)4 BendPoint (org.eclipse.zest.layouts.dataStructures.BendPoint)4 DisplayIndependentPoint (org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)2 List (java.util.List)2 Dimension (org.eclipse.draw2d.geometry.Dimension)2 Point (org.eclipse.draw2d.geometry.Point)2 LayoutBendPoint (org.eclipse.zest.layouts.LayoutBendPoint)2 TreeLayoutAlgorithm (org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm)2 InternalRelationship (org.eclipse.zest.layouts.dataStructures.InternalRelationship)2 ProgressEvent (org.eclipse.zest.layouts.progress.ProgressEvent)2 ProgressListener (org.eclipse.zest.layouts.progress.ProgressListener)2 Cursor (java.awt.Cursor)1 Point (java.awt.Point)1 Hashtable (java.util.Hashtable)1 LinkedList (java.util.LinkedList)1