package Vue;

import java.awt.Color;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;

import Controleurs.EcouteurConnexion;
import Modèle.DonneesXML;
import Modèle.Groupe;
import Modèle.Probleme;

public class IHMConnexion {
	protected DonneesXML DXML;
	protected Vector<Groupe> groupes;
	protected Vector<Probleme> pb;

	public IHMConnexion(DonneesXML DXML) {
		this.DXML=DXML;
		groupes = DXML.getGroupes();
		pb = DXML.getPb(DXML.getArbrePb());
		
		JFrame jf = new JFrame("Optim'Eisti");
		jf.setSize(500, 250);
		jf.setLayout(null);
		jf.setResizable(false);
		jf.setLocationRelativeTo(null);

		JPanel jp = new JPanel();
		jp.setLayout(null);
		jp.setLocation(110, 39);
		jp.setSize(300, 160);
		jf.add(jp);

		LineBorder border = new LineBorder(Color.blue);
		jp.setBorder(BorderFactory.createTitledBorder(border, "Connexion"));

		// jf.setIconImage(new ImageIcon("image/21845.png").);

		/*
		 * barre de menu JMenuBar m = new JMenuBar(); JMenu menu = new
		 * JMenu("Fichier");
		 */

		/* label */

		JLabel label = new JLabel("Login :", JLabel.RIGHT);
		label.setLocation(10, 25);
		label.setSize(100, 35);
		jp.add(label);

		JLabel label1 = new JLabel("Mot de passe :", JLabel.RIGHT);
		label1.setLocation(10, 65);
		label1.setSize(100, 35);
		jp.add(label1);

		JLabel JLErreur = new JLabel("", JLabel.CENTER);
		JLErreur.setLocation(15, 10);
		JLErreur.setSize(250, 20);
		JLErreur.setForeground(new Color(255, 0, 0));
		jp.add(JLErreur);

		ImageIcon icone = new ImageIcon("images/eisti.png");
		JLabel image = new JLabel(icone);
		image.setLocation(0, 39);
		image.setSize(75, 100);
		jf.add(image);

		/* textField */

		JTextField TFLogin = new JTextField("fongcynthi");
		TFLogin.setLocation(125, 30);
		TFLogin.setSize(100, 25);
		jp.add(TFLogin);

		JPasswordField pf = new JPasswordField("eisti");
		pf.setLocation(125, 70);
		pf.setSize(100, 25);
		jp.add(pf);

		/* Bouton */

		JButton bouton = new JButton("Connexion");
		bouton.setLocation(100, 115);
		bouton.setSize(100, 30);
		bouton.addActionListener(new EcouteurConnexion(jf,groupes,pb,DXML,TFLogin, pf, JLErreur));
		jp.add(bouton);

		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setVisible(true);

	}
}
