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.sourceforge.processdash.ui.web.CGIChartBase.java

/** Generate CGI chart output. */
@Override//from ww w. j a v a2  s  .  c  om
protected void writeContents() throws IOException {
    buildData(); // get the data for display

    chromeless = (parameters.get("chromeless") != null);
    JFreeChart chart = createChart();

    int width = getIntSetting("width");
    int height = getIntSetting("height");
    Color initGradColor = getColorSetting("initGradColor");
    Color finalGradColor = getColorSetting("finalGradColor");
    chart.setBackgroundPaint(new GradientPaint(0, 0, initGradColor, width, height, finalGradColor));
    if (parameters.get("hideOutline") != null)
        chart.getPlot().setOutlinePaint(INVISIBLE);

    String title = getSetting("title");
    if (chromeless || title == null || title.length() == 0)
        chart.setTitle((TextTitle) null);
    else {
        chart.setTitle(Translator.translate(title));
        String titleFontSize = getSetting("titleFontSize");
        if (titleFontSize != null)
            try {
                float fontSize = Float.parseFloat(titleFontSize);
                TextTitle t = chart.getTitle();
                t.setFont(t.getFont().deriveFont(fontSize));
            } catch (Exception tfe) {
            }
    }

    if (chromeless || parameters.get("hideLegend") != null)
        chart.removeLegend();
    else {
        LegendTitle l = chart.getLegend();
        String legendFontSize = getSetting("legendFontSize");
        if (l != null && legendFontSize != null)
            try {
                float fontSize = Float.parseFloat(legendFontSize);
                l.setItemFont(l.getItemFont().deriveFont(fontSize));
            } catch (Exception lfe) {
            }
    }

    chart.getPlot().setNoDataMessage(resources.getString("No_Data_Message"));

    Axis xAxis = getHorizontalAxis(chart);
    if (xAxis != null) {
        if (parameters.get("hideTickLabels") != null || parameters.get("hideXTickLabels") != null) {
            xAxis.setTickLabelsVisible(false);
        } else if (parameters.get("tickLabelFontSize") != null
                || parameters.get("xTickLabelFontSize") != null) {
            String tfs = getParameter("xTickLabelFontSize");
            if (tfs == null)
                tfs = getParameter("tickLabelFontSize");
            float fontSize = Float.parseFloat(tfs);
            xAxis.setTickLabelFont(xAxis.getTickLabelFont().deriveFont(fontSize));
        }
    }

    Axis yAxis = getVerticalAxis(chart);
    if (yAxis != null) {
        if (parameters.get("hideTickLabels") != null || parameters.get("hideYTickLabels") != null) {
            yAxis.setTickLabelsVisible(false);
        } else if (parameters.get("tickLabelFontSize") != null
                || parameters.get("yTickLabelFontSize") != null) {
            String tfs = getParameter("yTickLabelFontSize");
            if (tfs == null)
                tfs = getParameter("tickLabelFontSize");
            float fontSize = Float.parseFloat(tfs);
            yAxis.setTickLabelFont(yAxis.getTickLabelFont().deriveFont(fontSize));
        }
    }

    String axisFontSize = getSetting("axisLabelFontSize");
    if (axisFontSize != null)
        try {
            float fontSize = Float.parseFloat(axisFontSize);
            if (xAxis != null)
                xAxis.setLabelFont(xAxis.getLabelFont().deriveFont(fontSize));
            if (yAxis != null)
                yAxis.setLabelFont(yAxis.getLabelFont().deriveFont(fontSize));
        } catch (Exception afs) {
        }

    ChartRenderingInfo info = (isHtmlMode() ? new ChartRenderingInfo() : null);
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = img.createGraphics();
    if ("auto".equals(getSetting("titleFontSize")))
        maybeAdjustTitleFontSize(chart, g2, width);
    chart.draw(g2, new Rectangle2D.Double(0, 0, width, height), info);
    g2.dispose();

    String outputFormat = getSetting("outputFormat");
    OutputStream imgOut;
    if (isHtmlMode()) {
        imgOut = PngCache.getOutputStream();
    } else {
        imgOut = outStream;
    }
    ImageIO.write(img, outputFormat, imgOut);
    imgOut.flush();
    imgOut.close();
    if (isHtmlMode())
        writeImageHtml(width, height, imgOut.hashCode(), info);
}

