Search in sources :

Example 21 with Size2D

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

the class CenterArrangement method arrangeFN.

/**
 * 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);
}
Also used : Size2D(org.jfree.ui.Size2D) Rectangle2D(java.awt.geom.Rectangle2D) List(java.util.List)

Example 22 with Size2D

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

the class BorderArrangementTest method testBugX.

/**
 * This test is for a particular bug that arose just prior to the release
 * of JFreeChart 1.0.10.  A BorderArrangement with LEFT, CENTRE and RIGHT
 * blocks that is too wide, by default, for the available space, wasn't
 * shrinking the centre block as expected.
 */
@Test
public void testBugX() {
    RectangleConstraint constraint = new RectangleConstraint(new Range(0.0, 200.0), new Range(0.0, 100.0));
    BlockContainer container = new BlockContainer(new BorderArrangement());
    BufferedImage image = new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    container.add(new EmptyBlock(10.0, 6.0), RectangleEdge.LEFT);
    container.add(new EmptyBlock(20.0, 6.0), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(30.0, 6.0));
    Size2D size = container.arrange(g2, constraint);
    assertEquals(60.0, size.width, EPSILON);
    assertEquals(6.0, size.height, EPSILON);
    container.clear();
    container.add(new EmptyBlock(10.0, 6.0), RectangleEdge.LEFT);
    container.add(new EmptyBlock(20.0, 6.0), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(300.0, 6.0));
    size = container.arrange(g2, constraint);
    assertEquals(200.0, size.width, EPSILON);
    assertEquals(6.0, size.height, EPSILON);
}
Also used : Size2D(org.jfree.ui.Size2D) Range(org.jfree.data.Range) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) Test(org.junit.Test)

Example 23 with Size2D

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

the class BorderArrangementTest method testSizingWithWidthConstraint.

/**
 * Run some checks on sizing when there is a fixed width constraint.
 */
