package de.rico.editor.gui.dialog;

import java.awt.Font;
import java.awt.Frame;
import java.awt.Rectangle;
import java.util.ArrayList;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

import de.rico.editor.WorldEditor;
import de.rico.engine.effect.light.LightIface;
import de.rico.engine.effect.light.ogllight.PositionalLight;

/**
 * A dialog to set the shadow reference light.
 * @author Frank Bruns
 *
 */
public class DialogSetShadowRefLight extends JDialog
{

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JButton btnAddLight = null;

	private JLabel labelHeadline = null;

	private JLabel labelNr = null;

	private JComboBox comboNr = null;

	/**
	 * @param owner
	 */
	public DialogSetShadowRefLight(Frame owner)
	{
		super(owner, "Set shadow reference light", true);
		this.initialize();
	}

	/**
	 * This method initializes this
	 *
	 * @return void
	 */
	private void initialize()
	{
		this.setSize(277, 181);
		this.setContentPane(this.getJContentPane());
	}

	/**
	 * This method initializes jContentPane
	 *
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane()
	{
		if (this.jContentPane == null)
		{
			this.labelNr = new JLabel();
			this.labelNr.setBounds(new Rectangle(15, 60, 106, 16));
			this.labelNr.setText("Possible lights:");
			this.labelHeadline = new JLabel();
			this.labelHeadline.setBounds(new Rectangle(15, 15, 226, 31));
			this.labelHeadline.setFont(new Font("Tahoma", Font.BOLD, 14));
			this.labelHeadline.setText("Set the shadow reference light");
			this.jContentPane = new JPanel();
			this.jContentPane.setLayout(null);
			this.jContentPane.add(this.getBtnAddLight(), null);
			this.jContentPane.add(this.labelHeadline, null);
			this.jContentPane.add(this.labelNr, null);
			this.jContentPane.add(this.getComboNr(), null);
		}
		return this.jContentPane;
	}

	/**
	 * This method initializes btnAddLight
	 *
	 * @return javax.swing.JButton
	 */
	private JButton getBtnAddLight()
	{
		if (this.btnAddLight == null)
		{
			this.btnAddLight = new JButton();
			this.btnAddLight.setBounds(new Rectangle(135, 105, 90, 32));
			this.btnAddLight.setText("Confirm");
			this.btnAddLight.addActionListener(new java.awt.event.ActionListener()
			{
				public void actionPerformed(java.awt.event.ActionEvent e)
				{
					int nr = new Integer((String)DialogSetShadowRefLight.this.comboNr.getSelectedItem());
					PositionalLight light = (PositionalLight)WorldEditor.room.getLight(nr);

					// set the shadow reference light to the selected light
					WorldEditor.room.setShadowReferenceLight(light);
					DialogSetShadowRefLight.this.dispose();
				}
			});
		}
		return this.btnAddLight;
	}

	/**
	 * This method initializes comboNr
	 *
	 * @return javax.swing.JComboBox
	 */
	private JComboBox getComboNr()
	{
		if (this.comboNr == null)
		{
			this.comboNr = new JComboBox(new DefaultComboBoxModel());
			this.comboNr.setBounds(new Rectangle(120, 60, 55, 25));

			// get possible light numbers (positional lights)
			ArrayList<Integer> posNumbers = new ArrayList<Integer>();
			for(LightIface light : WorldEditor.room.getLights())
			{
				if(light instanceof PositionalLight)
				{
					PositionalLight l = (PositionalLight)light;
					posNumbers.add(l.getLightNr());
				}
			}

			// only add possible light numbers (positional lights)
			for(Integer nr : posNumbers)
			{
				this.comboNr.addItem(""+nr);
			}
		}
		return this.comboNr;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
