org.jfree.ui.Size2D Java Examples

The following examples show how to use org.jfree.ui.Size2D. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GridArrangement.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Arrange with a fixed width and a height 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 arrangeFR(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);
    }
}
 
Example #2
Source File: GridArrangement.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Arrange with a fixed width and a height within a given range.
 *
 * @param container  the container.
 * @param g2  the graphics device.
 * @param constraint  the constraint.
 *
 * @return The size of the arrangement.
 */
protected Size2D arrangeFN(BlockContainer container, Graphics2D g2,
                           RectangleConstraint constraint) {

    double width = constraint.getWidth() / this.columns;
    RectangleConstraint bc = constraint.toFixedWidth(width);
    List blocks = container.getBlocks();
    double maxH = 0.0;
    for (int r = 0; r < this.rows; r++) {
        for (int c = 0; c < this.columns; c++) {
            int index = r * this.columns + c;
            if (index >= blocks.size()) {
                break;
            }
            Block b = (Block) blocks.get(index);
            if (b != null) {
                Size2D s = b.arrange(g2, bc);
                maxH = Math.max(maxH, s.getHeight());
            }
        }
    }
    RectangleConstraint cc = constraint.toFixedHeight(maxH * this.rows);
    return arrange(container, g2, cc);
}
 
Example #3
Source File: GridArrangement.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #4
Source File: GridArrangement.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #5
Source File: FlowArrangement.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Arranges the block with a range constraint on the width, and no
 * constraint on the height.
 *
 * @param container  the container.
 * @param constraint  the constraint.
 * @param g2  the graphics device.
 *
 * @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);
    }
}
 
Example #6
Source File: LegendTitle.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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>).
 */
@Override
public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) {
    Size2D result = new Size2D();
    fetchLegendItems();
    if (this.items.isEmpty()) {
        return result;
    }
    BlockContainer container = this.wrapper;
    if (container == null) {
        container = this.items;
    }
    RectangleConstraint c = toContentConstraint(constraint);
    Size2D size = container.arrange(g2, c);
    result.height = calculateTotalHeight(size.height);
    result.width = calculateTotalWidth(size.width);
    return result;
}
 
Example #7
Source File: FlowArrangement.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Arranges the blocks with the overall width and height to fit within 
 * specified ranges.
 * 
 * @param container  the container.
 * @param constraint  the constraint.
 * @param g2  the graphics device.
 * 
 * @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);
    }
}
 
Example #8
Source File: LegendTitle.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * 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>).
 */
@Override
public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) {
    Size2D result = new Size2D();
    fetchLegendItems();
    if (this.items.isEmpty()) {
        return result;
    }
    BlockContainer container = this.wrapper;
    if (container == null) {
        container = this.items;
    }
    RectangleConstraint c = toContentConstraint(constraint);
    Size2D size = container.arrange(g2, c);
    result.height = calculateTotalHeight(size.height);
    result.width = calculateTotalWidth(size.width);
    return result;
}
 
Example #9
Source File: FlowArrangement.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Arranges the block with a range constraint on the width, and no
 * constraint on the height.
 *
 * @param container  the container.
 * @param constraint  the constraint.
 * @param g2  the graphics device.
 *
 * @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);
    }
}
 
Example #10
Source File: FlowArrangement.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Arranges the block with a range constraint on the width, and no
 * constraint on the height.
 *
 * @param container  the container.
 * @param constraint  the constraint.
 * @param g2  the graphics device.
 *
 * @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);
    }
}
 
Example #11
Source File: GridArrangement.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Arrange with a fixed width and no height constraint.
 *
 * @param container  the container.
 * @param constraint  the constraint.
 * @param g2  the graphics device.
 *
 * @return The size of the arrangement.
 */
protected Size2D arrangeRN(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);
    }
}
 
Example #12
Source File: GridArrangement.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #13
Source File: LegendTitle.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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>).
 */
@Override
public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) {
    Size2D result = new Size2D();
    fetchLegendItems();
    if (this.items.isEmpty()) {
        return result;
    }
    BlockContainer container = this.wrapper;
    if (container == null) {
        container = this.items;
    }
    RectangleConstraint c = toContentConstraint(constraint);
    Size2D size = container.arrange(g2, c);
    result.height = calculateTotalHeight(size.height);
    result.width = calculateTotalWidth(size.width);
    return result;
}
 