public void testSizingWithWidthConstraint() {
    RectangleConstraint constraint = new RectangleConstraint(10.0, new Range(10.0, 10.0), LengthConstraintType.FIXED, 0.0, new Range(0.0, 0.0), LengthConstraintType.NONE);
    BlockContainer container = new BlockContainer(new BorderArrangement());
    BufferedImage image = new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    // TBLRC
    // 00001 - center item only
    container.add(new EmptyBlock(5.0, 6.0));
    Size2D size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(6.0, size.height, EPSILON);
    container.clear();
    container.add(new EmptyBlock(15.0, 16.0));
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(16.0, size.height, EPSILON);
    // TBLRC
    // 00010 - right item only
    container.clear();
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(45.6, size.height, EPSILON);
    // TBLRC
    // 00011 - right and center items
    container.clear();
    container.add(new EmptyBlock(7.0, 20.0));
    container.add(new EmptyBlock(8.0, 45.6), RectangleEdge.RIGHT);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(45.6, size.height, EPSILON);
    // TBLRC
    // 00100 - left item only
    container.clear();
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(45.6, size.height, EPSILON);
    // TBLRC
    // 00101 - left and center items
    container.clear();
    container.add(new EmptyBlock(10.0, 20.0));
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(45.6, size.height, EPSILON);
    // TBLRC
    // 00110 - left and right items
    container.clear();
    container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(45.6, size.height, EPSILON);
    // TBLRC
    // 00111 - left, right and center items
    container.clear();
    container.add(new EmptyBlock(10.0, 20.0));
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
    container.add(new EmptyBlock(5.4, 3.2), RectangleEdge.RIGHT);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(45.6, size.height, EPSILON);
    // TBLRC
    // 01000 - bottom item only
    container.clear();
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(45.6, size.height, EPSILON);
    // TBLRC
    // 01001 - bottom and center only
    container.clear();
    container.add(new EmptyBlock(10.0, 20.0));
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(65.6, size.height, EPSILON);
    // TBLRC
    // 01010 - bottom and right only
    container.clear();
    container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(65.6, size.height, EPSILON);
    // TBLRC
    // 01011 - bottom, right and center
    container.clear();
    container.add(new EmptyBlock(21.0, 12.3));
    container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(65.6, size.height, EPSILON);
    // TBLRC
    // 01100
    container.clear();
    container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(65.6, size.height, EPSILON);
    // TBLRC
    // 01101 - bottom, left and center
    container.clear();
    container.add(new EmptyBlock(21.0, 12.3));
    container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(65.6, size.height, EPSILON);
    // TBLRC
    // 01110 - bottom. left and right
    container.clear();
    container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(65.6, size.height, EPSILON);
    // TBLRC
    // 01111
    container.clear();
    container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
    container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
    container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(9.0, 10.0));
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(14.0, size.height, EPSILON);
    // TBLRC
    // 10000 - top item only
    container.clear();
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(45.6, size.height, EPSILON);
    // TBLRC
    // 10001 - top and center only
    container.clear();
    container.add(new EmptyBlock(10.0, 20.0));
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(65.6, size.height, EPSILON);
    // TBLRC
    // 10010 - right and top only
    container.clear();
    container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(65.6, size.height, EPSILON);
    // TBLRC
    // 10011 - top, right and center
    container.clear();
    container.add(new EmptyBlock(21.0, 12.3));
    container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(65.6, size.height, EPSILON);
    // TBLRC
    // 10100 - top and left only
    container.clear();
    container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(65.6, size.height, EPSILON);
    // TBLRC
    // 10101 - top, left and center
    container.clear();
    container.add(new EmptyBlock(21.0, 12.3));
    container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(65.6, size.height, EPSILON);
    // TBLRC
    // 10110 - top, left and right
    container.clear();
    container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(65.6, size.height, EPSILON);
    // TBLRC
    // 10111
    container.clear();
    container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
    container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
    container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(9.0, 10.0));
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(12.0, size.height, EPSILON);
    // TBLRC
    // 11000 - top and bottom only
    container.clear();
    container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(65.6, size.height, EPSILON);
    // TBLRC
    // 11001
    container.clear();
    container.add(new EmptyBlock(21.0, 12.3));
    container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(77.9, size.height, EPSILON);
    // TBLRC
    // 11010 - top, bottom and right
    container.clear();
    container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(77.9, size.height, EPSILON);
    // TBLRC
    // 11011
    container.clear();
    container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
    container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
    container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(9.0, 10.0));
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(16.0, size.height, EPSILON);
    // TBLRC
    // 11100
    container.clear();
    container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.LEFT);
    container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
    container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(77.9, size.height, EPSILON);
    // TBLRC
    // 11101
    container.clear();
    container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
    container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
    container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
    container.add(new EmptyBlock(9.0, 10.0));
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(16.0, size.height, EPSILON);
    // TBLRC
    // 11110
    container.clear();
    container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
    container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
    container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
    container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(14.0, size.height, EPSILON);
    // TBLRC
    // 11111 - all
    container.clear();
    container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
    container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
    container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
    container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(9.0, 10.0));
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(16.0, size.height, EPSILON);
    // TBLRC
    // 00000 - no items
    container.clear();
    size = container.arrange(g2, constraint);
    assertEquals(10.0, size.width, EPSILON);
    assertEquals(0.0, size.height, EPSILON);
}
Also used : Size2D(org.jfree.ui.Size2D) Range(org.jfree.data.Range) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 24 with Size2D

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

the class DialValueIndicator method draw.

