211 lines
5.8 KiB
Java
211 lines
5.8 KiB
Java
package models;
|
|
|
|
import java.io.IOException;
|
|
import java.io.ObjectInputStream;
|
|
import java.io.ObjectOutputStream;
|
|
import java.io.Serializable;
|
|
import java.time.LocalDate;
|
|
import java.time.format.DateTimeFormatter;
|
|
import javafx.beans.property.*;
|
|
|
|
public class Flight implements Serializable {
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private String datumStr; // String zur Speicherung des Datums in XML
|
|
private transient ObjectProperty<LocalDate> datum; // transient, um die direkte Serialization zu vermeiden
|
|
private StringProperty muster;
|
|
private StringProperty abflugort;
|
|
private StringProperty abflugzeit;
|
|
private StringProperty ankunftszeit;
|
|
private DoubleProperty tToF;
|
|
private IntegerProperty anzahlLandungen;
|
|
private ObjectProperty<Pilot> pilot;
|
|
private BooleanProperty nachtflug;
|
|
private StringProperty kommentar;
|
|
|
|
private static final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
|
|
|
|
// Standardkonstruktor
|
|
public Flight() {
|
|
this.datum = new SimpleObjectProperty<>();
|
|
this.muster = new SimpleStringProperty();
|
|
this.abflugort = new SimpleStringProperty();
|
|
this.abflugzeit = new SimpleStringProperty();
|
|
this.ankunftszeit = new SimpleStringProperty();
|
|
this.tToF = new SimpleDoubleProperty();
|
|
this.anzahlLandungen = new SimpleIntegerProperty();
|
|
this.pilot = new SimpleObjectProperty<>();
|
|
this.nachtflug = new SimpleBooleanProperty();
|
|
this.kommentar = new SimpleStringProperty();
|
|
}
|
|
|
|
public Flight(LocalDate datum, String muster, String abflugort, String abflugzeit, String ankunftszeit, double tToF, int anzahlLandungen, Pilot pilot, boolean nachtflug, String kommentar) {
|
|
this();
|
|
this.setDatum(datum);
|
|
this.muster.set(muster);
|
|
this.abflugort.set(abflugort);
|
|
this.abflugzeit.set(abflugzeit);
|
|
this.ankunftszeit.set(ankunftszeit);
|
|
this.tToF.set(tToF);
|
|
this.anzahlLandungen.set(anzahlLandungen);
|
|
this.pilot.set(pilot);
|
|
this.nachtflug.set(nachtflug);
|
|
this.kommentar.set(kommentar);
|
|
}
|
|
|
|
public LocalDate getDatum() {
|
|
return datum.get();
|
|
}
|
|
|
|
public void setDatum(LocalDate datum) {
|
|
this.datum.set(datum);
|
|
this.datumStr = datum != null ? datum.format(formatter) : null;
|
|
}
|
|
|
|
public ObjectProperty<LocalDate> datumProperty() {
|
|
return datum;
|
|
}
|
|
|
|
public String getDatumStr() {
|
|
return datumStr;
|
|
}
|
|
|
|
public void setDatumStr(String datumStr) {
|
|
this.datumStr = datumStr;
|
|
this.datum.set(datumStr != null ? LocalDate.parse(datumStr, formatter) : null);
|
|
}
|
|
|
|
public String getMuster() {
|
|
return muster.get();
|
|
}
|
|
|
|
public void setMuster(String muster) {
|
|
this.muster.set(muster);
|
|
}
|
|
|
|
public StringProperty musterProperty() {
|
|
return muster;
|
|
}
|
|
|
|
public String getAbflugort() {
|
|
return abflugort.get();
|
|
}
|
|
|
|
public void setAbflugort(String abflugort) {
|
|
this.abflugort.set(abflugort);
|
|
}
|
|
|
|
public StringProperty abflugortProperty() {
|
|
return abflugort;
|
|
}
|
|
|
|
public String getAbflugzeit() {
|
|
return abflugzeit.get();
|
|
}
|
|
|
|
public void setAbflugzeit(String abflugzeit) {
|
|
this.abflugzeit.set(abflugzeit);
|
|
}
|
|
|
|
public StringProperty abflugzeitProperty() {
|
|
return abflugzeit;
|
|
}
|
|
|
|
public String getAnkunftszeit() {
|
|
return ankunftszeit.get();
|
|
}
|
|
|
|
public void setAnkunftszeit(String ankunftszeit) {
|
|
this.ankunftszeit.set(ankunftszeit);
|
|
}
|
|
|
|
public StringProperty ankunftszeitProperty() {
|
|
return ankunftszeit;
|
|
}
|
|
|
|
public double getTToF() {
|
|
return tToF.get();
|
|
}
|
|
|
|
public void setTToF(double tToF) {
|
|
this.tToF.set(tToF);
|
|
}
|
|
|
|
public DoubleProperty tToFProperty() {
|
|
return tToF;
|
|
}
|
|
|
|
public int getAnzahlLandungen() {
|
|
return anzahlLandungen.get();
|
|
}
|
|
|
|
public void setAnzahlLandungen(int anzahlLandungen) {
|
|
this.anzahlLandungen.set(anzahlLandungen);
|
|
}
|
|
|
|
public IntegerProperty anzahlLandungenProperty() {
|
|
return anzahlLandungen;
|
|
}
|
|
|
|
public Pilot getPilot() {
|
|
return pilot.get();
|
|
}
|
|
|
|
public void setPilot(Pilot pilot) {
|
|
this.pilot.set(pilot);
|
|
}
|
|
|
|
public ObjectProperty<Pilot> pilotProperty() {
|
|
return pilot;
|
|
}
|
|
|
|
public boolean isNachtflug() {
|
|
return nachtflug.get();
|
|
}
|
|
|
|
public void setNachtflug(boolean nachtflug) {
|
|
this.nachtflug.set(nachtflug);
|
|
}
|
|
|
|
public BooleanProperty nachtflugProperty() {
|
|
return nachtflug;
|
|
}
|
|
|
|
public String getKommentar() {
|
|
return kommentar.get();
|
|
}
|
|
|
|
public void setKommentar(String kommentar) {
|
|
this.kommentar.set(kommentar);
|
|
}
|
|
|
|
public StringProperty kommentarProperty() {
|
|
return kommentar;
|
|
}
|
|
|
|
public String getPilotInformationen() {
|
|
Pilot pilot = getPilot();
|
|
if (pilot != null) {
|
|
return "Name: " + pilot.getName() + ", Adresse: " + pilot.getAdresse() + ", Kontaktinformationen: " + pilot.getKontaktinformationen();
|
|
}
|
|
return "Keine Pilotinformationen verfügbar";
|
|
}
|
|
|
|
// Custom Serialization
|
|
private void writeObject(ObjectOutputStream oos) throws IOException {
|
|
oos.defaultWriteObject();
|
|
oos.writeObject(datum.get() != null ? datum.get().format(formatter) : null);
|
|
}
|
|
|
|
// Custom Deserialization
|
|
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
|
|
ois.defaultReadObject();
|
|
String datumStr = (String) ois.readObject();
|
|
if (datumStr != null) {
|
|
this.datum = new SimpleObjectProperty<>(LocalDate.parse(datumStr, formatter));
|
|
} else {
|
|
this.datum = new SimpleObjectProperty<>();
|
|
}
|
|
}
|
|
}
|