package ui.view;

import java.awt.BorderLayout;

import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import classes.IdCounter;

import javax.swing.JCheckBox;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * This Class represents a Popup to edit the shown Information.
 * 
 * @author Gruppe14
 */
public class ShowedInformationPopUp extends JDialog {

	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();
	private final JButton btnOk = new JButton("OK");
	private MyCanvas canvas;
	private JCheckBox objectEnergyCheckbox;
	private JCheckBox connectionCheckbox;
	private JCheckBox colorizedBorderCheckbox;

	/**
	 * Constructor.
	 * 
	 * @param canvas
	 *            the Canvas
	 */
	public ShowedInformationPopUp(MyCanvas canvas) {
		super((java.awt.Frame) null, true);
		setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
		this.setTitle(Languages.getLanguage()[31]);
		setBounds(100, 100, 400, 220);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		this.canvas = canvas;

		objectEnergyCheckbox = new JCheckBox(Languages.getLanguage()[32]);
		objectEnergyCheckbox.setBounds(19, 19, 300, 23);
		contentPanel.add(objectEnergyCheckbox);

		connectionCheckbox = new JCheckBox(Languages.getLanguage()[33]);
		connectionCheckbox.setBounds(19, 57, 300, 23);
		contentPanel.add(connectionCheckbox);

		objectEnergyCheckbox.setSelected(canvas.getShowedInformation()[1]);
		connectionCheckbox.setSelected(canvas.getShowedInformation()[0]);
		btnOk.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				setInformation(connectionCheckbox.isSelected(), objectEnergyCheckbox.isSelected(),
						colorizedBorderCheckbox.isSelected());
				dispose();
			}
		});
		btnOk.setBounds(171, 147, 82, 23);
		contentPanel.add(btnOk);

		JButton btnCancel = new JButton(Languages.getLanguage()[34]);
		btnCancel.setActionCommand(Languages.getLanguage()[34]);
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		btnCancel.setBounds(72, 147, 89, 23);
		contentPanel.add(btnCancel);
		
		colorizedBorderCheckbox = new JCheckBox("Show colorized Border for Objects");
		colorizedBorderCheckbox.setBounds(19, 96, 195, 23);
		contentPanel.add(colorizedBorderCheckbox);
		colorizedBorderCheckbox.setSelected(canvas.getShowedInformation()[3]);
	}

	/**
	 * Set the Information true or false.
	 * 
	 * @param connection
	 *            conection Information
	 * @param object
	 *            Object Information
	 */
	private void setInformation(boolean connection, boolean object, boolean borders) {
		canvas.setShowedInformation(connection, object, borders);
		canvas.repaint();
	}
}
