Example usage for org.jfree.chart.axis Axis setTickLabelFont

List of usage examples for org.jfree.chart.axis Axis setTickLabelFont

Introduction

In this page you can find the example usage for org.jfree.chart.axis Axis setTickLabelFont.

Prototype

public void setTickLabelFont(Font font) 

Source Link

Document

Sets the font for the tick labels and sends an AxisChangeEvent to all registered listeners.

Usage

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

protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask,
        AxisSettings axisSettings) {/*w w  w.  j a  va  2  s  .  c o m*/
    boolean axisTickLabelsVisible = axisSettings.getTickLabelsVisible() == null
            || axisSettings.getTickLabelsVisible();//FIXMETHEME axis visibility should be dealt with above;

    axis.setTickLabelsVisible(axisTickLabelsVisible);

    if (axisTickLabelsVisible) {
        JRBaseFont font = new JRBaseFont();
        FontUtil.copyNonNullOwnProperties(axisSettings.getTickLabelFont(), font);
        FontUtil.copyNonNullOwnProperties(tickLabelFont, font);
        font = new JRBaseFont(getChart(), font);
        axis.setTickLabelFont(getFontUtil().getAwtFont(font, getLocale()));

        RectangleInsets tickLabelInsets = axisSettings.getTickLabelInsets();
        if (tickLabelInsets != null) {
            axis.setTickLabelInsets(tickLabelInsets);
        }

        Paint tickLabelPaint = tickLabelColor != null ? tickLabelColor
                : axisSettings.getTickLabelPaint() != null ? axisSettings.getTickLabelPaint().getPaint() : null;

        if (tickLabelPaint != null) {
            axis.setTickLabelPaint(tickLabelPaint);
        }

        TimeZone timeZone = getChartContext().getTimeZone();
        if (axis instanceof DateAxis && timeZone != null) {
            // used when no mask is set
            ((DateAxis) axis).setTimeZone(timeZone);
        }

        if (tickLabelMask != null) {
            if (axis instanceof NumberAxis) {
                NumberFormat fmt = NumberFormat.getInstance(getLocale());
                if (fmt instanceof DecimalFormat)
                    ((DecimalFormat) fmt).applyPattern(tickLabelMask);
                ((NumberAxis) axis).setNumberFormatOverride(fmt);
            } else if (axis instanceof DateAxis) {
                DateFormat fmt;
                if (tickLabelMask.equals("SHORT") || tickLabelMask.equals("DateFormat.SHORT"))
                    fmt = DateFormat.getDateInstance(DateFormat.SHORT, getLocale());
                else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM"))
                    fmt = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale());
                else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG"))
                    fmt = DateFormat.getDateInstance(DateFormat.LONG, getLocale());
                else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL"))
                    fmt = DateFormat.getDateInstance(DateFormat.FULL, getLocale());
                else
                    fmt = new SimpleDateFormat(tickLabelMask, getLocale());

                // FIXME fmt cannot be null
                if (fmt != null) {
                    if (timeZone != null) {
                        fmt.setTimeZone(timeZone);
                    }

                    ((DateAxis) axis).setDateFormatOverride(fmt);
                } else
                    ((DateAxis) axis).setDateFormatOverride(
                            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, getLocale()));
            }
            // ignore mask for other axis types.
        }
    }
}