import java.awt.Checkbox;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;





public class EventsBouttons implements ActionListener{

	private JCheckBox c;
	
	public EventsBouttons(JCheckBox c){
		this.c = c;
	}
	@Override
	public void actionPerformed(ActionEvent arg0) {
		
		if(arg0.getSource() instanceof JCheckBox){
			
			JPanel bob = new JPanel();
			bob.setLayout(new BoxLayout(bob, BoxLayout.PAGE_AXIS));

			JPanel question = new JPanel();
			JLabel textQuestion = new JLabel("Choisissez la question filtre: ");
			JComboBox questions = new JComboBox();
			question.add(textQuestion);
			question.add(questions);
			
			JPanel reponse = new JPanel();
			JLabel textReponse = new JLabel("Choisissez la reponse filtre: ");
			JComboBox reponses = new JComboBox();
			reponse.add(textReponse);
			reponse.add(reponses);
			
			bob.add(question);
			bob.add(reponse);
			
			/*JPanel globalPane = new JPanel();
			JLabel l1 = new JLabel("L'article "+((Nomenclature)((DefaultMutableTreeNode) node.getParent()).getUserObject()).getArticle().getDesignation()+" a besoin de ");

			JLabel l2 = new JLabel(" "+((Nomenclature)node.getUserObject()).getArticle());


			final JTextField t = new JTextField(""+((Nomenclature)node.getUserObject()).getQuantite());
			t.setPreferredSize(new Dimension(40,20));

			globalPane.add(t);
			globalPane.add(l2);


			bob.add(l1);
			bob.add(globalPane);
			new BorderLayout();		*/	
			int res = JOptionPane.showConfirmDialog(FenetrePrincipale.f, bob, "Ajout d'un filtre", JOptionPane.OK_CANCEL_OPTION);
			if (res == JOptionPane.OK_OPTION) {
				try {
					if (questions.getSelectedItem()==null || reponses.getSelectedItem()==null) {
						JOptionPane.showMessageDialog(FenetrePrincipale.f, "Veuillez remplir tout les champs", "Erreur",JOptionPane.ERROR_MESSAGE);
						c.setSelected(false);
						//mouseReleased(e);
					}
					else {
						//int quantite = Integer.parseInt(t.getText());
						//((Nomenclature)node.getUserObject()).setQuantite(quantite);
						//a.getJTree().updateUI();


					}
				} catch (NumberFormatException nbe) {
					JOptionPane.showMessageDialog(FenetrePrincipale.f, "Erreur dans le format d'entree", "Erreur",JOptionPane.ERROR_MESSAGE);
					//mouseReleased(e);
				}
			}
			else{
				c.setSelected(false);
			}
		}
	}

}