Example #14
Source File: GridArrangementTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The arrangement should be able to handle null blocks in the layout.
 */
@Test
public void testNullBlock_FN() {
    BlockContainer c = new BlockContainer(new GridArrangement(1, 1));
    c.add(null);
    Size2D s = c.arrange(null, RectangleConstraint.NONE.toFixedWidth(10));
    assertEquals(10.0, s.getWidth(), EPSILON);
    assertEquals(0.0, s.getHeight(), EPSILON);
}
 
Example #15
Source File: GridArrangementTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test arrangement with a fixed width and no height constraint.
 */
@Test
public void testFN() {
    BlockContainer c = createTestContainer1();
    RectangleConstraint constraint = new RectangleConstraint(100.0, null,
            LengthConstraintType.FIXED, 0.0, null,
            LengthConstraintType.NONE);
    Size2D s = c.arrange(null, constraint);
    assertEquals(100.0, s.width, EPSILON);
    assertEquals(33.0, s.height, EPSILON);
}
 
Example #16
Source File: ColumnArrangement.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Arranges the blocks without any constraints.  This puts all blocks
 * into a single column.
 *
 * @param container  the container.
 * @param g2  the graphics device.
 *
 * @return The size after the arrangement.
 */
protected Size2D arrangeNN(BlockContainer container, Graphics2D g2) {
    double y = 0.0;
    double height = 0.0;
    double maxWidth = 0.0;
    List blocks = container.getBlocks();
    int blockCount = blocks.size();
    if (blockCount > 0) {
        Size2D[] sizes = new Size2D[blocks.size()];
        for (int i = 0; i < blocks.size(); i++) {
            Block block = (Block) blocks.get(i);
            sizes[i] = block.arrange(g2, RectangleConstraint.NONE);
            height = height + sizes[i].getHeight();
            maxWidth = Math.max(sizes[i].width, maxWidth);
            block.setBounds(
                new Rectangle2D.Double(
                    0.0, y, sizes[i].width, sizes[i].height
                )
            );
            y = y + sizes[i].height + this.verticalGap;
        }
        if (blockCount > 1) {
            height = height + this.verticalGap * (blockCount - 1);
        }
        if (this.horizontalAlignment != HorizontalAlignment.LEFT) {
            for (int i = 0; i < blocks.size(); i++) {
                //Block b = (Block) blocks.get(i);
                if (this.horizontalAlignment
                        == HorizontalAlignment.CENTER) {
                    //TODO: shift block right by half
                }
                else if (this.horizontalAlignment
                        == HorizontalAlignment.RIGHT) {
                    //TODO: shift block over to right
                }
            }
        }
    }
    return new Size2D(maxWidth, height);
}
 
Example #17
Source File: CategoryAxis.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A utility method for determining the height of a text block.
 *
 * @param block  the text block.
 * @param position  the label position.
 * @param g2  the graphics device.
 *
 * @return The height.
 */
protected double calculateTextBlockHeight(TextBlock block,
        CategoryLabelPosition position, Graphics2D g2) {
    RectangleInsets insets = getTickLabelInsets();
    Size2D size = block.calculateDimensions(g2);
    Rectangle2D box = new Rectangle2D.Double(0.0, 0.0, size.getWidth(),
            size.getHeight());
    Shape rotatedBox = ShapeUtilities.rotateShape(box, position.getAngle(),
            0.0f, 0.0f);
    double h = rotatedBox.getBounds2D().getHeight()
               + insets.getTop() + insets.getBottom();
    return h;
}
 
Example #18
Source File: GridArrangementTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * The arrangement should be able to handle null blocks in the layout.
 */
@Test
public void testNullBlock_NN() {
    BlockContainer c = new BlockContainer(new GridArrangement(1, 1));
    c.add(null);
    Size2D s = c.arrange(null, RectangleConstraint.NONE);
    assertEquals(0.0, s.getWidth(), EPSILON);
    assertEquals(0.0, s.getHeight(), EPSILON);
}
 
Example #19
Source File: JFreeChart.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a rectangle that is aligned to the frame.
 *
 * @param dimensions  the dimensions for the rectangle.
 * @param frame  the frame to align to.
 * @param hAlign  the horizontal alignment.
 * @param vAlign  the vertical alignment.
 *
 * @return A rectangle.
 */