From source file:lucee.runtime.tag.Chart.java

private void setAxis(Axis axis, Font font) {
    if (axis != null) {
        axis.setLabelFont(font);//w  w  w.ja  v a  2 s .co m
        axis.setLabelPaint(foregroundcolor);

        axis.setTickLabelFont(font);
        axis.setTickLabelPaint(foregroundcolor);
        axis.setTickLabelsVisible(true);
    }
}

From source file:com.xpn.xwiki.plugin.charts.ChartCustomizer.java

public static void customizeAxis(Axis axis, ChartParams params, String prefix) {

    if (params.get(prefix + ChartParams.AXIS_VISIBLE_SUFIX) != null
            && params.getBoolean(prefix + ChartParams.AXIS_VISIBLE_SUFIX).booleanValue() == false) {
        axis.setVisible(false);//from  w w  w  . j  av a  2  s .c o  m

    } else {
        if (params.get(prefix + ChartParams.AXIS_LINE_VISIBLE_SUFFIX) != null) {
            if (params.getBoolean(prefix + ChartParams.AXIS_LINE_VISIBLE_SUFFIX).booleanValue()) {
                axis.setAxisLineVisible(true);

                if (params.get(prefix + ChartParams.AXIS_LINE_COLOR_SUFFIX) != null) {
                    axis.setAxisLinePaint(params.getColor(prefix + ChartParams.AXIS_LINE_COLOR_SUFFIX));
                }

                if (params.get(prefix + ChartParams.AXIS_LINE_STROKE_SUFFIX) != null) {
                    axis.setAxisLineStroke(params.getStroke(prefix + ChartParams.AXIS_LINE_STROKE_SUFFIX));
                }
            } else {
                axis.setAxisLineVisible(false);
            }
        }

        if (params.get(prefix + ChartParams.AXIS_LABEL_SUFFIX) != null) {
            axis.setLabel(params.getString(prefix + ChartParams.AXIS_LABEL_SUFFIX));

            if (params.get(prefix + ChartParams.AXIS_LABEL_FONT_SUFFIX) != null) {
                axis.setLabelFont(params.getFont(prefix + ChartParams.AXIS_LABEL_FONT_SUFFIX));
            }

            if (params.get(prefix + ChartParams.AXIS_LABEL_COLOR_SUFFIX) != null) {
                axis.setLabelPaint(params.getColor(prefix + ChartParams.AXIS_LABEL_COLOR_SUFFIX));
            }

            if (params.get(prefix + ChartParams.AXIS_LABEL_INSERTS_SUFFIX) != null) {
                axis.setLabelInsets(params.getRectangleInsets(prefix + ChartParams.AXIS_LABEL_INSERTS_SUFFIX));
            }
        }

        if (params.get(prefix + ChartParams.AXIS_TICK_LABEL_VISIBLE_SUFFIX) != null) {
            if (params.getBoolean(prefix + ChartParams.AXIS_TICK_LABEL_VISIBLE_SUFFIX).booleanValue()) {
                axis.setTickLabelsVisible(true);

                if (params.get(prefix + ChartParams.AXIS_TICK_LABEL_FONT_SUFFIX) != null) {
                    axis.setTickLabelFont(params.getFont(prefix + ChartParams.AXIS_TICK_LABEL_FONT_SUFFIX));
                }

                if (params.get(prefix + ChartParams.AXIS_TICK_LABEL_COLOR_SUFFIX) != null) {
                    axis.setTickLabelPaint(params.getColor(prefix + ChartParams.AXIS_TICK_LABEL_COLOR_SUFFIX));
                }

                if (params.get(prefix + ChartParams.AXIS_TICK_LABEL_INSERTS_SUFFIX) != null) {
                    axis.setTickLabelInsets(
                            params.getRectangleInsets(prefix + ChartParams.AXIS_TICK_LABEL_INSERTS_SUFFIX));
                }

            } else {
                axis.setTickLabelsVisible(false);
            }
        }

        if (params.get(prefix + ChartParams.AXIS_TICK_MARK_VISIBLE_SUFFIX) != null) {
            if (params.getBoolean(prefix + ChartParams.AXIS_TICK_MARK_VISIBLE_SUFFIX).booleanValue()) {
                axis.setTickMarksVisible(true);

                if (params.get(prefix + ChartParams.AXIS_TICK_MARK_INSIDE_LENGTH_SUFFIX) != null) {
                    axis.setTickMarkInsideLength(params
                            .getFloat(prefix + ChartParams.AXIS_TICK_MARK_INSIDE_LENGTH_SUFFIX).floatValue());
                }

                if (params.get(prefix + ChartParams.AXIS_TICK_MARK_OUTSIDE_LENGTH_SUFFIX) != null) {
                    axis.setTickMarkOutsideLength(params
                            .getFloat(prefix + ChartParams.AXIS_TICK_MARK_OUTSIDE_LENGTH_SUFFIX).floatValue());
                }

                if (params.get(prefix + ChartParams.AXIS_TICK_MARK_COLOR_SUFFIX) != null) {
                    axis.setTickMarkPaint(params.getColor(prefix + ChartParams.AXIS_TICK_MARK_COLOR_SUFFIX));
                }

                if (params.get(prefix + ChartParams.AXIS_TICK_MARK_COLOR_SUFFIX) != null) {
                    axis.setTickMarkStroke(params.getStroke(prefix + ChartParams.AXIS_TICK_MARK_STROKE_SUFFIX));
                }

            } else {
                axis.setTickMarksVisible(false);
            }
        }
    }
}

