// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) space 
// Source File Name:   Grid.java

package lt.monarch.chart;

import java.awt.*;
import lt.monarch.chart.chart2D.Axis2D;
import lt.monarch.chart.chart2D.PlainMapper2D;

// Referenced classes of package lt.monarch.chart:
//            AbstractChartObject, Chart, PlainMapper, Projector, 
//            AxisMapper, Axis

public class Grid extends AbstractChartObject
{

    public void setGridColor(Color color)
    {
        gridColor = color;
    }

    public void setFillColor(Color color)
    {
        fillColor = color;
    }

    public void draw(Graphics g)
    {
        Projector projector = chart().projector();
        NormalizedPoint normalizedpoint = mapper.map(0.0D, 0.0D);
        if (fillColor != null)
        {
            g.setColor(fillColor);
            Point point = projector.project(mapper.map(0.0D, 0.0D, normalizedpoint));
            Point point2 = projector.project(mapper.map(0.0D, 1.0D, normalizedpoint));
            Point point4 = projector.project(mapper.map(1.0D, 1.0D, normalizedpoint));
            Point point5 = projector.project(mapper.map(1.0D, 0.0D, normalizedpoint));
            Polygon polygon = new Polygon();
            polygon.addPoint(point.x, point.y);
            polygon.addPoint(point2.x, point2.y);
            polygon.addPoint(point4.x, point4.y);
            polygon.addPoint(point5.x, point5.y);
            g.fillPolygon(polygon);
            g.setColor(gridColor);
            g.drawPolygon(polygon);
        }
        Point point1 = new Point();
        Point point3 = new Point();
        g.setColor(gridColor);
        if (yMapper != null)
        {
            for (int i = 0; i < yMapper.labelCount(); i++)
            {
                double d = yMapper.mapLabel(i);
                projector.project(mapper.map(0.0D, d, normalizedpoint), point1);
                projector.project(mapper.map(1.0D, d, normalizedpoint), point3);
                g.drawLine(point1.x, point1.y, point3.x, point3.y);
            }

        }
        if (xMapper != null)
        {
            for (int j = 0; j < xMapper.labelCount(); j++)
            {
                double d1 = xMapper.mapLabel(j);
                projector.project(mapper.map(d1, 0.0D, normalizedpoint), point1);
                projector.project(mapper.map(d1, 1.0D, normalizedpoint), point3);
                g.drawLine(point1.x, point1.y, point3.x, point3.y);
            }

        }
    }

    public Grid(PlainMapper plainmapper, AxisMapper axismapper, AxisMapper axismapper1)
    {
        mapper = plainmapper;
        xMapper = axismapper;
        yMapper = axismapper1;
        gridColor = Color.gray;
        fillColor = new Color(240, 240, 240);
    }

    public Grid(Axis2D axis2d, Axis2D axis2d1)
    {
        this(((PlainMapper) (new PlainMapper2D())), axis2d != null ? ((Axis) (axis2d)).mapper : null, axis2d1 != null ? ((Axis) (axis2d1)).mapper : null);
    }

    protected final PlainMapper mapper;
    protected final AxisMapper xMapper;
    protected final AxisMapper yMapper;
    protected Color gridColor;
    protected Color fillColor;
}
