Search in sources :

Example 56 with Size2D

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

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?
    VerticalAlignment alignment = getVerticalAlignment();
    double startY = 0.0;
    if (alignment == VerticalAlignment.CENTER) {
        startY = chartArea.getMinY() + topSpace + chartArea.getHeight() / 2.0 - h / 2.0;
    } else if (alignment == VerticalAlignment.TOP) {
        startY = chartArea.getMinY() + topSpace;
    } else if (alignment == VerticalAlignment.BOTTOM) {
        startY = chartArea.getMaxY() - bottomSpace - h;
    }
    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) VerticalAlignment(org.jfree.ui.VerticalAlignment)

Example 57 with Size2D

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

the class PaintScaleLegend 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();
        // determine the space required for the axis
        AxisSpace space = this.axis.reserveSpace(g2, null, new Rectangle2D.Double(0, 0, maxWidth, 100), RectangleEdge.BOTTOM, null);
        return new Size2D(maxWidth, this.stripWidth + this.axisOffset + space.getTop() + space.getBottom());
    } else if (position == RectangleEdge.LEFT || position == RectangleEdge.RIGHT) {
        float maxHeight = (float) heightRange.getUpperBound();
        AxisSpace space = this.axis.reserveSpace(g2, null, new Rectangle2D.Double(0, 0, 100, maxHeight), RectangleEdge.RIGHT, null);
        return new Size2D(this.stripWidth + this.axisOffset + space.getLeft() + space.getRight(), maxHeight);
    } else {
        throw new RuntimeException("Unrecognised position.");
    }
}
Also used : Size2D(org.jfree.ui.Size2D) Rectangle2D(java.awt.geom.Rectangle2D) AxisSpace(org.jfree.chart.axis.AxisSpace) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 58 with Size2D

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

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.
 *
 * @since 1.0.9
 */
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 = TextUtilities.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 = TextUtilities.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.ui.Size2D) G2TextMeasurer(org.jfree.text.G2TextMeasurer) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 59 with Size2D

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

the class TextTitle 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) {
    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.");
        }
    }
    // suppress compiler warning
    assert contentSize != null;
    return new Size2D(calculateTotalWidth(contentSize.getWidth()), calculateTotalHeight(contentSize.getHeight()));
}
Also used : Size2D(org.jfree.ui.Size2D) LengthConstraintType(org.jfree.chart.block.LengthConstraintType) RectangleConstraint(org.jfree.chart.block.RectangleConstraint)

Example 60 with Size2D

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

the class LegendGraphic 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) {
    RectangleConstraint contentConstraint = toContentConstraint(constraint);
    LengthConstraintType w = contentConstraint.getWidthConstraintType();
    LengthConstraintType h = contentConstraint.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) {
            throw new RuntimeException("Not yet implemented.");
        } 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.FIXED) {
        if (h == LengthConstraintType.NONE) {
            throw new RuntimeException("Not yet implemented.");
        } else if (h == LengthConstraintType.RANGE) {
            throw new RuntimeException("Not yet implemented.");
        } else if (h == LengthConstraintType.FIXED) {
            contentSize = new Size2D(contentConstraint.getWidth(), contentConstraint.getHeight());
        }
    }
    assert contentSize != null;
    return new Size2D(calculateTotalWidth(contentSize.getWidth()), calculateTotalHeight(contentSize.getHeight()));
}
Also used : Size2D(org.jfree.ui.Size2D) LengthConstraintType(org.jfree.chart.block.LengthConstraintType) RectangleConstraint(org.jfree.chart.block.RectangleConstraint)

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