Finalisation du mastter detail

master
Louis PERRET 3 years ago
parent 860156ac2c
commit 7a17003124

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

@ -9,6 +9,7 @@
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.TextField?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="vues.MainWindow">
@ -24,11 +25,11 @@
<Insets left="10"/>
</padding>
<HBox>
<Label fx:id="nomOiseau">
<TextField fx:id="nomOiseau">
<padding>
<Insets right="10"/>
</padding>
</Label>
</TextField>
<Label fx:id="ageOiseau">
<padding>
<Insets right="10"/>
@ -54,6 +55,7 @@
<HBox>
<Button onAction="#passerUnJour" text="Passer à demain"/>
<Button fx:id="ajouterOiseau" onAction="#ajouterOiseau" text="Ajouter oiseau"/>
<Button onAction="#fermerFenetre" text="Quitter"/>
</HBox>
</bottom>
</BorderPane>

Binary file not shown.

@ -2,9 +2,11 @@ package data.chargeur;
import modele.metier.oiseaux.Oiseau;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
public interface Chargeur {
public List<Oiseau> charger(String nomFichier);
public List<Oiseau> charger(String nomFichier) throws IOException, ClassNotFoundException;
}

@ -0,0 +1,22 @@
package data.chargeur;
import modele.metier.oiseaux.Oiseau;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;
public class ChargeurSimple implements Chargeur{
@Override
public List<Oiseau> charger(String nomFichier) throws IOException, ClassNotFoundException {
List<Oiseau> oiseaux;
try(ObjectInputStream reader = new ObjectInputStream(new FileInputStream(nomFichier))){
oiseaux = (List<Oiseau>) reader.readObject();
}
return oiseaux;
}
}

@ -0,0 +1,11 @@
package data.chargeur;
import modele.metier.oiseaux.Oiseau;
import java.io.IOException;
import java.util.List;
public interface Sauveur {
public void sauver(List<Oiseau> listeOiseaux, String nomFichier) throws IOException;
}

@ -0,0 +1,19 @@
package data.chargeur;
import modele.metier.oiseaux.Oiseau;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.List;
public class SauveurSimple implements Sauveur{
@Override
public void sauver(List<Oiseau> listeOiseaux, String nomFichier) throws IOException {
try(ObjectOutputStream writer = new ObjectOutputStream(new FileOutputStream(nomFichier))){
writer.writeObject(listeOiseaux);
}
}
}

@ -7,7 +7,7 @@ import modele.metier.oiseaux.Oiseau;
import java.util.ArrayList;
import java.util.List;
public class SimpleChargeur implements Chargeur {
public class Stub implements Chargeur {
@Override
public List<Oiseau> charger(String nomFichier) {

@ -17,9 +17,9 @@ import java.util.List;
public class ManagerOiseau {
protected List<Oiseau> oiseaux;
private List<Oiseau> oiseaux;
protected OiseauFactory factoryOiseau;
private OiseauFactory factoryOiseau;
private LocalDate dateDuJour;

@ -1,6 +1,8 @@
package modele.metier.etat;
public abstract class Etat {
import java.io.Serializable;
public abstract class Etat implements Serializable {
private String couleur;

@ -9,12 +9,13 @@ import modele.metier.etat.Rassasie;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.sql.Array;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
public class Oiseau {
public class Oiseau implements Serializable {
private String nom;
private int age;
@ -93,6 +94,10 @@ public class Oiseau {
return etat;
}
public void setNom(String nom) {
this.nom = nom;
}
public void setEtat(Etat etat){
Etat oldValue = this.etat;
this.etat = etat;

@ -1,6 +1,6 @@
package viewmodel;
import data.chargeur.SimpleChargeur;
import data.chargeur.*;
import javafx.beans.property.ListProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleListProperty;
@ -12,6 +12,7 @@ import modele.metier.oiseaux.Oiseau;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.time.LocalDate;
public class ManagerOiseauVM implements PropertyChangeListener {
@ -35,9 +36,21 @@ public class ManagerOiseauVM implements PropertyChangeListener {
public ListProperty<OiseauVM> listeOiseauxProperty() { return listeOiseaux; }
public void setListeOiseaux(ObservableList<OiseauVM> listeOiseaux) {this.listeOiseaux.set(listeOiseaux); }
public ManagerOiseauVM(){
private Chargeur chargeur;
private Sauveur sauveur;
public ManagerOiseauVM() { // PAS DE PARAMETRE DANS UNE VM
modele = new ManagerOiseau();
modele.addOiseaux(new SimpleChargeur().charger(""));
chargeur = new ChargeurSimple();
sauveur = new SauveurSimple();
try {
modele.addOiseaux(chargeur.charger("source.bin"));
} catch (Exception e){
modele.addOiseaux(new Stub().charger(""));
}
for(Oiseau oiseau : modele.getOiseaux()){
oiseauxObs.add(new OiseauVM(oiseau));
}
@ -70,4 +83,8 @@ public class ManagerOiseauVM implements PropertyChangeListener {
break;
}
}
public void sauver() throws IOException {
sauveur.sauver(modele.getOiseaux(), "source.bin");
}
}

@ -46,6 +46,7 @@ public class OiseauVM implements PropertyChangeListener {
setEtat(modele.getEtat());
setDateDernierRepas(modele.getDateDernierRepas());
modele.ajouterListener(this);
nom.addListener((__,___,newV) -> modele.setNom(newV));
}
public OiseauVM(String nom, int age, String couleurAiles){

@ -1,12 +1,14 @@
package vues;
import javafx.beans.binding.Bindings;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.stage.Modality;
import javafx.stage.Stage;
import viewmodel.ManagerOiseauVM;
@ -21,10 +23,7 @@ public class MainWindow {
public Label dateDuJour;
@FXML
public Button passerJour;
@FXML
public Label nomOiseau;
public TextField nomOiseau;
@FXML
public Label ageOiseau;
@ -53,14 +52,23 @@ public class MainWindow {
listeOiseaux.setItems(managerVM.getListeOiseaux());
listeOiseaux.setCellFactory((__) -> new CelluleOiseau());
listeOiseaux.getSelectionModel().selectedItemProperty().addListener((__, oldV, newV) -> {
if(oldV != newV){
nomOiseau.textProperty().bind(Bindings.concat("Nom : ", newV.nomProperty()));
if(oldV != null){
nomOiseau.textProperty().unbindBidirectional(oldV.nomProperty());
ageOiseau.textProperty().unbind();
couleurAile.textProperty().unbind();
dateDernierRepas.textProperty().unbind();
dateDernierRepas.textProperty().unbind();
boutonTuerOiseau.setDisable(true);
}
if(newV != null){
nomOiseau.textProperty().bindBidirectional(newV.nomProperty());
ageOiseau.textProperty().bind(Bindings.concat("Age : ", newV.ageProperty().asString(), " ans"));
couleurAile.textProperty().bind(Bindings.concat("Couleur de ses ailes : ", newV.couleurAilesProperty()));
dateDernierRepas.textProperty().bind(Bindings.concat("Date du dernier repas : ", newV.dateDernierRepasProperty().asString()));
boutonTuerOiseau.setDisable(false);
}
});
}
@ -86,4 +94,10 @@ public class MainWindow {
public void tuerOiseau() {
managerVM.supprimerOiseau(listeOiseaux.getSelectionModel().getSelectedItem());
}
@FXML
public void fermerFenetre() throws IOException {
managerVM.sauver();
((Stage)listeOiseaux.getScene().getWindow()).close();
}
}

Loading…
Cancel
Save