package net.sf.jasperreports.charts.util;

import java.util.Map;
import org.jfree.chart.labels.StandardXYItemLabelGenerator;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeriesCollection;

public class XYDatasetLabelGenerator extends StandardXYItemLabelGenerator {
  private static final long serialVersionUID = 10200L;
  
  private Map labelsMap = null;
  
  public XYDatasetLabelGenerator(Map labelsMap) {
    this.labelsMap = labelsMap;
  }
  
  public String generateLabel(XYDataset dataset, int series, int item) {
    Comparable seriesName = dataset.getSeriesKey(series);
    Map labels = (Map)this.labelsMap.get(seriesName);
    if (labels != null)
      return (String)labels.get(((XYSeriesCollection)dataset).getX(series, item)); 
    return super.generateLabel(dataset, series, item);
  }
}
