This commit is contained in:
2025-10-23 02:21:32 +02:00
9 changed files with 469 additions and 206 deletions
@@ -0,0 +1,37 @@
import javax.swing.*;
import javax.swing.Icon;
import java.awt.*;
/**
* Renderer simple pour afficher un petit carré coloré dans la liste déroulante.
* J'utilise juste un switch pour déterminer la couleur à partir du nom.
*/
public class CouleurList extends DefaultListCellRenderer {
/** renvoie la couleur correspondant au nom affiché dans le menu */
public static Color couleurDe(String nom) {
switch (nom) {
case "Bleu": return Color.CYAN; // ou Color.BLUE si tu veux un bleu plus foncé
case "Rouge": return Color.RED;
case "Vert": return Color.GREEN;
case "Jaune": return Color.YELLOW;
case "Gris": return Color.LIGHT_GRAY;
default: return Color.WHITE;
}
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index,boolean isSelected, boolean cellHasFocus) {
JLabel lbl = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value != null) {
String nom = value.toString();
lbl.setIcon(new ColorIcon(couleurDe(nom), 14, 14));
lbl.setIconTextGap(8); // petit espace entre le carré et le texte
}
return lbl;
}
}
+14 -19
View File
@@ -6,29 +6,24 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Crud extends ArrayList<JButton> implements ActionListener{
public class Crud extends ArrayList<JButton>{
private JButton btnAdd = new JButton("Ajouter");
private JButton btnDel = new JButton("Supprimer");
private final Main main;
private Main main;
private BtnAjouter btnAjt;
private BtnSupprimer btnSpr;
private BtnModifier btnMdf;
public Crud(Main main){
this.main = main;
btnAdd.setPreferredSize(new Dimension(120, 25));
btnDel.setPreferredSize(new Dimension(120, 25));
btnAdd.addActionListener(this);
btnDel.addActionListener(this);
add(btnAdd);
add(btnDel);
btnAjt = new BtnAjouter(main);
btnSpr = new BtnSupprimer(main);
btnMdf = new BtnModifier(main);
add(btnAjt);
add(btnSpr);
add(btnMdf);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==btnAdd){
System.out.println("test ajouter");
main.ouvrirFenetreAjout();
}
if(e.getSource()==btnDel){
System.out.println("test supprimer");
}
}
}
+53 -42
View File
@@ -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<Integer> rang = new JComboBox<>(nombres);
private final String[] nomsCouleurs = {"Bleu", "Rouge", "Vert", "Jaune", "Gris"};
private final JComboBox<String> 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.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();
}
}
+140
View File
@@ -0,0 +1,140 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FenetreModif extends JFrame implements ActionListener {
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 GestionRappel ges = new GestionRappel();
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 JTextField theme;
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 (peut être null si tu veux juste récupérer des valeurs)
* @param titre titre initial à afficher (utilisé si rappel==null ou si tu préfères passer la valeur)
* @param contenu contenu initial à afficher (idem)
*/
public FenetreModif(Main parent, Rappel rappel, String titre, String contenu) {
super("Modifier un rappel");
this.parent = parent;
this.rappel = rappel;
setSize(350, 250);
setResizable(false);
setLocation(parent.getLocation()); // même position que Main
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// ------ 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;
// Titre
JLabel lblTitre = new JLabel("Titre :");
champTitre = new JTextField(20);
c.gridx = 0; c.gridy = 0; c.weightx = 0;
centre.add(lblTitre, c);
c.gridx = 1; c.gridy = 0; 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);
c.gridx = 0; c.gridy = 1; c.weightx = 0;
centre.add(lblContenu, c);
c.fill = GridBagConstraints.BOTH;
c.gridx = 1; c.gridy = 1; c.weightx = 1; 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;
centre.add(lblRang, c);
c.gridx = 1; c.gridy = 2; c.weightx = 1;
centre.add(rang, c);
// theme
JLabel lblTheme = new JLabel("Theme");
theme = new JTextField(20);
c.gridx = 0; c.gridy = 3; c.weightx = 0;
centre.add(lblTheme, c);
c.gridx = 1; c.gridy = 3; c.weightx = 1;
centre.add(theme, c);
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);
add(bas, BorderLayout.SOUTH);
champTitre.setText(rappel.getTitre());
champContenu.setText(rappel.getContenu());
}
@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();
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);
try{
ges.modifierParId(rappel.getId(), rappel);
} catch (Exception ex) {
ex.printStackTrace();
}
Main reParent = new Main();
reParent.setLocation(this.getLocation());
reParent.setVisible(true);
dispose();
}
}
}
+32 -29
View File
@@ -2,8 +2,12 @@
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
public class Main extends JFrame {
private final List<PanelRappel> listRpl = new ArrayList<>();
public Main(){
super("Papillon");
@@ -25,25 +29,31 @@ public class Main extends JFrame {
// Colonne 0 : boutons
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.NORTHWEST;
c.insets = new Insets(5, 5, 5, 5);
c.insets = new Insets(4, 4, 4, 4);
for(int i = 0; i< crud.size() ;i++){
c.gridx = 0;
c.gridy = 0;
body.add(crud.get(0), c);
c.gridx = 0;
c.gridy = 1;
body.add(crud.get(1), c);
c.gridy = i;
c.weighty = 0;
body.add(crud.get(i), c);
}
// Colonne 1 : liste verticale de Rappel dans un JScrollPane
JPanel liste = new JPanel();
liste.setLayout(new BoxLayout(liste, BoxLayout.Y_AXIS));
//rappels
//Rappels
GestionRappel g = new GestionRappel();
List<Rappel> listBd = new ArrayList<>();
try {
listBd = g.lister();
} catch (Exception e) {
e.printStackTrace(); // affiche l'erreur dans le terminal
}
for (int i = 0; i < 5; i++) {
Rappel r = new Rappel();
for (int i = 0; i < listBd.size() ; i++) {
PanelRappel r = new PanelRappel(listBd.get(i));
liste.add(r);
listRpl.add(r);
}
JScrollPane scroll = new JScrollPane(
@@ -56,17 +66,25 @@ public class Main extends JFrame {
// place le scrollpane a droite, sur la hauteur des 2 lignes
c.gridx = 1;
c.gridy = 0;
c.gridheight = 2;
c.gridheight = 3;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(0, 0, 0, 0);
c.weightx = 1.0; // prend la largeur dispo
c.weighty = 1.0; // prend la hauteur dispo
body.add(scroll, c);
// barre en bas
JLabel txtbarre = new JLabel("-", SwingConstants.CENTER);
JPanel barre = new JPanel();
barre.add(txtbarre);
barre.setBorder(BorderFactory.createEmptyBorder(1,1,1,1));
// barre.setBackground(Color.GRAY);
// Conteneur racine
JPanel root = new JPanel(new BorderLayout());
root.add(titre, BorderLayout.NORTH);
root.add(body, BorderLayout.CENTER);
root.add(barre, BorderLayout.SOUTH);
setContentPane(root);
// Taille fixe
@@ -76,23 +94,8 @@ public class Main extends JFrame {
}
public void ouvrirFenetreAjout() {
FenetreAjout f = new FenetreAjout(this);
// cacher la fenetre actuelle et montrer celle d ajout
// récupère la position actuelle de Main
Point pos = this.getLocation();
f.setLocation(pos); // place FenetreAjout au même endroit
f.setVisible(true);
this.setVisible(false);
public List<PanelRappel> getPanelRpl(){
return listRpl;
}
public static void main(String[] args) {
Main f = new Main();
f.setVisible(true);
}
}
+116
View File
@@ -0,0 +1,116 @@
// package fr.iutfbleau.papillon;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PanelRappel extends JPanel implements ActionListener, MouseListener{
private final JLabel lbtitre;
private final JLabel lbcontenu;
private final Rappel r;
private final JPopupMenu menu;
private final JMenuItem itemOuvrir;
private boolean estSelectionne = false;
public PanelRappel(Rappel r){
super(new BorderLayout(2,0));
this.r = r;
lbtitre = new JLabel("["+r.getRang()+"] "+r.getTitre());
lbcontenu = new JLabel(r.getContenu());
this.setPreferredSize(new Dimension(70, 50));
this.setBackground(Color.CYAN);
this.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 2));
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.NORTHWEST;
// --- Position du titre (en haut)
c.gridx = 0;
c.gridy = 0;
c.weightx = 1; // prend l'espace
c.fill = GridBagConstraints.NONE;
add(lbtitre, c);
// --- Position du contenu (en dessous)
c.gridx = 0;
c.gridy = 1;
c.weightx = 1;
c.fill = GridBagConstraints.NONE;
add(lbcontenu, c);
// --- Menu contextuel (clic droit) ---
menu = new JPopupMenu();
itemOuvrir = new JMenuItem("Ouvrir");
itemOuvrir.addActionListener(this);
menu.add(itemOuvrir);
// écouteur de souris ajouté ici
addMouseListener(this);
}
public boolean getSelection(){
return estSelectionne;
}
public int getId(){
return r.getId();
}
public Rappel getRappel(){
return r;
}
// ACTIONS
@Override
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src == itemOuvrir) {
JOptionPane.showMessageDialog(
this,
"Ouverture du rappel : " + lbtitre.getText(),
"Ouvrir",
JOptionPane.INFORMATION_MESSAGE
);
}
}
@Override
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger()) {
menu.show(e.getComponent(), e.getX(), e.getY());
}else {
// clic gauche = sélection
estSelectionne = !estSelectionne;
if (estSelectionne) {
setBackground(Color.LIGHT_GRAY);
setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
} else {
setBackground(Color.CYAN);
setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 2));
}
repaint();
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
menu.show(e.getComponent(), e.getX(), e.getY());
}
}
// Les autres méthodes sont obligatoires mais inutilisées ici
@Override public void mouseClicked(MouseEvent e) {}
@Override public void mouseEntered(MouseEvent e) {}
@Override public void mouseExited(MouseEvent e) {}
}
+57 -38
View File
@@ -1,48 +1,67 @@
// package fr.iutfbleau.papillon;
public class Rappel {
private int id;
private String titre;
private String contenu;
private String theme;
private int rang;
import javax.swing.*;
import java.awt.*;
public Rappel(String titre, String contenu, String theme, int rang) {
this(0, titre, contenu, theme, rang);
}
public class Rappel extends JPanel{
private final int ide = -1;
private final String titre = "loute";
private final String contenu = "que veux tu";
private final String theme = "";
private final int rang = -1;
public Rappel(int id, String titre, String contenu, String theme, int rang) {
this.id = id;
this.titre = titre;
this.contenu = contenu;
this.theme = theme;
this.rang = rang;
}
private final JLabel lbtitre;
private final JLabel lbcontenu;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Rappel(){
super(new BorderLayout(2,0));
public String getTitre() {
return titre;
}
public void setTitre(String titre) {
this.titre = titre;
}
lbtitre = new JLabel(titre);
lbcontenu = new JLabel(contenu);
public String getContenu() {
return contenu;
}
public void setContenu(String contenu) {
this.contenu = contenu;
}
this.setPreferredSize(new Dimension(70, 50));
this.setBackground(Color.CYAN);
this.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 2));
public String getTheme() {
return theme;
}
public void setTheme(String theme) {
this.theme = theme;
}
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.NORTHWEST;
// --- Position du titre (en haut)
c.gridx = 0;
c.gridy = 0;
c.weighty = 0; // ne prend pas l'espace
c.fill = GridBagConstraints.NONE;
add(lbtitre, c);
// --- Position du contenu (en dessous)
c.gridx = 0;
c.gridy = 1;
c.weighty = 0;
c.fill = GridBagConstraints.NONE;
add(lbcontenu, c);
public int getRang() {
return rang;
}
public void setRang(int rang) {
this.rang = rang;
}
// @Override
// public String toString() {
// @Override
// public String toString() {
// String texte = "[" + id + "] " + titre + " | " + theme + " | rang=" + rang + " | ";
// if (contenu != null) {
// texte = texte + contenu;
// }
// return texte;
// }
}
// }
}
-67
View File
@@ -1,67 +0,0 @@
public class Rappel {
private int id;
private String titre;
private String contenu;
private String theme;
private int rang;
public Rappel(String titre, String contenu, String theme, int rang) {
this(0, titre, contenu, theme, rang);
}
public Rappel(int id, String titre, String contenu, String theme, int rang) {
this.id = id;
this.titre = titre;
this.contenu = contenu;
this.theme = theme;
this.rang = rang;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitre() {
return titre;
}
public void setTitre(String titre) {
this.titre = titre;
}
public String getContenu() {
return contenu;
}
public void setContenu(String contenu) {
this.contenu = contenu;
}
public String getTheme() {
return theme;
}
public void setTheme(String theme) {
this.theme = theme;
}
public int getRang() {
return rang;
}
public void setRang(int rang) {
this.rang = rang;
}
@Override
public String toString() {
@Override
public String toString() {
String texte = "[" + id + "] " + titre + " | " + theme + " | rang=" + rang + " | ";
if (contenu != null) {
texte = texte + contenu;
}
return texte;
}
}
}
+9
View File
@@ -0,0 +1,9 @@
import javax.swing.*;
import java.awt.*;
public class Start{
public static void main(String[] args) {
Main f = new Main();
f.setVisible(true);
}
}