Search in sources :

Example 1 with VerticalAlignment

use of org.jfree.chart.util.VerticalAlignment in project graphcode2vec by graphcode2vec.

the class TextTitle method drawVertical.

/**
 * Draws a the title vertically 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 drawVertical(Graphics2D g2, Rectangle2D area) {
    Rectangle2D titleArea = (Rectangle2D) area.clone();
    g2.setFont(this.font);
    g2.setPaint(this.paint);
    TextBlockAnchor anchor = null;
    float y = 0.0f;
    VerticalAlignment verticalAlignment = getVerticalAlignment();
    if (verticalAlignment == VerticalAlignment.TOP) {
        y = (float) titleArea.getY();
        anchor = TextBlockAnchor.TOP_RIGHT;
    } else if (verticalAlignment == VerticalAlignment.BOTTOM) {
        y = (float) titleArea.getMaxY();
        anchor = TextBlockAnchor.TOP_LEFT;
    } else if (verticalAlignment == VerticalAlignment.CENTER) {
        y = (float) titleArea.getCenterY();
        anchor = TextBlockAnchor.TOP_CENTER;
    }
    float x = 0.0f;
    RectangleEdge position = getPosition();
    if (position == RectangleEdge.LEFT) {
        x = (float) titleArea.getX();
    } else if (position == RectangleEdge.RIGHT) {
        x = (float) titleArea.getMaxX();
        if (verticalAlignment == VerticalAlignment.TOP) {
            anchor = TextBlockAnchor.BOTTOM_RIGHT;
        } else if (verticalAlignment == VerticalAlignment.CENTER) {
            anchor = TextBlockAnchor.BOTTOM_CENTER;
        } else if (verticalAlignment == VerticalAlignment.BOTTOM) {
            anchor = TextBlockAnchor.BOTTOM_LEFT;
        }
    }
    this.content.draw(g2, x, y, anchor, x, y, -Math.PI / 2.0);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) VerticalAlignment(org.jfree.chart.util.VerticalAlignment) TextBlockAnchor(org.jfree.chart.text.TextBlockAnchor) RectangleEdge(org.jfree.chart.util.RectangleEdge)

Example 2 with VerticalAlignment

use of org.jfree.chart.util.VerticalAlignment in project graphcode2vec by graphcode2vec.

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 = 0.0;
    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.chart.util.Size2D) RectangleInsets(org.jfree.chart.util.RectangleInsets) VerticalAlignment(org.jfree.chart.util.VerticalAlignment)

Aggregations

VerticalAlignment (org.jfree.chart.util.VerticalAlignment)2 Rectangle2D (java.awt.geom.Rectangle2D)1 TextBlockAnchor (org.jfree.chart.text.TextBlockAnchor)1 RectangleEdge (org.jfree.chart.util.RectangleEdge)1 RectangleInsets (org.jfree.chart.util.RectangleInsets)1 Size2D (org.jfree.chart.util.Size2D)1