/**
 *
 */
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;

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

	private static final long serialVersionUID = 1L;

	private DialogSaveRecording self = null;

	private JPanel jContentPane = null;

	private JLabel labelHead = null;

	private JTextField txtFileToSave = null;

	private JButton btnChooseFile = null;

	private JButton btnSaveFile = null;

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

	/**
	 * This method initializes this
	 *
	 * @return void
	 */
	private void initialize()
	{
		this.setSize(300, 153);
		this.setTitle("Save the recording");
		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 save...");
			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.getTxtFileToSave(), null);
			this.jContentPane.add(this.getBtnChooseFile(), null);
			this.jContentPane.add(this.getBtnSaveFile(), null);
		}
		return this.jContentPane;
	}

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

	/**
	 * 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.showSaveDialog(DialogSaveRecording.this.self);

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

	/**
	 * This method initializes btnSaveFile
	 *
	 * @return javax.swing.JButton
	 */
	private JButton getBtnSaveFile()
	{
		if (this.btnSaveFile == null)
		{
			this.btnSaveFile = new JButton();
			this.btnSaveFile.setBounds(new Rectangle(210, 90, 61, 22));
			this.btnSaveFile.setText("OK");
			this.btnSaveFile.addActionListener(new java.awt.event.ActionListener()
			{
				public void actionPerformed(java.awt.event.ActionEvent e)
				{
					WorldEditor.camFlightRecorder.save(DialogSaveRecording.this.txtFileToSave.getText());
					DialogSaveRecording.this.dispose();
				}
			});
		}
		return this.btnSaveFile;
	}

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