private void layoutShrink()

in src/main/java/org/jetbrains/plugins/spotbugs/gui/common/MultiSplitLayout.java [386:489]


	private void layoutShrink(final Split split, final Rectangle bounds) {
		final Rectangle splitBounds = split.getBounds();
		final ListIterator<Node> splitChildren = split.getChildren().listIterator();
		//final Node lastWeightedChild = split.lastWeightedChild();

		if (split.isRowLayout()) {
			int totalWidth = 0;		  // sum of the children's widths
			int minWeightedWidth = 0;	// sum of the weighted childrens' min widths
			int totalWeightedWidth = 0;  // sum of the weighted childrens' widths
			for (final Node splitChild : split.getChildren()) {
				final int nodeWidth = splitChild.getBounds().width;
				final int nodeMinWidth = Math.min(nodeWidth, minimumNodeSize(splitChild).width);
				totalWidth += nodeWidth;
				if (splitChild.getWeight() > 0.0) {
					minWeightedWidth += nodeMinWidth;
					totalWeightedWidth += nodeWidth;
				}
			}

			double x = bounds.getX();
			final double extraWidth = splitBounds.getWidth() - bounds.getWidth();
			double availableWidth = extraWidth;
			final boolean onlyShrinkWeightedComponents = totalWeightedWidth - minWeightedWidth > extraWidth;

			while (splitChildren.hasNext()) {
				final Node splitChild = splitChildren.next();
				final Rectangle splitChildBounds = splitChild.getBounds();
				final double minSplitChildWidth = minimumNodeSize(splitChild).getWidth();
				final double splitChildWeight = onlyShrinkWeightedComponents ? splitChild.getWeight() : splitChildBounds.getWidth() / (double) totalWidth;

				if (!splitChildren.hasNext()) {
					final double newWidth = Math.max(minSplitChildWidth, bounds.getMaxX() - x);
					final Rectangle newSplitChildBounds = boundsWithXandWidth(bounds, x, newWidth);
					layout2(splitChild, newSplitChildBounds);
				} else if (availableWidth > 0.0 && splitChildWeight > 0.0) {
					final double allocatedWidth = Math.rint(splitChildWeight * extraWidth);
					final double oldWidth = splitChildBounds.getWidth();
					final double newWidth = Math.max(minSplitChildWidth, oldWidth - allocatedWidth);
					final Rectangle newSplitChildBounds = boundsWithXandWidth(bounds, x, newWidth);
					layout2(splitChild, newSplitChildBounds);
					availableWidth -= oldWidth - splitChild.getBounds().getWidth();
				} else {
					final double existingWidth = splitChildBounds.getWidth();
					final Rectangle newSplitChildBounds = boundsWithXandWidth(bounds, x, existingWidth);
					layout2(splitChild, newSplitChildBounds);
				}
				x = splitChild.getBounds().getMaxX();
			}
		} else {
			int totalHeight = 0;		  // sum of the children's heights
			int minWeightedHeight = 0;	// sum of the weighted childrens' min heights
			int totalWeightedHeight = 0;  // sum of the weighted childrens' heights
			for (final Node splitChild : split.getChildren()) {
				final int nodeHeight = splitChild.getBounds().height;
				final int nodeMinHeight = Math.min(nodeHeight, minimumNodeSize(splitChild).height);
				totalHeight += nodeHeight;
				if (splitChild.getWeight() > 0.0) {
					minWeightedHeight += nodeMinHeight;
					totalWeightedHeight += nodeHeight;
				}
			}

			double y = bounds.getY();
			final double extraHeight = splitBounds.getHeight() - bounds.getHeight();
			double availableHeight = extraHeight;
			final boolean onlyShrinkWeightedComponents = totalWeightedHeight - minWeightedHeight > extraHeight;

			while (splitChildren.hasNext()) {
				final Node splitChild = splitChildren.next();
				final Rectangle splitChildBounds = splitChild.getBounds();
				final double minSplitChildHeight = minimumNodeSize(splitChild).getHeight();
				final double splitChildWeight = onlyShrinkWeightedComponents ? splitChild.getWeight() : splitChildBounds.getHeight() / (double) totalHeight;

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

		/* The bounds of the Split node root are set to be
		 * big enough to contain all of its children. Since
		 * Leaf children can't be reduced below their
		 * (corresponding java.awt.Component) minimum sizes,
		 * the size of the Split's bounds maybe be larger than
		 * the bounds we were asked to fit within.
		 */
		minimizeSplitBounds(split, bounds);
	}