2025-10-19 02:30:54 +02:00
|
|
|
// package fr.iutfbleau.papillon;
|
|
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
import java.awt.*;
|
2025-10-23 00:34:04 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Arrays;
|
2025-10-19 02:30:54 +02:00
|
|
|
|
|
|
|
|
public class Main extends JFrame {
|
2025-10-23 00:34:04 +02:00
|
|
|
private final List<PanelRappel> listRpl = new ArrayList<>();
|
2025-10-19 02:30:54 +02:00
|
|
|
|
|
|
|
|
public Main(){
|
2025-10-20 23:15:55 +02:00
|
|
|
super("Papillon");
|
2025-10-23 20:27:57 +02:00
|
|
|
|
|
|
|
|
// Taille fixe
|
|
|
|
|
setSize(350, 250);
|
|
|
|
|
setResizable(false);
|
|
|
|
|
setAlwaysOnTop(true);
|
2025-10-20 23:15:55 +02:00
|
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
2025-10-19 02:30:54 +02:00
|
|
|
|
2025-10-21 16:49:52 +02:00
|
|
|
// Titre en haut
|
2025-10-20 23:15:55 +02:00
|
|
|
JLabel titre = new JLabel("Rappel : Papillon", SwingConstants.CENTER);
|
|
|
|
|
titre.setBorder(BorderFactory.createEmptyBorder(6,10,6,10));
|
2025-10-23 08:57:13 +02:00
|
|
|
// titre.setBackground(Color.CYAN);
|
2025-10-20 23:15:55 +02:00
|
|
|
|
2025-10-19 02:30:54 +02:00
|
|
|
|
|
|
|
|
|
2025-10-20 23:15:55 +02:00
|
|
|
// ----- Grille centrale : boutons a gauche + liste scrollable a droite -----
|
|
|
|
|
JPanel body = new JPanel(new GridBagLayout());
|
|
|
|
|
GridBagConstraints c = new GridBagConstraints();
|
|
|
|
|
|
|
|
|
|
Crud crud = new Crud(this);
|
|
|
|
|
|
|
|
|
|
// Colonne 0 : boutons
|
|
|
|
|
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
|
|
c.anchor = GridBagConstraints.NORTHWEST;
|
2025-10-23 00:34:04 +02:00
|
|
|
c.insets = new Insets(4, 4, 4, 4);
|
|
|
|
|
for(int i = 0; i< crud.size() ;i++){
|
2025-10-20 23:15:55 +02:00
|
|
|
c.gridx = 0;
|
2025-10-23 00:34:04 +02:00
|
|
|
c.gridy = i;
|
|
|
|
|
c.weighty = 0;
|
|
|
|
|
body.add(crud.get(i), c);
|
|
|
|
|
}
|
2025-10-20 23:15:55 +02:00
|
|
|
|
|
|
|
|
// Colonne 1 : liste verticale de Rappel dans un JScrollPane
|
|
|
|
|
JPanel liste = new JPanel();
|
|
|
|
|
liste.setLayout(new BoxLayout(liste, BoxLayout.Y_AXIS));
|
|
|
|
|
|
2025-10-23 00:34:04 +02:00
|
|
|
//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
|
|
|
|
|
}
|
2025-10-20 23:15:55 +02:00
|
|
|
|
2025-10-23 00:34:04 +02:00
|
|
|
for (int i = 0; i < listBd.size() ; i++) {
|
|
|
|
|
PanelRappel r = new PanelRappel(listBd.get(i));
|
|
|
|
|
liste.add(r);
|
|
|
|
|
listRpl.add(r);
|
2025-10-19 02:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2025-10-20 23:15:55 +02:00
|
|
|
JScrollPane scroll = new JScrollPane(
|
|
|
|
|
liste,
|
|
|
|
|
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
|
|
|
|
|
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER
|
|
|
|
|
);
|
|
|
|
|
scroll.getVerticalScrollBar().setUnitIncrement(16); // molette fluide
|
2025-10-19 02:30:54 +02:00
|
|
|
|
2025-10-20 23:15:55 +02:00
|
|
|
// place le scrollpane a droite, sur la hauteur des 2 lignes
|
|
|
|
|
c.gridx = 1;
|
|
|
|
|
c.gridy = 0;
|
2025-10-23 00:34:04 +02:00
|
|
|
c.gridheight = 3;
|
2025-10-20 23:15:55 +02:00
|
|
|
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);
|
|
|
|
|
|
2025-10-23 00:34:04 +02:00
|
|
|
// 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);
|
|
|
|
|
|
2025-10-20 23:15:55 +02:00
|
|
|
// Conteneur racine
|
|
|
|
|
JPanel root = new JPanel(new BorderLayout());
|
|
|
|
|
root.add(titre, BorderLayout.NORTH);
|
|
|
|
|
root.add(body, BorderLayout.CENTER);
|
2025-10-23 00:34:04 +02:00
|
|
|
root.add(barre, BorderLayout.SOUTH);
|
2025-10-20 23:15:55 +02:00
|
|
|
setContentPane(root);
|
|
|
|
|
|
2025-10-23 20:27:57 +02:00
|
|
|
|
2025-10-20 23:15:55 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-21 16:49:52 +02:00
|
|
|
|
2025-10-23 00:34:04 +02:00
|
|
|
public List<PanelRappel> getPanelRpl(){
|
|
|
|
|
return listRpl;
|
2025-10-20 23:15:55 +02:00
|
|
|
}
|
2025-10-21 16:49:52 +02:00
|
|
|
|
2025-10-19 02:30:54 +02:00
|
|
|
}
|