diff --git a/src/fr/iutfbleau/papillon/PanelRappel.java b/src/fr/iutfbleau/papillon/PanelRappel.java index a5fe92f..603c29d 100644 --- a/src/fr/iutfbleau/papillon/PanelRappel.java +++ b/src/fr/iutfbleau/papillon/PanelRappel.java @@ -1,116 +1,118 @@ -// 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) {} - +// 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 static CouleurList couleur = new CouleurList(); + + 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(couleur.couleurDe(r.getTheme())); + 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); + + // a améliorer + 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()); + } + } + + + @Override public void mouseClicked(MouseEvent e) {} + @Override public void mouseEntered(MouseEvent e) {} + @Override public void mouseExited(MouseEvent e) {} + } \ No newline at end of file