Example usage for org.jfree.chart.title TextTitle setHorizontalAlignment

List of usage examples for org.jfree.chart.title TextTitle setHorizontalAlignment

Introduction

In this page you can find the example usage for org.jfree.chart.title TextTitle setHorizontalAlignment.

Prototype

public void setHorizontalAlignment(HorizontalAlignment alignment) 

Source Link

Document

Sets the horizontal alignment for the title and sends a TitleChangeEvent to all registered listeners.

Usage

From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java

protected void setChartSubtitles(JFreeChart jfreeChart, Integer baseFontSize) throws JRException {
    Boolean subtitleVisibility = (Boolean) getDefaultValue(defaultChartPropertiesMap,
            ChartThemesConstants.SUBTITLE_VISIBLE);

    if (subtitleVisibility != null && subtitleVisibility.booleanValue()) {
        String subtitleText = (String) evaluateExpression(getChart().getSubtitleExpression());
        if (subtitleText != null) {
            TextTitle subtitle = new TextTitle(subtitleText);

            Font themeSubtitleFont = getFont(
                    (JRFont) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_FONT),
                    getChart().getSubtitleFont(), baseFontSize);
            subtitle.setFont(themeSubtitleFont);

            HorizontalAlignment defaultSubtitleHAlignment = (HorizontalAlignment) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_HORIZONTAL_ALIGNMENT);
            if (defaultSubtitleHAlignment != null)
                subtitle.setHorizontalAlignment(defaultSubtitleHAlignment);

            VerticalAlignment defaultSubtitleVAlignment = (VerticalAlignment) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_VERTICAL_ALIGNMENT);
            if (defaultSubtitleVAlignment != null)
                subtitle.setVerticalAlignment(defaultSubtitleVAlignment);

            RectangleInsets defaultSubtitlePadding = (RectangleInsets) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_PADDING);
            RectangleInsets subtitlePadding = subtitle.getPadding() != null ? subtitle.getPadding()
                    : defaultSubtitlePadding;
            if (subtitlePadding != null)
                subtitle.setPadding(subtitlePadding);

            Color subtitleForecolor = getChart().getOwnSubtitleColor() != null
                    ? getChart().getOwnSubtitleColor()
                    : (getDefaultValue(defaultChartPropertiesMap,
                            ChartThemesConstants.SUBTITLE_FORECOLOR) != null
                                    ? (Color) getDefaultValue(defaultChartPropertiesMap,
                                            ChartThemesConstants.SUBTITLE_FORECOLOR)
                                    : getChart().getSubtitleColor());
            if (subtitleForecolor != null)
                subtitle.setPaint(subtitleForecolor);

            Color subtitleBackcolor = getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.SUBTITLE_BACKCOLOR) != null
                            ? (Color) getDefaultValue(defaultChartPropertiesMap,
                                    ChartThemesConstants.SUBTITLE_BACKCOLOR)
                            : null;/*from  w  ww.j a v  a2  s  . c o m*/
            if (subtitleBackcolor != null)
                subtitle.setBackgroundPaint(subtitleBackcolor);

            RectangleEdge defaultSubtitlePosition = (RectangleEdge) getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.SUBTITLE_POSITION);
            //Subtitle has not its own position set, and by default this will be set the same as title position
            RectangleEdge subtitleEdge = null;
            if (defaultSubtitlePosition == null) {
                subtitleEdge = jfreeChart.getTitle().getPosition();
            } else {
                subtitleEdge = defaultSubtitlePosition;
            }
            if (subtitleEdge != null)
                subtitle.setPosition(subtitleEdge);

            jfreeChart.addSubtitle(subtitle);
        }
    }
}

From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java

