Skip to content
Commits on Source (9)
No preview for this file type
......@@ -7,7 +7,7 @@
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:3.1.0:exec</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:3.0.0:exec</goal>
</goals>
<properties>
<exec.vmArgs></exec.vmArgs>
......@@ -24,7 +24,7 @@
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:3.1.0:exec</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:3.0.0:exec</goal>
</goals>
<properties>
<exec.vmArgs>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</exec.vmArgs>
......@@ -42,7 +42,7 @@
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:3.1.0:exec</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:3.0.0:exec</goal>
</goals>
<properties>
<exec.vmArgs></exec.vmArgs>
......
package fr.ldnr.herbert.miamle;
import enums.Meal;
import gui.MiammleGui;
import java.time.LocalDate;
import java.time.Month;
import java.util.logging.Level;
......@@ -15,41 +16,44 @@ import models.Inn;
public class MainClass {
public static void main(String[] args) {
Inn inn = new Inn(LocalDate.of(2023, Month.APRIL, 12));
// Créer des participations
Attendance alf = new Attendance("Danlta", "Alphonse", "0123456789", 3, "");
Attendance sophie = new Attendance("Stule", "Sophie", "9876543210", 5, "Avec la famille");
Attendance guy = new Attendance("Tare", "Guy", "@guitounet", 1, "");
// Configurer le premier participant et l'ajouter à l'événement
alf.addMeal(Meal.STARTERS, 5);
alf.addMeal(Meal.MAIN_COURSES, 3);
alf.addMeal(Meal.DRINKS, 5);
alf.addMeal(Meal.DESSERTS, 2);
inn.add(alf);
// Configurer le second participant et l'ajouter à l'événement
sophie.addMeal(Meal.DRINKS, 2);
sophie.addMeal(Meal.DESSERTS, 6);
sophie.addMeal(Meal.MAIN_COURSES, 6);
sophie.addMeal(Meal.STARTERS, 3);
inn.add(sophie);
// Configurer le troisième participant et l'ajouter à l'événement
guy.addMeal(Meal.DRINKS, 6);
inn.add(guy);
System.out.println("Affichage de l'événement créé");
System.out.println(inn);
MiammleGui gui = new MiammleGui("Miammle");
// Sauvegarder l'événement
inn.save();
System.out.println("Évenement sauvegardé");
// Récupérer l'évenùeent et l'afficher
try {
Inn loaded = Inn.load("2023-04-12.bin");
System.out.println("Affichage de l'événement récupéré dans le fichier");
System.out.println(loaded);
} catch (Exception ex) {
Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
}
// Inn inn = new Inn(LocalDate.of(2023, Month.APRIL, 12));
// // Créer des participations
// Attendance alf = new Attendance("Danlta", "Alphonse", "0123456789", 3, "");
// Attendance sophie = new Attendance("Stule", "Sophie", "9876543210", 5, "Avec la famille");
// Attendance guy = new Attendance("Tare", "Guy", "@guitounet", 1, "");
// // Configurer le premier participant et l'ajouter à l'événement
// alf.addMeal(Meal.STARTERS, 5);
// alf.addMeal(Meal.MAIN_COURSES, 3);
// alf.addMeal(Meal.DRINKS, 5);
// alf.addMeal(Meal.DESSERTS, 2);
// inn.add(alf);
// // Configurer le second participant et l'ajouter à l'événement
// sophie.addMeal(Meal.DRINKS, 2);
// sophie.addMeal(Meal.DESSERTS, 6);
// sophie.addMeal(Meal.MAIN_COURSES, 6);
// sophie.addMeal(Meal.STARTERS, 3);
// inn.add(sophie);
// // Configurer le troisième participant et l'ajouter à l'événement
// guy.addMeal(Meal.DRINKS, 6);
// inn.add(guy);
//
// System.out.println("Affichage de l'événement créé");
// System.out.println(inn);
//
// // Sauvegarder l'événement
// inn.save();
// System.out.println("Évenement sauvegardé");
//
// // Récupérer l'évenùeent et l'afficher
// try {
// Inn loaded = Inn.load("2023-04-12.bin");
// System.out.println("Affichage de l'événement récupéré dans le fichier");
// System.out.println(loaded);
// } catch (Exception ex) {
// Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
// }
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gui;
import enums.Meal;
import java.util.ArrayList;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import models.DTO.Attendance;
import models.Inn;
/**
*
* @author stag
*/
public class AttendanceTableModel extends AbstractTableModel {
private static final long serialVersionUID = 1L;
private final ArrayList<Attendance> data;
private final String[] columnNames;
private JTable dataDisplay;
private final Class[] columnClasses = {
String.class, // nom
String.class, // contact
Integer.class, // nb entrées
Integer.class, // nb plats
Integer.class, // nb desserts
Integer.class, // nb boissons
Integer.class, // nb invités
String.class
}; // commentaires
/**
* Constructeur.
*
* @param columnNames les entêtes des colonnes
*/
public AttendanceTableModel(String[] columnNames) {
this.columnNames = columnNames;
data = new ArrayList<>();
}
/**
* Constructeur.
*
* @param columnNames les entêtes des colonnes
* @param inn la liste des participants
*/
public AttendanceTableModel(String[] columnNames, Inn inn) {
this(columnNames);
data.addAll(inn);
}
@Override
public int getRowCount() {
return data.size();
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public String getColumnName(int col) {
return columnNames[col];
}
@Override
public Class getColumnClass(int col) {
return columnClasses[col];
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Attendance attendance = data.get(rowIndex);
switch (columnIndex) {
case 0:
return attendance.getFullName();
case 1:
return attendance.getContact();
case 2:
return attendance.getValueByType(Meal.STARTERS);
case 3:
return attendance.getValueByType(Meal.MAIN_COURSES);
case 4:
return attendance.getValueByType(Meal.DESSERTS);
case 5:
return attendance.getValueByType(Meal.DRINKS);
case 6:
return attendance.getGuests();
case 7:
return attendance.getComment();
default:
throw new AssertionError("invalid column");
}
}
/**
* Vide la table.
*/
public void clear() {
data.clear();
fireTableDataChanged();
}
/**
* Ajoute un élement à la table.
*
* @param attendance la participation ajoutée.
*/
public void add(Attendance attendance) {
data.add(attendance);
}
/**
* Getter.
*
* @return la liste des participations.
*/
public ArrayList<Attendance> getData() {
return data;
}
/**
* Getter.
*
* @return le tableau des entêtes de colonne
*/
public String[] getColumnNames() {
return columnNames;
}
/**
* Getter.
*
* @return le tableau des classes des valeurs par colonne.
*/
public Class[] getColumnClasses() {
return columnClasses;
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package gui;
import java.awt.Dimension;
import javax.swing.BorderFactory;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
/**
*
* @author stag
*/
public class CommentairePanel extends JScrollPane {
private JTextArea commentaireArea;
public JTextArea getCommentaireArea() {
return commentaireArea;
}
/**
* Constructor.
*/
public CommentairePanel() {
commentaireArea = new JTextArea();
createGUI();
}
private void createGUI() {
commentaireArea.setLineWrap(true);
commentaireArea.setWrapStyleWord(true);
this.setViewportView(commentaireArea);
this.setBorder(BorderFactory.createTitledBorder("Commentaires"));
this.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
this.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
this.setPreferredSize(new Dimension(100, 75));
}
}
\ No newline at end of file
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package gui;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
* @author stag
*/
public class LabelAndField extends JPanel {
private JLabel label;
private JTextField textField;
public LabelAndField(String label, int size) {
this.label = new JLabel(label);
this.textField = new JTextField(size);
createGUI();
}
public LabelAndField(String label, int size, String toolTip) {
this(label, size);
this.textField.setToolTipText(toolTip);
}
private void createGUI() {
this.setLayout(new BorderLayout());
this.add(this.label, BorderLayout.WEST);
this.add(this.textField, BorderLayout.EAST);
}
public JTextField getTextField() {
return textField;
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package gui;
import java.awt.HeadlessException;
import java.time.LocalDate;
import java.time.Month;
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JPanel;
import models.Inn;
/**
*
* @author stag
*/
public class MiammleGui extends JFrame {
Inn inn = new Inn(LocalDate.of(2023, Month.APRIL, 12));
JPanel formulaire;
JPanel affichage;
Box content;
public MiammleGui(String title) throws HeadlessException {
super(title);
this.content = Box.createVerticalBox();
this.formulaire = new formulaireUI(inn);
this.affichage = new affichageUI(inn);
this.createUI();
}
private void createUI() {
this.content.add(formulaire);
this.content.add(affichage);
this.getContentPane().add(content);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package gui;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JTable;
import models.DTO.Attendance;
import models.Inn;
/**
*
* @author stag
*/
public class affichageUI extends JPanel {
Inn inn;
private JTable dataDisplay;
public final String[] columnNames = {"Nom", "Contact", "Entrées", "Plats", "Desserts", "Boissons", "Invités", "Commentaires"};
affichageUI(Inn inn) {
this.inn = inn;
createUI();
}
private void createUI() {
this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
this.setBorder(BorderFactory.createTitledBorder("Affichage"));
dataDisplay = new JTable(new AttendanceTableModel(columnNames, inn));
this.add(dataDisplay);
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package gui;
import enums.Meal;
import fr.ldnr.herbert.miamle.MainClass;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.time.LocalDate;
import java.time.Month;
import java.util.List;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import models.DTO.Attendance;
import models.Inn;
/**
*
* @author stag
*/
public class formulaireUI extends JPanel {
LabelAndField nomPanel, prenomPanel, contactPanel;
CommentairePanel commentaire;
JPanel platsPanel, invitesPanel, submitPanel;
JLabel entreeLabel, platLabel, dessertLabel, boissonLabel, inviteLabel;
JComboBox entree, plat, boisson, dessert, invite;
JButton submit;
Inn inn;
formulaireUI(Inn inn) {
platsPanel = new JPanel();
entreeLabel = new JLabel();
platLabel = new JLabel();
dessertLabel = new JLabel();
boissonLabel = new JLabel();
invitesPanel = new JPanel();
inviteLabel = new JLabel();
submitPanel = new JPanel();
submit = new JButton("Valider");
this.inn = inn;
createUI();
}
private void createUI() {
this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
this.setBorder(BorderFactory.createTitledBorder("Formulaire"));
nomPanel = new LabelAndField("Nom ", 25, "Entrez votre nom ");
prenomPanel = new LabelAndField("Prénom ", 25, "Entrez votre prénom");
contactPanel = new LabelAndField("Contact ", 25, "Entrez vote e-mail ou votre numéro de téléphone");
platsPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
entreeLabel.setText("Entrée");
platsPanel.add(entreeLabel);
List<Integer> entrees = new ArrayList<>();
for (int i = 0; i <= 15; i++) {
entrees.add(i);
}
entree = new JComboBox(entrees.toArray());
platsPanel.add(entree);
platLabel.setText("Plat");
platsPanel.add(platLabel);
List<Integer> plats = new ArrayList<>();
for (int i = 0; i <= 15; i++) {
plats.add(i);
}
plat = new JComboBox(plats.toArray());
platsPanel.add(plat);
dessertLabel.setText("Dessert");
platsPanel.add(dessertLabel);
List<Integer> desserts = new ArrayList<>();
for (int i = 0; i <= 15; i++) {
desserts.add(i);
}
dessert = new JComboBox(desserts.toArray());
platsPanel.add(dessert);
boissonLabel.setText("Boisson");
platsPanel.add(boissonLabel);
List<Integer> boissons = new ArrayList<>();
for (int i = 0; i <= 15; i++) {
boissons.add(i);
}
boisson = new JComboBox(boissons.toArray());
platsPanel.add(boisson);
invitesPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
inviteLabel.setText("Nombre invités");
invitesPanel.add(inviteLabel);
List<Integer> invites = new ArrayList<>();
for (int i = 1; i <= 20; i++) {
invites.add(i);
}
invite = new JComboBox(invites.toArray());
invitesPanel.add(invite);
commentaire = new CommentairePanel();
submitPanel.setLayout(new FlowLayout());
submit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
Attendance select = new Attendance(
nomPanel.getTextField().getText(),
prenomPanel.getTextField().getText(),
contactPanel.getTextField().getText(),
invite.getSelectedIndex(),
commentaire.getCommentaireArea().getText()
);
select.addMeal(Meal.STARTERS, entree.getSelectedIndex());
select.addMeal(Meal.MAIN_COURSES, plat.getSelectedIndex());
select.addMeal(Meal.DRINKS, boisson.getSelectedIndex());
select.addMeal(Meal.DESSERTS, dessert.getSelectedIndex());
inn.add(select);
inn.save();
try {
Inn loaded = Inn.load("2023-04-12.bin");
System.out.println("Affichage de l'événement récupéré dans le fichier");
System.out.println(loaded);
} catch (Exception ex) {
Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
submitPanel.add(submit);
this.add(nomPanel);
this.add(prenomPanel);
this.add(contactPanel);
this.add(platsPanel);
this.add(invitesPanel);
this.add(commentaire);
this.add(submitPanel);
}
}
......@@ -3,6 +3,7 @@ package models.DTO;
import enums.Meal;
import java.io.Serializable;
import java.util.HashMap;
import models.DTO.Person;
/**
*
......@@ -51,9 +52,7 @@ public class Attendance extends Person implements Comparable<Attendance>, Serial
* @param guests Le nombre d'invités pour cette participation
* @param comment Cmmentaires éventuels
*/
public Attendance(
Person person, String contact,
int guests, String comment) {
public Attendance(Person person, String contact, int guests, String comment) {
super(person.name, person.forname);
this.meals = new HashMap<>();
this.contact = contact;
......
......@@ -37,6 +37,10 @@ public class Person implements Serializable {
this.name = name;
}
public String getFullName() {
return this.name + " " + this.forname;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
......
package models;
import models.DTO.Attendance;
import enums.Meal;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
......@@ -12,7 +13,6 @@ import java.time.LocalDate;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import models.DTO.Attendance;
/**
*
......