package cnp.ew.slider;

import java.awt.*;
import cnp.ew.util.*;
import cnp.ew.displayer.*;
import cnp.ew.image.*;
import cnp.ew.lightweight.*;
import cnp.ew.scrolling.*;

public class CpBarSliderLc extends CpSliderLc
{
    static int verticalThumbImageId;
    static int horizontalThumbImageId;

    static Cp3DBorderDisplayer borderDisplayer = new Cp3DBorderDisplayer(false, true);

    static {
        verticalThumbImageId = CpToolkit.registerImageName("vbslider.gif");
        horizontalThumbImageId = CpToolkit.registerImageName("hbslider.gif");
    }

    public CpBarSliderLc(int orientation)
    {
        super(orientation);
        if (orientation == CpScrollbarLc.VERTICAL) {
            thumbImage = CpToolkit.getImage(verticalThumbImageId);
            pageSize = thumbImage.getHeight(CpToolkit.defaultComponent());
        } else {
            thumbImage = CpToolkit.getImage(horizontalThumbImageId);
            pageSize = thumbImage.getWidth(CpToolkit.defaultComponent());
        }
        setBorderStyle(BORDER_INWARD3D);
    }

    public void paintBackground(Graphics g)
    {
        int inset = thumbImage.getWidth(CpToolkit.defaultComponent()) / 3;
        Rectangle clientRect = getClientRect();
        borderDisplayer.paintIn(this, g,
            inset + clientRect.x,
            clientRect.y + clientRect.height / 2,
            clientRect.width - (2 * inset),
            3);
    }

    public Dimension preferredSize()
    {
        if (orientation == CpScrollbarLc.HORIZONTAL) {
            return borderedPreferredSize(new Dimension(100, thumbImage.getHeight(CpToolkit.defaultComponent())));
        } else {
            return borderedPreferredSize(new Dimension(thumbImage.getWidth(CpToolkit.defaultComponent()), 100));
        }
    }
}

