Package org.eclipse.zest.layouts.dataStructures

Examples of org.eclipse.zest.layouts.dataStructures.InternalNode


  /**
   * Updates the layout locations so the external nodes know about the new locations
   */
  protected void updateLayoutLocations(InternalNode[] nodes) {
    for (int i = 0; i < nodes.length; i++) {
      InternalNode node = nodes[i];
      if (!node.hasPreferredLocation()) {
        node.setLocation(node.getInternalX(), node.getInternalY());

        if ((layout_styles & LayoutStyles.NO_LAYOUT_NODE_RESIZING) != 1) {
          // Only set the size if we are supposed to
          node.setSize(node.getInternalWidth(), node.getInternalHeight());
        }
      }
    }
  }
View Full Code Here


    public InternalComparator(Comparator externalComparator) {
      this.externalComparator = externalComparator;
    }

    public int compare(Object o1, Object o2) {
      InternalNode internalNode1 = (InternalNode) o1;
      InternalNode internalNode2 = (InternalNode) o2;

      return this.externalComparator.compare(internalNode1.getLayoutEntity(), internalNode2.getLayoutEntity());
    }
View Full Code Here

    if (unplacedEntities.size() == 0) {
      return; // no more entities to place
    }
   
    // get the first entity in the list of unplaced entities, find its root, and build this root's tree
    InternalNode layoutEntity = (InternalNode) unplacedEntities.get(0);
    InternalNode rootEntity = findRootObjectRecursive(layoutEntity, new HashSet(), relationships);
        int rootEntityIndex = indexOfInternalNode(entities, rootEntity);
    buildTreeRecursively(rootEntity, rootEntityIndex, 0, entities, relationships);
    roots.add(rootEntity);
   
    // now see which nodes are left to be placed in a tree somewhere
    List unmarkedCopy = new ArrayList(unplacedEntities);
    for (Iterator iter = unmarkedCopy.iterator(); iter.hasNext();) {
            InternalNode tmpEntity = (InternalNode) iter.next();
            int tmpEntityIndex = indexOfInternalNode(entities, tmpEntity);
            boolean isMarked = markedArr[tmpEntityIndex];
       if (isMarked) {
          unplacedEntities.remove(tmpEntity);
      }
View Full Code Here

  /**
   * Finds the root node that can be treated as the root of a tree.
   * The found root node should be one of the unmarked nodes.
   */
  private InternalNode findRootObjectRecursive(InternalNode currentEntity, Set seenAlready, InternalRelationship [] relationshipsToConsider) {
    InternalNode rootEntity = null;
    InternalRelationship rel = findRelationship(currentEntity, AS_DESTINATION, relationshipsToConsider);
    if (rel == null) {
      rootEntity = currentEntity;
    } else {
      InternalNode parentEntity = rel.getSource();
      if (!seenAlready.contains(parentEntity)) {
        seenAlready.add(parentEntity);
        rootEntity = findRootObjectRecursive(parentEntity, seenAlready, relationshipsToConsider);
      } else {
        rootEntity = currentEntity;
View Full Code Here

    // 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 () {          
                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);
    }
  }
View Full Code Here

        seenAlready.add(layoutEntity);
        numDescendentsAndLevel[NUM_LEVELS_INDEX] = Math.max(numDescendentsAndLevel[NUM_LEVELS_INDEX], currentLevel);
        Collection rels = findRelationships(layoutEntity, AS_SOURCE, relationships);
        for (Iterator iter = rels.iterator(); iter.hasNext();) {
            InternalRelationship layoutRel = (InternalRelationship) iter.next();
            InternalNode childEntity = layoutRel.getDestination();
            numDescendentsAndLevel[NUM_DESCENDENTS_INDEX]++;
            getNumDescendentsAndLevelRecursive(childEntity, relationships, seenAlready, numDescendentsAndLevel, currentLevel + 1);
           
        }
    }
View Full Code Here

    Collection rels = findRelationships(layoutEntity, AS_SOURCE, relationships);
   
   
    for (Iterator iter = rels.iterator(); iter.hasNext();) {
      InternalRelationship tmpRel = (InternalRelationship) iter.next();
      InternalNode tmpEntity = tmpRel.getDestination();
            int tmpEntityIndex = indexOfInternalNode(entities, tmpEntity);
      modifyWeightRecursively(tmpEntity, tmpEntityIndex, weight + 1, descendentsSeenSoFar, entities, relationships);
    }
  }
View Full Code Here

    if (children.isEmpty()) {
      result = weights[i];
    } else {
      //TODO: SLOW
            for (Iterator iter = children.iterator(); iter.hasNext();) {
                InternalNode childEntity = (InternalNode) iter.next();
                int childEntityIndex = indexOfInternalNode(entities, childEntity);
                result = Math.max(result, getMaxiumWeightRecursive(childEntity, childEntityIndex, seenAlready, entities));
      }
    }
    return result;
View Full Code Here

    }

    int totalLeafCount = 0;
    double maxWeight = 0;
    for (int i = 0; i < roots.size(); i++) {
      InternalNode rootEntity = (InternalNode) roots.get(i);
            int rootEntityIndex = indexOfInternalNode(entities, rootEntity);
      totalLeafCount = totalLeafCount + getNumberOfLeaves(rootEntity, rootEntityIndex, entities);
      maxWeight = Math.max(maxWeight, getMaxiumWeightRecursive(rootEntity, rootEntityIndex, new HashSet(), entities) + 1.0);
    }
   
    double width = 1.0 / totalLeafCount;
    double height = 1.0 / maxWeight;

    int leafCountSoFar = 0;
   
    //TODO: SLOW!
    for (int i = 0; i < roots.size(); i++) {
      InternalNode rootEntity = (InternalNode) roots.get(i);
            int rootEntityIndex = indexOfInternalNode(entities, rootEntity);
      computePositionRecursively(rootEntity, rootEntityIndex, leafCountSoFar, width, height, new HashSet(), entities);
      leafCountSoFar = leafCountSoFar + getNumberOfLeaves(rootEntity, rootEntityIndex, entities);
    }
  }
View Full Code Here

    int relativeCount = 0;
    List children = childrenLists[i];
    //TODO: Slow
        for (Iterator iter = children.iterator(); iter.hasNext();) {
            InternalNode childEntity = (InternalNode) iter.next();
            int childEntityIndex = indexOfInternalNode(entities, childEntity);
      computePositionRecursively(childEntity, childEntityIndex, relativePosition + relativeCount, width, height, seenAlready, entities);
      relativeCount = relativeCount + getNumberOfLeaves(childEntity, childEntityIndex, entities);
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.zest.layouts.dataStructures.InternalNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.