private Rectangle2D createAlignedRectangle2D(Size2D dimensions,
        Rectangle2D frame, HorizontalAlignment hAlign,
        VerticalAlignment vAlign) {
    double x = Double.NaN;
    double y = Double.NaN;
    if (hAlign == HorizontalAlignment.LEFT) {
        x = frame.getX();
    }
    else if (hAlign == HorizontalAlignment.CENTER) {
        x = frame.getCenterX() - (dimensions.width / 2.0);
    }
    else if (hAlign == HorizontalAlignment.RIGHT) {
        x = frame.getMaxX() - dimensions.width;
    }
    if (vAlign == VerticalAlignment.TOP) {
        y = frame.getY();
    }
    else if (vAlign == VerticalAlignment.CENTER) {
        y = frame.getCenterY() - (dimensions.height / 2.0);
    }
    else if (vAlign == VerticalAlignment.BOTTOM) {
        y = frame.getMaxY() - dimensions.height;
    }

    return new Rectangle2D.Double(x, y, dimensions.width,
            dimensions.height);
}
 
Example #20
Source File: GridArrangementTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test arrangement with a range for the width and no height constraint.
 */
@Test
public void testRN() {
    BlockContainer c = createTestContainer1();
    RectangleConstraint constraint = RectangleConstraint.NONE.toRangeWidth(
            new Range(40.0, 60.0));
    Size2D s = c.arrange(null, constraint);
    assertEquals(60.0, s.width, EPSILON);
    assertEquals(33.0, s.height, EPSILON);
}
 
Example #21
Source File: JFreeChart.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a rectangle that is aligned to the frame.
 * 
 * @param dimensions
 * @param frame
 * @param hAlign
 * @param vAlign
 * 
 * @return A rectangle.
 */
private Rectangle2D createAlignedRectangle2D(Size2D dimensions, 
        Rectangle2D frame, HorizontalAlignment hAlign, 
        VerticalAlignment vAlign) {
    double x = Double.NaN;
    double y = Double.NaN;
    if (hAlign == HorizontalAlignment.LEFT) {
        x = frame.getX();   
    }
    else if (hAlign == HorizontalAlignment.CENTER) {
        x = frame.getCenterX() - (dimensions.width / 2.0);   
    }
    else if (hAlign == HorizontalAlignment.RIGHT) {
        x = frame.getMaxX() - dimensions.width;   
    }
    if (vAlign == VerticalAlignment.TOP) {
        y = frame.getY();   
    }
    else if (vAlign == VerticalAlignment.CENTER) {
        y = frame.getCenterY() - (dimensions.height / 2.0);   
    }
    else if (vAlign == VerticalAlignment.BOTTOM) {
        y = frame.getMaxY() - dimensions.height;   
    }
    
    return new Rectangle2D.Double(x, y, dimensions.width, 
            dimensions.height);
}
 
Example #22
Source File: CenterArrangement.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #23
Source File: ShortTextTitle.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Arranges the content for this title assuming a range constraint for the
 * width and no bounds on the height, and returns the required size.
 *
 * @param g2  the graphics target.
 * @param widthRange  the range for the width.
 *
 * @return The content size.
 */
@Override
protected Size2D arrangeRN(Graphics2D g2, Range widthRange) {
    Size2D s = arrangeNN(g2);
    if (widthRange.contains(s.getWidth())) {
        return s;
    }
    double ww = widthRange.constrain(s.getWidth());
    return arrangeFN(g2, ww);
}
 
Example #24
Source File: TextBlock.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws the text block, aligning it with the specified anchor point and 
 * rotating it about the specified rotation point.
 * 
 * @param g2  the graphics device.
 * @param anchorX  the x-coordinate for the anchor point.
 * @param anchorY  the y-coordinate for the anchor point.
 * @param anchor  the point on the text block that is aligned to the 
 *                anchor point.
 * @param rotateX  the x-coordinate for the rotation point.
 * @param rotateY  the x-coordinate for the rotation point.
 * @param angle  the rotation (in radians).
 */
