package cnp.ew.misc;
import cnp.ew.util.*;
import cnp.ew.displayer.*;
import java.awt.*;
import cnp.ew.lightweight.*;

public class CpValueViewerLc extends CpAbstractLc
{

    public static final int ORIENT_HORZ = CpOrientable.ORIENT_LEFT_TO_RIGHT;
    public static final int ORIENT_VERT = CpOrientable.ORIENT_BOTTOM_TO_TOP;
    public static final int STYLE_BOXED = 0;
    public static final int STYLE_SOLID = 1;
    public static final int STYLE_LABELED_SOLID=2;

    CpOrientableValueDisplayable statusDisplayer;
    int style;

    public CpValueViewerLc(int newStyle)
    {
        style = newStyle;
        setBorderStyle(BORDER_INWARD3D);
        setStyle(style);
    }

    public CpValueViewerLc()
    {
        this(STYLE_BOXED);
    }

    public void setOrientation(int orientation)
    {
        statusDisplayer.setOrientation(orientation);
    }

    public int getOrientation()
    {
        return statusDisplayer.getOrientation();
    }

    public void setValues(int min, int max, int value)
    {
        statusDisplayer.setMin(min);
        statusDisplayer.setMax(max);
        statusDisplayer.setValue(value);
    }

    public void setStyle(int newStyle)
    {
        CpOrientableValueDisplayable newStatusDisplayer;
        style = newStyle;

        switch (newStyle) {
        case STYLE_BOXED:
            statusDisplayer = new CpBoxedValueDisplayer();
            break;
        case STYLE_LABELED_SOLID:
            statusDisplayer = new CpBarValueDisplayer();
            ((CpBarValueDisplayer)statusDisplayer).setShowPercentage(true);
            break;
        case STYLE_SOLID:
            statusDisplayer = new CpBarValueDisplayer();
            ((CpBarValueDisplayer)statusDisplayer).setShowPercentage(false);
            break;
        default:
            throw new IllegalArgumentException("invalid value viewer style");
        }
        repaint();
    }

    public int getStyle()
    {
        return style;
    }

    public void setValue(int value)
    {
        statusDisplayer.setValue(value);
        repaint();
    }

    public int getValue()
    {
        return statusDisplayer.getValue();
    }

    public Dimension preferredSize()
    {
        return borderedPreferredSize(statusDisplayer.preferredSize(this));
    }


    public void paint(Graphics g, Rectangle clipRect)
    {
        statusDisplayer.paintIn(this, g, getClientRect());
    }
}

