Search in sources :

Example 21 with Size2D

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

the class PaintScaleLegend 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} not permitted).
 *
 * @return The block size (in Java2D units, never {@code null}).
 */
@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 = new Size2D(getWidth(), getHeight());
        } 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) {
            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) {
            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.");
        }
    }
    // suppress compiler warning
    assert contentSize != null;
    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 22 with Size2D

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

the class TextLine method draw.

/**
 * Draws the text line.
 *
 * @param g2  the graphics device.
 * @param anchorX  the x-coordinate for the anchor point.
 * @param anchorY  the y-coordinate for the anchor point.
 * @param anchor  the point on the text line that is aligned to the anchor
 *                point.
 * @param rotateX  the x-coordinate for the rotation point.
 * @param rotateY  the y-coordinate for the rotation point.
 * @param angle  the rotation angle (in radians).
 */
public void draw(Graphics2D g2, float anchorX, float anchorY, TextAnchor anchor, float rotateX, float rotateY, double angle) {
    Size2D dim = calculateDimensions(g2);
    float xAdj = 0.0f;
    if (anchor.isHorizontalCenter()) {
        xAdj = (float) -dim.getWidth() / 2.0f;
    } else if (anchor.isRight()) {
        xAdj = (float) -dim.getWidth();
    }
    float x = anchorX + xAdj;
    final float yOffset = calculateBaselineOffset(g2, anchor);
    for (TextFragment fragment : this.fragments) {
        final Size2D d = fragment.calculateDimensions(g2);
        fragment.draw(g2, x, anchorY + yOffset, TextAnchor.BASELINE_LEFT, rotateX, rotateY, angle);
        x = x + (float) d.getWidth();
    }
}
Also used : Size2D(org.jfree.chart.block.Size2D)

Example 23 with Size2D

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

the class TextBlock method calculateDimensions.

/**
 * Returns the width and height of the text block.
 *
 * @param g2  the graphics device.
 *
 * @return The width and height.
 */
public Size2D calculateDimensions(Graphics2D g2) {
    double width = 0.0;
    double height = 0.0;
    for (TextLine line : this.lines) {
        final Size2D dimension = line.calculateDimensions(g2);
        width = Math.max(width, dimension.getWidth());
        height = height + dimension.getHeight();
    }
    return new Size2D(width, height);
}
Also used : Size2D(org.jfree.chart.block.Size2D)

Example 24 with Size2D

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

the class TextBlock method calculateBounds.

/**
 * Returns the bounds of the text block.
 *
 * @param g2  the graphics device ({@code null} not permitted).
 * @param anchorX  the x-coordinate for the anchor point.
 * @param anchorY  the y-coordinate for the anchor point.
 * @param anchor  the text block anchor ({@code null} not permitted).
 * @param rotateX  the x-coordinate for the rotation point.
 * @param rotateY  the y-coordinate for the rotation point.
 * @param angle  the rotation angle.
 *
 * @return The bounds.
 */
public Shape calculateBounds(Graphics2D g2, float anchorX, float anchorY, TextBlockAnchor anchor, float rotateX, float rotateY, double angle) {
    Size2D d = calculateDimensions(g2);
    float[] offsets = calculateOffsets(anchor, d.getWidth(), d.getHeight());
    Rectangle2D bounds = new Rectangle2D.Double(anchorX + offsets[0], anchorY + offsets[1], d.getWidth(), d.getHeight());
    Shape rotatedBounds = ShapeUtils.rotateShape(bounds, angle, rotateX, rotateY);
    return rotatedBounds;
}
Also used : Size2D(org.jfree.chart.block.Size2D) Shape(java.awt.Shape) Rectangle2D(java.awt.geom.Rectangle2D)

Example 25 with Size2D

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

the class TextBox method draw.

/**
 * Draws the text box.
 *
 * @param g2  the graphics device.
 * @param x  the x-coordinate.
 * @param y  the y-coordinate.
 * @param anchor  the anchor point.
 */
public void draw(Graphics2D g2, float x, float y, RectangleAnchor anchor) {
    final Size2D d1 = this.textBlock.calculateDimensions(g2);
    final double w = this.interiorGap.extendWidth(d1.getWidth());
    final double h = this.interiorGap.extendHeight(d1.getHeight());
    final Size2D d2 = new Size2D(w, h);
    final Rectangle2D bounds = RectangleAnchor.createRectangle(d2, x, y, anchor);
    double xx = bounds.getX();
    double yy = bounds.getY();
    if (this.shadowPaint != null) {
        final Rectangle2D shadow = new Rectangle2D.Double(xx + this.shadowXOffset, yy + this.shadowYOffset, bounds.getWidth(), bounds.getHeight());
        g2.setPaint(this.shadowPaint);
        g2.fill(shadow);
    }
    if (this.backgroundPaint != null) {
        g2.setPaint(this.backgroundPaint);
        g2.fill(bounds);
    }
    if (this.outlinePaint != null && this.outlineStroke != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.outlineStroke);
        g2.draw(bounds);
    }
    this.textBlock.draw(g2, (float) (xx + this.interiorGap.calculateLeftInset(w)), (float) (yy + this.interiorGap.calculateTopInset(h)), TextBlockAnchor.TOP_LEFT);
}
Also used : Size2D(org.jfree.chart.block.Size2D) Rectangle2D(java.awt.geom.Rectangle2D)

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