Search in sources :

Example 1 with Size2D

use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class ShortTextTitle method arrange.

/**
 * Performs a layout for this title, subject to the supplied constraint,
 * and returns the dimensions required for the title (if the title
 * cannot be displayed in the available space, this method will return
 * zero width and height for the dimensions).
 *
 * @param g2  the graphics target.
 * @param constraint  the layout constraints.
 *
 * @return The dimensions for the title.
 */
@Override
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) {
        if (h == LengthConstraintType.NONE) {
            contentSize = arrangeNN(g2);
        } else if (h == LengthConstraintType.RANGE) {
            throw new RuntimeException("Not yet implemented.");
        } else if (h == LengthConstraintType.FIXED) {
            throw new RuntimeException("Not yet implemented.");
        }
    } else if (w == LengthConstraintType.RANGE) {
        if (h == LengthConstraintType.NONE) {
            contentSize = arrangeRN(g2, cc.getWidthRange());
        } else if (h == LengthConstraintType.RANGE) {
            contentSize = arrangeRR(g2, cc.getWidthRange(), cc.getHeightRange());
        } else if (h == LengthConstraintType.FIXED) {
            throw new RuntimeException("Not yet implemented.");
        }
    } else if (w == LengthConstraintType.FIXED) {
        if (h == LengthConstraintType.NONE) {
            contentSize = arrangeFN(g2, cc.getWidth());
        } else if (h == LengthConstraintType.RANGE) {
            throw new RuntimeException("Not yet implemented.");
        } else if (h == LengthConstraintType.FIXED) {
            throw new RuntimeException("Not yet implemented.");
        }
    }
    assert contentSize != null;
    if (contentSize.width <= 0.0 || contentSize.height <= 0.0) {
        return new Size2D(0.0, 0.0);
    } else {
        return new Size2D(calculateTotalWidth(contentSize.getWidth()), calculateTotalHeight(contentSize.getHeight()));
    }
}
Also used : Size2D(org.jfree.chart.block.Size2D) LengthConstraintType(org.jfree.chart.block.LengthConstraintType) RectangleConstraint(org.jfree.chart.block.RectangleConstraint)

Example 2 with Size2D

use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class ShortTextTitle method arrangeFN.

/**
 * Arranges the content for this title assuming a fixed width and no bounds
 * on the height, and returns the required size.  This will reflect the
 * fact that a text title positioned on the left or right of a chart will
 * be rotated by 90 degrees.
 *
 * @param g2  the graphics target.
 * @param w  the width.
 *
 * @return The content size.
 */
@Override
protected Size2D arrangeFN(Graphics2D g2, double w) {
    g2.setFont(getFont());
    FontMetrics fm = g2.getFontMetrics(getFont());
    Rectangle2D bounds = TextUtils.getTextBounds(getText(), g2, fm);
    if (bounds.getWidth() <= w) {
        return new Size2D(w, bounds.getHeight());
    } else {
        return new Size2D(0.0, 0.0);
    }
}
Also used : Size2D(org.jfree.chart.block.Size2D) FontMetrics(java.awt.FontMetrics) Rectangle2D(java.awt.geom.Rectangle2D)

Example 3 with Size2D

use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class TextFragment method calculateDimensions.

/**
 * Calculates the dimensions of the text fragment.
 *
 * @param g2  the graphics device.
 *
 * @return The width and height of the text.
 */
public Size2D calculateDimensions(Graphics2D g2) {
    FontMetrics fm = g2.getFontMetrics(this.font);
    Rectangle2D bounds = TextUtils.getTextBounds(this.text, g2, fm);
    Size2D result = new Size2D(bounds.getWidth(), bounds.getHeight());
    return result;
}
Also used : Size2D(org.jfree.chart.block.Size2D) FontMetrics(java.awt.FontMetrics) Rectangle2D(java.awt.geom.Rectangle2D)

Example 4 with Size2D

use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

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?
    double startX = 0.0;
    switch(getHorizontalAlignment()) {
        case CENTER:
            startX = chartArea.getX() + leftSpace + chartArea.getWidth() / 2.0 - w / 2.0;
            break;
        case LEFT:
            startX = chartArea.getX() + leftSpace;
            break;
        case RIGHT:
            startX = chartArea.getX() + chartArea.getWidth() - rightSpace - w;
            break;
        default:
            throw new IllegalStateException("Unexpected horizontal alignment.");
    }
    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.chart.block.Size2D) RectangleInsets(org.jfree.chart.api.RectangleInsets)

Example 5 with Size2D

use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class ImageTitle method drawVertical.

/**
 * 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 drawVertical(Graphics2D g2, Rectangle2D chartArea) {
    double startX;
    double topSpace = 0.0;
    double bottomSpace = 0.0;
    double leftSpace = 0.0;
    double rightSpace = 0.0;
    double w = getWidth();
    double h = getHeight();
    RectangleInsets padding = getPadding();
    if (padding != null) {
        topSpace = padding.calculateTopOutset(h);
        bottomSpace = padding.calculateBottomOutset(h);
        leftSpace = padding.calculateLeftOutset(w);
        rightSpace = padding.calculateRightOutset(w);
    }
    if (getPosition() == RectangleEdge.LEFT) {
        startX = chartArea.getX() + leftSpace;
    } else {
        startX = chartArea.getMaxX() - rightSpace - w;
    }
    // what is our alignment?
    double startY = 0.0;
    switch(getVerticalAlignment()) {
        case CENTER:
            startY = chartArea.getMinY() + topSpace + chartArea.getHeight() / 2.0 - h / 2.0;
            break;
        case TOP:
            startY = chartArea.getMinY() + topSpace;
            break;
        case BOTTOM:
            startY = chartArea.getMaxY() - bottomSpace - h;
            break;
        default:
            throw new IllegalStateException("Unexpected vertical alignment.");
    }
    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.chart.block.Size2D) RectangleInsets(org.jfree.chart.api.RectangleInsets)

Aggregations

Size2D (org.jfree.chart.block.Size2D)27 Rectangle2D (java.awt.geom.Rectangle2D)11 RectangleConstraint (org.jfree.chart.block.RectangleConstraint)8 RectangleEdge (org.jfree.chart.api.RectangleEdge)5 FontMetrics (java.awt.FontMetrics)4 Shape (java.awt.Shape)4 LengthConstraintType (org.jfree.chart.block.LengthConstraintType)4 Point2D (java.awt.geom.Point2D)2 RectangleInsets (org.jfree.chart.api.RectangleInsets)2 BlockParams (org.jfree.chart.block.BlockParams)2 EntityBlockResult (org.jfree.chart.block.EntityBlockResult)2 G2TextMeasurer (org.jfree.chart.text.G2TextMeasurer)2 Range (org.jfree.data.Range)2 Arc2D (java.awt.geom.Arc2D)1 AxisLocation (org.jfree.chart.axis.AxisLocation)1 AxisSpace (org.jfree.chart.axis.AxisSpace)1 BlockContainer (org.jfree.chart.block.BlockContainer)1 EntityCollection (org.jfree.chart.entity.EntityCollection)1 PlotOrientation (org.jfree.chart.plot.PlotOrientation)1