Maj de la fenetre modification
This commit is contained in:
@@ -1,99 +1,107 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class FenetreModif extends JFrame implements ActionListener {
|
||||
public class FenetreModif extends JFrame {
|
||||
|
||||
private final Main parent;
|
||||
private final Rappel rappel;
|
||||
private GestionRappel ges = new GestionRappel();
|
||||
|
||||
private GestionModif listBtnModif;
|
||||
|
||||
private final JTextField champTitre;
|
||||
private final JTextArea champContenu;
|
||||
private Integer[] nombres = {1, 2, 3, 4, 5};
|
||||
private JComboBox<Integer> rang = new JComboBox<>(nombres);
|
||||
|
||||
|
||||
private final String[] nomsCouleurs = {"Bleu", "Rouge", "Vert", "Jaune", "Gris"};
|
||||
private final String[] nomsCouleurs = {"Bleu", "Rouge", "Vert", "Jaune", "Rose"};
|
||||
private final JComboBox<String> comboTheme = new JComboBox<>(nomsCouleurs);
|
||||
|
||||
private final JButton boutonValider;
|
||||
private final JButton boutonAnnuler;
|
||||
|
||||
/**
|
||||
* @param parent la fenêtre principale (utilisée pour revenir au même endroit)
|
||||
* @param rappel le rappel à modifier
|
||||
* @param titre titre initial à afficher
|
||||
* @param contenu contenu initial à afficher
|
||||
*/
|
||||
public FenetreModif(Main parent, Rappel rappel, String titre, String contenu) {
|
||||
public FenetreModif(Main parent, Rappel rappel) {
|
||||
super("Modifier un rappel");
|
||||
this.parent = parent;
|
||||
this.rappel = rappel;
|
||||
ImageIcon logo = new ImageIcon("logo.png");
|
||||
setIconImage(logo.getImage());
|
||||
|
||||
setSize(350, 250);
|
||||
setResizable(false);
|
||||
setAlwaysOnTop(true);
|
||||
setLocation(parent.getLocation()); // même position que Main
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
// ------ UI ------
|
||||
// UI
|
||||
setLayout(new BorderLayout(10, 10));
|
||||
|
||||
JPanel centre = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.insets = new Insets(4, 4, 4, 4);
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
|
||||
add(centre, BorderLayout.CENTER);
|
||||
// Titre
|
||||
JLabel lblTitre = new JLabel("Titre :");
|
||||
champTitre = new JTextField(20);
|
||||
c.gridx = 0; c.gridy = 0; c.weightx = 0;
|
||||
champTitre.setDocument(new LimiteContenu(50));
|
||||
c.gridx = 0;
|
||||
c.gridy = 1;
|
||||
c.weightx = 0;
|
||||
centre.add(lblTitre, c);
|
||||
c.gridx = 1; c.gridy = 0; 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.setDocument(new LimiteContenu(200));
|
||||
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 scroll = new JScrollPane(champContenu,
|
||||
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
|
||||
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
|
||||
c.gridx = 0; c.gridy = 1; c.weightx = 0;
|
||||
centre.add(lblContenu, c);
|
||||
c.gridx = 0;
|
||||
c.gridy = 2;
|
||||
c.weightx = 0;
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
c.gridx = 1; c.gridy = 1; c.weightx = 1; c.weighty = 1.0;
|
||||
centre.add(lblContenu, c);
|
||||
c.gridx = 1;
|
||||
c.gridy = 2;
|
||||
c.weightx = 1.0;
|
||||
c.weighty = 1.0;
|
||||
centre.add(scroll, c);
|
||||
|
||||
// rang
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
|
||||
rang.setSelectedIndex(rappel.getRang()-1);
|
||||
JLabel lblRang = new JLabel("Rang :");
|
||||
c.gridx = 0; c.gridy = 2; c.weightx = 0;
|
||||
c.gridx = 0;
|
||||
c.gridy = 3;
|
||||
c.weightx = 0;
|
||||
c.weighty = 0.0;
|
||||
centre.add(lblRang, c);
|
||||
c.gridx = 1; c.gridy = 2; c.weightx = 1;
|
||||
c.gridx = 1;
|
||||
c.gridy = 3;
|
||||
c.weightx = 1;
|
||||
centre.add(rang, c);
|
||||
|
||||
// theme
|
||||
c.gridx = 0; c.gridy = 4; c.weightx = 0;
|
||||
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;
|
||||
c.gridx = 1;
|
||||
c.gridy = 4;
|
||||
c.weightx = 1;
|
||||
comboTheme.setRenderer(new CouleurList());
|
||||
comboTheme.setSelectedItem(rappel.getTheme()); // valeur par défaut
|
||||
centre.add(comboTheme, c);
|
||||
|
||||
add(centre, BorderLayout.CENTER);
|
||||
// add(centre, BorderLayout.CENTER);
|
||||
|
||||
// Bas : boutons
|
||||
JPanel bas = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
boutonValider = new JButton("Valider");
|
||||
boutonAnnuler = new JButton("Annuler");
|
||||
boutonValider.addActionListener(this);
|
||||
boutonAnnuler.addActionListener(this);
|
||||
bas.add(boutonValider);
|
||||
bas.add(boutonAnnuler);
|
||||
|
||||
listBtnModif = new GestionModif(this,parent,champTitre,champContenu,rang,comboTheme,rappel);
|
||||
bas.add(listBtnModif.get(0));
|
||||
bas.add(listBtnModif.get(1));
|
||||
add(bas, BorderLayout.SOUTH);
|
||||
|
||||
champTitre.setText(rappel.getTitre());
|
||||
@@ -101,48 +109,4 @@ public class FenetreModif extends JFrame implements ActionListener {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Object src = e.getSource();
|
||||
|
||||
if (src == boutonAnnuler) {
|
||||
|
||||
parent.setLocation(this.getLocation());
|
||||
parent.setVisible(true);
|
||||
this.dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
if (src == boutonValider) {
|
||||
String t = champTitre.getText().trim();
|
||||
String c = champContenu.getText().trim();
|
||||
int r = (Integer) rang.getSelectedItem();
|
||||
String th = (String) comboTheme.getSelectedItem();
|
||||
|
||||
if (t.isEmpty() || c.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(this, "Veuillez remplir les deux champs.", "Champs manquants", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
// MAJ directe du rappel
|
||||
|
||||
rappel.setTitre(t);
|
||||
rappel.setContenu(c);
|
||||
rappel.setRang(r);
|
||||
rappel.setTheme(th);
|
||||
try{
|
||||
ges.modifierParId(rappel.getId(), rappel);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
Main reParent = new Main();
|
||||
reParent.setLocation(this.getLocation());
|
||||
reParent.setVisible(true);
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user