implementation des theme

This commit is contained in:
2025-10-23 09:00:30 +02:00
parent a747e2867e
commit 5b71dc5553
+148 -140
View File
@@ -1,140 +1,148 @@
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
public class FenetreModif extends JFrame implements ActionListener { public class FenetreModif extends JFrame implements ActionListener {
private final Main parent; // fenêtre principal (peut être null si tu veux) private final Main parent; // fenêtre principal (peut être null si tu veux)
private final Rappel rappel; // rappel à modifier (peut être null si tu veux) private final Rappel rappel; // rappel à modifier (peut être null si tu veux)
private GestionRappel ges = new GestionRappel(); private GestionRappel ges = new GestionRappel();
private final JTextField champTitre; private final JTextField champTitre;
private final JTextArea champContenu; private final JTextArea champContenu;
private Integer[] nombres = {1, 2, 3, 4, 5}; private Integer[] nombres = {1, 2, 3, 4, 5};
private JComboBox<Integer> rang = new JComboBox<>(nombres); private JComboBox<Integer> rang = new JComboBox<>(nombres);
private final JTextField theme; // private final JTextField theme;
private final JButton boutonValider;
private final JButton boutonAnnuler; private final String[] nomsCouleurs = {"Bleu", "Rouge", "Vert", "Jaune", "Gris"};
private final JComboBox<String> comboTheme = new JComboBox<>(nomsCouleurs);
/**
* @param parent la fenêtre principale (utilisée pour revenir au même endroit) private final JButton boutonValider;
* @param rappel le rappel à modifier (peut être null si tu veux juste récupérer des valeurs) private final JButton boutonAnnuler;
* @param titre titre initial à afficher (utilisé si rappel==null ou si tu préfères passer la valeur)
* @param contenu contenu initial à afficher (idem) /**
*/ * @param parent la fenêtre principale (utilisée pour revenir au même endroit)
public FenetreModif(Main parent, Rappel rappel, String titre, String contenu) { * @param rappel le rappel à modifier (peut être null si tu veux juste récupérer des valeurs)
super("Modifier un rappel"); * @param titre titre initial à afficher (utilisé si rappel==null ou si tu préfères passer la valeur)
this.parent = parent; * @param contenu contenu initial à afficher (idem)
this.rappel = rappel; */
public FenetreModif(Main parent, Rappel rappel, String titre, String contenu) {
setSize(350, 250); super("Modifier un rappel");
setResizable(false); this.parent = parent;
setLocation(parent.getLocation()); // même position que Main this.rappel = rappel;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(350, 250);
// ------ UI ------ setResizable(false);
setLayout(new BorderLayout(10, 10)); setLocation(parent.getLocation()); // même position que Main
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel centre = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints(); // ------ UI ------
c.insets = new Insets(4, 4, 4, 4); setLayout(new BorderLayout(10, 10));
c.fill = GridBagConstraints.HORIZONTAL;
JPanel centre = new JPanel(new GridBagLayout());
// Titre GridBagConstraints c = new GridBagConstraints();
JLabel lblTitre = new JLabel("Titre :"); c.insets = new Insets(4, 4, 4, 4);
champTitre = new JTextField(20); c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0; c.gridy = 0; c.weightx = 0;
centre.add(lblTitre, c); // Titre
c.gridx = 1; c.gridy = 0; c.weightx = 1; JLabel lblTitre = new JLabel("Titre :");
centre.add(champTitre, c); champTitre = new JTextField(20);
c.gridx = 0; c.gridy = 0; c.weightx = 0;
// Contenu centre.add(lblTitre, c);
JLabel lblContenu = new JLabel("Contenu :"); c.gridx = 1; c.gridy = 0; c.weightx = 1;
champContenu = new JTextArea(4, 20); centre.add(champTitre, c);
champContenu.setLineWrap(true); // active le retour à la ligne
champContenu.setWrapStyleWord(true); // évite de couper un mot en plein milieu // Contenu
JScrollPane scroll = new JScrollPane(champContenu); JLabel lblContenu = new JLabel("Contenu :");
champContenu = new JTextArea(4, 20);
c.gridx = 0; c.gridy = 1; c.weightx = 0; champContenu.setLineWrap(true); // active le retour à la ligne
centre.add(lblContenu, c); champContenu.setWrapStyleWord(true); // évite de couper un mot en plein milieu
c.fill = GridBagConstraints.BOTH; JScrollPane scroll = new JScrollPane(champContenu);
c.gridx = 1; c.gridy = 1; c.weightx = 1; c.weighty = 1.0;
centre.add(scroll, c); c.gridx = 0; c.gridy = 1; c.weightx = 0;
centre.add(lblContenu, c);
// rang c.fill = GridBagConstraints.BOTH;
c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 1; c.weightx = 1; c.weighty = 1.0;
rang.setSelectedIndex(rappel.getRang()-1); centre.add(scroll, c);
JLabel lblRang = new JLabel("Rang :");
c.gridx = 0; c.gridy = 2; c.weightx = 0; // rang
centre.add(lblRang, c); c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 1; c.gridy = 2; c.weightx = 1; rang.setSelectedIndex(rappel.getRang()-1);
centre.add(rang, c); JLabel lblRang = new JLabel("Rang :");
c.gridx = 0; c.gridy = 2; c.weightx = 0;
// theme centre.add(lblRang, c);
JLabel lblTheme = new JLabel("Theme"); c.gridx = 1; c.gridy = 2; c.weightx = 1;
theme = new JTextField(20); centre.add(rang, c);
c.gridx = 0; c.gridy = 3; c.weightx = 0;
centre.add(lblTheme, c); // theme
c.gridx = 1; c.gridy = 3; c.weightx = 1; c.gridx = 0; c.gridy = 4; c.weightx = 0;
centre.add(theme, c); centre.add(new JLabel("Theme :"), c);
add(centre, BorderLayout.CENTER); // liste déroulante de couleurs
c.gridx = 1; c.gridy = 4; c.weightx = 1;
// Bas : boutons comboTheme.setRenderer(new CouleurList());
JPanel bas = new JPanel(new FlowLayout(FlowLayout.RIGHT)); comboTheme.setSelectedItem(rappel.getTheme()); // valeur par défaut
boutonValider = new JButton("Valider"); centre.add(comboTheme, c);
boutonAnnuler = new JButton("Annuler");
boutonValider.addActionListener(this); add(centre, BorderLayout.CENTER);
boutonAnnuler.addActionListener(this);
bas.add(boutonValider); // Bas : boutons
bas.add(boutonAnnuler); JPanel bas = new JPanel(new FlowLayout(FlowLayout.RIGHT));
add(bas, BorderLayout.SOUTH); boutonValider = new JButton("Valider");
boutonAnnuler = new JButton("Annuler");
champTitre.setText(rappel.getTitre()); boutonValider.addActionListener(this);
champContenu.setText(rappel.getContenu()); boutonAnnuler.addActionListener(this);
bas.add(boutonValider);
} bas.add(boutonAnnuler);
add(bas, BorderLayout.SOUTH);
@Override champTitre.setText(rappel.getTitre());
public void actionPerformed(ActionEvent e) { champContenu.setText(rappel.getContenu());
Object src = e.getSource();
}
if (src == boutonAnnuler) {
parent.setLocation(this.getLocation()); @Override
parent.setVisible(true); public void actionPerformed(ActionEvent e) {
this.dispose(); Object src = e.getSource();
return;
} if (src == boutonAnnuler) {
if (src == boutonValider) { parent.setLocation(this.getLocation());
String t = champTitre.getText().trim(); parent.setVisible(true);
String c = champContenu.getText().trim(); this.dispose();
int r = (Integer) rang.getSelectedItem(); return;
}
if (t.isEmpty() || c.isEmpty()) {
JOptionPane.showMessageDialog(this, "Veuillez remplir les deux champs.", "Champs manquants", JOptionPane.WARNING_MESSAGE); if (src == boutonValider) {
return; String t = champTitre.getText().trim();
} String c = champContenu.getText().trim();
int r = (Integer) rang.getSelectedItem();
// MAJ directe du rappel String th = (String) comboTheme.getSelectedItem();
rappel.setTitre(t); if (t.isEmpty() || c.isEmpty()) {
rappel.setContenu(c); JOptionPane.showMessageDialog(this, "Veuillez remplir les deux champs.", "Champs manquants", JOptionPane.WARNING_MESSAGE);
rappel.setRang(r); return;
try{ }
ges.modifierParId(rappel.getId(), rappel);
} catch (Exception ex) { // MAJ directe du rappel
ex.printStackTrace();
} rappel.setTitre(t);
rappel.setContenu(c);
rappel.setRang(r);
Main reParent = new Main(); rappel.setTheme(th);
reParent.setLocation(this.getLocation()); try{
reParent.setVisible(true); ges.modifierParId(rappel.getId(), rappel);
dispose(); } catch (Exception ex) {
} ex.printStackTrace();
} }
}
Main reParent = new Main();
reParent.setLocation(this.getLocation());
reParent.setVisible(true);
dispose();
}
}
}