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

package lt.monarch.charts;

import java.awt.*;

// Referenced classes of package lt.monarch.charts:
//            Axis, AxisMapper

public class YAxis extends Axis
{

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

    public void draw(Graphics g, Rectangle rectangle)
    {
        g.setColor(Color.black);
        if (alignRight)
            g.drawLine(rectangle.x + rectangle.width, rectangle.y, rectangle.x + rectangle.width, rectangle.y + rectangle.height);
        else
            g.drawLine(rectangle.x, rectangle.y, rectangle.x, rectangle.y + rectangle.height);
        g.setFont(super.font);
        FontMetrics fontmetrics = g.getFontMetrics();
        int i = fontmetrics.stringWidth(" ");
        int j = 0;
        for (int k = 0; k < super.mapper.labelCount(); k++)
            j += fontmetrics.getHeight();

        int l = (int)Math.floor((double)j / (double)rectangle.height) + 1;
        int i1 = super.label == null ? 0 : l;
        for (int j1 = 0; j1 < super.mapper.labelCount() - i1; j1 += l)
        {
            String s = super.mapper.label(j1);
            int l1 = alignRight ? (rectangle.x + rectangle.width) - fontmetrics.stringWidth(s) - i * 2 : rectangle.x + i * 2;
            int i2 = mapLabel(rectangle, j1);
            g.drawString(s, l1, i2 + fontmetrics.getHeight() / 3);
            if (alignRight)
                g.drawLine(rectangle.x + rectangle.width, i2, (rectangle.x + rectangle.width) - i, i2);
            else
                g.drawLine(rectangle.x, i2, rectangle.x + i, i2);
        }

        if (super.label != null)
        {
            int k1 = alignRight ? (rectangle.x + rectangle.width) - fontmetrics.stringWidth(super.label) - i : rectangle.x + i;
            g.drawString(super.label, k1, rectangle.y + fontmetrics.getHeight() / 2);
        }
    }

    public int map(Rectangle rectangle, Object obj)
    {
        return (rectangle.height - super.mapper.map(rectangle.height, obj)) + rectangle.y;
    }

    public int mapLabel(Rectangle rectangle, int i)
    {
        return (rectangle.height - super.mapper.mapLabel(rectangle.height, i)) + rectangle.y;
    }

    public int width(Graphics g)
    {
        FontMetrics fontmetrics = g.getFontMetrics(super.font);
        int i = fontmetrics.stringWidth(" ");
        int j = 0;
        for (int k = 0; k < super.mapper.labelCount(); k++)
            j = Math.max(j, fontmetrics.stringWidth(super.mapper.label(k)));

        if (super.label != null)
            j = Math.max(j, fontmetrics.stringWidth(super.label));
        return j + i;
    }

    boolean alignRight;
}
