/** * Arranges the block with a range constraint on the width, and no constraint on the height. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * @return The size following the arrangement. */ protected Size2D arrangeRN( BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { // first arrange without constraints, then see if the width fits // within the required range...if not, call arrangeFN() at max width Size2D s1 = arrangeNN(container, g2); if (constraint.getWidthRange().contains(s1.width)) { return s1; } else { RectangleConstraint c = constraint.toFixedWidth(constraint.getWidthRange().getUpperBound()); return arrangeFN(container, g2, c); } }
/** * Arranges the blocks in the container with a range constraint on the width and a fixed height. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * @return The size following the arrangement. */ protected Size2D arrangeRF( BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { Size2D s = arrangeNF(container, g2, constraint); if (constraint.getWidthRange().contains(s.width)) { return s; } else { RectangleConstraint c = constraint.toFixedWidth(constraint.getWidthRange().constrain(s.getWidth())); return arrangeFF(container, g2, c); } }
/** * Arranges the blocks with the overall width and height to fit within specified ranges. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * @return The size after the arrangement. */ protected Size2D arrangeRR( BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { // first arrange without constraints, and see if this fits within // the required ranges... Size2D s1 = arrangeNN(container, g2); if (constraint.getWidthRange().contains(s1.width)) { return s1; // TODO: we didn't check the height yet } else { RectangleConstraint c = constraint.toFixedWidth(constraint.getWidthRange().getUpperBound()); return arrangeFR(container, g2, c); } }
/** * Returns a constraint for the content of this block that will result in the bounds of the block * matching the specified constraint. * * @param c the outer constraint (<code>null</code> not permitted). * @return The content constraint. */ protected RectangleConstraint toContentConstraint(RectangleConstraint c) { ParamChecks.nullNotPermitted(c, "c"); if (c.equals(RectangleConstraint.NONE)) { return c; } double w = c.getWidth(); Range wr = c.getWidthRange(); double h = c.getHeight(); Range hr = c.getHeightRange(); double ww = trimToContentWidth(w); double hh = trimToContentHeight(h); Range wwr = trimToContentWidth(wr); Range hhr = trimToContentHeight(hr); return new RectangleConstraint( ww, wwr, c.getWidthConstraintType(), hh, hhr, c.getHeightConstraintType()); }
/** * Arranges the items in the specified container, subject to the given constraint. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * @return The block size. */ @Override public Size2D arrange(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { RectangleConstraint contentConstraint = container.toContentConstraint(constraint); Size2D contentSize = null; LengthConstraintType w = contentConstraint.getWidthConstraintType(); LengthConstraintType h = contentConstraint.getHeightConstraintType(); if (w == LengthConstraintType.NONE) { if (h == LengthConstraintType.NONE) { contentSize = arrangeNN(container, g2); } else if (h == LengthConstraintType.FIXED) { throw new RuntimeException("Not implemented."); } else if (h == LengthConstraintType.RANGE) { throw new RuntimeException("Not implemented."); } } else if (w == LengthConstraintType.FIXED) { if (h == LengthConstraintType.NONE) { contentSize = arrangeFN(container, g2, constraint.getWidth()); } else if (h == LengthConstraintType.FIXED) { contentSize = arrangeFF(container, g2, constraint); } else if (h == LengthConstraintType.RANGE) { contentSize = arrangeFR(container, g2, constraint); } } else if (w == LengthConstraintType.RANGE) { if (h == LengthConstraintType.NONE) { throw new RuntimeException("Not implemented."); } else if (h == LengthConstraintType.FIXED) { throw new RuntimeException("Not implemented."); } else if (h == LengthConstraintType.RANGE) { contentSize = arrangeRR(container, constraint.getWidthRange(), constraint.getHeightRange(), g2); } } return new Size2D( container.calculateTotalWidth(contentSize.getWidth()), container.calculateTotalHeight(contentSize.getHeight())); }