Search in sources :

Example 1 with HorizontalAlignment

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

the class TextTitle method drawHorizontal.

/**
 * Draws a the title horizontally within the specified area.  This method
 * will be called from the {@link #draw(Graphics2D, Rectangle2D) draw}
 * method.
 *
 * @param g2  the graphics device.
 * @param area  the area for the title.
 */
protected void drawHorizontal(Graphics2D g2, Rectangle2D area) {
    Rectangle2D titleArea = (Rectangle2D) area.clone();
    g2.setFont(this.font);
    g2.setPaint(this.paint);
    TextBlockAnchor anchor = null;
    float x = 0.0f;
    HorizontalAlignment horizontalAlignment = getHorizontalAlignment();
    if (horizontalAlignment == HorizontalAlignment.LEFT) {
        x = (float) titleArea.getX();
        anchor = TextBlockAnchor.TOP_LEFT;
    } else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
        x = (float) titleArea.getMaxX();
        anchor = TextBlockAnchor.TOP_RIGHT;
    } else if (horizontalAlignment == HorizontalAlignment.CENTER) {
        x = (float) titleArea.getCenterX();
        anchor = TextBlockAnchor.TOP_CENTER;
    }
    float y = 0.0f;
    RectangleEdge position = getPosition();
    if (position == RectangleEdge.TOP) {
        y = (float) titleArea.getY();
    } else if (position == RectangleEdge.BOTTOM) {
        y = (float) titleArea.getMaxY();
        if (horizontalAlignment == HorizontalAlignment.LEFT) {
            anchor = TextBlockAnchor.BOTTOM_LEFT;
        } else if (horizontalAlignment == HorizontalAlignment.CENTER) {
            anchor = TextBlockAnchor.BOTTOM_CENTER;
        } else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
            anchor = TextBlockAnchor.BOTTOM_RIGHT;
        }
    }
    this.content.draw(g2, x, y, anchor);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) TextBlockAnchor(org.jfree.chart.text.TextBlockAnchor) HorizontalAlignment(org.jfree.chart.api.HorizontalAlignment) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Aggregations

Rectangle2D (java.awt.geom.Rectangle2D)1 HorizontalAlignment (org.jfree.chart.api.HorizontalAlignment)1 RectangleEdge (org.jfree.chart.api.RectangleEdge)1 TextBlockAnchor (org.jfree.chart.text.TextBlockAnchor)1