protected void setChartTitle(JFreeChart jfreeChart, Integer baseFontSize) {
    Boolean titleVisibility = (Boolean) getDefaultValue(defaultChartPropertiesMap,
            ChartThemesConstants.TITLE_VISIBLE);
    if (titleVisibility != null && titleVisibility.booleanValue()) {
        TextTitle title = jfreeChart.getTitle();

        RectangleEdge titleEdge = null;//from   w  w  w .j  ava  2 s.  c  o  m

        if (title != null) {
            JRFont titleFont = getChart().getTitleFont();

            Font themeTitleFont = getFont(
                    (JRFont) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_FONT),
                    titleFont, baseFontSize);
            title.setFont(themeTitleFont);

            HorizontalAlignment defaultTitleHAlignment = (HorizontalAlignment) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.TITLE_HORIZONTAL_ALIGNMENT);
            if (defaultTitleHAlignment != null)
                title.setHorizontalAlignment(defaultTitleHAlignment);

            VerticalAlignment defaultTitleVAlignment = (VerticalAlignment) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.TITLE_VERTICAL_ALIGNMENT);
            if (defaultTitleVAlignment != null)
                title.setVerticalAlignment(defaultTitleVAlignment);

            RectangleInsets defaultTitlePadding = (RectangleInsets) getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.TITLE_PADDING);
            RectangleInsets titlePadding = title.getPadding() != null ? title.getPadding()
                    : defaultTitlePadding;
            if (titlePadding != null)
                title.setPadding(titlePadding);

            Color titleForecolor = getChart().getOwnTitleColor() != null ? getChart().getOwnTitleColor()
                    : (getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_FORECOLOR) != null
                            ? (Color) getDefaultValue(defaultChartPropertiesMap,
                                    ChartThemesConstants.TITLE_FORECOLOR)
                            : getChart().getTitleColor());
            if (titleForecolor != null)
                title.setPaint(titleForecolor);

            Color titleBackcolor = (Color) getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.TITLE_BACKCOLOR);
            if (titleBackcolor != null)
                title.setBackgroundPaint(titleBackcolor);

            RectangleEdge defaultTitlePosition = (RectangleEdge) getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.TITLE_POSITION);
            titleEdge = getEdge(getChart().getTitlePositionValue(), defaultTitlePosition);
            if (titleEdge != null)
                title.setPosition(titleEdge);
        }
    } else {
        TextTitle title = null;
        jfreeChart.setTitle(title);
    }
}

From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java

protected void handleTitleSettings(TextTitle title, TitleSettings titleSettings, JRFont titleFont,
        Paint titleForegroundPaint, RectangleEdge titleEdge) {
    JRBaseFont font = new JRBaseFont();
    FontUtil.copyNonNullOwnProperties(titleSettings.getFont(), font);
    FontUtil.copyNonNullOwnProperties(titleFont, font);
    font = new JRBaseFont(getChart(), font);
    title.setFont(getFontUtil().getAwtFont(font, getLocale()));

    HorizontalAlignment hAlign = titleSettings.getHorizontalAlignment();
    if (hAlign != null)
        title.setHorizontalAlignment(hAlign);

    VerticalAlignment vAlign = titleSettings.getVerticalAlignment();
    if (vAlign != null)
        title.setVerticalAlignment(vAlign);

    RectangleInsets padding = titleSettings.getPadding();
    if (padding != null)
        title.setPadding(padding);//from  w w w.j  a  v  a2 s. c o m

    if (titleForegroundPaint != null)
        title.setPaint(titleForegroundPaint);

    Paint backPaint = titleSettings.getBackgroundPaint() != null ? titleSettings.getBackgroundPaint().getPaint()
            : null;
    if (backPaint != null)
        title.setBackgroundPaint(backPaint);
    if (titleEdge != null)
        title.setPosition(titleEdge);
}

From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java