From source file:org.operamasks.faces.render.graph.ChartRenderer.java

protected void setAxisStyles(Axis axis, UIAxis comp) {
    axis.setVisible(comp.isVisible());//from   w w w . j a  v  a  2 s  .c  o m
    axis.setAxisLineVisible(comp.isDrawLine());
    axis.setTickLabelsVisible(comp.isDrawTickLabels());
    axis.setTickMarksVisible(comp.isDrawTickMarks());

    String label = comp.getLabel();
    Font labelFont = comp.getLabelFont();
    Paint labelColor = comp.getLabelColor();
    Paint lineColor = comp.getLineColor();
    Font tickLabelFont = comp.getTickLabelFont();
    Paint tickLabelColor = comp.getTickLabelColor();
    Paint tickMarkColor = comp.getTickMarkColor();

    if (label != null)
        axis.setLabel(label);
    if (labelFont != null)
        axis.setLabelFont(labelFont);
    if (labelColor != null)
        axis.setLabelPaint(labelColor);
    if (lineColor != null)
        axis.setAxisLinePaint(lineColor);
    if (tickLabelFont != null)
        axis.setTickLabelFont(tickLabelFont);
    if (tickLabelColor != null)
        axis.setTickLabelPaint(tickLabelColor);
    if (tickMarkColor != null)
        axis.setTickMarkPaint(tickMarkColor);
    axis.setTickMarkInsideLength(comp.getTickMarkInsideLength());
    axis.setTickMarkOutsideLength(comp.getTickMarkOutsideLength());

    if (axis instanceof CategoryAxis) {
        setCategoryAxisStyles((CategoryAxis) axis, comp);
    } else if (axis instanceof DateAxis) {
        setDateAxisStyles((DateAxis) axis, comp);
    } else if (axis instanceof NumberAxis) {
        setNumberAxisStyles((NumberAxis) axis, comp);
    }
}

From source file:com.appnativa.rare.ui.chart.jfreechart.ChartHandler.java

