package net.sf.jasperreports.charts.util;

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

public class TimePeriodDatasetLabelGenerator extends StandardXYItemLabelGenerator {
  private static final long serialVersionUID = 10200L;
  
  private Map labelsMap = null;
  
  public TimePeriodDatasetLabelGenerator(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(((TimePeriodValuesCollection)dataset).getSeries(series).getTimePeriod(item)); 
    return super.generateLabel(dataset, series, item);
  }
}
