package cnp.ew.charts;

import cnp.ew.util.*;
import java.awt.*;
import cnp.ew.displayer.*;

public class CpPieChartLc extends CpAbstractChartLc
{
    CpGeneralStringDisplayer textLabelDisplayer;

    public CpPieChartLc()
    {
        super();

        textLabelDisplayer = new CpGeneralStringDisplayer();
        textLabelDisplayer.setHorizontalAlignment(CpAlignable.ALIGN_CENTER);

        setValuesDisplayer(new CpPieValuesDisplayer());
        // TBD: should have a wrapper model for handling percentages...
        valueAxisModel.setMin(0);
        valueAxisModel.setMax(100);
        valueAxisModel.setMajorStep(10);
    }

    public void paint(Graphics g, Rectangle clip)
    {
        Rectangle bounds = getClientRect();
        g.setColor(getBackground());
        g.fillRect(0, 0, size().width, size().height);
        textLabelDisplayer.setText(chartDataModel.getCategoryForIndex(0));
        textLabelDisplayer.paintIn(this, g, bounds.x, bounds.y, bounds.width, bounds.height);
        int textDisplayerHeight = textLabelDisplayer.preferredSize(this).height + 10;
        valuesDisplayer.paintIn(this, g, bounds.x, bounds.y + textDisplayerHeight, bounds.width, bounds.height - textDisplayerHeight);
    }

    public Point seriesAndCategoryForPoint(Point mouseLocation)
    {
        Rectangle clientRect = getClientRect();
        textLabelDisplayer.setText(chartDataModel.getCategoryForIndex(0));
        int textDisplayerHeight = textLabelDisplayer.preferredSize(this).height + 10;
        Point adjustedMouseLoc = new Point(mouseLocation.x, mouseLocation.y - textDisplayerHeight);
        return valuesDisplayer.seriesAndCategoryForPoint(adjustedMouseLoc, new Rectangle(0, 0, clientRect.width, clientRect.height - textDisplayerHeight));

    }

}