private void customizeAxisEx(ChartDefinition cd, ChartAxis ai, Axis axis) {
    axis.setLabelPaint(getAxisTitleColor(ai));
    axis.setTickLabelPaint(getAxisLabelColor(ai));
    axis.setLabelFont(getAxisTitleFont(ai));
    axis.setTickLabelFont(getAxisLabelFont(ai));
    axis.setVisible(ai.isVisible());/*from ww w .jav a 2  s. c o  m*/
    axis.setTickLabelsVisible(ai.isLabelsVisible());
}

From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java

/**
 * Sets all the axis formatting options.  This includes the colors and fonts to use on
 * the axis as well as the color to use when drawing the axis line.
 *
 * @param axis the axis to format//from w  ww .  j  a v a 2 s.c  o m
 * @param labelFont the font to use for the axis label
 * @param labelColor the color of the axis label
 * @param tickLabelFont the font to use for each tick mark value label
 * @param tickLabelColor the color of each tick mark value label
 * @param tickLabelMask formatting mask for the label.  If the axis is a NumberAxis then
 *                    the mask should be <code>java.text.DecimalFormat</code> mask, and
 *                   if it is a DateAxis then the mask should be a
 *                   <code>java.text.SimpleDateFormat</code> mask.
 * @param verticalTickLabels flag to draw tick labels at 90 degrees
 * @param lineColor color to use when drawing the axis line and any tick marks
 */