/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been
 * set to this window before this method is called.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle (<code>null</code> not permitted).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {
    // work out the anchor point
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius);
    Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();
    // the indicator bounds is calculated from the templateValue (which
    // determines the minimum size), the maxTemplateValue (which, if
    // specified, provides a maximum size) and the actual value
    FontMetrics fm = g2.getFontMetrics(this.font);
    double value = plot.getValue(this.datasetIndex);
    String valueStr = this.formatter.format(value);
    Rectangle2D valueBounds = TextUtilities.getTextBounds(valueStr, g2, fm);
    // calculate the bounds of the template value
    String s = this.formatter.format(this.templateValue);
    Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm);
    double minW = tb.getWidth();
    double minH = tb.getHeight();
    double maxW = Double.MAX_VALUE;
    double maxH = Double.MAX_VALUE;
    if (this.maxTemplateValue != null) {
        s = this.formatter.format(this.maxTemplateValue);
        tb = TextUtilities.getTextBounds(s, g2, fm);
        maxW = Math.max(tb.getWidth(), minW);
        maxH = Math.max(tb.getHeight(), minH);
    }
    double w = fixToRange(valueBounds.getWidth(), minW, maxW);
    double h = fixToRange(valueBounds.getHeight(), minH, maxH);
    // align this rectangle to the frameAnchor
    Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(w, h), pt.getX(), pt.getY(), this.frameAnchor);
    // add the insets
    Rectangle2D fb = this.insets.createOutsetRectangle(bounds);
    // draw the background
    g2.setPaint(this.backgroundPaint);
    g2.fill(fb);
    // draw the border
    g2.setStroke(this.outlineStroke);
    g2.setPaint(this.outlinePaint);
    g2.draw(fb);
    // now find the text anchor point
    Shape savedClip = g2.getClip();
    g2.clip(fb);
    Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor);
    g2.setPaint(this.paint);
    g2.setFont(this.font);
    TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.textAnchor);
    g2.setClip(savedClip);
}
Also used : Size2D(org.jfree.ui.Size2D) Shape(java.awt.Shape) Point2D(java.awt.geom.Point2D) FontMetrics(java.awt.FontMetrics) Rectangle2D(java.awt.geom.Rectangle2D) Arc2D(java.awt.geom.Arc2D)

Example 25 with Size2D

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

the class ImageTitle method drawHorizontal.

/**
 * Draws the title on a Java 2D graphics device (such as the screen or a
 * printer).
 *
 * @param g2  the graphics device.
 * @param chartArea  the area within which the title (and plot) should be
 *                   drawn.
 *
 * @return The size of the area used by the title.
 */
protected Size2D drawHorizontal(Graphics2D g2, Rectangle2D chartArea) {
    double startY;
    double topSpace;
    double bottomSpace;
    double leftSpace;
    double rightSpace;
    double w = getWidth();
    double h = getHeight();
    RectangleInsets padding = getPadding();
    topSpace = padding.calculateTopOutset(h);
    bottomSpace = padding.calculateBottomOutset(h);
    leftSpace = padding.calculateLeftOutset(w);
    rightSpace = padding.calculateRightOutset(w);
    if (getPosition() == RectangleEdge.TOP) {
        startY = chartArea.getY() + topSpace;
    } else {
        startY = chartArea.getY() + chartArea.getHeight() - bottomSpace - h;
    }
    // what is our alignment?
    HorizontalAlignment horizontalAlignment = getHorizontalAlignment();
    double startX = 0.0;
    if (horizontalAlignment == HorizontalAlignment.CENTER) {
        startX = chartArea.getX() + leftSpace + chartArea.getWidth() / 2.0 - w / 2.0;
    } else if (horizontalAlignment == HorizontalAlignment.LEFT) {
        startX = chartArea.getX() + leftSpace;
    } else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
        startX = chartArea.getX() + chartArea.getWidth() - rightSpace - w;
    }
    g2.drawImage(this.image, (int) startX, (int) startY, (int) w, (int) h, null);
    return new Size2D(chartArea.getWidth() + leftSpace + rightSpace, h + topSpace + bottomSpace);
}
Also used : Size2D(org.jfree.ui.Size2D) RectangleInsets(org.jfree.ui.RectangleInsets) HorizontalAlignment(org.jfree.ui.HorizontalAlignment)

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