Search in sources :

Example 1 with G2TextMeasurer

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

the class Plot method drawNoDataMessage.

/**
 * Draws a message to state that there is no data to plot.
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 */
protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {
    Shape savedClip = g2.getClip();
    g2.clip(area);
    String message = this.noDataMessage;
    if (message != null) {
        g2.setFont(this.noDataMessageFont);
        g2.setPaint(this.noDataMessagePaint);
        TextBlock block = TextUtils.createTextBlock(this.noDataMessage, this.noDataMessageFont, this.noDataMessagePaint, 0.9f * (float) area.getWidth(), new G2TextMeasurer(g2));
        block.draw(g2, (float) area.getCenterX(), (float) area.getCenterY(), TextBlockAnchor.CENTER);
    }
    g2.setClip(savedClip);
}
Also used : Shape(java.awt.Shape) G2TextMeasurer(org.jfree.chart.text.G2TextMeasurer) TextBlock(org.jfree.chart.text.TextBlock)

Example 2 with G2TextMeasurer

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

the class TextTitle 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.
 */
protected Size2D arrangeFN(Graphics2D g2, double w) {
    RectangleEdge position = getPosition();
    if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) {
        float maxWidth = (float) w;
        g2.setFont(this.font);
        this.content = TextUtils.createTextBlock(this.text, this.font, this.paint, maxWidth, this.maximumLinesToDisplay, new G2TextMeasurer(g2));
        this.content.setLineAlignment(this.textAlignment);
        Size2D contentSize = this.content.calculateDimensions(g2);
        if (this.expandToFitSpace) {
            return new Size2D(maxWidth, contentSize.getHeight());
        } else {
            return contentSize;
        }
    } else if (position == RectangleEdge.LEFT || position == RectangleEdge.RIGHT) {
        float maxWidth = Float.MAX_VALUE;
        g2.setFont(this.font);
        this.content = TextUtils.createTextBlock(this.text, this.font, this.paint, maxWidth, this.maximumLinesToDisplay, new G2TextMeasurer(g2));
        this.content.setLineAlignment(this.textAlignment);
        Size2D contentSize = this.content.calculateDimensions(g2);
        // transpose the dimensions, because the title is rotated
        if (this.expandToFitSpace) {
            return new Size2D(contentSize.getHeight(), maxWidth);
        } else {
            return new Size2D(contentSize.height, contentSize.width);
        }
    } else {
        throw new RuntimeException("Unrecognised exception.");
    }
}
Also used : Size2D(org.jfree.chart.block.Size2D) G2TextMeasurer(org.jfree.chart.text.G2TextMeasurer) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 3 with G2TextMeasurer

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

the class TextTitle method arrangeRR.

/**
 * Returns the content size for the title.  This will reflect the fact that
 * a text title positioned on the left or right of a chart will be rotated
 * 90 degrees.
 *
 * @param g2  the graphics device.
 * @param widthRange  the width range.
 * @param heightRange  the height range.
 *
 * @return The content size.
 */
protected Size2D arrangeRR(Graphics2D g2, Range widthRange, Range heightRange) {
    RectangleEdge position = getPosition();
    if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) {
        float maxWidth = (float) widthRange.getUpperBound();
        g2.setFont(this.font);
        this.content = TextUtils.createTextBlock(this.text, this.font, this.paint, maxWidth, this.maximumLinesToDisplay, new G2TextMeasurer(g2));
        this.content.setLineAlignment(this.textAlignment);
        Size2D contentSize = this.content.calculateDimensions(g2);
        if (this.expandToFitSpace) {
            return new Size2D(maxWidth, contentSize.getHeight());
        } else {
            return contentSize;
        }
    } else if (position == RectangleEdge.LEFT || position == RectangleEdge.RIGHT) {
        float maxWidth = (float) heightRange.getUpperBound();
        g2.setFont(this.font);
        this.content = TextUtils.createTextBlock(this.text, this.font, this.paint, maxWidth, this.maximumLinesToDisplay, new G2TextMeasurer(g2));
        this.content.setLineAlignment(this.textAlignment);
        Size2D contentSize = this.content.calculateDimensions(g2);
        // transpose the dimensions, because the title is rotated
        if (this.expandToFitSpace) {
            return new Size2D(contentSize.getHeight(), maxWidth);
        } else {
            return new Size2D(contentSize.height, contentSize.width);
        }
    } else {
        throw new RuntimeException("Unrecognised exception.");
    }
}
Also used : Size2D(org.jfree.chart.block.Size2D) G2TextMeasurer(org.jfree.chart.text.G2TextMeasurer) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Aggregations

G2TextMeasurer (org.jfree.chart.text.G2TextMeasurer)3 RectangleEdge (org.jfree.chart.api.RectangleEdge)2 Size2D (org.jfree.chart.block.Size2D)2 Shape (java.awt.Shape)1 TextBlock (org.jfree.chart.text.TextBlock)1