parent
c69bd84221
commit
860156ac2c
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="18" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/tp2.iml" filepath="$PROJECT_DIR$/tp2.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<BorderPane xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="vues.AjouterOiseau"
|
||||
prefHeight="400.0" prefWidth="600.0">
|
||||
<center>
|
||||
<VBox>
|
||||
<HBox>
|
||||
<Label text="Nom de l'oiseau : "/>
|
||||
<TextField fx:id="nomOiseau"/>
|
||||
</HBox>
|
||||
<HBox>
|
||||
<Label text="Age de l'oiseau : "/>
|
||||
<Spinner fx:id="ageOiseau"/>
|
||||
</HBox>
|
||||
<HBox>
|
||||
<Label text="Couleur de son plumage : "/>
|
||||
<TextField fx:id="couleurOiseau"/>
|
||||
</HBox>
|
||||
<Button text="Ajouter" fx:id="boutonAjouter" onAction="#ajouterOiseau"/>
|
||||
</VBox>
|
||||
</center>
|
||||
|
||||
</BorderPane>
|
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
|
||||
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<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">
|
||||
|
||||
<top>
|
||||
<Label fx:id="dateDuJour"/>
|
||||
</top>
|
||||
<left>
|
||||
<ListView fx:id="listeOiseaux"/>
|
||||
</left>
|
||||
<center>
|
||||
<VBox>
|
||||
<padding>
|
||||
<Insets left="10"/>
|
||||
</padding>
|
||||
<HBox>
|
||||
<Label fx:id="nomOiseau">
|
||||
<padding>
|
||||
<Insets right="10"/>
|
||||
</padding>
|
||||
</Label>
|
||||
<Label fx:id="ageOiseau">
|
||||
<padding>
|
||||
<Insets right="10"/>
|
||||
</padding>
|
||||
</Label>
|
||||
</HBox>
|
||||
<Label fx:id="couleurAile">
|
||||
<padding>
|
||||
<Insets right="10"/>
|
||||
</padding>
|
||||
</Label>
|
||||
<Label fx:id="dateDernierRepas">
|
||||
<padding>
|
||||
<Insets right="10"/>
|
||||
</padding>
|
||||
</Label>
|
||||
<Button text="Tuer oiseau" fx:id="boutonTuerOiseau" onAction="#tuerOiseau"/>
|
||||
</VBox>
|
||||
|
||||
|
||||
</center>
|
||||
<bottom>
|
||||
<HBox>
|
||||
<Button onAction="#passerUnJour" text="Passer à demain"/>
|
||||
<Button fx:id="ajouterOiseau" onAction="#ajouterOiseau" text="Ajouter oiseau"/>
|
||||
</HBox>
|
||||
</bottom>
|
||||
</BorderPane>
|
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<?import javafx.scene.shape.Rectangle?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<fx:root type="BorderPane" xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml">
|
||||
|
||||
<left>
|
||||
<Label fx:id="labelEtat" prefWidth="20" prefHeight="20"/>
|
||||
</left>
|
||||
<center>
|
||||
<VBox>
|
||||
<padding>
|
||||
<Insets left="10"/>
|
||||
</padding>
|
||||
<Label fx:id="nomOiseau"/>
|
||||
<Button fx:id="nourrirOiseau" onAction="#nourrirOiseau" text="Nourrir"/>
|
||||
</VBox>
|
||||
</center>
|
||||
</fx:root>
|
@ -0,0 +1,10 @@
|
||||
package data.chargeur;
|
||||
|
||||
import modele.metier.oiseaux.Oiseau;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Chargeur {
|
||||
|
||||
public List<Oiseau> charger(String nomFichier);
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package data.chargeur;
|
||||
|
||||
import modele.metier.factory.OiseauFactory;
|
||||
import modele.metier.factory.SimpleOiseauFactory;
|
||||
import modele.metier.oiseaux.Oiseau;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleChargeur implements Chargeur {
|
||||
|
||||
@Override
|
||||
public List<Oiseau> charger(String nomFichier) {
|
||||
List<Oiseau> listeOiseaux = new ArrayList<>();
|
||||
OiseauFactory oiseauFactory = new SimpleOiseauFactory();
|
||||
|
||||
listeOiseaux.add(oiseauFactory.creerOiseau("Pedro", 20, "noires"));
|
||||
listeOiseaux.add(oiseauFactory.creerOiseau("Jeremy", 5, "blanches"));
|
||||
listeOiseaux.add(oiseauFactory.creerOiseau("Louis", 14, "roses"));
|
||||
listeOiseaux.add(oiseauFactory.creerOiseau("Deku", 9, "violet"));
|
||||
listeOiseaux.add(oiseauFactory.creerOiseau("Buble", 16, "noires"));
|
||||
listeOiseaux.add(oiseauFactory.creerOiseau("Poppy", 21, "vertes"));
|
||||
|
||||
return listeOiseaux;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package launch;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class Launcher extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
Parent parent = FXMLLoader.load(getClass().getResource("/vues/MainWindow.fxml"));
|
||||
Scene scene = new Scene(parent);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package modele;
|
||||
|
||||
public class Manager {
|
||||
|
||||
/*private ManagerOiseau managerOiseau = new SimpleOiseauManager();
|
||||
|
||||
private Chargeur chargeur;
|
||||
|
||||
private ObjectProperty<LocalDate> dateDuJour = new SimpleObjectProperty<>();
|
||||
public LocalDate getDateDuJour() { return dateDuJour.get(); }
|
||||
public ObjectProperty<LocalDate> dateDuJourProperty() { return dateDuJour; }
|
||||
public void setDateDuJour(LocalDate dateDuJour) { this.dateDuJour.set(dateDuJour); }
|
||||
|
||||
private ObjectProperty<Oiseau> oiseauCourant = new SimpleObjectProperty<>();
|
||||
public Oiseau getOiseauCourant() { return oiseauCourant.get(); }
|
||||
public ObjectProperty<Oiseau> oiseauCourantProperty() { return oiseauCourant; }
|
||||
public void setOiseauCourant(Oiseau oiseauCourant) { this.oiseauCourant.set(oiseauCourant); }
|
||||
|
||||
|
||||
|
||||
private ListProperty<Oiseau> listeOiseaux = new SimpleListProperty<>(managerOiseau.getOiseaux());
|
||||
public ObservableList<Oiseau> getListeOiseaux() { return listeOiseaux.get(); }
|
||||
public ListProperty<Oiseau> listeOiseauxProperty() { return listeOiseaux; }
|
||||
public void setListeOiseaux(ObservableList<Oiseau> listeOiseaux) {this.listeOiseaux.set(listeOiseaux); }
|
||||
|
||||
private int nombreDeJour = 0;
|
||||
|
||||
public Manager(Chargeur chargeur) {
|
||||
this.chargeur = chargeur;
|
||||
this.managerOiseau.addOiseaux(chargeur.charger(""));
|
||||
setDateDuJour(LocalDate.now());
|
||||
}
|
||||
|
||||
|
||||
public void addOiseau(String nom, int age, String couleurAiles){
|
||||
managerOiseau.addOiseau(nom, age, couleurAiles);
|
||||
}
|
||||
|
||||
public void incrementerJour(){
|
||||
setDateDuJour(getDateDuJour().plusDays(1));
|
||||
managerOiseau.verifierDateDernierRepas(getDateDuJour());
|
||||
}
|
||||
|
||||
public void supprimerOiseau(Oiseau oiseau){
|
||||
managerOiseau.supprimerOiseau(oiseau);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package modele.metier;
|
||||
|
||||
import data.chargeur.Chargeur;
|
||||
import javafx.beans.property.ListProperty;
|
||||
import javafx.beans.property.SimpleListProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import modele.metier.factory.OiseauFactory;
|
||||
import modele.metier.factory.SimpleOiseauFactory;
|
||||
import modele.metier.oiseaux.Oiseau;
|
||||
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ManagerOiseau {
|
||||
|
||||
protected List<Oiseau> oiseaux;
|
||||
|
||||
protected OiseauFactory factoryOiseau;
|
||||
|
||||
private LocalDate dateDuJour;
|
||||
|
||||
private Oiseau oiseauCourant;
|
||||
|
||||
private int nombreDeJour = 0;
|
||||
|
||||
private PropertyChangeSupport support = new PropertyChangeSupport(this); // transforme l'objet en beans
|
||||
|
||||
public static final String PROP_DATE_DU_JOUR = "DateDuJour";
|
||||
|
||||
public ManagerOiseau() {
|
||||
dateDuJour = LocalDate.now();
|
||||
oiseaux = new ArrayList<>();
|
||||
factoryOiseau = new SimpleOiseauFactory();
|
||||
}
|
||||
|
||||
public void incrementerJour(){
|
||||
setDateDuJour(getDateDuJour().plusDays(1));
|
||||
verifierDateDernierRepas(getDateDuJour());
|
||||
}
|
||||
|
||||
public void verifierDateDernierRepas(LocalDate dateDuJour){
|
||||
for(Oiseau oiseau : oiseaux){
|
||||
oiseau.updateEtat(dateDuJour);
|
||||
}
|
||||
}
|
||||
|
||||
public void addOiseau(String nom, int age, String couleurAiles){
|
||||
oiseaux.add(factoryOiseau.creerOiseau(nom, age, couleurAiles));
|
||||
}
|
||||
|
||||
public void addOiseau(Oiseau oiseau){
|
||||
oiseaux.add(oiseau);
|
||||
}
|
||||
|
||||
public void addListener(PropertyChangeListener listener){
|
||||
support.addPropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
public void addOiseaux(List<Oiseau> listeOiseaux){
|
||||
oiseaux.addAll(listeOiseaux);
|
||||
}
|
||||
|
||||
public void supprimerOiseau(Oiseau oiseau) {
|
||||
oiseaux.remove(oiseau);
|
||||
}
|
||||
|
||||
public LocalDate getDateDuJour() {
|
||||
return dateDuJour;
|
||||
}
|
||||
|
||||
public void setDateDuJour(LocalDate dateDuJour) {
|
||||
LocalDate oldValue = this.dateDuJour;
|
||||
this.dateDuJour = dateDuJour;
|
||||
support.firePropertyChange(PROP_DATE_DU_JOUR, oldValue, this.dateDuJour);
|
||||
}
|
||||
|
||||
public Oiseau getOiseauCourant() {
|
||||
return oiseauCourant;
|
||||
}
|
||||
|
||||
public void setOiseauCourant(Oiseau oiseauCourant) {
|
||||
this.oiseauCourant = oiseauCourant;
|
||||
}
|
||||
|
||||
public List<Oiseau> getOiseaux() {
|
||||
return oiseaux;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package modele.metier.etat;
|
||||
|
||||
public class Affame extends Etat{
|
||||
|
||||
public Affame(){
|
||||
super("#FF0000");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package modele.metier.etat;
|
||||
|
||||
public class Decede extends Etat{
|
||||
|
||||
public Decede(){
|
||||
super("#000000");
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package modele.metier.etat;
|
||||
|
||||
public abstract class Etat {
|
||||
|
||||
private String couleur;
|
||||
|
||||
protected Etat(String couleur){
|
||||
this.couleur = couleur;
|
||||
}
|
||||
|
||||
public String getEtat(){
|
||||
return couleur;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package modele.metier.etat;
|
||||
|
||||
public class Rassasie extends Etat{
|
||||
|
||||
public Rassasie(){
|
||||
super("#00FF00");
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package modele.metier.factory;
|
||||
|
||||
import modele.metier.oiseaux.Oiseau;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public interface OiseauFactory {
|
||||
|
||||
public Oiseau creerOiseau(String nom, int age, String couleurAiles);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package modele.metier.factory;
|
||||
|
||||
import modele.metier.oiseaux.Oiseau;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class SimpleOiseauFactory implements OiseauFactory {
|
||||
|
||||
@Override
|
||||
public Oiseau creerOiseau(String nom, int age, String couleurAiles) {
|
||||
return new Oiseau(nom, age, couleurAiles, LocalDate.now());
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
package modele.metier.oiseaux;
|
||||
|
||||
import com.sun.webkit.LoadListenerClient;
|
||||
import javafx.beans.property.*;
|
||||
import modele.metier.etat.Affame;
|
||||
import modele.metier.etat.Decede;
|
||||
import modele.metier.etat.Etat;
|
||||
import modele.metier.etat.Rassasie;
|
||||
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.sql.Array;
|
||||
import java.time.LocalDate;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Oiseau {
|
||||
|
||||
private String nom;
|
||||
private int age;
|
||||
private String couleurAiles;
|
||||
private LocalDate dateDernierRepas;
|
||||
private Etat etat;
|
||||
|
||||
private PropertyChangeSupport support = new PropertyChangeSupport(this); // transforme mon objet en beans
|
||||
|
||||
public static final String PROP_ETAT = "Etat";
|
||||
|
||||
public static final String PROP_DATE_DERNIER_REPAS = "DateDernierRepas";
|
||||
|
||||
public Oiseau(String nom, int age, String couleurAiles, LocalDate dateDernierRepas) {
|
||||
this.nom = nom;
|
||||
this.age = age;
|
||||
this.couleurAiles = couleurAiles;
|
||||
this.dateDernierRepas = dateDernierRepas;
|
||||
this.etat = new Rassasie();
|
||||
}
|
||||
|
||||
public Oiseau(String nom, int age, String couleurAiles) {
|
||||
this.nom = nom;
|
||||
this.age = age;
|
||||
this.couleurAiles = couleurAiles;
|
||||
this.dateDernierRepas = LocalDate.now();
|
||||
this.etat = new Rassasie();
|
||||
}
|
||||
|
||||
public void updateEtat(LocalDate dateActuel) {
|
||||
if (ChronoUnit.DAYS.between(getDateDernierRepas(), dateActuel) == 1) {
|
||||
setEtat(new Affame());
|
||||
} else if (ChronoUnit.DAYS.between(getDateDernierRepas(), dateActuel) == 3){
|
||||
setEtat(new Decede());
|
||||
}
|
||||
}
|
||||
|
||||
public void seNourrir(LocalDate date){
|
||||
if(getEtat().getClass() != Decede.class){
|
||||
setEtat(new Rassasie());
|
||||
setDateDernierRepas(date);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj == null) return false;
|
||||
if(this == obj) return true;
|
||||
if(this.getClass() != obj.getClass()) return false;
|
||||
|
||||
Oiseau other = (Oiseau)obj;
|
||||
return getNom().equals(((Oiseau) obj).getNom()) && getAge() == other.getAge() && getCouleurAiles().equals(other.getCouleurAiles());
|
||||
}
|
||||
|
||||
public void ajouterListener(PropertyChangeListener listener){
|
||||
support.addPropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public String getCouleurAiles() {
|
||||
return couleurAiles;
|
||||
}
|
||||
|
||||
public LocalDate getDateDernierRepas() {
|
||||
return dateDernierRepas;
|
||||
}
|
||||
|
||||
public Etat getEtat() {
|
||||
return etat;
|
||||
}
|
||||
|
||||
public void setEtat(Etat etat){
|
||||
Etat oldValue = this.etat;
|
||||
this.etat = etat;
|
||||
support.firePropertyChange(PROP_ETAT, oldValue, this.etat); // prévient l'observateur que la propriété a changé
|
||||
}
|
||||
|
||||
public void setDateDernierRepas(LocalDate dateDernierRepas){
|
||||
LocalDate oldValue = this.dateDernierRepas;
|
||||
this.dateDernierRepas = dateDernierRepas;
|
||||
support.firePropertyChange(PROP_DATE_DERNIER_REPAS, oldValue, this.dateDernierRepas);
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package viewmodel;
|
||||
|
||||
import data.chargeur.SimpleChargeur;
|
||||
import javafx.beans.property.ListProperty;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleListProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import modele.metier.ManagerOiseau;
|
||||
import modele.metier.oiseaux.Oiseau;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class ManagerOiseauVM implements PropertyChangeListener {
|
||||
|
||||
private ManagerOiseau modele;
|
||||
|
||||
private ObjectProperty<LocalDate> dateDuJour = new SimpleObjectProperty<>();
|
||||
public LocalDate getDateDuJour() { return dateDuJour.get(); }
|
||||
public ObjectProperty<LocalDate> dateDuJourProperty() { return dateDuJour; }
|
||||
public void setDateDuJour(LocalDate dateDuJour) { this.dateDuJour.set(dateDuJour); }
|
||||
|
||||
private ObjectProperty<OiseauVM> oiseauCourant = new SimpleObjectProperty<>();
|
||||
public OiseauVM getOiseauCourant() { return oiseauCourant.get(); }
|
||||
public ObjectProperty<OiseauVM> oiseauCourantProperty() { return oiseauCourant; }
|
||||
public void setOiseauCourant(OiseauVM oiseauCourant) { this.oiseauCourant.set(oiseauCourant); }
|
||||
|
||||
|
||||
private ObservableList<OiseauVM> oiseauxObs = FXCollections.observableArrayList();
|
||||
private ListProperty<OiseauVM> listeOiseaux = new SimpleListProperty<>(oiseauxObs);
|
||||
public ObservableList<OiseauVM> getListeOiseaux() { return listeOiseaux.get(); }
|
||||
public ListProperty<OiseauVM> listeOiseauxProperty() { return listeOiseaux; }
|
||||
public void setListeOiseaux(ObservableList<OiseauVM> listeOiseaux) {this.listeOiseaux.set(listeOiseaux); }
|
||||
|
||||
public ManagerOiseauVM(){
|
||||
modele = new ManagerOiseau();
|
||||
modele.addOiseaux(new SimpleChargeur().charger(""));
|
||||
for(Oiseau oiseau : modele.getOiseaux()){
|
||||
oiseauxObs.add(new OiseauVM(oiseau));
|
||||
}
|
||||
setDateDuJour(modele.getDateDuJour());
|
||||
modele.addListener(this);
|
||||
}
|
||||
|
||||
public void incrementerJour(){
|
||||
modele.incrementerJour();
|
||||
}
|
||||
|
||||
public void addOiseau(String nom, int age, String couleurAiles){
|
||||
OiseauVM oiseauVM = new OiseauVM(nom, age, couleurAiles);
|
||||
Oiseau oiseau = oiseauVM.getModele();
|
||||
modele.addOiseau(oiseau.getNom(), oiseau.getAge(), oiseau.getCouleurAiles());
|
||||
oiseauxObs.add(oiseauVM);
|
||||
|
||||
}
|
||||
|
||||
public void supprimerOiseau(OiseauVM oiseau) {
|
||||
modele.supprimerOiseau(oiseau.getModele());
|
||||
oiseauxObs.remove(oiseau);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
switch (evt.getPropertyName()){
|
||||
case ManagerOiseau.PROP_DATE_DU_JOUR:
|
||||
setDateDuJour((LocalDate) evt.getNewValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package viewmodel;
|
||||
|
||||
import javafx.beans.property.*;
|
||||
import modele.metier.etat.Etat;
|
||||
import modele.metier.oiseaux.Oiseau;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class OiseauVM implements PropertyChangeListener {
|
||||
|
||||
private Oiseau modele;
|
||||
|
||||
private StringProperty nom = new SimpleStringProperty();
|
||||
public String getNom() { return nom.get(); }
|
||||
public StringProperty nomProperty() { return nom; }
|
||||
public void setNom(String nom) { this.nom.set(nom); }
|
||||
|
||||
private IntegerProperty age = new SimpleIntegerProperty();
|
||||
public int getAge() { return age.get(); }
|
||||
public IntegerProperty ageProperty() { return age; }
|
||||
public void setAge(int age) { this.age.set(age); }
|
||||
|
||||
private StringProperty couleurAiles = new SimpleStringProperty();
|
||||
public String getCouleurAiles() { return couleurAiles.get(); }
|
||||
public StringProperty couleurAilesProperty() { return couleurAiles; }
|
||||
public void setCouleurAiles(String couleurAiles) { this.couleurAiles.set(couleurAiles); }
|
||||
|
||||
private ObjectProperty<LocalDate> dateDernierRepas = new SimpleObjectProperty<>();
|
||||
public LocalDate getDateDernierRepas() { return dateDernierRepas.get(); }
|
||||
public ObjectProperty<LocalDate> dateDernierRepasProperty() { return dateDernierRepas; }
|
||||
public void setDateDernierRepas(LocalDate dateDernierRepas) { this.dateDernierRepas.set(dateDernierRepas); }
|
||||
|
||||
private ObjectProperty<Etat> etat = new SimpleObjectProperty<>();
|
||||
public Etat getEtat() { return etat.get(); }
|
||||
public ObjectProperty<Etat> etatProperty() { return etat; }
|
||||
public void setEtat(Etat etat) { this.etat.set(etat); }
|
||||
|
||||
|
||||
public OiseauVM(Oiseau modele) {
|
||||
this.modele = modele;
|
||||
setNom(modele.getNom());
|
||||
setAge(modele.getAge());
|
||||
setCouleurAiles(modele.getCouleurAiles());
|
||||
setEtat(modele.getEtat());
|
||||
setDateDernierRepas(modele.getDateDernierRepas());
|
||||
modele.ajouterListener(this);
|
||||
}
|
||||
|
||||
public OiseauVM(String nom, int age, String couleurAiles){
|
||||
this(new Oiseau(nom, age, couleurAiles));
|
||||
}
|
||||
|
||||
public void seNourrir(LocalDate dateDuJour) {
|
||||
modele.seNourrir(dateDuJour);
|
||||
}
|
||||
|
||||
public Oiseau getModele() {
|
||||
return modele;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
switch (evt.getPropertyName()){
|
||||
case Oiseau.PROP_ETAT:
|
||||
setEtat((Etat)evt.getNewValue());
|
||||
break;
|
||||
case Oiseau.PROP_DATE_DERNIER_REPAS:
|
||||
setDateDernierRepas((LocalDate) evt.getNewValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package vues;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Spinner;
|
||||
import javafx.scene.control.SpinnerValueFactory;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class AjouterOiseau {
|
||||
|
||||
|
||||
@FXML
|
||||
public TextField nomOiseau;
|
||||
|
||||
@FXML
|
||||
public Spinner ageOiseau;
|
||||
|
||||
@FXML
|
||||
public TextField couleurOiseau;
|
||||
|
||||
|
||||
@FXML
|
||||
public void ajouterOiseau() {
|
||||
MainWindow.managerVM.addOiseau(nomOiseau.getText(), (Integer)ageOiseau.getValue(), couleurOiseau.getText());
|
||||
Stage stage = (Stage)nomOiseau.getScene().getWindow();
|
||||
stage.close();
|
||||
}
|
||||
|
||||
public void initialize(){
|
||||
ageOiseau.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0,20));
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package vues;
|
||||
|
||||
import javafx.beans.binding.Bindings;
|
||||
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.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import viewmodel.ManagerOiseauVM;
|
||||
import viewmodel.OiseauVM;
|
||||
import vues.celulles.CelluleOiseau;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class MainWindow {
|
||||
|
||||
@FXML
|
||||
public Label dateDuJour;
|
||||
|
||||
@FXML
|
||||
public Button passerJour;
|
||||
|
||||
@FXML
|
||||
public Label nomOiseau;
|
||||
|
||||
@FXML
|
||||
public Label ageOiseau;
|
||||
|
||||
@FXML
|
||||
public Label couleurAile;
|
||||
|
||||
@FXML
|
||||
public Label dateDernierRepas;
|
||||
|
||||
@FXML
|
||||
public Button boutonTuerOiseau;
|
||||
|
||||
@FXML
|
||||
private ListView<OiseauVM> listeOiseaux;
|
||||
|
||||
@FXML
|
||||
private Button ajouterOiseau;
|
||||
|
||||
public static ManagerOiseauVM managerVM;
|
||||
|
||||
public void initialize(){
|
||||
boutonTuerOiseau.setDisable(true);
|
||||
managerVM = new ManagerOiseauVM();
|
||||
dateDuJour.textProperty().bind(managerVM.dateDuJourProperty().asString());
|
||||
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()));
|
||||
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);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void passerUnJour() {
|
||||
managerVM.incrementerJour();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void ajouterOiseau() throws IOException {
|
||||
Scene scene = new Scene(FXMLLoader.load(getClass().getResource("/vues/AjouterOiseau.fxml")));
|
||||
Stage secondStage = new Stage();
|
||||
Stage stage = (Stage)ajouterOiseau.getScene().getWindow();
|
||||
secondStage.initOwner(stage);
|
||||
secondStage.setScene(scene);
|
||||
secondStage.initModality(Modality.WINDOW_MODAL);
|
||||
|
||||
secondStage.show();
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void tuerOiseau() {
|
||||
managerVM.supprimerOiseau(listeOiseaux.getSelectionModel().getSelectedItem());
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package vues.celulles;
|
||||
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.scene.control.ListCell;
|
||||
import modele.metier.oiseaux.Oiseau;
|
||||
import viewmodel.OiseauVM;
|
||||
import vues.uc.UserControl_CelluleOiseau;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class CelluleOiseau extends ListCell<OiseauVM> {
|
||||
|
||||
private UserControl_CelluleOiseau userControl_celluleOiseau;
|
||||
|
||||
@Override
|
||||
protected void updateItem(OiseauVM item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if(!empty){
|
||||
try {
|
||||
userControl_celluleOiseau = new UserControl_CelluleOiseau(item);
|
||||
setGraphic(userControl_celluleOiseau);
|
||||
} catch (IOException e) {
|
||||
textProperty().bind(item.nomProperty());
|
||||
}
|
||||
}
|
||||
else{
|
||||
setGraphic(null); // pour éviter que le uc reste apparant
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package vues.uc;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.Background;
|
||||
import javafx.scene.layout.BackgroundFill;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import viewmodel.OiseauVM;
|
||||
import vues.MainWindow;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class UserControl_CelluleOiseau extends BorderPane {
|
||||
|
||||
@FXML
|
||||
private Label labelEtat;
|
||||
|
||||
@FXML
|
||||
private Label nomOiseau;
|
||||
|
||||
@FXML
|
||||
private Button nourrirOiseau;
|
||||
|
||||
private OiseauVM oiseau;
|
||||
|
||||
public UserControl_CelluleOiseau(OiseauVM oiseau) throws IOException {
|
||||
this.oiseau = oiseau;
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/vues/uc/UserControl_Cellule.fxml"));
|
||||
fxmlLoader.setRoot(this);
|
||||
fxmlLoader.setController(this);
|
||||
fxmlLoader.load();
|
||||
}
|
||||
|
||||
private void setBackground(){
|
||||
labelEtat.setBackground(new Background(new BackgroundFill(Color.valueOf(oiseau.getEtat().getEtat()), null, null)));
|
||||
}
|
||||
|
||||
|
||||
@FXML
|
||||
private void nourrirOiseau(){
|
||||
oiseau.seNourrir(MainWindow.managerVM.getDateDuJour());
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
nomOiseau.textProperty().bind(oiseau.nomProperty());
|
||||
setBackground();
|
||||
oiseau.etatProperty().addListener((__) -> setBackground());
|
||||
}
|
||||
|
||||
public void unbind() {
|
||||
nomOiseau.textProperty().unbind();
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/ressources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="lib" level="application" />
|
||||
</component>
|
||||
</module>
|
Loading…
Reference in new issue