Search in sources :

Example 41 with Size2D

use of org.jfree.ui.Size2D in project SIMVA-SoS by SESoS.

the class GridArrangementTest method testGridNotFull_NN.

/**
 * The arrangement should be able to handle less blocks than grid spaces.
 */
@Test
public void testGridNotFull_NN() {
    Block b1 = new EmptyBlock(5, 5);
    BlockContainer c = new BlockContainer(new GridArrangement(2, 3));
    c.add(b1);
    Size2D s = c.arrange(null, RectangleConstraint.NONE);
    assertEquals(15.0, s.getWidth(), EPSILON);
    assertEquals(10.0, s.getHeight(), EPSILON);
}
Also used : Size2D(org.jfree.ui.Size2D) Test(org.junit.Test)

Example 42 with Size2D

use of org.jfree.ui.Size2D in project SIMVA-SoS by SESoS.

the class GridArrangementTest method testNullBlock_FF.

/**
 * The arrangement should be able to handle null blocks in the layout.
 */
@Test
public void testNullBlock_FF() {
    BlockContainer c = new BlockContainer(new GridArrangement(1, 1));
    c.add(null);
    Size2D s = c.arrange(null, new RectangleConstraint(20, 10));
    assertEquals(20.0, s.getWidth(), EPSILON);
    assertEquals(10.0, s.getHeight(), EPSILON);
}
Also used : Size2D(org.jfree.ui.Size2D) Test(org.junit.Test)

Example 43 with Size2D

use of org.jfree.ui.Size2D in project SIMVA-SoS by SESoS.

the class LabelBlock method arrange.

/**
 * 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) {
    g2.setFont(this.font);
    Size2D s = this.label.calculateDimensions(g2);
    return new Size2D(calculateTotalWidth(s.getWidth()), calculateTotalHeight(s.getHeight()));
}
Also used : Size2D(org.jfree.ui.Size2D)

Example 44 with Size2D

use of org.jfree.ui.Size2D in project SIMVA-SoS by SESoS.

the class FlowArrangement method arrangeFN.

/**
 * Arranges the blocks in the container with a fixed width and no height
 * constraint.
 *
 * @param container  the container.
 * @param constraint  the constraint.
 * @param g2  the graphics device.
 *
 * @return The size.
 */
protected Size2D arrangeFN(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) {
    List blocks = container.getBlocks();
    double width = constraint.getWidth();
    double x = 0.0;
    double y = 0.0;
    double maxHeight = 0.0;
    List itemsInRow = new ArrayList();
    for (int i = 0; i < blocks.size(); i++) {
        Block block = (Block) blocks.get(i);
        Size2D size = block.arrange(g2, RectangleConstraint.NONE);
        if (x + size.width <= width) {
            itemsInRow.add(block);
            block.setBounds(new Rectangle2D.Double(x, y, size.width, size.height));
            x = x + size.width + this.horizontalGap;
            maxHeight = Math.max(maxHeight, size.height);
        } else {
            if (itemsInRow.isEmpty()) {
                // place in this row (truncated) anyway
                block.setBounds(new Rectangle2D.Double(x, y, Math.min(size.width, width - x), size.height));
                x = 0.0;
                y = y + size.height + this.verticalGap;
            } else {
                // start new row
                itemsInRow.clear();
                x = 0.0;
                y = y + maxHeight + this.verticalGap;
                maxHeight = size.height;
                block.setBounds(new Rectangle2D.Double(x, y, Math.min(size.width, width), size.height));
                x = size.width + this.horizontalGap;
                itemsInRow.add(block);
            }
        }
    }
    return new Size2D(constraint.getWidth(), y + maxHeight);
}
Also used : Size2D(org.jfree.ui.Size2D) ArrayList(java.util.ArrayList) Rectangle2D(java.awt.geom.Rectangle2D) List(java.util.List) ArrayList(java.util.ArrayList)

Example 45 with Size2D

use of org.jfree.ui.Size2D in project SIMVA-SoS by SESoS.

the class GridArrangement method arrangeNF.

/**
 * Arrange with a fixed height and no constraint for the width.
 *
 * @param container  the container.
 * @param g2  the graphics device.
 * @param constraint  the constraint.
 *
 * @return The size of the arrangement.
 */
protected Size2D arrangeNF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) {
    double height = constraint.getHeight() / this.rows;
    RectangleConstraint bc = constraint.toFixedHeight(height);
    List blocks = container.getBlocks();
    double maxW = 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);
                maxW = Math.max(maxW, s.getWidth());
            }
        }
    }
    RectangleConstraint cc = constraint.toFixedWidth(maxW * this.columns);
    return arrange(container, g2, cc);
}
Also used : Size2D(org.jfree.ui.Size2D) List(java.util.List)

Aggregations

Size2D (org.jfree.ui.Size2D)62 Test (org.junit.Test)19 Rectangle2D (java.awt.geom.Rectangle2D)18 Range (org.jfree.data.Range)14 List (java.util.List)10 RectangleConstraint (org.jfree.chart.block.RectangleConstraint)8 RectangleEdge (org.jfree.ui.RectangleEdge)5 Graphics2D (java.awt.Graphics2D)4 BufferedImage (java.awt.image.BufferedImage)4 ArrayList (java.util.ArrayList)4 LengthConstraintType (org.jfree.chart.block.LengthConstraintType)4 RectangleInsets (org.jfree.ui.RectangleInsets)4 FontMetrics (java.awt.FontMetrics)3 Shape (java.awt.Shape)3 Point2D (java.awt.geom.Point2D)2 BlockParams (org.jfree.chart.block.BlockParams)2 EntityBlockResult (org.jfree.chart.block.EntityBlockResult)2 G2TextMeasurer (org.jfree.text.G2TextMeasurer)2 Arc2D (java.awt.geom.Arc2D)1 Iterator (java.util.Iterator)1