diff --git a/src/fr/iutfbleau/papillon/FenetreAjout.java b/src/fr/iutfbleau/papillon/FenetreAjout.java index 9e36236..e634342 100644 --- a/src/fr/iutfbleau/papillon/FenetreAjout.java +++ b/src/fr/iutfbleau/papillon/FenetreAjout.java @@ -8,8 +8,14 @@ public class FenetreAjout extends JFrame implements ActionListener { private final JTextField champTitre; private final JTextArea champContenu; - private final JTextField rang; - private final JTextField theme; + private Integer[] nombres = {1, 2, 3, 4, 5}; + private JComboBox rang = new JComboBox<>(nombres); + + + private final String[] nomsCouleurs = {"Bleu", "Rouge", "Vert", "Jaune", "Gris"}; + private final JComboBox comboTheme = new JComboBox<>(nomsCouleurs); + + private final JButton boutonValider; private final JButton boutonAnnuler; private final Main parent; @@ -20,7 +26,6 @@ public class FenetreAjout extends JFrame implements ActionListener { setSize(350, 250); setResizable(false); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Layout principal @@ -34,64 +39,51 @@ public class FenetreAjout extends JFrame implements ActionListener { // Titre JLabel lblTitre = new JLabel("Titre :"); champTitre = new JTextField(20); - c.gridx = 0; - c.gridy = 1; - c.weightx = 0; + c.gridx = 0; c.gridy = 1; c.weightx = 0; centre.add(lblTitre, c); - c.gridx = 1; - c.gridy = 1; - c.weightx = 1; + c.gridx = 1; c.gridy = 1; c.weightx = 1; centre.add(champTitre, c); // Contenu JLabel lblContenu = new JLabel("Contenu :"); champContenu = new JTextArea(4, 20); + champContenu.setLineWrap(true); // active le retour à la ligne + champContenu.setWrapStyleWord(true); // évite de couper un mot en plein milieu JScrollPane scroll = new JScrollPane(champContenu, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - c.gridx = 0; - c.gridy = 2; - c.weightx = 0; + c.gridx = 0; c.gridy = 2; c.weightx = 0; c.fill = GridBagConstraints.BOTH; centre.add(lblContenu, c); - c.gridx = 1; - c.gridy = 2; - c.weightx = 1; - c.weighty = 1.0; // prend la hauteur dispo + c.gridx = 1; c.gridy = 2; c.weightx = 1; c.weighty = 1.0; centre.add(scroll, c); // Rang JLabel lblrang = new JLabel("Rang :"); - rang = new JTextField(20); - c.gridx = 0; - c.gridy = 3; - c.weightx = 0; - c.weighty = 0.0; // prend la hauteur dispo + c.gridx = 0; c.gridy = 3; c.weightx = 0; c.weighty = 0.0; centre.add(lblrang, c); - c.gridx = 1; - c.gridy = 3; - c.weightx = 1; + c.gridx = 1; c.gridy = 3; c.weightx = 1; centre.add(rang, c); - // theme - JLabel lbltheme = new JLabel("Theme :"); - theme = new JTextField(20); - c.gridx = 0; - c.gridy = 4; - c.weightx = 0; - centre.add(lbltheme, c); - c.gridx = 1; - c.gridy = 4; - c.weightx = 1; - centre.add(theme, c); + + + // Theme + c.gridx = 0; c.gridy = 4; c.weightx = 0; + centre.add(new JLabel("Theme :"), c); + + // liste déroulante de couleurs + c.gridx = 1; c.gridy = 4; c.weightx = 1; + comboTheme.setRenderer(new CouleurList()); + comboTheme.setSelectedItem("Bleu"); // valeur par défaut + centre.add(comboTheme, c); + // Bas : boutons JPanel bas = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 10)); boutonValider = new JButton("Valider"); boutonAnnuler = new JButton("Annuler"); - // on enregistre les actions ici boutonValider.addActionListener(this); boutonAnnuler.addActionListener(this); @@ -100,6 +92,12 @@ public class FenetreAjout extends JFrame implements ActionListener { add(bas, BorderLayout.SOUTH); } + public Color getCouleurChoix() { + String nom = (String) comboTheme.getSelectedItem(); + return CouleurList.couleurDe(nom); +} + + @Override public void actionPerformed(ActionEvent e) { Object src = e.getSource(); @@ -107,25 +105,38 @@ public class FenetreAjout extends JFrame implements ActionListener { if (src == boutonAnnuler) { // revenir à la fenêtre principale Point pos = this.getLocation(); + parent.setLocation(pos); - parent.setVisible(true); - this.setVisible(false); + this.dispose(); return; } if (src == boutonValider) { String titre = champTitre.getText().trim(); String contenu = champContenu.getText().trim(); + int Nrang = (Integer) rang.getSelectedItem(); + String cTheme = (String)comboTheme.getSelectedItem(); + + + GestionRappel g = new GestionRappel(); + if (titre.isEmpty() || contenu.isEmpty()) { - JOptionPane.showMessageDialog(this, "Veuillez remplir les deux champs."); + JOptionPane.showMessageDialog(this, "Veuillez remplir tout les champs.", "Champs manquants", JOptionPane.WARNING_MESSAGE); return; + }else{ + + try{ + g.ajouter(new Rappel(titre,contenu,cTheme,Nrang)); + } catch (Exception ex) { + ex.printStackTrace(); // affiche l'erreur dans le terminal } - // TODO: ici appeler une méthode du parent pour ajouter le rappel - // parent.ajouterRappel(titre, contenu); - - parent.setVisible(true); + } + + Main reParent = new Main(); + reParent.setLocation(this.getLocation()); + reParent.setVisible(true); dispose(); } }