/**
 *
 */
package de.rico.editor.gui.dialog;

import java.awt.Font;
import java.awt.Frame;
import java.awt.Rectangle;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import de.rico.editor.WorldEditor;
import de.rico.editor.gui.filter.FilterRecordingFile;
import de.rico.engine.camera.recorder.CamPlayer;

/**
 * A dialog to load recorded camera flights.
 * @author Frank Bruns
 *
 */
public class DialogLoadRecording extends JDialog
{

	private static final long serialVersionUID = 1L;

	private DialogLoadRecording self = null;

	private JPanel jContentPane = null;

	private JLabel labelHead = null;

	private JTextField txtFileToLoad = null;

	private JButton btnChooseFile = null;

	private JButton btnLoadFile = null;

	/**
	 * @param owner
	 */
	public DialogLoadRecording(Frame owner)
	{
		super(owner);
		this.initialize();
		this.self = this;
	}

	/**
	 * This method initializes this
	 *
	 * @return void
	 */
	private void initialize()
	{
		this.setSize(300, 153);
		this.setTitle("Load a recorded camera flight");
		this.setContentPane(this.getJContentPane());
	}

	/**
	 * This method initializes jContentPane
	 *
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane()
	{
		if (this.jContentPane == null)
		{
			this.labelHead = new JLabel();
			this.labelHead.setText("Choose a file to load");
			this.labelHead.setBounds(new Rectangle(60, 15, 166, 19));
			this.labelHead.setFont(new Font("Dialog", Font.BOLD, 14));
			this.jContentPane = new JPanel();
			this.jContentPane.setLayout(null);
			this.jContentPane.add(this.labelHead, null);
			this.jContentPane.add(this.getTxtFileToLoad(), null);
			this.jContentPane.add(this.getBtnChooseFile(), null);
			this.jContentPane.add(this.getBtnLoadFile(), null);
		}
		return this.jContentPane;
	}

	/**
	 * This method initializes txtFileToLoad
	 *
	 * @return javax.swing.JTextField
	 */
	private JTextField getTxtFileToLoad()
	{
		if (this.txtFileToLoad == null)
		{
			this.txtFileToLoad = new JTextField();
			this.txtFileToLoad.setBounds(new Rectangle(15, 60, 211, 16));
		}
		return this.txtFileToLoad;
	}

	/**
	 * This method initializes btnChooseFile
	 *
	 * @return javax.swing.JButton
	 */
	private JButton getBtnChooseFile()
	{
		if (this.btnChooseFile == null)
		{
			this.btnChooseFile = new JButton();
			this.btnChooseFile.setBounds(new Rectangle(240, 60, 31, 16));
			this.btnChooseFile.setText("...");
			this.btnChooseFile.addActionListener(new java.awt.event.ActionListener()
			{
				public void actionPerformed(java.awt.event.ActionEvent e)
				{
					JFileChooser fc = new JFileChooser();
					fc.setCurrentDirectory(new File("./"));
					fc.setAcceptAllFileFilterUsed(false);
					fc.setFileFilter(new FilterRecordingFile());

					int returnVal = fc.showOpenDialog(DialogLoadRecording.this.self);

					if (returnVal == JFileChooser.APPROVE_OPTION)
					{
						File file = fc.getSelectedFile();
						DialogLoadRecording.this.txtFileToLoad.setText(file.getAbsolutePath());
					}
				}
			});
		}
		return this.btnChooseFile;
	}

	/**
	 * This method initializes btnLoadFile
	 *
	 * @return javax.swing.JButton
	 */
	private JButton getBtnLoadFile()
	{
		if (this.btnLoadFile == null)
		{
			this.btnLoadFile = new JButton();
			this.btnLoadFile.setBounds(new Rectangle(210, 90, 61, 22));
			this.btnLoadFile.setText("OK");
			this.btnLoadFile.addActionListener(new java.awt.event.ActionListener()
			{
				public void actionPerformed(java.awt.event.ActionEvent e)
				{
					WorldEditor.camFlightPlayer = new CamPlayer(DialogLoadRecording.this.txtFileToLoad.getText());
					DialogLoadRecording.this.dispose();
				}
			});
		}
		return this.btnLoadFile;
	}

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