Search in sources :

Example 1 with SimpleRelationship

use of org.eclipse.zest.layouts.exampleStructures.SimpleRelationship in project archi by archimatetool.

the class SimpleSWTExample method createTreeGraph.

/**
 * @param maxLevels Max number of levels wanted in tree
 * @param maxChildren Max number of children for each node in the tree
 * @param random Whether or not to pick random number of levels (from 1 to maxLevels) and
 * random number of children (from 1 to maxChildren)
 */
private void createTreeGraph(int maxLevels, int maxChildren, boolean random) {
    entities = new ArrayList();
    relationships = new ArrayList();
    // ccallendar - testing out having 2 roots
    SimpleNode root = createSimpleNode(getNextID());
    entities.add(root);
    SimpleNode root2 = createSimpleNode(getNextID());
    entities.add(root2);
    // end
    SimpleNode currentParent = createSimpleNode(getNextID());
    entities.add(currentParent);
    // ccallendar - adding relationships from the parent to the 2 roots
    SimpleRelationship rel = new SimpleRelationship(root, currentParent, false);
    root.addRelationship(rel);
    currentParent.addRelationship(rel);
    relationships.add(rel);
    rel = new SimpleRelationship(root2, currentParent, false);
    root2.addRelationship(rel);
    currentParent.addRelationship(rel);
    relationships.add(rel);
    // end
    int levels = random ? (int) (Math.random() * maxLevels + 1) : maxLevels;
    createTreeGraphRecursive(currentParent, maxChildren, levels, 1, random);
}
Also used : ArrayList(java.util.ArrayList) SimpleRelationship(org.eclipse.zest.layouts.exampleStructures.SimpleRelationship) Point(org.eclipse.swt.graphics.Point) LayoutBendPoint(org.eclipse.zest.layouts.LayoutBendPoint) SimpleNode(org.eclipse.zest.layouts.exampleStructures.SimpleNode)

Example 2 with SimpleRelationship

use of org.eclipse.zest.layouts.exampleStructures.SimpleRelationship in project archi by archimatetool.

the class CycleChecker method hasCycle.

/**
 * Checks all the nodes attached to the nodeToCheck node for a cycle.  All nodes
 * checked are placed in nodePathSoFar.
 *
 * @returns true if there is a cycle
 */
private static boolean hasCycle(Object nodeToCheck, List nodePathSoFar, SimpleRelationship cameFrom, Hashtable endPoints, List nodesChecked, List cycle) {
    if (nodePathSoFar.contains(nodeToCheck)) {
        cycle.addAll(nodePathSoFar);
        cycle.add(nodeToCheck);
        return true;
    }
    nodePathSoFar.add(nodeToCheck);
    nodesChecked.add(nodeToCheck);
    List relations = (List) endPoints.get(nodeToCheck);
    if (relations != null) {
        for (Iterator iter = relations.iterator(); iter.hasNext(); ) {
            SimpleRelationship rel = (SimpleRelationship) iter.next();
            if (cameFrom == null || !rel.equals(cameFrom)) {
                Object currentNode = null;
                currentNode = rel.getDestinationInLayout();
                if (hasCycle(currentNode, nodePathSoFar, rel, endPoints, nodesChecked, cycle)) {
                    return true;
                }
            }
        }
    }
    nodePathSoFar.remove(nodeToCheck);
    return false;
}
Also used : Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) SimpleRelationship(org.eclipse.zest.layouts.exampleStructures.SimpleRelationship)

Example 3 with SimpleRelationship

use of org.eclipse.zest.layouts.exampleStructures.SimpleRelationship 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)

Example 4 with SimpleRelationship

use of org.eclipse.zest.layouts.exampleStructures.SimpleRelationship in project archi by archimatetool.

the class SimpleSWTExample method createTreeGraphRecursive.

private void createTreeGraphRecursive(SimpleNode currentParentNode, int maxChildren, int maxLevel, int level, boolean random) {
    if (level > maxLevel) {
        return;
    }
    int numChildren = random ? (int) (Math.random() * maxChildren + 1) : maxChildren;
    for (int child = 0; child < numChildren; child++) {
        SimpleNode childNode = createSimpleNode(getNextID());
        entities.add(childNode);
        SimpleRelationship rel = new SimpleRelationship(currentParentNode, childNode, false);
        childNode.addRelationship(rel);
        currentParentNode.addRelationship(rel);
        relationships.add(rel);
        SimpleRelationship.setDefaultSize(2);
        createTreeGraphRecursive(childNode, maxChildren, maxLevel, level + 1, random);
    }
}
Also used : Point(org.eclipse.swt.graphics.Point) LayoutBendPoint(org.eclipse.zest.layouts.LayoutBendPoint) SimpleRelationship(org.eclipse.zest.layouts.exampleStructures.SimpleRelationship) SimpleNode(org.eclipse.zest.layouts.exampleStructures.SimpleNode)

Aggregations

SimpleRelationship (org.eclipse.zest.layouts.exampleStructures.SimpleRelationship)4 LayoutBendPoint (org.eclipse.zest.layouts.LayoutBendPoint)3 ArrayList (java.util.ArrayList)2 Point (org.eclipse.swt.graphics.Point)2 SimpleNode (org.eclipse.zest.layouts.exampleStructures.SimpleNode)2 Point (java.awt.Point)1 Iterator (java.util.Iterator)1 List (java.util.List)1 LayoutEntity (org.eclipse.zest.layouts.LayoutEntity)1 LayoutRelationship (org.eclipse.zest.layouts.LayoutRelationship)1