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);
}
}
Aggregations