Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider d61cd63b rédigé par Youness's avatar Youness
Parcourir les fichiers

Modification code

parent 2368bdc8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 243 ajouts et 197 suppressions
/.metadata/
/lry/
/mainVeto.class
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
package lry.dip.tcp;
package lry.dip.tcp;
import java.io.*;
import java.net.*;
......@@ -10,6 +10,8 @@ import lry.dip.tcp.Echantillon;
public class ClientSocketTCP {
/***** Attributs *****/
private Inet4Address IPServeur;
private int portServeur;
private ObjectOutputStream fluxSortie;
......@@ -20,9 +22,14 @@ public class ClientSocketTCP {
private String ligne;
private PrintWriter ecrire;
private int PortClient = 0;
/*****Constructeur*****/
public ClientSocketTCP() {}
public ClientSocketTCP() {
}
/*****Mthodes*****/
public void connecter(int pPort, String pIP) {
System.out.println("Connexion au serveur : " + pIP + " /" + pPort);
this.portServeur = pPort;
......@@ -61,7 +68,7 @@ public class ClientSocketTCP {
e.printStackTrace();
}
}
public void envoyerEchantillon(Echantillon e) {
System.out.println("Envoi de l'chantillon.");
try {
......@@ -71,17 +78,15 @@ public class ClientSocketTCP {
IOex.printStackTrace();
}
}
public Echantillon recevoirRequete() {
while (true) {
try {
Echantillon e = (Echantillon) this.fluxEntree.readObject();
if(e.getNom().equals("suppression")) {
if (e.getNom().equals("suppression")) {
System.out.println("Recevoir requete : Suppression");
return e;
}
else {
} else {
System.out.println("Recevoir requete : Insertion");
return e;
}
......
......@@ -3,8 +3,10 @@ package lry.dip.tcp;
import java.io.Serializable;
import java.util.Date;
public class Echantillon implements Serializable{
public class Echantillon implements Serializable {
/***** Attributs *****/
private int id;
private String nom;
private String espece;
......@@ -12,16 +14,18 @@ public class Echantillon implements Serializable{
private String date_entree;
private String date_sortie;
/*****Constructeur*****/
public Echantillon(int pId, String pNom, String pEspece, int pAge, String pEntree, String pSortie) {
this.setId(pId);
this.setNom(pNom);
this.setEspece(pEspece);
this.setAge(pAge);
this.setDate_entree(pEntree);
this.setDate_sortie(pSortie);
}
/*****Getters - Setters*****/
public int getId() {
return id;
......@@ -71,27 +75,26 @@ public class Echantillon implements Serializable{
this.date_sortie = date_sortie;
}
public String getValueColumn(String ColumnName) {
switch (ColumnName) {
case "Nom": {
return getNom();
}
case "Espèce": {
return getEspece();
}
case "Âge": {
return Integer.toString(getAge());
}
case "Date entrée": {
return (getDate_entree().toString()).substring(0,10) + " " + (getDate_entree().toString()).substring(24,29);
}
case "Date sortie": {
return (getDate_sortie().toString()).substring(0,10) + " " + (getDate_sortie().toString()).substring(24,29);
}
case "Nom": {
return getNom();
}
case "Espèce": {
return getEspece();
}
case "Âge": {
return Integer.toString(getAge());
}
case "Date entrée": {
return (getDate_entree().toString()).substring(0, 10) + " "
+ (getDate_entree().toString()).substring(24, 29);
}
case "Date sortie": {
return (getDate_sortie().toString()).substring(0, 10) + " "
+ (getDate_sortie().toString()).substring(24, 29);
}
}
return ColumnName;
}
}
......@@ -14,10 +14,14 @@ import lry.dip.tcp.Echantillon;
public class TacheSW extends SwingWorker<Integer, Echantillon> implements PropertyChangeListener {
/***** Attributs *****/
private ClientSocketTCP socketServeur;
private GUI gui;
private ModeleTable table;
/***** Constructeur *****/
public TacheSW(ClientSocketTCP pSocket, GUI pGui, ModeleTable pTable) {
this.socketServeur = pSocket;
addPropertyChangeListener(this);
......@@ -25,6 +29,7 @@ public class TacheSW extends SwingWorker<Integer, Echantillon> implements Proper
this.table = pTable;
}
/***** Mthodes *****/
@Override
protected Integer doInBackground() throws Exception {
while (isCancelled() == false) {
......
......@@ -10,6 +10,8 @@ import lry.dip.tcp.*;
@SuppressWarnings("serial")
public class GUI extends JFrame implements Action {
/***** Attributs *****/
private JMenuBar menuBar;
private JMenu menuFichier;
private JMenuItem itemAjouter, itemSupprimer, itemQuitter;
......@@ -19,6 +21,8 @@ public class GUI extends JFrame implements Action {
private ClientSocketTCP client;
private TacheSW tsw;
/***** Constructeur *****/
public GUI(int pLarg, int pHaut, boolean pResize, String pTitre) {
this.client = new ClientSocketTCP();
......@@ -65,6 +69,8 @@ public class GUI extends JFrame implements Action {
this.tsw.execute();
}
/***** Mthodes *****/
@Override
public void actionPerformed(ActionEvent e) {
......@@ -90,7 +96,7 @@ public class GUI extends JFrame implements Action {
UIManager.put("OptionPane.minimumSize", new Dimension(100, 100));
int result = JOptionPane.showConfirmDialog(null, "Voulez-vous vraiment quitter l'application ?",
"Fermeture de l'application...", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE);
if (result == 0) {
System.exit(0);
}
......
......@@ -6,41 +6,49 @@ import java.util.*;
import javax.swing.table.*;
@SuppressWarnings("serial")
public class ModeleTable extends AbstractTableModel{
public class ModeleTable extends AbstractTableModel {
/***** Attributs *****/
private final String[] entetes = { "Nom", "Espce", "ge", "Date entre", "Date sortie" };
private ArrayList<Echantillon> echantillons;
/***** Constructeur *****/
public ModeleTable() {
this.setEchantillons(new ArrayList<Echantillon>());
}
public ArrayList<Echantillon> getEchantillons() {
return echantillons;
}
public void setEchantillons(ArrayList<Echantillon> echantillons) {
this.echantillons = echantillons;
}
/***** Mthodes *****/
public void addEchantillons(Echantillon e) {
this.echantillons.add(e);
this.echantillons.add(e);
this.fireTableDataChanged();
}
public void addData(Echantillon echantillon) {
this.addEchantillons(echantillon);
}
public void removeData(int rowIndex) {
this.echantillons.remove(rowIndex);
this.fireTableDataChanged();
}
public void insertData(String pNom, String pEspece, int pAge, Date pEntree, Date pSortie) {
}
/***** Getters - Setters *****/
public ArrayList<Echantillon> getEchantillons() {
return echantillons;
}
public void setEchantillons(ArrayList<Echantillon> echantillons) {
this.echantillons = echantillons;
}
@Override
public int getColumnCount() {
......@@ -51,7 +59,6 @@ public class ModeleTable extends AbstractTableModel{
public String getColumnName(int columnIndex) {
return entetes[columnIndex];
}
@Override
public int getRowCount() {
......@@ -62,5 +69,5 @@ public class ModeleTable extends AbstractTableModel{
public Object getValueAt(int rowIndex, int columnIndex) {
return this.getEchantillons().get(rowIndex).getValueColumn(getColumnName(columnIndex));
}
}
......@@ -12,48 +12,52 @@ import org.junit.jupiter.api.Test;
import lry.dip.tcp.Echantillon;
class ModeleTableTest {
/***** Attributs *****/
private static ModeleTable table;
static ArrayList<Echantillon> EchantillonsListe;
/***** Tests *****/
@BeforeAll
static void initAll() {
EchantillonsListe = new ArrayList<Echantillon>();
table = new ModeleTable();
}
@BeforeEach
void clearDatas() {
@BeforeEach
void clearDatas() {
EchantillonsListe.clear();
Echantillon e1 = new Echantillon(1,"Echantillon1","Espece1",10,"Sat Jun 20","Sat Jun 20");
Echantillon e2 = new Echantillon(2,"Echantillon2","Espece2",10,"Sat Jun 20","Sat Jun 20");
Echantillon e3 = new Echantillon(3,"Echantillon3","Espece3",10,"Sat Jun 20","Sat Jun 20");
Echantillon e1 = new Echantillon(1, "Echantillon1", "Espece1", 10, "Sat Jun 20", "Sat Jun 20");
Echantillon e2 = new Echantillon(2, "Echantillon2", "Espece2", 10, "Sat Jun 20", "Sat Jun 20");
Echantillon e3 = new Echantillon(3, "Echantillon3", "Espece3", 10, "Sat Jun 20", "Sat Jun 20");
EchantillonsListe.add(e1);
EchantillonsListe.add(e2);
EchantillonsListe.add(e3);
table.setEchantillons(EchantillonsListe);
}
}
@Test
void addingData() {
System.out.println("Adding Datas : TEST");
Echantillon echantillontoAdd = new Echantillon(4,"Echantillon4","Especee4",10,"Sat Jun 20","Sat Jun 20");
Echantillon echantillontoAdd = new Echantillon(4, "Echantillon4", "Especee4", 10, "Sat Jun 20", "Sat Jun 20");
table.addData(echantillontoAdd);
Assertions.assertEquals(table.getEchantillons().size(),4);
Assertions.assertEquals(table.getEchantillons().get(3).getNom(),"Echantillon4");
Assertions.assertEquals(table.getEchantillons().size(), 4);
Assertions.assertEquals(table.getEchantillons().get(3).getNom(), "Echantillon4");
System.out.println("Adding Datas : TEST SUCCESSFUL");
}
@Test
void removingData() {
System.out.println("Removing Datas : TEST");
table.removeData(2);
Assertions.assertEquals(table.getEchantillons().size(),2);
Assertions.assertEquals(table.getEchantillons().get(0).getNom(),"Echantillon1");
Assertions.assertEquals(table.getEchantillons().get(1).getNom(),"Echantillon2");
Assertions.assertEquals(table.getEchantillons().size(), 2);
Assertions.assertEquals(table.getEchantillons().get(0).getNom(), "Echantillon1");
Assertions.assertEquals(table.getEchantillons().get(1).getNom(), "Echantillon2");
System.out.println("Removing Datas : TEST SUCCESSFUL");
}
......
package lry.dip.veto;
import java.awt.*;
import java.text.*;
import java.util.*;
......@@ -9,46 +8,49 @@ import javax.swing.*;
public class Panneau extends JPanel {
/***** Attributs *****/
private JComboBox<String> titre;
private JTextField nom,espece,age;
private JTextField nom, espece, age;
private JPanel panLabel, panSaisie;
private JLabel labNom,labEspece, labAge, labEntree, labSortie;
private JFormattedTextField entree,sortie;
public Panneau() {
private JLabel labNom, labEspece, labAge, labEntree, labSortie;
private JFormattedTextField entree, sortie;
/***** Constructeur *****/
public Panneau() {
this.setLayout(new BorderLayout());
this.panLabel = new JPanel();
this.panLabel.setLayout(new GridLayout(5,1,10,10));
this.panLabel.setLayout(new GridLayout(5, 1, 10, 10));
this.panSaisie = new JPanel();
this.panSaisie.setLayout(new GridLayout(5,1,10,10));
this.panSaisie.setLayout(new GridLayout(5, 1, 10, 10));
this.labNom = new JLabel("Nom:");
this.nom = new JTextField();
this.labEspece = new JLabel("Espece:");
this.espece = new JTextField();
this.labAge = new JLabel("Age:");
this.age = new JTextField();
this.labEntree = new JLabel("Entree:");
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
this.entree = new JFormattedTextField(df);
this.labSortie = new JLabel("Sortie:");
this.sortie = new JFormattedTextField(df);
this.entree.setValue(new Date());
this.sortie.setValue(new Date());
this.panLabel.add(labNom);
this.panSaisie.add(nom);
this.panLabel.add(labEspece);
......@@ -59,34 +61,42 @@ public class Panneau extends JPanel {
this.panSaisie.add(entree);
this.panLabel.add(labSortie);
this.panSaisie.add(sortie);
add(this.panLabel, BorderLayout.WEST);
add(this.panSaisie, BorderLayout.CENTER);
}
/***** Mthodes *****/
public void resetForm() {
this.nom.setText("");
this.espece.setText("");
this.age.setText("");
this.entree.setValue(new Date());
this.sortie.setValue(new Date());
}
/***** Getters - Setters *****/
public String getNom() {
return this.nom.getText();
}
public String getEspece() {
return this.espece.getText();
}
public int getAge() {
return Integer.parseInt(this.age.getText());
}
public Date getEntree() {
return (Date) this.entree.getValue();
}
public Date getSortie() {
return (Date) this.sortie.getValue();
}
public void resetForm() {
this.nom.setText("");
this.espece.setText("");
this.age.setText("");
this.entree.setValue(new Date());
this.sortie.setValue(new Date());
}
}
......@@ -6,9 +6,6 @@ public class mainVeto {
private GUI fenetre;
public static void main(String[] args) {
GUI Fenetre = new GUI(700,400,true,"ZOO OSIRIS - Clinique Vtrinaire");
GUI Fenetre = new GUI(700, 400, true, "ZOO OSIRIS - Clinique Vtrinaire");
}
}
......@@ -3,7 +3,9 @@ package lry.dip.tcp;
import java.io.Serializable;
import java.util.Date;
public class Echantillon implements Serializable{
public class Echantillon implements Serializable {
/***** Attributs *****/
private int id;
private String nom;
......@@ -11,7 +13,9 @@ public class Echantillon implements Serializable{
private int age;
private String date_entree;
private String date_sortie;
/***** Constructeur *****/
public Echantillon(int pId, String pNom, String pEspece, int pAge, String pEntree, String pSortie) {
this.setId(pId);
this.setNom(pNom);
......@@ -20,6 +24,8 @@ public class Echantillon implements Serializable{
this.setDate_entree(pEntree);
this.setDate_sortie(pSortie);
}
/*****Getters - Setters*****/
public int getId() {
return id;
......@@ -69,27 +75,25 @@ public class Echantillon implements Serializable{
this.date_sortie = date_sortie;
}
public String getValueColumn(String ColumnName) {
switch (ColumnName) {
case "Nom": {
return getNom();
}
case "Espèce": {
return getEspece();
}
case "Âge": {
return Integer.toString(getAge());
}
case "Date entrée": {
return (getDate_entree().toString()).substring(0,10) + " " + (getDate_entree().toString()).substring(24,29);
}
case "Date sortie": {
return getDate_sortie().toString();
}
case "Nom": {
return getNom();
}
case "Espèce": {
return getEspece();
}
case "Âge": {
return Integer.toString(getAge());
}
case "Date entrée": {
return (getDate_entree().toString()).substring(0, 10) + " "
+ (getDate_entree().toString()).substring(24, 29);
}
case "Date sortie": {
return getDate_sortie().toString();
}
}
return ColumnName;
}
}
......@@ -13,114 +13,116 @@ import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
public class ServerSocketTCP extends Thread{
public class ServerSocketTCP extends Thread {
/***** Attributs *****/
private ServerSocket server;
private Inet4Address IPServeur;
private int portServeur;
private boolean tacheServeur;
private int nbClients;
private ArrayList<gestionClient> listeClients;
private commandesServeur cmd;
private gestionBDD bdd;
/***** Constructeur *****/
public ServerSocketTCP(int pPort, String pIP, gestionBDD pBdd) {
this.bdd = pBdd;
this.portServeur = pPort;
try {
this.IPServeur = (Inet4Address)InetAddress.getByName(pIP);
} catch (UnknownHostException event) {
System.out.println("Le serveur n'est pas sur coute. Vrifier que le format de l'adresse IP est correct.");
}
this.nbClients = 0;
this.listeClients = new ArrayList<>();
try {
this.server = new ServerSocket(this.portServeur, 0, this.IPServeur);
} catch (IOException IOex) {
System.out.println("Le serveur n'est pas sur coute. Vrifier que le port soit disponible.");
}
this.cmd = new commandesServeur(this);
this.cmd.start();
}
this.portServeur = pPort;
try {
this.IPServeur = (Inet4Address) InetAddress.getByName(pIP);
} catch (UnknownHostException event) {
System.out.println("Le serveur n'est pas sur coute. Vrifier que le format de l'adresse IP est correct.");
}
this.nbClients = 0;
this.listeClients = new ArrayList<>();
try {
this.server = new ServerSocket(this.portServeur, 0, this.IPServeur);
} catch (IOException IOex) {
System.out.println("Le serveur n'est pas sur coute. Vrifier que le port soit disponible.");
}
this.cmd = new commandesServeur(this);
this.cmd.start();
}
/***** Mthodes *****/
public void run() {
this.tacheServeur = true;
while (this.tacheServeur) {
try {
this.tacheServeur = true;
while (this.tacheServeur) {
try {
new gestionClient(this.server.accept(), this, this.bdd);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}
public synchronized void envoyerATous(Echantillon echantillon) {
for (int i = 0; i < this.listeClients.size(); i++)
((gestionClient)this.listeClients.get(i)).envoyerReponse(echantillon);
}
for (int i = 0; i < this.listeClients.size(); i++)
((gestionClient) this.listeClients.get(i)).envoyerReponse(echantillon);
}
public synchronized int ajouterClient(gestionClient pClient) {
this.nbClients++;
this.listeClients.add(pClient);
pClient.start();
return this.listeClients.size() - 1;
}
this.nbClients++;
this.listeClients.add(pClient);
pClient.start();
return this.listeClients.size() - 1;
}
public synchronized void deconnecterTousClients() {
for (int i = 0; i < this.listeClients.size(); i++)
((gestionClient)this.listeClients.get(i)).deconnecterClient();
}
public synchronized void supprimerClient(int numClient) {
this.listeClients.remove(numClient);
this.nbClients--;
for (int j = numClient; j < this.listeClients.size(); j++)
((gestionClient)this.listeClients.get(numClient)).setNumClient(((gestionClient)this.listeClients.get(numClient)).getNumClient() - 1);
}
public void lancerServeur(int pPort, String pIP){
for (int i = 0; i < this.listeClients.size(); i++)
((gestionClient) this.listeClients.get(i)).deconnecterClient();
}
public synchronized void supprimerClient(int numClient) {
this.listeClients.remove(numClient);
this.nbClients--;
for (int j = numClient; j < this.listeClients.size(); j++)
((gestionClient) this.listeClients.get(numClient))
.setNumClient(((gestionClient) this.listeClients.get(numClient)).getNumClient() - 1);
}
public void lancerServeur(int pPort, String pIP) {
try {
this.portServeur = pPort;
this.IPServeur = (Inet4Address) InetAddress.getByName(pIP);
this.server = new ServerSocket(this.portServeur,1,this.IPServeur);
System.out.println(this.portServeur+this.IPServeur.toString());
this.server = new ServerSocket(this.portServeur, 1, this.IPServeur);
System.out.println(this.portServeur + this.IPServeur.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
public void arreterServeur(){
public void arreterServeur() {
try {
this.server.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/***** Getters - Setters *****/
public int getNbClients() {
return this.nbClients;
}
public Inet4Address getIPServeur() {
return this.IPServeur;
}
public int getPortServeur() {
return this.portServeur;
}
public ServerSocket getServerSocket() {
return this.server;
}
public void setTache(boolean pTache) {
this.tacheServeur = pTache;
}
return this.nbClients;
}
public Inet4Address getIPServeur() {
return this.IPServeur;
}
public int getPortServeur() {
return this.portServeur;
}
public ServerSocket getServerSocket() {
return this.server;
}
public void setTache(boolean pTache) {
this.tacheServeur = pTache;
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter