package interfaz;

import javax.swing.JPanel;
import java.awt.Frame;
import java.awt.BorderLayout;
import javax.swing.JDialog;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.JComboBox;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.FlowLayout;
import javax.swing.JButton;
import java.awt.SystemColor;
import java.util.Iterator;
import java.util.List;

import javax.swing.BorderFactory;

import negocio.Idioma;
import negocio.Plantilla;

import org.hibernate.Session;
import org.hibernate.Transaction;

import persistencia.UtilidadHibernate;


public class PortafolioDeAplicaciones extends JDialog {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JPanel jPanel = null;

	private JPanel jPanel1 = null;

	private JButton jButton = null;

	private JPanel jPanel2 = null;

	private JLabel jLabel = null;

	private JComboBox jComboBox2 = null;

	private JLabel jLabel1 = null;

	private JComboBox jComboBox4 = null;
	
	public RellenarInstancia padreRellenarInstancia;
	
	private Idioma idioma;  //  @jve:decl-index=0:

	/**
	 * @param owner
	 */
	/*public PortafolioDeAplicaciones(Frame owner) {
		super(owner);
		initialize();
	}*/
	
	
	public PortafolioDeAplicaciones(RellenarInstancia owner) {
		super(owner);
		padreRellenarInstancia = owner;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		
		//Calcular idioma
		Session session = UtilidadHibernate.getSessionFactory().openSession();
		
		List message = session.createQuery("from Idioma").list();
		
		Iterator iter = message.iterator();
		
		idioma = (Idioma) iter.next();
		
		session.close();
		this.setSize(834, 220);
		if (idioma.getNombre().equals("español"))
			this.setTitle("Matriz portafolio de aplicaciones");
		else
			this.setTitle("Application portfolio matrix");
		this.setContentPane(getJContentPane());
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
			gridBagConstraints6.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints6.gridy = 1;
			gridBagConstraints6.weightx = 1.0;
			gridBagConstraints6.insets = new Insets(0, 10, 0, 0);
			gridBagConstraints6.gridx = 1;
			GridBagConstraints gridBagConstraints41 = new GridBagConstraints();
			gridBagConstraints41.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints41.gridy = -1;
			gridBagConstraints41.weightx = 1.0;
			gridBagConstraints41.insets = new Insets(0, 10, 0, 0);
			gridBagConstraints41.gridx = -1;
			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
			gridBagConstraints3.gridx = 0;
			gridBagConstraints3.anchor = GridBagConstraints.EAST;
			gridBagConstraints3.gridy = 1;
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJPanel(), BorderLayout.CENTER);
			jContentPane.add(getJPanel1(), BorderLayout.EAST);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jPanel = new JPanel();
			jPanel.setLayout(new BorderLayout());
			jPanel.add(getJPanel2(), BorderLayout.CENTER);
		}
		return jPanel;
	}

	/**
	 * This method initializes jPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jPanel1 = new JPanel();
			jPanel1.setLayout(new FlowLayout());
			jPanel1.setPreferredSize(new Dimension(89, 36));
			jPanel1.setBackground(SystemColor.controlHighlight);
			jPanel1.setBorder(BorderFactory.createMatteBorder(0, 1, 0, 0, Color.lightGray));
			jPanel1.add(getJButton(), null);
		}
		return jPanel1;
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			

			jButton = new JButton();
			if (idioma.getNombre().equals("español"))
				jButton.setText("Aceptar");
			else
				jButton.setText("Accept");
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					padreRellenarInstancia.Aceptar(true);
					
					if ((jComboBox2.getSelectedIndex()==3) || (jComboBox2.getSelectedIndex()==0 && jComboBox4.getSelectedIndex()==0) || (jComboBox2.getSelectedIndex()==0 && jComboBox4.getSelectedIndex()==1)){
						padreRellenarInstancia.calculo_portafolio = "Aplicacion válida";
					}
					else if ((jComboBox2.getSelectedIndex()==0 && jComboBox4.getSelectedIndex()==2) || (jComboBox2.getSelectedIndex()==0 && jComboBox4.getSelectedIndex()==3 || (jComboBox2.getSelectedIndex()==1 && jComboBox4.getSelectedIndex()==2) || (jComboBox2.getSelectedIndex()==2 && jComboBox4.getSelectedIndex()==2))){
						padreRellenarInstancia.calculo_portafolio = "Aplicación crítica a medio o largo plazo";
					}
					else if ((jComboBox2.getSelectedIndex()==1 && jComboBox4.getSelectedIndex()==1) || (jComboBox2.getSelectedIndex()==1 && jComboBox4.getSelectedIndex()==3) || (jComboBox2.getSelectedIndex()==2 && jComboBox4.getSelectedIndex()==1) || (jComboBox2.getSelectedIndex()==2 && jComboBox4.getSelectedIndex()==3)){
						padreRellenarInstancia.calculo_portafolio = "Aplicación crítica a corto plazo";
					}
					else if ((jComboBox2.getSelectedIndex()==1 && jComboBox4.getSelectedIndex()==0)){
						padreRellenarInstancia.calculo_portafolio = "Aplicación a abandonar a medio o largo plazo";
					}
					else if ((jComboBox2.getSelectedIndex()==2 && jComboBox4.getSelectedIndex()==0)){
						padreRellenarInstancia.calculo_portafolio = "Aplicación a cambiar a medio o largo plazo";
					}
					
					padreRellenarInstancia.portafolio_rellenado=true;
					
					
					PortafolioDeAplicaciones.this.dispose();
					padreRellenarInstancia.PintarComponentes();
					padreRellenarInstancia.jPanel1.updateUI();
					
					
				}
			});
		}
		return jButton;
	}

	/**
	 * This method initializes jPanel2	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel2() {
		if (jPanel2 == null) {
			GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
			gridBagConstraints15.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints15.gridy = 2;
			gridBagConstraints15.weightx = 1.0;
			gridBagConstraints15.insets = new Insets(10, 10, 0, 0);
			gridBagConstraints15.anchor = GridBagConstraints.WEST;
			gridBagConstraints15.ipadx = 0;
			gridBagConstraints15.ipady = 0;
			gridBagConstraints15.gridx = 1;
			GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
			gridBagConstraints14.gridx = 0;
			gridBagConstraints14.insets = new Insets(10, 20, 0, 0);
			gridBagConstraints14.anchor = GridBagConstraints.WEST;
			gridBagConstraints14.gridy = 2;
			jLabel1 = new JLabel();
			jLabel1.setText("Importancia estratégica en el entorno actual / Importancia estratégica en el entorno futuro:");
			GridBagConstraints gridBagConstraints13 = new GridBagConstraints();
			gridBagConstraints13.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints13.gridy = 1;
			gridBagConstraints13.weightx = 1.0;
			gridBagConstraints13.anchor = GridBagConstraints.WEST;
			gridBagConstraints13.insets = new Insets(0, 10, 0, 0);
			gridBagConstraints13.ipadx = 0;
			gridBagConstraints13.ipady = 0;
			gridBagConstraints13.gridx = 1;
			GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
			gridBagConstraints12.gridx = 0;
			gridBagConstraints12.insets = new Insets(0, 10, 0, 0);
			gridBagConstraints12.anchor = GridBagConstraints.EAST;
			gridBagConstraints12.gridy = 1;
			jLabel = new JLabel();
			jLabel.setText("Alineación de negocio / Innovación tecnológica:");
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.insets = new Insets(10, 10, 0, 0);
			gridBagConstraints1.gridy = 0;
			gridBagConstraints1.gridx = -1;
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.anchor = GridBagConstraints.EAST;
			gridBagConstraints.gridx = -1;
			gridBagConstraints.gridy = -1;
			gridBagConstraints.insets = new Insets(0, 10, 0, 0);
			jPanel2 = new JPanel();
			jPanel2.setLayout(new GridBagLayout());
			jPanel2.setBackground(new Color(238, 238, 238));
			jPanel2.add(jLabel, gridBagConstraints12);
			jPanel2.add(getJComboBox2(), gridBagConstraints13);
			jPanel2.add(jLabel1, gridBagConstraints14);
			jPanel2.add(getJComboBox4(), gridBagConstraints15);
		}
		return jPanel2;
	}

	/**
	 * This method initializes jComboBox2	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox2() {
		if (jComboBox2 == null) {
			jComboBox2 = new JComboBox();
			jComboBox2.setPreferredSize(new Dimension(180, 25));
			jComboBox2.addItem("Alta-Baja");
			jComboBox2.addItem("Baja-Baja");
			jComboBox2.addItem("Baja-Alta");
			jComboBox2.addItem("Alta-Alta");
		}
		return jComboBox2;
	}

	/**
	 * This method initializes jComboBox4	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox4() {
		if (jComboBox4 == null) {
			jComboBox4 = new JComboBox();
			jComboBox4.setPreferredSize(new Dimension(180, 25));
			jComboBox4.addItem("Baja-Baja (Soporte)");
			jComboBox4.addItem("Alta-Baja (Operacional clave)");
			jComboBox4.addItem("Baja-Alta (Alto potencial)");
			jComboBox4.addItem("Alta-Alta (Estratégica)");
		}
		return jComboBox4;
	}

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