/**
  * Shifts the trees right of mark node
  *
  * @param mark to shift from
  * @param shift - factor by which to move right by.
  */
 private void shiftTreesRightOfMark(GXMoreThanNode mark, int shift) {
   mark.setLocation(mark.getX() + shift, mark.getY());
   GXMoreThanNode leftMostChild = getRightMostChild(mark);
   List<GXMoreThanNode> treeRoots =
       leftMostChild
           .getRow()
           .subList(leftMostChild.getRow().indexOf(leftMostChild), leftMostChild.getRow().size());
   for (GXMoreThanNode root : treeRoots) {
     shiftTree(root, shift);
   }
 }
  /**
   * 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);
    }
  }
 /**
  * Places the list of nodes horizontally at the given point and spaced on horizontally by given
  * spacing.
  *
  * @param strand - list of nodes to be laid out.
  * @param x - location to begin the placing
  * @param y - vertical location to lay out the entire list.
  * @param spacing the horizontal spacing between nodes.
  */
 private void placeStrand(List<GXMoreThanNode> strand, int x, int y, int spacing) {
   for (GXMoreThanNode item : strand) {
     item.setLocation(x, y);
     x += spacing;
   }
 }
 /**
  * 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);
   }
 }