reagencement du code
This commit is contained in:
@@ -5,8 +5,8 @@ import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class BtnAjouter extends JButton implements ActionListener{
|
||||
private Main main;
|
||||
|
||||
private Main main;
|
||||
|
||||
public BtnAjouter(Main main){
|
||||
super("Ajouter");
|
||||
@@ -18,8 +18,6 @@ public class BtnAjouter extends JButton implements ActionListener{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void actionPerformed(ActionEvent e){
|
||||
if(e.getSource()==this){
|
||||
FenetreAjout f = new FenetreAjout(main);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import javax.swing.*;
|
||||
import javax.swing.Icon;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
@@ -12,11 +11,11 @@ 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 "Bleu": return Color.CYAN;
|
||||
case "Rouge": return Color.RED;
|
||||
case "Vert": return Color.GREEN;
|
||||
case "Jaune": return Color.YELLOW;
|
||||
case "Gris": return Color.LIGHT_GRAY;
|
||||
case "Rose": return Color.PINK;
|
||||
default: return Color.WHITE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
// package fr.iutfbleau.papillon;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Crud extends ArrayList<JButton>{
|
||||
|
||||
private Main main;
|
||||
|
||||
private BtnAjouter btnAjt;
|
||||
private BtnSupprimer btnSpr;
|
||||
private BtnModifier btnMdf;
|
||||
|
||||
public Crud(Main main){
|
||||
this.main = main;
|
||||
|
||||
btnAjt = new BtnAjouter(main);
|
||||
btnSpr = new BtnSupprimer(main);
|
||||
btnMdf = new BtnModifier(main);
|
||||
@@ -25,5 +20,4 @@ add(btnMdf);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GestionAjout extends ArrayList<JButton> implements ActionListener{
|
||||
@@ -65,7 +63,7 @@ public class GestionAjout extends ArrayList<JButton> implements ActionListener{
|
||||
}else{
|
||||
|
||||
try{
|
||||
g.ajouter(new Rappel(titre,contenu,cTheme,Nrang));
|
||||
g.ajouter(titre, contenu, cTheme, Nrang);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace(); // affiche l'erreur dans le terminal
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GestionModif extends ArrayList<JButton> implements ActionListener{
|
||||
@@ -16,7 +13,7 @@ public class GestionModif extends ArrayList<JButton> implements ActionListener{
|
||||
private final JComboBox<String> comboTheme;
|
||||
private Rappel rappel;
|
||||
|
||||
private GestionRappel ges = new GestionRappel();
|
||||
private final GestionRappel ges = new GestionRappel();
|
||||
private final Main parent;
|
||||
private final JFrame f;
|
||||
|
||||
|
||||
@@ -1,29 +1,41 @@
|
||||
// package fr.iutfbleau.papillon;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class PanelRappel extends JPanel implements ActionListener, MouseListener {
|
||||
private boolean estSelectionne = false;
|
||||
|
||||
private final JLabel lbtitre;
|
||||
private final JLabel lbcontenu;
|
||||
private JLabel lbtitre;
|
||||
private JLabel lbcontenu;
|
||||
private Rappel r;
|
||||
|
||||
private final Rappel r;
|
||||
|
||||
private final JPopupMenu menu;
|
||||
private final JMenuItem itemOuvrir;
|
||||
private JPopupMenu menu;
|
||||
private JMenuItem itemOuvrir;
|
||||
private Main main;
|
||||
|
||||
private static CouleurList couleur = new CouleurList();
|
||||
|
||||
private boolean estSelectionne = false;
|
||||
public PanelRappel(Rappel r, Main main) {
|
||||
super(new BorderLayout(2, 0));
|
||||
this.main = main;
|
||||
createPanel(r);
|
||||
}
|
||||
|
||||
public PanelRappel(Rappel r) {
|
||||
super(new BorderLayout(2, 0));
|
||||
this.r = r;
|
||||
lbtitre = new JLabel("["+r.getRang()+"] "+r.getTitre());
|
||||
lbcontenu = new JLabel(r.getContenu());
|
||||
createPanel(r);
|
||||
}
|
||||
|
||||
public void createPanel(Rappel r){
|
||||
this.r = r;
|
||||
|
||||
// --- Titre et contenu raccourci ---
|
||||
lbtitre = new JLabel("[" + r.getRang() + "] " + r.getTitre());
|
||||
lbcontenu = new JLabel(
|
||||
"<html>" + (r.getContenu().length() > 40 ? r.getContenu().substring(0, 40) + "..." : r.getContenu()) + "</html>"
|
||||
);
|
||||
|
||||
// --- Apparence de base ---
|
||||
this.setPreferredSize(new Dimension(70, 50));
|
||||
this.setBackground(couleur.couleurDe(r.getTheme()));
|
||||
this.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 2));
|
||||
@@ -32,15 +44,14 @@ public PanelRappel(Rappel r){
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.anchor = GridBagConstraints.NORTHWEST;
|
||||
|
||||
// --- Position du titre (en haut)
|
||||
// --- Position du titre ---
|
||||
c.gridx = 0;
|
||||
c.gridy = 0;
|
||||
c.weightx = 1; // prend l'espace
|
||||
c.weightx = 1;
|
||||
c.fill = GridBagConstraints.NONE;
|
||||
add(lbtitre, c);
|
||||
|
||||
|
||||
// --- Position du contenu (en dessous)
|
||||
// --- Position du contenu ---
|
||||
c.gridx = 0;
|
||||
c.gridy = 1;
|
||||
c.weightx = 1;
|
||||
@@ -53,10 +64,11 @@ add(lbcontenu, c);
|
||||
itemOuvrir.addActionListener(this);
|
||||
menu.add(itemOuvrir);
|
||||
|
||||
// a améliorer
|
||||
// --- Activation des clics ---
|
||||
addMouseListener(this);
|
||||
}
|
||||
|
||||
// === GETTERS ===
|
||||
public boolean getSelection() {
|
||||
return estSelectionne;
|
||||
}
|
||||
@@ -68,39 +80,27 @@ public int getId(){
|
||||
public Rappel getRappel() {
|
||||
return r;
|
||||
}
|
||||
// ACTIONS
|
||||
|
||||
// === 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
|
||||
);
|
||||
// ouverture complète depuis le menu clic droit
|
||||
new FenetreRappel(r, main);
|
||||
}
|
||||
}
|
||||
|
||||
// === GESTION DES CLICS SOURIS ===
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
menu.show(e.getComponent(), e.getX(), e.getY());
|
||||
} else {
|
||||
// clic gauche = sélection
|
||||
// clic gauche = sélection / désélection
|
||||
estSelectionne = !estSelectionne;
|
||||
|
||||
if (estSelectionne) {
|
||||
setBackground(Color.LIGHT_GRAY);
|
||||
setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
} else {
|
||||
setBackground(couleur.couleurDe(r.getTheme()));
|
||||
setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
|
||||
|
||||
}
|
||||
|
||||
repaint();
|
||||
majApparence();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,21 +108,36 @@ public Rappel getRappel(){
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
menu.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// === Double clic pour ouvrir la vue complète ===
|
||||
if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
|
||||
new FenetreRappel(r, main);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override public void mouseClicked(MouseEvent e) {}
|
||||
@Override public void mouseEntered(MouseEvent e) {
|
||||
setBackground(Color.LIGHT_GRAY);
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
}
|
||||
@Override public void mouseExited(MouseEvent e) {
|
||||
if(!estSelectionne){
|
||||
setBackground(couleur.couleurDe(r.getTheme()));
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
|
||||
|
||||
}
|
||||
|
||||
private void majApparence() {
|
||||
if (estSelectionne) {
|
||||
setBackground(Color.LIGHT_GRAY);
|
||||
setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
} else {
|
||||
setBackground(couleur.couleurDe(r.getTheme()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 840 KiB |
Reference in New Issue
Block a user