Search in sources :

Example 1 with LegendItemSource

use of org.jfree.chart.LegendItemSource in project tdq-studio-se by Talend.

the class ChartDecorator method setLegendFont.

/**
 * if it contians CJK, set Font to "Arial Unicode MS".Or else, the Font is "Tahoma".
 *
 * @param chart
 */
private static void setLegendFont(JFreeChart chart) {
    Font font;
    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        // $NON-NLS-1$
        font = new Font("Tahoma", Font.PLAIN, BASE_LEGEND_LABEL_SIZE);
        // get legend label to judge if it contains CJK.
        LegendItemSource[] sources = legend.getSources();
        Set<String> itemLabels = new HashSet<String>();
        for (LegendItemSource source : sources) {
            LegendItemCollection legendItems = source.getLegendItems();
            for (int i = 0; i < legendItems.getItemCount(); i++) {
                String label = legendItems.get(i).getLabel();
                if (label != null) {
                    itemLabels.add(label);
                }
            }
        }
        if (isContainCJKCharacter(itemLabels.toArray())) {
            font = getCJKFont(Font.PLAIN, BASE_LEGEND_LABEL_SIZE);
        }
        legend.setItemFont(font);
    }
}
Also used : LegendItemSource(org.jfree.chart.LegendItemSource) LegendItemCollection(org.jfree.chart.LegendItemCollection) LegendTitle(org.jfree.chart.title.LegendTitle) Font(java.awt.Font) Paint(java.awt.Paint) HashSet(java.util.HashSet)

Aggregations

Font (java.awt.Font)1 Paint (java.awt.Paint)1 HashSet (java.util.HashSet)1 LegendItemCollection (org.jfree.chart.LegendItemCollection)1 LegendItemSource (org.jfree.chart.LegendItemSource)1 LegendTitle (org.jfree.chart.title.LegendTitle)1