protected void setChartSubtitles(JFreeChart jfreeChart, Integer baseFontSize) throws JRException {
    Boolean subtitleVisibility = (Boolean) getDefaultValue(defaultChartPropertiesMap,
            ChartThemesConstants.SUBTITLE_VISIBLE);

    if (subtitleVisibility != null && subtitleVisibility) {
        String subtitleText = evaluateTextExpression(getChart().getSubtitleExpression());
        if (subtitleText != null) {
            TextTitle subtitle = new TextTitle(subtitleText);

            Font themeSubtitleFont = getFont(
                    (JRFont) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_FONT),
                    getChart().getSubtitleFont(), baseFontSize);
            subtitle.setFont(themeSubtitleFont);

            HorizontalAlignment defaultSubtitleHAlignment = (HorizontalAlignment) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_HORIZONTAL_ALIGNMENT);
            if (defaultSubtitleHAlignment != null)
                subtitle.setHorizontalAlignment(defaultSubtitleHAlignment);

            VerticalAlignment defaultSubtitleVAlignment = (VerticalAlignment) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_VERTICAL_ALIGNMENT);
            if (defaultSubtitleVAlignment != null)
                subtitle.setVerticalAlignment(defaultSubtitleVAlignment);

            RectangleInsets defaultSubtitlePadding = (RectangleInsets) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_PADDING);
            RectangleInsets subtitlePadding = subtitle.getPadding() != null ? subtitle.getPadding()
                    : defaultSubtitlePadding;
            if (subtitlePadding != null)
                subtitle.setPadding(subtitlePadding);

            Color subtitleForecolor = getChart().getOwnSubtitleColor() != null
                    ? getChart().getOwnSubtitleColor()
                    : (getDefaultValue(defaultChartPropertiesMap,
                            ChartThemesConstants.SUBTITLE_FORECOLOR) != null
                                    ? (Color) getDefaultValue(defaultChartPropertiesMap,
                                            ChartThemesConstants.SUBTITLE_FORECOLOR)
                                    : getChart().getSubtitleColor());
            if (subtitleForecolor != null)
                subtitle.setPaint(subtitleForecolor);

            Color subtitleBackcolor = getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.SUBTITLE_BACKCOLOR) != null
                            ? (Color) getDefaultValue(defaultChartPropertiesMap,
                                    ChartThemesConstants.SUBTITLE_BACKCOLOR)
                            : null;//from www  .j a  v a 2  s.  c o  m
            if (subtitleBackcolor != null)
                subtitle.setBackgroundPaint(subtitleBackcolor);

            RectangleEdge defaultSubtitlePosition = (RectangleEdge) getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.SUBTITLE_POSITION);
            //Subtitle has not its own position set, and by default this will be set the same as title position
            RectangleEdge subtitleEdge = null;
            if (defaultSubtitlePosition == null) {
                subtitleEdge = jfreeChart.getTitle().getPosition();
            } else {
                subtitleEdge = defaultSubtitlePosition;
            }
            if (subtitleEdge != null)
                subtitle.setPosition(subtitleEdge);

            jfreeChart.addSubtitle(subtitle);
        }
    }
}

From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java

protected void setChartTitle(JFreeChart jfreeChart, Integer baseFontSize) {
    Boolean titleVisibility = (Boolean) getDefaultValue(defaultChartPropertiesMap,
            ChartThemesConstants.TITLE_VISIBLE);
    if (titleVisibility != null && titleVisibility) {
        TextTitle title = jfreeChart.getTitle();

        RectangleEdge titleEdge = null;//from w  ww  . ja  va2s  .  c o  m

        if (title != null) {
            JRFont titleFont = getChart().getTitleFont();

            Font themeTitleFont = getFont(
                    (JRFont) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_FONT),
                    titleFont, baseFontSize);
            title.setFont(themeTitleFont);

            HorizontalAlignment defaultTitleHAlignment = (HorizontalAlignment) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.TITLE_HORIZONTAL_ALIGNMENT);
            if (defaultTitleHAlignment != null)
                title.setHorizontalAlignment(defaultTitleHAlignment);

            VerticalAlignment defaultTitleVAlignment = (VerticalAlignment) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.TITLE_VERTICAL_ALIGNMENT);
            if (defaultTitleVAlignment != null)
                title.setVerticalAlignment(defaultTitleVAlignment);

            RectangleInsets defaultTitlePadding = (RectangleInsets) getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.TITLE_PADDING);
            RectangleInsets titlePadding = title.getPadding() != null ? title.getPadding()
                    : defaultTitlePadding;
            if (titlePadding != null)
                title.setPadding(titlePadding);

            Color titleForecolor = getChart().getOwnTitleColor() != null ? getChart().getOwnTitleColor()
                    : (getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_FORECOLOR) != null
                            ? (Color) getDefaultValue(defaultChartPropertiesMap,
                                    ChartThemesConstants.TITLE_FORECOLOR)
                            : getChart().getTitleColor());
            if (titleForecolor != null)
                title.setPaint(titleForecolor);

            Color titleBackcolor = (Color) getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.TITLE_BACKCOLOR);
            if (titleBackcolor != null)
                title.setBackgroundPaint(titleBackcolor);

            RectangleEdge defaultTitlePosition = (RectangleEdge) getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.TITLE_POSITION);
            titleEdge = getEdge(getChart().getTitlePositionValue(), defaultTitlePosition);
            if (titleEdge != null)
                title.setPosition(titleEdge);
        }
    } else {
        TextTitle title = null;
        jfreeChart.setTitle(title);
    }
}