package cnp.ew.tdemo;

import java.util.*;
import java.io.*;
import java.awt.*;

import cnp.ew.displayer.*;
import cnp.ew.converter.*;
import cnp.ew.lightweight.*;
import cnp.ew.properties.*;
import cnp.ew.util.*;

public class CpReportLine extends CpQuickenTransaction
{
    Object cat;
    int indentLevel;
    String label;
    int amount;
    boolean displayAmount;

    public CpReportLine()
    {
        super();
    }
    public CpReportLine(Object c, int i, String s, int a, boolean d)
    {
        super();
        cat = c;
        indentLevel = i;
        label = s;
        amount = a;
        displayAmount = d;
    }

	public void paintIn(CpLightweightComponent c, Graphics g, int x, int y, int w, int h)
	{
	    FontMetrics fontMetrics = g.getFontMetrics();
		int fontAscent = fontMetrics.getAscent();

        if (selected) {
            g.setColor(new Color(0, 0, 128));
            int mid = y + h / 2;
            Polygon p = new Polygon();
            p.addPoint(x + 3, mid - 6);
            p.addPoint(x + 3, mid + 6);
            p.addPoint(x + 9, mid);
            g.fillPolygon(p);
        }

        int rightNum = 410 - ((indentLevel - 1) * 85);
        if (rightNum > 410) {  // Hack for Major totals, where text is exdented but # isnot
            rightNum = 410;
        }

        if (showFocus) {
            CpFocusRect.drawFocusRect(g, x, y, rightNum + 10 - x, h);
        }

        if (label.equals("-") | label.equals("=")) {
            g.setColor(Color.black);
            if (label.equals("=")) {
                g.drawLine(rightNum - 85, y + 6, rightNum + 8, y + 6);
            }
            g.drawLine(rightNum - 85, y + 9, rightNum + 8, y + 9);
            return;
        }

        int xLabel = 14 + (indentLevel * 15);
        g.setColor(new Color(0, 0, 128));
        g.drawString(label, x + xLabel, y + fontAscent + 2);

        if (displayAmount) {
            if (amount < 0) {
                g.setColor(Color.red);
            } else {
                g.setColor(Color.black);
            }

            String amountString = CpBasicType.CURRENCY.getDefaultConverter().convert(new Double(amount / 100));
            g.drawString(amountString, rightNum - fontMetrics.stringWidth(amountString), y + fontAscent);
        }


    }

}