protected void configureAxis(Axis axis, JRFont labelFont, Color labelColor, JRFont tickLabelFont,
        Color tickLabelColor, String tickLabelMask, Boolean verticalTickLabels, Color lineColor,
        boolean isRangeAxis, Comparable<?> axisMinValue, Comparable<?> axisMaxValue) {
    axis.setLabelFont(fontUtil.getAwtFont(getFont(labelFont), getLocale()));
    axis.setTickLabelFont(fontUtil.getAwtFont(getFont(tickLabelFont), getLocale()));
    if (labelColor != null) {
        axis.setLabelPaint(labelColor);
    }

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

    if (lineColor != null) {
        axis.setAxisLinePaint(lineColor);
        axis.setTickMarkPaint(lineColor);
    }

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

    // FIXME use locale for formats
    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());
            }

            if (timeZone != null) {
                fmt.setTimeZone(timeZone);
            }

            ((DateAxis) axis).setDateFormatOverride(fmt);
        }
        // ignore mask for other axis types.
    }

    if (verticalTickLabels != null && axis instanceof ValueAxis) {
        ((ValueAxis) axis).setVerticalTickLabels(verticalTickLabels);
    }

    setAxisBounds(axis, isRangeAxis, axisMinValue, axisMaxValue);
}

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void draw(Graphics2D g2, Rectangle2D area, double shiftX, double shiftY) {
    //       g2.setPaint(Color.white);
    //      g2.fill(new Rectangle2D.Double(0, 0, getWidth(), getHeight()));
    //      if (getChart() != null) {
    ////         Image chartImage = getChart().createBufferedImage((int) area.getWidth(),
    ////               (int) area.getHeight());
    ////         g2.drawImage(chartImage, (int) area.getMinX(), (int) area.getMinY(), 
    ////               this);
    //         getChart().draw(g2, area, getAnchor(), null);
    //         ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), maskList, 
    //               null, getChart());
    //      }/*from   www  . j  ava 2s .c  o  m*/
    double widthRatio = area.getWidth() / getWidth();
    double heightRatio = area.getHeight() / getHeight();
    double overallRatio = 1;
    overallRatio = widthRatio < heightRatio ? widthRatio : heightRatio;

    XYPlot plot = (XYPlot) getChart().getPlot();
    Font domainFont = plot.getDomainAxis().getLabelFont();
    int domainSize = domainFont.getSize();
    Font rangeFont = plot.getRangeAxis().getLabelFont();
    int rangeSize = rangeFont.getSize();
    TextTitle titleBlock = getChart().getTitle();
    Font titleFont = null;
    int titleSize = 0;
    if (titleBlock != null) {
        titleFont = titleBlock.getFont();
        titleSize = titleFont.getSize();
        getChart().getTitle().setFont(titleFont.deriveFont((float) (titleSize * overallRatio)));
    }
    Font domainScaleFont = plot.getDomainAxis().getTickLabelFont();
    int domainScaleSize = domainScaleFont.getSize();
    Font rangeScaleFont = plot.getRangeAxis().getTickLabelFont();
    int rangeScaleSize = rangeScaleFont.getSize();
    plot.getDomainAxis().setLabelFont(domainFont.deriveFont((float) (domainSize * overallRatio)));
    plot.getRangeAxis().setLabelFont(rangeFont.deriveFont((float) (rangeSize * overallRatio)));
    plot.getDomainAxis().setTickLabelFont(domainScaleFont.deriveFont((float) (domainScaleSize * overallRatio)));
    plot.getRangeAxis().setTickLabelFont(rangeScaleFont.deriveFont((float) (rangeScaleSize * overallRatio)));
    LegendTitle legend = getChart().getLegend();
    Font legendFont = null;
    int legendFontSize = 0;
    if (legend != null) {
        legendFont = legend.getItemFont();
        legendFontSize = legendFont.getSize();
        legend.setItemFont(legendFont.deriveFont((float) (legendFontSize * overallRatio)));
    }

    Rectangle2D chartArea = (Rectangle2D) area.clone();
    getChart().getPadding().trim(chartArea);
    if (titleBlock != null) {
        AxisUtilities.trimTitle(chartArea, g2, titleBlock, titleBlock.getPosition());
    }

    Axis scaleAxis = null;
    Font scaleAxisFont = null;
    int scaleAxisFontSize = 0;
    for (Object object : getChart().getSubtitles()) {
        Title title = (Title) object;
        if (title instanceof PaintScaleLegend) {
            scaleAxis = ((PaintScaleLegend) title).getAxis();
            scaleAxisFont = scaleAxis.getTickLabelFont();
            scaleAxisFontSize = scaleAxisFont.getSize();
            scaleAxis.setTickLabelFont(scaleAxisFont.deriveFont((float) (scaleAxisFontSize * overallRatio)));
        }
        AxisUtilities.trimTitle(chartArea, g2, title, title.getPosition());
    }
    AxisSpace axisSpace = AxisUtilities.calculateAxisSpace(getChart().getXYPlot(), g2, chartArea);
    Rectangle2D dataArea = axisSpace.shrink(chartArea, null);
    getChart().getXYPlot().getInsets().trim(dataArea);
    getChart().getXYPlot().getAxisOffset().trim(dataArea);

    //        Rectangle2D screenArea = getScreenDataArea();
    //        Rectangle2D visibleArea = getVisibleRect();
    //        Rectangle2D printScreenArea = new Rectangle2D.Double(screenArea.getMinX() * overallRatio + x, 
    //              screenArea.getMinY() * overallRatio + y, 
    //              printArea.getWidth() - visibleArea.getWidth() + screenArea.getWidth(), 
    //              printArea.getHeight() - visibleArea.getHeight() + screenArea.getHeight());

    getChart().draw(g2, area, getAnchor(), null);
    ChartMaskingUtilities.drawMasks(g2, dataArea, maskList, null, getChart(), overallRatio);
    ChartMaskingUtilities.drawShapes(g2, dataArea, shapeMap, getChart());
    ChartMaskingUtilities.drawText(g2, dataArea, textContentMap, getChart());
    plot.getDomainAxis().setLabelFont(domainFont);
    plot.getRangeAxis().setLabelFont(rangeFont);
    if (titleBlock != null) {
        titleBlock.setFont(titleFont);
    }
    if (legend != null) {
        legend.setItemFont(legendFont);
    }
    plot.getDomainAxis().setTickLabelFont(domainScaleFont);
    plot.getRangeAxis().setTickLabelFont(rangeScaleFont);
    if (scaleAxis != null) {
        scaleAxis.setTickLabelFont(scaleAxisFont);
    }
    //        System.out.println("print " + titleBlock.getText() + 
    //              " at [" + area.getX() + ", " + area.getY() + ", " + 
    //              area.getWidth() + ", " + area.getHeight() + "]");
}

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

protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask,
        Integer baseFontSize) {//  ww  w .j  av a2  s  . com
    Boolean defaultAxisTickLabelsVisible = (Boolean) getDefaultValue(defaultAxisPropertiesMap,
            ChartThemesConstants.AXIS_TICK_LABELS_VISIBLE);
    if (defaultAxisTickLabelsVisible != null && defaultAxisTickLabelsVisible.booleanValue()) {
        Font themeTickLabelFont = getFont(
                (JRFont) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABEL_FONT),
                tickLabelFont, baseFontSize);
        axis.setTickLabelFont(themeTickLabelFont);

        RectangleInsets defaultTickLabelInsets = (RectangleInsets) getDefaultValue(defaultAxisPropertiesMap,
                ChartThemesConstants.AXIS_TICK_LABEL_INSETS);
        if (defaultTickLabelInsets != null) {
            axis.setTickLabelInsets(defaultTickLabelInsets);
        }
        Paint tickLabelPaint = tickLabelColor != null ? tickLabelColor
                : (Paint) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABEL_PAINT);
        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();
                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);
                else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM"))
                    fmt = DateFormat.getDateInstance(DateFormat.MEDIUM);
                else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG"))
                    fmt = DateFormat.getDateInstance(DateFormat.LONG);
                else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL"))
                    fmt = DateFormat.getDateInstance(DateFormat.FULL);
                else
                    fmt = new SimpleDateFormat(tickLabelMask);

                // 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));
            }
            // ignore mask for other axis types.
        }
    }
}

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

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

    axis.setTickLabelsVisible(axisTickLabelsVisible);

    if (axisTickLabelsVisible) {
        JRBaseFont font = new JRBaseFont();
        JRFontUtil.copyNonNullOwnProperties(axisSettings.getTickLabelFont(), font);
        JRFontUtil.copyNonNullOwnProperties(tickLabelFont, font);
        font = new JRBaseFont(getChart(), font);
        axis.setTickLabelFont(JRFontUtil.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();
                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);
                else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM"))
                    fmt = DateFormat.getDateInstance(DateFormat.MEDIUM);
                else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG"))
                    fmt = DateFormat.getDateInstance(DateFormat.LONG);
                else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL"))
                    fmt = DateFormat.getDateInstance(DateFormat.FULL);
                else
                    fmt = new SimpleDateFormat(tickLabelMask);

                // 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));
            }
            // ignore mask for other axis types.
        }
    }
}

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

protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask,
        Integer baseFontSize) {/*from ww  w . ja v a 2  s .co m*/
    Boolean defaultAxisTickLabelsVisible = (Boolean) getDefaultValue(defaultAxisPropertiesMap,
            ChartThemesConstants.AXIS_TICK_LABELS_VISIBLE);
    if (defaultAxisTickLabelsVisible != null && defaultAxisTickLabelsVisible) {
        Font themeTickLabelFont = getFont(
                (JRFont) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABEL_FONT),
                tickLabelFont, baseFontSize);
        axis.setTickLabelFont(themeTickLabelFont);

        RectangleInsets defaultTickLabelInsets = (RectangleInsets) getDefaultValue(defaultAxisPropertiesMap,
                ChartThemesConstants.AXIS_TICK_LABEL_INSETS);
        if (defaultTickLabelInsets != null) {
            axis.setTickLabelInsets(defaultTickLabelInsets);
        }
        Paint tickLabelPaint = tickLabelColor != null ? tickLabelColor
                : (Paint) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABEL_PAINT);
        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.
        }
    }
}