public void draw(final Graphics2D g2,
                 final float anchorX, final float anchorY, 
                 final TextBlockAnchor anchor,
                 final float rotateX, final float rotateY, 
                 final double angle) {

    final Size2D d = calculateDimensions(g2);
    final float[] offsets = calculateOffsets(anchor, d.getWidth(), 
            d.getHeight());
    final Iterator iterator = this.lines.iterator();
    float yCursor = 0.0f;
    while (iterator.hasNext()) {
        TextLine line = (TextLine) iterator.next();
        Size2D dimension = line.calculateDimensions(g2);
        float lineOffset = 0.0f;
        if (this.lineAlignment == HorizontalAlignment.CENTER) {
            lineOffset = (float) (d.getWidth() - dimension.getWidth()) 
                / 2.0f;   
        }
        else if (this.lineAlignment == HorizontalAlignment.RIGHT) {
            lineOffset = (float) (d.getWidth() - dimension.getWidth());   
        }
        line.draw(
            g2, anchorX + offsets[0] + lineOffset, anchorY + offsets[1] + yCursor,
            TextAnchor.TOP_LEFT, rotateX, rotateY, angle
        );
        yCursor = yCursor + (float) dimension.getHeight();
    }
    
}
 
Example #25
Source File: FlowArrangement.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Arranges the blocks without any constraints.  This puts all blocks
 * into a single row.
 *
 * @param container  the container.
 * @param g2  the graphics device.
 *
 * @return The size after the arrangement.
 */
protected Size2D arrangeNN(BlockContainer container, Graphics2D g2) {
    double x = 0.0;
    double width = 0.0;
    double maxHeight = 0.0;
    List blocks = container.getBlocks();
    int blockCount = blocks.size();
    if (blockCount > 0) {
        Size2D[] sizes = new Size2D[blocks.size()];
        for (int i = 0; i < blocks.size(); i++) {
            Block block = (Block) blocks.get(i);
            sizes[i] = block.arrange(g2, RectangleConstraint.NONE);
            width = width + sizes[i].getWidth();
            maxHeight = Math.max(sizes[i].height, maxHeight);
            block.setBounds(
                new Rectangle2D.Double(
                    x, 0.0, sizes[i].width, sizes[i].height
                )
            );
            x = x + sizes[i].width + this.horizontalGap;
        }
        if (blockCount > 1) {
            width = width + this.horizontalGap * (blockCount - 1);
        }
        if (this.verticalAlignment != VerticalAlignment.TOP) {
            for (int i = 0; i < blocks.size(); i++) {
                //Block b = (Block) blocks.get(i);
                if (this.verticalAlignment == VerticalAlignment.CENTER) {
                    //TODO: shift block down by half
                }
                else if (this.verticalAlignment
                        == VerticalAlignment.BOTTOM) {
                    //TODO: shift block down to bottom
                }
            }
        }
    }
    return new Size2D(width, maxHeight);
}
 
Example #26
Source File: CenterArrangement.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Arranges the blocks in the container with a fixed width and no height
 * constraint.
 *
 * @param container  the container.
 * @param g2  the graphics device.
 * @param constraint  the constraint.
 *
 * @return The size.
 */
protected Size2D arrangeFN(BlockContainer container, Graphics2D g2,
                           RectangleConstraint constraint) {

    List blocks = container.getBlocks();
    Block b = (Block) blocks.get(0);
    Size2D s = b.arrange(g2, RectangleConstraint.NONE);
    double width = constraint.getWidth();
    Rectangle2D bounds = new Rectangle2D.Double((width - s.width) / 2.0,
            0.0, s.width, s.height);
    b.setBounds(bounds);
    return new Size2D((width - s.width) / 2.0, s.height);
}
 
Example #27
Source File: CenterArrangement.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #28
Source File: BorderArrangement.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #29
Source File: GridArrangementTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Test arrangement with a range for the width and a fixed height.
 */
@Test
public void testRF() {
    BlockContainer c = createTestContainer1();
    RectangleConstraint constraint = new RectangleConstraint(new Range(40.0,
            60.0), 100.0);
    Size2D s = c.arrange(null, constraint);
    assertEquals(60.0, s.width, EPSILON);
    assertEquals(100.0, s.height, EPSILON);
}
 
Example #30
Source File: GridArrangementTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Test arrangement with no constraints.
 */
@Test
public void testNN() {
    BlockContainer c = createTestContainer1();
    Size2D s = c.arrange(null, RectangleConstraint.NONE);
    assertEquals(90.0, s.width, EPSILON);
    assertEquals(33.0, s.height, EPSILON);
}