package litebrite.paintingbased;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import litebrite.ColorNamePair;

public class LiteBriteFrame extends JFrame
{
  public LiteBriteFrame()
  {
    // Set the size of the window
    setSize(500, 500);

    // Add a lite brite board to the frame
    final LiteBriteBoard board = new LiteBriteBoard(20, 20);
    add(board);

    // Add a panel to hold the color controls
    JPanel colorPanel = new JPanel();
    colorPanel.add(new JLabel("Color: "));

    // Make a combo box for picking the current color
    JComboBox colorBox = new JComboBox(ColorNamePair.COLOR_LIST);

    // Update the current color of the board when a color is selected from the
    // combo box
    colorBox.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        JComboBox source = (JComboBox) e.getSource();
        ColorNamePair pair = (ColorNamePair) source.getSelectedItem();
        board.setCurrentColor(pair.getColor());
      }
    });

    colorPanel.add(colorBox);
    add(colorPanel, BorderLayout.NORTH);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
  }

  public static void main(String[] args)
  {
    java.awt.EventQueue.invokeLater(new Runnable()
    {
      public void run()
      {
        new LiteBriteFrame().setVisible(true);
      }
    });
  }
}
