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 CpScrollbarSliderLc extends CpAbstractSliderLc
{
    static Cp3DBorderDisplayer thumbDisplayer = new Cp3DBorderDisplayer(true, false, true);

    public CpScrollbarSliderLc(int orientation)
    {
        super(orientation);
        min = 0;
    }

	public void setValues(int value, int pageSize, int max)
    {
        if (this.max != max || this.pageSize != pageSize || this.value != value) {
            this.max = max;
            this.pageSize = pageSize;
            this.value = value;
            repaint();
        }
    }

    public void paintBackground(Graphics g)
    {
        g.setColor(new Color(220, 220, 220));
        g.fillRect(0, 0, size().width, size().height);
    }

    public void paintThumb(Graphics g)
    {
        g.setColor(Color.lightGray);
        Rectangle thumbRect = getThumbRect();
        g.fillRect(thumbRect.x, thumbRect.y, thumbRect.width, thumbRect.height);
        thumbDisplayer.paintIn(this, g, thumbRect);
    }

    int getThumbSizeInPixels()
    {
        int range = max - min;
        // This always rounds up; otherwise, we'd potentially be one pixel
        // short when we hit the right or bottom, which is annoying...
        return (pageSize * getScaleDimension()  + (range - 1))/ range;
    }

    int getWindowSize()
    {
        return pageSize;
    }

    int getAmountToPage()
    {
        return getWindowSize() - 1;
    }

    public Dimension preferredSize()
    {
        if (orientation == CpScrollbarLc.HORIZONTAL) {
            return new Dimension(100, 16);
        } else {
            return new Dimension(16, 100);
        }
    }
}

