// 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:   Axis2DX.java

package lt.monarch.chart.chart2D;

import java.awt.*;
import lt.monarch.chart.*;

// Referenced classes of package lt.monarch.chart.chart2D:
//            Axis2D, NormalizedPoint2D

public class Axis2DX extends Axis2D
{

    public Axis2DX(AxisMapper axismapper)
    {
        super(axismapper);
    }

    public void draw(Graphics g)
    {
        Projector projector = chart().projector();
        Point point = projector.project(new NormalizedPoint2D(0.0D, 0.0D));
        Point point1 = projector.project(new NormalizedPoint2D(1.0D, 1.0D));
        g.setColor(Color.black);
        g.drawLine(point.x, point.y, point1.x, point.y);
        g.setFont(super.font);
        FontMetrics fontmetrics = g.getFontMetrics();
        int i = fontmetrics.stringWidth(" ");
        String s = "";
        for (int j = 0; j < super.mapper.labelCount(); j++)
            s = s + " " + super.mapper.label(j) + " ";

        int k = fontmetrics.stringWidth(s) / Math.abs(point1.x - point.x) + 1;
        int l = super.label == null ? 0 : point1.x - fontmetrics.stringWidth(super.label);
        for (int i1 = k / 2; i1 < super.mapper.labelCount(); i1 += k)
        {
            String s1 = super.mapper.label(i1);
            Point point2 = projector.project(new NormalizedPoint2D(super.mapper.mapLabel(i1), 0.0D));
            if (l != 0 && point2.x + fontmetrics.stringWidth(s1) / 2 > l)
                break;
            g.drawString(s1, point2.x - fontmetrics.stringWidth(s1) / 2, (point2.y + fontmetrics.getHeight() + i) - 1);
            g.drawLine(point2.x, point2.y, point2.x, point2.y + i);
        }

        if (super.label != null)
            g.drawString(super.label, point1.x - fontmetrics.stringWidth(super.label), (point.y + fontmetrics.getHeight() + i) - 1);
    }

    public int height(Graphics g)
    {
        FontMetrics fontmetrics = g.getFontMetrics(super.font);
        return fontmetrics.getHeight();
    }
}
