/** * 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) { if (c == null) { throw new IllegalArgumentException("Null 'c' argument."); } 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() ); }
/** * Arrange with a fixed height and no width constraint. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size of the arrangement. */ protected Size2D arrangeNR(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { RectangleConstraint c1 = constraint.toUnconstrainedHeight(); Size2D size1 = arrange(container, g2, c1); if (constraint.getHeightRange().contains(size1.getHeight())) { return size1; } else { double h = constraint.getHeightRange().constrain(size1.getHeight()); RectangleConstraint c2 = constraint.toFixedHeight(h); return arrange(container, g2, c2); } }
/** * 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); } }
/** * Performs an arrangement with a fixed width and a range for the height. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The container size after the arrangement. */ protected Size2D arrangeFR(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { Size2D size1 = arrangeFN(container, g2, constraint.getWidth()); if (constraint.getHeightRange().contains(size1.getHeight())) { return size1; } else { double h = constraint.getHeightRange().constrain(size1.getHeight()); RectangleConstraint c2 = constraint.toFixedHeight(h); return arrange(container, g2, c2); } }
LengthConstraintType w = cc.getWidthConstraintType(); LengthConstraintType h = cc.getHeightConstraintType(); Size2D contentSize = null; if (w == LengthConstraintType.NONE) { contentSize = arrangeRN(g2, cc.getWidthRange()); contentSize = arrangeRR(g2, cc.getWidthRange(), cc.getHeightRange()); contentSize = arrangeFN(g2, cc.getWidth());
/** * Returns a constraint that matches this one on the width attributes, * but has a fixed height constraint. * * @param height the fixed height. * * @return A new constraint. */ public RectangleConstraint toFixedHeight(double height) { return new RectangleConstraint(this.width, this.widthRange, this.widthConstraintType, height, this.heightRange, LengthConstraintType.FIXED); }
/** * Arrange with a fixed height and a width within a given range. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size of the arrangement. */ protected Size2D arrangeRF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { RectangleConstraint c1 = constraint.toUnconstrainedWidth(); Size2D size1 = arrange(container, g2, c1); if (constraint.getWidthRange().contains(size1.getWidth())) { return size1; } else { double w = constraint.getWidthRange().constrain(size1.getWidth()); RectangleConstraint c2 = constraint.toFixedWidth(w); return arrange(container, g2, c2); } }
public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) { RectangleConstraint contentConstraint = toContentConstraint(constraint); LengthConstraintType w = contentConstraint.getWidthConstraintType(); LengthConstraintType h = contentConstraint.getHeightConstraintType(); Size2D contentSize = null; if (w == LengthConstraintType.NONE) { contentSize = new Size2D(contentConstraint.getWidth(), contentConstraint.getHeight());
RectangleConstraint constraint) { LengthConstraintType w = constraint.getWidthConstraintType(); LengthConstraintType h = constraint.getHeightConstraintType(); if (w == LengthConstraintType.NONE) { if (h == LengthConstraintType.NONE) {
if (constraint.getWidthRange().contains(size1.getWidth())) { if (constraint.getHeightRange().contains(size1.getHeight())) { return size1; double h = constraint.getHeightRange().constrain( size1.getHeight()); RectangleConstraint cc = new RectangleConstraint( size1.getWidth(), h); return arrangeFF(container, g2, cc); if (constraint.getHeightRange().contains(size1.getHeight())) { double w = constraint.getWidthRange().constrain( size1.getWidth()); RectangleConstraint cc = new RectangleConstraint(w, size1.getHeight()); return arrangeFF(container, g2, cc); double w = constraint.getWidthRange().constrain( size1.getWidth()); double h = constraint.getHeightRange().constrain( size1.getHeight()); RectangleConstraint cc = new RectangleConstraint(w, h); return arrangeFF(container, g2, cc);
double[] w = new double[5]; double[] h = new double[5]; w[0] = constraint.getWidth(); if (this.topBlock != null) { RectangleConstraint c1 = new RectangleConstraint(w[0], null, LengthConstraintType.FIXED, 0.0, new Range(0.0, constraint.getHeight()), LengthConstraintType.RANGE); Size2D size = this.topBlock.arrange(g2, c1); RectangleConstraint c2 = new RectangleConstraint(w[0], null, LengthConstraintType.FIXED, 0.0, new Range(0.0, constraint.getHeight() - h[0]), LengthConstraintType.RANGE); Size2D size = this.bottomBlock.arrange(g2, c2); h[1] = size.height; h[2] = constraint.getHeight() - h[1] - h[0]; if (this.leftBlock != null) { RectangleConstraint c3 = new RectangleConstraint(0.0, new Range(0.0, constraint.getWidth()), LengthConstraintType.RANGE, h[2], null, LengthConstraintType.FIXED); RectangleConstraint c4 = new RectangleConstraint(0.0, new Range(0.0, Math.max(constraint.getWidth() - w[2], 0.0)), LengthConstraintType.RANGE, h[2], null, LengthConstraintType.FIXED); w[4] = constraint.getWidth() - w[3] - w[2];
/** * Arranges a container with range constraints for both the horizontal * and vertical. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The size of the container. */ 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.getHeightRange().contains(s1.height)) { return s1; // TODO: we didn't check the width yet } else { RectangleConstraint c = constraint.toFixedHeight( constraint.getHeightRange().getUpperBound() ); return arrangeRF(container, g2, c); } }
RectangleConstraint constraint) { double height = constraint.getHeight() / this.rows; RectangleConstraint bc = constraint.toFixedHeight(height); List blocks = container.getBlocks(); double maxW = 0.0; RectangleConstraint cc = constraint.toFixedWidth(maxW * this.columns); return arrange(container, g2, cc);
RectangleConstraint constraint) { double width = constraint.getWidth() / this.columns; RectangleConstraint bc = constraint.toFixedWidth(width); List blocks = container.getBlocks(); double maxH = 0.0; RectangleConstraint cc = constraint.toFixedHeight(maxH * this.rows); return arrange(container, g2, cc);
/** * Arranges the container with a fixed overall width and height. * * @param container the container (<code>null</code> not permitted). * @param g2 the graphics device. * @param constraint the constraint (<code>null</code> not permitted). * * @return The size following the arrangement. */ protected Size2D arrangeFF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { double width = constraint.getWidth() / this.columns; double height = constraint.getHeight() / this.rows; List blocks = container.getBlocks(); for (int c = 0; c < this.columns; c++) { for (int r = 0; r < this.rows; r++) { int index = r * this.columns + c; if (index >= blocks.size()) { break; } Block b = (Block) blocks.get(index); if (b != null) { b.setBounds(new Rectangle2D.Double(c * width, r * height, width, height)); } } } return new Size2D(this.columns * width, this.rows * height); }
/** * Arranges the contents of the block, within the given constraints, and * returns the block size. * * @param g2 the graphics device. * @param constraint the constraint (<code>null</code> not permitted). * * @return The block size (in Java2D units, never <code>null</code>). */ public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) { Size2D base = new Size2D(getWidth(), getHeight()); return constraint.calculateConstrainedSize(base); }
public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) { RectangleConstraint cc = toContentConstraint(constraint); LengthConstraintType w = cc.getWidthConstraintType(); LengthConstraintType h = cc.getHeightConstraintType(); Size2D contentSize = null; if (w == LengthConstraintType.NONE) { contentSize = arrangeRN(g2, cc.getWidthRange()); contentSize = arrangeRR(g2, cc.getWidthRange(), cc.getHeightRange()); contentSize = arrangeFN(g2, cc.getWidth());
/** * Returns a constraint that matches this one on the height attributes, * but has a fixed width constraint. * * @param width the fixed width. * * @return A new constraint. */ public RectangleConstraint toFixedWidth(double width) { return new RectangleConstraint(width, this.widthRange, LengthConstraintType.FIXED, this.height, this.heightRange, this.heightConstraintType); }