From e0614485881f23046e5f9a0b287e68cbea15fd42 Mon Sep 17 00:00:00 2001 From: Jenson VAL Date: Thu, 23 Oct 2025 00:30:20 +0200 Subject: [PATCH 1/6] suppresion ancien rappel --- src/fr/iutfbleau/papillon/Rappel.java | 48 --------------------------- 1 file changed, 48 deletions(-) delete mode 100644 src/fr/iutfbleau/papillon/Rappel.java diff --git a/src/fr/iutfbleau/papillon/Rappel.java b/src/fr/iutfbleau/papillon/Rappel.java deleted file mode 100644 index 914074e..0000000 --- a/src/fr/iutfbleau/papillon/Rappel.java +++ /dev/null @@ -1,48 +0,0 @@ -// package fr.iutfbleau.papillon; - -import javax.swing.*; -import java.awt.*; - -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; - - private final JLabel lbtitre; - private final JLabel lbcontenu; - -public Rappel(){ - super(new BorderLayout(2,0)); - - lbtitre = new JLabel(titre); - lbcontenu = new JLabel(contenu); - - 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.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); - - -} - -} \ No newline at end of file From 49516eb980438e05368efe1ec1e824507181a0c5 Mon Sep 17 00:00:00 2001 From: Jenson VAL Date: Thu, 23 Oct 2025 00:31:17 +0200 Subject: [PATCH 2/6] suppresion ancien rappel --- src/fr/iutfbleau/papillon/RappelM.java | 67 -------------------------- 1 file changed, 67 deletions(-) delete mode 100644 src/fr/iutfbleau/papillon/RappelM.java diff --git a/src/fr/iutfbleau/papillon/RappelM.java b/src/fr/iutfbleau/papillon/RappelM.java deleted file mode 100644 index e2e51bc..0000000 --- a/src/fr/iutfbleau/papillon/RappelM.java +++ /dev/null @@ -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; - } - -} -} \ No newline at end of file From b1ca41dcc11165222d73961fdfb04234707b3302 Mon Sep 17 00:00:00 2001 From: Jenson VAL Date: Thu, 23 Oct 2025 00:31:56 +0200 Subject: [PATCH 3/6] =?UTF-8?q?fonctionnalit=C3=A9=20crud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fr/iutfbleau/papillon/Crud.java | 33 ++++++++++++----------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/fr/iutfbleau/papillon/Crud.java b/src/fr/iutfbleau/papillon/Crud.java index 9400669..b69dd9e 100644 --- a/src/fr/iutfbleau/papillon/Crud.java +++ b/src/fr/iutfbleau/papillon/Crud.java @@ -6,29 +6,24 @@ import javax.swing.*; import java.awt.*; import java.awt.event.*; -public class Crud extends ArrayList implements ActionListener{ +public class Crud extends ArrayList{ - 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"); - } - } + } \ No newline at end of file From 5e6155861ab8eaa9cb1270d3ead5fd68f11e8335 Mon Sep 17 00:00:00 2001 From: Jenson VAL Date: Thu, 23 Oct 2025 00:33:21 +0200 Subject: [PATCH 4/6] =?UTF-8?q?fonctionnalit=C3=A9=20crud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fr/iutfbleau/papillon/FenetreAjout.java | 97 ++++++++++++--------- 1 file changed, 54 insertions(+), 43 deletions(-) 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(); } } From f2f054631f54ffac9fc051085ed2772fc7e61d40 Mon Sep 17 00:00:00 2001 From: Jenson VAL Date: Thu, 23 Oct 2025 00:34:04 +0200 Subject: [PATCH 5/6] =?UTF-8?q?fonctionnalit=C3=A9=20crud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fr/iutfbleau/papillon/Main.java | 63 +++++++++++++++-------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/src/fr/iutfbleau/papillon/Main.java b/src/fr/iutfbleau/papillon/Main.java index 9407483..bd3b66a 100644 --- a/src/fr/iutfbleau/papillon/Main.java +++ b/src/fr/iutfbleau/papillon/Main.java @@ -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 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 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(); - liste.add(r); - + 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 getPanelRpl(){ + return listRpl; } - public static void main(String[] args) { - - Main f = new Main(); - f.setVisible(true); - } } \ No newline at end of file From 8710600b37aacdda56e1c49eaec9ae82a95bdb9f Mon Sep 17 00:00:00 2001 From: Jenson VAL Date: Thu, 23 Oct 2025 00:35:41 +0200 Subject: [PATCH 6/6] =?UTF-8?q?fonctionnalit=C3=A9=20crud=20+=20r=C3=A9age?= =?UTF-8?q?ncement=20des=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fr/iutfbleau/papillon/CouleurList.java | 37 ++++++ src/fr/iutfbleau/papillon/FenetreModif.java | 140 ++++++++++++++++++++ src/fr/iutfbleau/papillon/PanelRappel.java | 116 ++++++++++++++++ src/fr/iutfbleau/papillon/Rappel.java | 67 ++++++++++ src/fr/iutfbleau/papillon/Start.java | 9 ++ 5 files changed, 369 insertions(+) create mode 100644 src/fr/iutfbleau/papillon/CouleurList.java create mode 100644 src/fr/iutfbleau/papillon/FenetreModif.java create mode 100644 src/fr/iutfbleau/papillon/PanelRappel.java create mode 100644 src/fr/iutfbleau/papillon/Rappel.java create mode 100644 src/fr/iutfbleau/papillon/Start.java diff --git a/src/fr/iutfbleau/papillon/CouleurList.java b/src/fr/iutfbleau/papillon/CouleurList.java new file mode 100644 index 0000000..850967f --- /dev/null +++ b/src/fr/iutfbleau/papillon/CouleurList.java @@ -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; + } +} diff --git a/src/fr/iutfbleau/papillon/FenetreModif.java b/src/fr/iutfbleau/papillon/FenetreModif.java new file mode 100644 index 0000000..d4558b1 --- /dev/null +++ b/src/fr/iutfbleau/papillon/FenetreModif.java @@ -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 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(); + } + } + +} diff --git a/src/fr/iutfbleau/papillon/PanelRappel.java b/src/fr/iutfbleau/papillon/PanelRappel.java new file mode 100644 index 0000000..a5fe92f --- /dev/null +++ b/src/fr/iutfbleau/papillon/PanelRappel.java @@ -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) {} + +} \ No newline at end of file diff --git a/src/fr/iutfbleau/papillon/Rappel.java b/src/fr/iutfbleau/papillon/Rappel.java new file mode 100644 index 0000000..686e739 --- /dev/null +++ b/src/fr/iutfbleau/papillon/Rappel.java @@ -0,0 +1,67 @@ +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; +// } + +// } +} \ No newline at end of file diff --git a/src/fr/iutfbleau/papillon/Start.java b/src/fr/iutfbleau/papillon/Start.java new file mode 100644 index 0000000..e1a6a07 --- /dev/null +++ b/src/fr/iutfbleau/papillon/Start.java @@ -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); + } +} \ No newline at end of file