コード例 #1
0
  /**
   * Returns the right most child of parent
   *
   * @param parent
   * @return the right most child of parent given.
   */
  private GXMoreThanNode getRightMostChild(GXMoreThanNode parent) {
    GXMoreThanNode rightMost = parent.getChildren().get(0);

    // run through children
    for (GXMoreThanNode child : parent.getChildren()) {
      if (child.getX() < rightMost.getX()) {
        rightMost = child;
      }
    }
    return rightMost;
  }
コード例 #2
0
  /**
   * Lays out row with respect to it's children.
   *
   * @param yLocation - the vertical location to start placing the nodes.
   * @param row - the row who's nodes we'd like to lay out.
   */
  private void placeRow(List<GXMoreThanNode> row, int yLocation) {
    List<GXMoreThanNode> childlessStrand = new ArrayList<GXMoreThanNode>();
    GXMoreThanNode parentLeft = null;

    // for each parent in this parent row
    for (int j = 0; j < row.size(); j++) {
      GXMoreThanNode parentRight = row.get(j);
      // if the node has children
      if (!parentRight.getChildren().isEmpty()) {

        // place the node in the center above his children
        int parentX = 0;
        for (GXMoreThanNode child : parentRight.getChildren()) {
          parentX += child.getX();
        }
        parentX /= parentRight.getChildren().size();
        parentRight.setLocation(parentX, yLocation);

        // and layout the childless strand
        if (!childlessStrand.isEmpty()) {
          placeChildless(childlessStrand, parentLeft, parentRight, yLocation);
          childlessStrand.clear();
        }
        parentLeft = parentRight;

      } else { // accumulate the childless nodes
        childlessStrand.add(parentRight);
      }
    }

    // place childless who are extra on the right. as in did not get taken care of when
    // the parents were laid out.
    if (!childlessStrand.isEmpty()) {
      placeChildless(childlessStrand, parentLeft, null, yLocation);
    }
  }
コード例 #3
0
 /**
  * Shifts the given tree by the shift factor given to the right.
  *
  * @param root - root of tree to shift
  * @param shift - factor to shirt by
  */
 private void shiftTree(GXMoreThanNode root, int shift) {
   root.setLocation(root.getX() + shift, root.getY());
   for (GXMoreThanNode child : root.getChildren()) {
     shiftTree(child, shift);
   }
 }