/** * Calculates and returns the preferred size of the input figure. Since in XYLayout the location * of the child should be preserved, the preferred size would be a region which would hold all the * children of the input figure. If no constraint is set, that child is ignored for calculation. * If width and height are not positive, the preferred dimensions of the child are taken. * * @see AbstractLayout#calculatePreferredSize(IFigure, int, int) * @since 2.0 */ protected Dimension calculatePreferredSize(IFigure f, int wHint, int hHint) { Rectangle rect = new Rectangle(); ListIterator children = f.getChildren().listIterator(); while (children.hasNext()) { IFigure child = (IFigure) children.next(); Rectangle r = (Rectangle) constraints.get(child); if (r == null) continue; if (r.width == -1 || r.height == -1) { Dimension preferredSize = child.getPreferredSize(r.width, r.height); r = r.getCopy(); if (r.width == -1) r.width = preferredSize.width; if (r.height == -1) r.height = preferredSize.height; } rect.union(r); } Dimension d = rect.getSize(); Insets insets = f.getInsets(); return new Dimension(d.width + insets.getWidth(), d.height + insets.getHeight()) .union(getBorderPreferredSize(f)); }