Exemple #1
0
  private void layoutGrow(Split split, Rectangle bounds) {
    Rectangle splitBounds = split.getBounds();
    ListIterator<Node> splitChildren = split.getChildren().listIterator();
    Node lastWeightedChild = split.lastWeightedChild();

    /* Layout the Split's child Nodes' along the X axis.  The bounds
     * of each child will have the same y coordinate and height as the
     * layoutGrow() bounds argument.  Extra width is allocated to the
     * to each child with a non-zero weight:
     *     newWidth = currentWidth + (extraWidth * splitChild.getWeight())
     * Any extraWidth "left over" (that's availableWidth in the loop
     * below) is given to the last child.  Note that Dividers always
     * have a weight of zero, and they're never the last child.
     */
    if (split.isRowLayout()) {
      double x = bounds.getX();
      double extraWidth = bounds.getWidth() - splitBounds.getWidth();
      double availableWidth = extraWidth;

      while (splitChildren.hasNext()) {
        Node splitChild = splitChildren.next();
        Rectangle splitChildBounds = splitChild.getBounds();
        double splitChildWeight = splitChild.getWeight();

        if (!splitChildren.hasNext()) {
          double newWidth = bounds.getMaxX() - x;
          Rectangle newSplitChildBounds = boundsWithXandWidth(bounds, x, newWidth);
          layout2(splitChild, newSplitChildBounds);
        } else if ((availableWidth > 0.0) && (splitChildWeight > 0.0)) {
          double allocatedWidth =
              (splitChild.equals(lastWeightedChild))
                  ? availableWidth
                  : Math.rint(splitChildWeight * extraWidth);
          double newWidth = splitChildBounds.getWidth() + allocatedWidth;
          Rectangle newSplitChildBounds = boundsWithXandWidth(bounds, x, newWidth);
          layout2(splitChild, newSplitChildBounds);
          availableWidth -= allocatedWidth;
        } else {
          double existingWidth = splitChildBounds.getWidth();
          Rectangle newSplitChildBounds = boundsWithXandWidth(bounds, x, existingWidth);
          layout2(splitChild, newSplitChildBounds);
        }
        x = splitChild.getBounds().getMaxX();
      }
    }

    /* Layout the Split's child Nodes' along the Y axis.  The bounds
     * of each child will have the same x coordinate and width as the
     * layoutGrow() bounds argument.  Extra height is allocated to the
     * to each child with a non-zero weight:
     *     newHeight = currentHeight + (extraHeight * splitChild.getWeight())
     * Any extraHeight "left over" (that's availableHeight in the loop
     * below) is given to the last child.  Note that Dividers always
     * have a weight of zero, and they're never the last child.
     */
    else {
      double y = bounds.getY();
      double extraHeight = bounds.getMaxY() - splitBounds.getHeight();
      double availableHeight = extraHeight;

      while (splitChildren.hasNext()) {
        Node splitChild = splitChildren.next();
        Rectangle splitChildBounds = splitChild.getBounds();
        double splitChildWeight = splitChild.getWeight();

        if (!splitChildren.hasNext()) {
          double newHeight = bounds.getMaxY() - y;
          Rectangle newSplitChildBounds = boundsWithYandHeight(bounds, y, newHeight);
          layout2(splitChild, newSplitChildBounds);
        } else if ((availableHeight > 0.0) && (splitChildWeight > 0.0)) {
          double allocatedHeight =
              (splitChild.equals(lastWeightedChild))
                  ? availableHeight
                  : Math.rint(splitChildWeight * extraHeight);
          double newHeight = splitChildBounds.getHeight() + allocatedHeight;
          Rectangle newSplitChildBounds = boundsWithYandHeight(bounds, y, newHeight);
          layout2(splitChild, newSplitChildBounds);
          availableHeight -= allocatedHeight;
        } else {
          double existingHeight = splitChildBounds.getHeight();
          Rectangle newSplitChildBounds = boundsWithYandHeight(bounds, y, existingHeight);
          layout2(splitChild, newSplitChildBounds);
        }
        y = splitChild.getBounds().getMaxY();
      }
    }
  }