// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) fieldsfirst 
// Source File Name:   Axis2DY.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 Axis2DY extends Axis2D
{

	boolean alignRight;

	public Axis2DY(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);
		if(alignRight)
			g.drawLine(point1.x, point.y, point1.x, point1.y);
		else
			g.drawLine(point.x, point.y, point.x, point1.y);
		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 = j / Math.abs(point.y - point1.y) + 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);
			Point point2 = projector.project(new NormalizedPoint2D(alignRight ? 1 : 0, super.mapper.mapLabel(j1)));
			if(alignRight)
			{
				g.drawString(s, point2.x + i * 2, point2.y + fontmetrics.getHeight() / 3);
				g.drawLine(point2.x, point2.y, point2.x + i, point2.y);
			} else
			{
				g.drawString(s, point2.x - i * 2 - fontmetrics.stringWidth(s), point2.y + fontmetrics.getHeight() / 3);
				g.drawLine(point2.x, point2.y, point2.x - i, point2.y);
			}
		}

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

	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;
	}
}
