/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.stephenphilbin.colourcoder;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import javax.swing.JSlider;

/**
 *
 * @author Stephen Philbin
 */
public class LightSliderPanel extends JPanel {

    public static final int RED = 0;
    public static final int GREEN = 1;
    public static final int BLUE = 2;
    protected int represents;
    protected JSlider r;
    protected JSlider g;
    protected JSlider b;

    public LightSliderPanel(int colour) {
        super();
        setDoubleBuffered(true);
        setColour(colour);
    }

    public final void setColour(int colour) {
        represents = colour;
    }

    public void setRedSource(JSlider r) {
        this.r = r;
    }

    public void setGreenSource(JSlider g) {
        this.g = g;
    }

    public void setBlueSource(JSlider b) {
        this.b = b;
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (this.getSize().height == 256 && this.getBorder() == null) {
            switch (this.represents) {

                case RED:
                    for (int h = 0; h < 256; h++) {
                        g.setColor(new Color(h, this.g.getValue(), this.b.getValue()));
                        g.drawLine(0, 255 - h, this.getSize().width, 255 - h);
                    }
                    break;
                    
                case GREEN:
                    for (int h = 0; h < 256; h++) {
                        g.setColor(new Color(this.r.getValue(), h, this.b.getValue()));
                        g.drawLine(0, 255 - h, this.getSize().width, 255 - h);
                    }
                    break;
                    
                case BLUE:
                    for (int h = 0; h < 256; h++) {
                        g.setColor(new Color(this.r.getValue(), this.g.getValue(), h));
                        g.drawLine(0, 255 - h, this.getSize().width, 255 - h);
                    }
                    break;
            }
        }
        g.dispose();
    }
}
