package com.srbenoit.color;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * A panel to display gradients with various parameters.
 */
public class GradientPanel extends JPanel {

    /** version number for serialization */
    private static final long serialVersionUID = 5938339262415238099L;

    /** gradient with one cycle */
    private final transient Gradient one;

    /** gradient with two cycles */
    private final transient Gradient two;

    /** gradient with three cycles */
    private final transient Gradient three;

    /** gradient with four cycles */
    private final transient Gradient four;

    /** gradient with five cycles */
    private final transient Gradient five;

    /** gradient with six cycles */
    private final transient Gradient six;

    /**
     * Constructs a new <code>GradientPanel</code>.
     */
    public GradientPanel() {

        super();

        setBackground(Color.BLACK);
        setPreferredSize(new Dimension(1024, 600));

        this.one = new Gradient(1024, 1);
        this.two = new Gradient(1024, 2);
        this.three = new Gradient(1024, 3);
        this.four = new Gradient(1024, 4);
        this.five = new Gradient(1024, 5);
        this.six = new Gradient(1024, 6);
    }

    /**
     * Draws the panel.
     *
     * @param  grx  the <code>Graphics</code> to which to draw
     */
    @Override public void paintComponent(final Graphics grx) {

        super.paintComponent(grx);

        for (int i = 0; i < 1024; i++) {
            grx.setColor(this.one.getColor(i));
            grx.drawLine(i, 10, i, 80);
            grx.setColor(this.two.getColor(i));
            grx.drawLine(i, 110, i, 180);
            grx.setColor(this.three.getColor(i));
            grx.drawLine(i, 210, i, 280);
            grx.setColor(this.four.getColor(i));
            grx.drawLine(i, 310, i, 380);
            grx.setColor(this.five.getColor(i));
            grx.drawLine(i, 410, i, 480);
            grx.setColor(this.six.getColor(i));
            grx.drawLine(i, 510, i, 580);
        }
    }

    /**
     * Main method to display the panel.
     *
     * @param  args  command-line arguments
     */
    public static void main(final String... args) {

        GradientPanel panel;
        JFrame frame;

        panel = new GradientPanel();

        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setContentPane(panel);
        frame.pack();
        frame.setLocation(200, 0);
        frame.setVisible(true);
    }
}
