Search in sources :

Example 61 with Size2D

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

the class JFreeChartInfo method drawTitle.

/**
 * Draws a title.  The title should be drawn at the top, bottom, left or
 * right of the specified area, and the area should be updated to reflect
 * the amount of space used by the title.
 *
 * @param t  the title (<code>null</code> not permitted).
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param area  the chart area, excluding any existing titles
 *              (<code>null</code> not permitted).
 * @param entities  a flag that controls whether or not an entity
 *                  collection is returned for the title.
 *
 * @return An entity collection for the title (possibly <code>null</code>).
 */
protected EntityCollection drawTitle(Title t, Graphics2D g2, Rectangle2D area, boolean entities) {
    ParamChecks.nullNotPermitted(t, "t");
    ParamChecks.nullNotPermitted(area, "area");
    Rectangle2D titleArea;
    RectangleEdge position = t.getPosition();
    double ww = area.getWidth();
    if (ww <= 0.0) {
        return null;
    }
    double hh = area.getHeight();
    if (hh <= 0.0) {
        return null;
    }
    RectangleConstraint constraint = new RectangleConstraint(ww, new Range(0.0, ww), LengthConstraintType.RANGE, hh, new Range(0.0, hh), LengthConstraintType.RANGE);
    Object retValue = null;
    BlockParams p = new BlockParams();
    p.setGenerateEntities(entities);
    if (position == RectangleEdge.TOP) {
        Size2D size = t.arrange(g2, constraint);
        titleArea = createAlignedRectangle2D(size, area, t.getHorizontalAlignment(), VerticalAlignment.TOP);
        retValue = t.draw(g2, titleArea, p);
        area.setRect(area.getX(), Math.min(area.getY() + size.height, area.getMaxY()), area.getWidth(), Math.max(area.getHeight() - size.height, 0));
    } else if (position == RectangleEdge.BOTTOM) {
        Size2D size = t.arrange(g2, constraint);
        titleArea = createAlignedRectangle2D(size, area, t.getHorizontalAlignment(), VerticalAlignment.BOTTOM);
        retValue = t.draw(g2, titleArea, p);
        area.setRect(area.getX(), area.getY(), area.getWidth(), area.getHeight() - size.height);
    } else if (position == RectangleEdge.RIGHT) {
        Size2D size = t.arrange(g2, constraint);
        titleArea = createAlignedRectangle2D(size, area, HorizontalAlignment.RIGHT, t.getVerticalAlignment());
        retValue = t.draw(g2, titleArea, p);
        area.setRect(area.getX(), area.getY(), area.getWidth() - size.width, area.getHeight());
    } else if (position == RectangleEdge.LEFT) {
        Size2D size = t.arrange(g2, constraint);
        titleArea = createAlignedRectangle2D(size, area, HorizontalAlignment.LEFT, t.getVerticalAlignment());
        retValue = t.draw(g2, titleArea, p);
        area.setRect(area.getX() + size.width, area.getY(), area.getWidth() - size.width, area.getHeight());
    } else {
        throw new RuntimeException("Unrecognised title position.");
    }
    EntityCollection result = null;
    if (retValue instanceof EntityBlockResult) {
        EntityBlockResult ebr = (EntityBlockResult) retValue;
        result = ebr.getEntityCollection();
    }
    return result;
}
Also used : Size2D(org.jfree.ui.Size2D) EntityCollection(org.jfree.chart.entity.EntityCollection) Rectangle2D(java.awt.geom.Rectangle2D) EntityBlockResult(org.jfree.chart.block.EntityBlockResult) RectangleConstraint(org.jfree.chart.block.RectangleConstraint) Range(org.jfree.data.Range) RectangleEdge(org.jfree.ui.RectangleEdge) BlockParams(org.jfree.chart.block.BlockParams)

Example 62 with Size2D

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

the class ImageTitleTest method testArrangeNN.

/**
 * Some checks for the arrange method.
 */
@Test
public void testArrangeNN() {
    BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    ImageTitle t = new ImageTitle(JFreeChart.INFO.getLogo());
    Size2D s = t.arrange(g2);
    assertEquals(102.0, s.getWidth(), EPSILON);
    assertEquals(102.0, s.getHeight(), EPSILON);
    t.setPadding(1.0, 2.0, 3.0, 4.0);
    s = t.arrange(g2);
    assertEquals(106.0, s.getWidth(), EPSILON);
    assertEquals(104.0, s.getHeight(), EPSILON);
    t.setMargin(5.0, 6.0, 7.0, 8.0);
    s = t.arrange(g2);
    assertEquals(120.0, s.getWidth(), EPSILON);
    assertEquals(116.0, s.getHeight(), EPSILON);
}
Also used : Size2D(org.jfree.ui.Size2D) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) Test(org.junit.Test)

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