Fix für das Datum in XML
parent
dc8c10b552
commit
950a4a9078
Binary file not shown.
Binary file not shown.
260
flights.xml
260
flights.xml
|
|
@ -8,274 +8,36 @@
|
||||||
<double>2.0</double>
|
<double>2.0</double>
|
||||||
</void>
|
</void>
|
||||||
<void property="abflugort">
|
<void property="abflugort">
|
||||||
<string>ea</string>
|
<string>123</string>
|
||||||
</void>
|
</void>
|
||||||
<void property="abflugzeit">
|
<void property="abflugzeit">
|
||||||
<string>2</string>
|
|
||||||
</void>
|
|
||||||
<void property="ankunftszeit">
|
|
||||||
<string>2</string>
|
|
||||||
</void>
|
|
||||||
<void property="anzahlLandungen">
|
|
||||||
<int>1</int>
|
|
||||||
</void>
|
|
||||||
<void property="kommentar">
|
|
||||||
<string>2</string>
|
|
||||||
</void>
|
|
||||||
<void property="muster">
|
|
||||||
<string>aed</string>
|
|
||||||
</void>
|
|
||||||
<void property="pilot">
|
|
||||||
<object class="models.Pilot" id="Pilot0">
|
|
||||||
<void property="adresse">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void property="kontaktinformationen">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void property="lizenzen">
|
|
||||||
<void method="add">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void method="add">
|
|
||||||
<string>ss</string>
|
|
||||||
</void>
|
|
||||||
<void method="add">
|
|
||||||
<string>ddas</string>
|
|
||||||
</void>
|
|
||||||
</void>
|
|
||||||
<void property="name">
|
|
||||||
<string>sad</string>
|
|
||||||
</void>
|
|
||||||
<void property="zertifikate">
|
|
||||||
<void method="add">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void method="add">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void method="add">
|
|
||||||
<string>eee</string>
|
|
||||||
</void>
|
|
||||||
</void>
|
|
||||||
</object>
|
|
||||||
</void>
|
|
||||||
</object>
|
|
||||||
</void>
|
|
||||||
<void method="add">
|
|
||||||
<object class="models.Flight">
|
|
||||||
<void property="TToF">
|
|
||||||
<double>2.0</double>
|
|
||||||
</void>
|
|
||||||
<void property="abflugort">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void property="abflugzeit">
|
|
||||||
<string>11:00</string>
|
|
||||||
</void>
|
|
||||||
<void property="ankunftszeit">
|
|
||||||
<string>12:00</string>
|
<string>12:00</string>
|
||||||
</void>
|
</void>
|
||||||
<void property="anzahlLandungen">
|
|
||||||
<int>2</int>
|
|
||||||
</void>
|
|
||||||
<void property="kommentar">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void property="muster">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void property="pilot">
|
|
||||||
<object class="models.Pilot" id="Pilot1">
|
|
||||||
<void property="adresse">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void property="kontaktinformationen">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void property="lizenzen">
|
|
||||||
<void method="add">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void method="add">
|
|
||||||
<string>ss</string>
|
|
||||||
</void>
|
|
||||||
<void method="add">
|
|
||||||
<string>ddas</string>
|
|
||||||
</void>
|
|
||||||
</void>
|
|
||||||
<void property="name">
|
|
||||||
<string>sad</string>
|
|
||||||
</void>
|
|
||||||
<void property="zertifikate">
|
|
||||||
<void method="add">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void method="add">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void method="add">
|
|
||||||
<string>eee</string>
|
|
||||||
</void>
|
|
||||||
</void>
|
|
||||||
</object>
|
|
||||||
</void>
|
|
||||||
</object>
|
|
||||||
</void>
|
|
||||||
<void method="add">
|
|
||||||
<object class="models.Flight">
|
|
||||||
<void property="TToF">
|
|
||||||
<double>123.0</double>
|
|
||||||
</void>
|
|
||||||
<void property="abflugort">
|
|
||||||
<string>sad</string>
|
|
||||||
</void>
|
|
||||||
<void property="abflugzeit">
|
|
||||||
<string>123</string>
|
|
||||||
</void>
|
|
||||||
<void property="ankunftszeit">
|
<void property="ankunftszeit">
|
||||||
<string>123</string>
|
<string>14:00</string>
|
||||||
</void>
|
|
||||||
<void property="anzahlLandungen">
|
|
||||||
<int>123</int>
|
|
||||||
</void>
|
|
||||||
<void property="kommentar">
|
|
||||||
<string>123</string>
|
|
||||||
</void>
|
|
||||||
<void property="muster">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void property="nachtflug">
|
|
||||||
<boolean>true</boolean>
|
|
||||||
</void>
|
|
||||||
<void property="pilot">
|
|
||||||
<object class="models.Pilot" id="Pilot2">
|
|
||||||
<void property="adresse">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void property="kontaktinformationen">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void property="lizenzen">
|
|
||||||
<void method="add">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void method="add">
|
|
||||||
<string>ss</string>
|
|
||||||
</void>
|
|
||||||
<void method="add">
|
|
||||||
<string>ddas</string>
|
|
||||||
</void>
|
|
||||||
</void>
|
|
||||||
<void property="name">
|
|
||||||
<string>sad</string>
|
|
||||||
</void>
|
|
||||||
<void property="zertifikate">
|
|
||||||
<void method="add">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void method="add">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void method="add">
|
|
||||||
<string>eee</string>
|
|
||||||
</void>
|
|
||||||
</void>
|
|
||||||
</object>
|
|
||||||
</void>
|
|
||||||
</object>
|
|
||||||
</void>
|
|
||||||
<void method="add">
|
|
||||||
<object class="models.Flight">
|
|
||||||
<void property="TToF">
|
|
||||||
<double>123.0</double>
|
|
||||||
</void>
|
|
||||||
<void property="abflugort">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
<void property="abflugzeit">
|
|
||||||
<string>dsa</string>
|
|
||||||
</void>
|
|
||||||
<void property="ankunftszeit">
|
|
||||||
<string>asda</string>
|
|
||||||
</void>
|
|
||||||
<void property="anzahlLandungen">
|
|
||||||
<int>12</int>
|
|
||||||
</void>
|
|
||||||
<void property="kommentar">
|
|
||||||
<string>123</string>
|
|
||||||
</void>
|
|
||||||
<void property="muster">
|
|
||||||
<string>asda</string>
|
|
||||||
</void>
|
|
||||||
<void property="pilot">
|
|
||||||
<object class="models.Pilot" id="Pilot3">
|
|
||||||
<void property="adresse">
|
|
||||||
<string>asdasdasd</string>
|
|
||||||
</void>
|
|
||||||
<void property="kontaktinformationen">
|
|
||||||
<string>asdasd</string>
|
|
||||||
</void>
|
|
||||||
<void property="lizenzen">
|
|
||||||
<void method="add">
|
|
||||||
<string>124312</string>
|
|
||||||
</void>
|
|
||||||
</void>
|
|
||||||
<void property="name">
|
|
||||||
<string>asdasd</string>
|
|
||||||
</void>
|
|
||||||
<void property="zertifikate">
|
|
||||||
<void method="add">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
</void>
|
|
||||||
</object>
|
|
||||||
</void>
|
|
||||||
</object>
|
|
||||||
</void>
|
|
||||||
<void method="add">
|
|
||||||
<object class="models.Flight">
|
|
||||||
<void property="TToF">
|
|
||||||
<double>1.0</double>
|
|
||||||
</void>
|
|
||||||
<void property="abflugort">
|
|
||||||
<string>ea</string>
|
|
||||||
</void>
|
|
||||||
<void property="abflugzeit">
|
|
||||||
<string>11:00</string>
|
|
||||||
</void>
|
|
||||||
<void property="ankunftszeit">
|
|
||||||
<string>12:30</string>
|
|
||||||
</void>
|
</void>
|
||||||
<void property="anzahlLandungen">
|
<void property="anzahlLandungen">
|
||||||
<int>2</int>
|
<int>2</int>
|
||||||
</void>
|
</void>
|
||||||
|
<void property="datumStr">
|
||||||
|
<string>2024-06-10</string>
|
||||||
|
</void>
|
||||||
<void property="kommentar">
|
<void property="kommentar">
|
||||||
<string>lol</string>
|
<string>asd</string>
|
||||||
</void>
|
</void>
|
||||||
<void property="muster">
|
<void property="muster">
|
||||||
<string>test</string>
|
<string>asdasd</string>
|
||||||
</void>
|
</void>
|
||||||
<void property="pilot">
|
<void property="pilot">
|
||||||
<object class="models.Pilot" id="Pilot4">
|
<object class="models.Pilot">
|
||||||
<void property="adresse">
|
<void property="adresse">
|
||||||
<string>asdasdasd</string>
|
<string>sad</string>
|
||||||
</void>
|
</void>
|
||||||
<void property="kontaktinformationen">
|
<void property="kontaktinformationen">
|
||||||
<string>asdasd</string>
|
<string>ads</string>
|
||||||
</void>
|
|
||||||
<void property="lizenzen">
|
|
||||||
<void method="add">
|
|
||||||
<string>124312</string>
|
|
||||||
</void>
|
|
||||||
</void>
|
</void>
|
||||||
<void property="name">
|
<void property="name">
|
||||||
<string>asdasd</string>
|
<string>sad</string>
|
||||||
</void>
|
|
||||||
<void property="zertifikate">
|
|
||||||
<void method="add">
|
|
||||||
<string>asd</string>
|
|
||||||
</void>
|
|
||||||
</void>
|
</void>
|
||||||
</object>
|
</object>
|
||||||
</void>
|
</void>
|
||||||
|
|
|
||||||
26
pilots.xml
26
pilots.xml
|
|
@ -15,6 +15,32 @@
|
||||||
</void>
|
</void>
|
||||||
</object>
|
</object>
|
||||||
</void>
|
</void>
|
||||||
|
<void method="add">
|
||||||
|
<object class="models.Pilot">
|
||||||
|
<void property="adresse">
|
||||||
|
<string>asdasd</string>
|
||||||
|
</void>
|
||||||
|
<void property="kontaktinformationen">
|
||||||
|
<string>asdasd</string>
|
||||||
|
</void>
|
||||||
|
<void property="name">
|
||||||
|
<string>sad</string>
|
||||||
|
</void>
|
||||||
|
</object>
|
||||||
|
</void>
|
||||||
|
<void method="add">
|
||||||
|
<object class="models.Pilot">
|
||||||
|
<void property="adresse">
|
||||||
|
<string>asdasd</string>
|
||||||
|
</void>
|
||||||
|
<void property="kontaktinformationen">
|
||||||
|
<string>23</string>
|
||||||
|
</void>
|
||||||
|
<void property="name">
|
||||||
|
<string>adsasd</string>
|
||||||
|
</void>
|
||||||
|
</object>
|
||||||
|
</void>
|
||||||
</void>
|
</void>
|
||||||
</object>
|
</object>
|
||||||
</java>
|
</java>
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ import javafx.beans.property.*;
|
||||||
public class Flight implements Serializable {
|
public class Flight implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private transient ObjectProperty<LocalDate> datum;
|
private String datumStr; // String zur Speicherung des Datums in XML
|
||||||
private String datumStr;
|
private transient ObjectProperty<LocalDate> datum; // transient, um die direkte Serialization zu vermeiden
|
||||||
private StringProperty muster;
|
private StringProperty muster;
|
||||||
private StringProperty abflugort;
|
private StringProperty abflugort;
|
||||||
private StringProperty abflugzeit;
|
private StringProperty abflugzeit;
|
||||||
|
|
@ -23,6 +23,8 @@ public class Flight implements Serializable {
|
||||||
private BooleanProperty nachtflug;
|
private BooleanProperty nachtflug;
|
||||||
private StringProperty kommentar;
|
private StringProperty kommentar;
|
||||||
|
|
||||||
|
private static final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
|
||||||
|
|
||||||
// Standardkonstruktor
|
// Standardkonstruktor
|
||||||
public Flight() {
|
public Flight() {
|
||||||
this.datum = new SimpleObjectProperty<>();
|
this.datum = new SimpleObjectProperty<>();
|
||||||
|
|
@ -38,17 +40,17 @@ public class Flight implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Flight(LocalDate datum, String muster, String abflugort, String abflugzeit, String ankunftszeit, double tToF, int anzahlLandungen, Pilot pilot, boolean nachtflug, String kommentar) {
|
public Flight(LocalDate datum, String muster, String abflugort, String abflugzeit, String ankunftszeit, double tToF, int anzahlLandungen, Pilot pilot, boolean nachtflug, String kommentar) {
|
||||||
this.datum = new SimpleObjectProperty<>(datum);
|
this();
|
||||||
this.datumStr = datum.format(DateTimeFormatter.ISO_LOCAL_DATE);
|
this.setDatum(datum);
|
||||||
this.muster = new SimpleStringProperty(muster);
|
this.muster.set(muster);
|
||||||
this.abflugort = new SimpleStringProperty(abflugort);
|
this.abflugort.set(abflugort);
|
||||||
this.abflugzeit = new SimpleStringProperty(abflugzeit);
|
this.abflugzeit.set(abflugzeit);
|
||||||
this.ankunftszeit = new SimpleStringProperty(ankunftszeit);
|
this.ankunftszeit.set(ankunftszeit);
|
||||||
this.tToF = new SimpleDoubleProperty(tToF);
|
this.tToF.set(tToF);
|
||||||
this.anzahlLandungen = new SimpleIntegerProperty(anzahlLandungen);
|
this.anzahlLandungen.set(anzahlLandungen);
|
||||||
this.pilot = new SimpleObjectProperty<>(pilot);
|
this.pilot.set(pilot);
|
||||||
this.nachtflug = new SimpleBooleanProperty(nachtflug);
|
this.nachtflug.set(nachtflug);
|
||||||
this.kommentar = new SimpleStringProperty(kommentar);
|
this.kommentar.set(kommentar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDate getDatum() {
|
public LocalDate getDatum() {
|
||||||
|
|
@ -57,13 +59,22 @@ public class Flight implements Serializable {
|
||||||
|
|
||||||
public void setDatum(LocalDate datum) {
|
public void setDatum(LocalDate datum) {
|
||||||
this.datum.set(datum);
|
this.datum.set(datum);
|
||||||
this.datumStr = datum.format(DateTimeFormatter.ISO_LOCAL_DATE);
|
this.datumStr = datum != null ? datum.format(formatter) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectProperty<LocalDate> datumProperty() {
|
public ObjectProperty<LocalDate> datumProperty() {
|
||||||
return datum;
|
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() {
|
public String getMuster() {
|
||||||
return muster.get();
|
return muster.get();
|
||||||
}
|
}
|
||||||
|
|
@ -180,5 +191,20 @@ public class Flight implements Serializable {
|
||||||
return "Keine Pilotinformationen verfügbar";
|
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<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,15 @@ import models.Pilots;
|
||||||
import utils.XMLHelper;
|
import utils.XMLHelper;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.format.DateTimeParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AddFlightScreen {
|
public class AddFlightScreen {
|
||||||
private Stage stage;
|
private Stage stage;
|
||||||
|
private DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
|
||||||
|
|
||||||
public AddFlightScreen(Stage stage) {
|
public AddFlightScreen(Stage stage) {
|
||||||
this.stage = stage;
|
this.stage = stage;
|
||||||
|
|
@ -42,25 +46,43 @@ public class AddFlightScreen {
|
||||||
datumField.setPromptText("YYYY-MM-DD");
|
datumField.setPromptText("YYYY-MM-DD");
|
||||||
musterField.setPromptText("Muster");
|
musterField.setPromptText("Muster");
|
||||||
abflugortField.setPromptText("Abflugort");
|
abflugortField.setPromptText("Abflugort");
|
||||||
abflugzeitField.setPromptText("HH:MM");
|
abflugzeitField.setPromptText("HH:mm");
|
||||||
ankunftszeitField.setPromptText("HH:MM");
|
ankunftszeitField.setPromptText("HH:mm");
|
||||||
tToFField.setPromptText("Flugdauer (Stunden)");
|
tToFField.setPromptText("Flugdauer (Stunden)");
|
||||||
anzahlLandungenField.setPromptText("Anzahl der Landungen");
|
anzahlLandungenField.setPromptText("Anzahl der Landungen");
|
||||||
kommentarField.setPromptText("Kommentar");
|
kommentarField.setPromptText("Kommentar");
|
||||||
|
|
||||||
// Nur numerische Eingaben für Flugdauer und Anzahl der Landungen zulassen
|
// Nur numerische Eingaben für Flugdauer und Anzahl der Landungen zulassen
|
||||||
tToFField.textProperty().addListener((observable, oldValue, newValue) -> {
|
tToFField.setEditable(false);
|
||||||
if (!newValue.matches("\\d*\\.?\\d*")) {
|
|
||||||
tToFField.setText(oldValue);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
anzahlLandungenField.textProperty().addListener((observable, oldValue, newValue) -> {
|
anzahlLandungenField.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
if (!newValue.matches("\\d*")) {
|
if (!newValue.matches("\\d*")) {
|
||||||
anzahlLandungenField.setText(oldValue);
|
anzahlLandungenField.setText(oldValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Validierung und Berechnung der Flugdauer
|
||||||
|
abflugzeitField.focusedProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
if (!newValue) {
|
||||||
|
if (!isValidTime(abflugzeitField.getText())) {
|
||||||
|
abflugzeitField.setStyle("-fx-border-color: red;");
|
||||||
|
} else {
|
||||||
|
abflugzeitField.setStyle(null);
|
||||||
|
calculateFlightDuration(abflugzeitField, ankunftszeitField, tToFField);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ankunftszeitField.focusedProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
if (!newValue) {
|
||||||
|
if (!isValidTime(ankunftszeitField.getText())) {
|
||||||
|
ankunftszeitField.setStyle("-fx-border-color: red;");
|
||||||
|
} else {
|
||||||
|
ankunftszeitField.setStyle(null);
|
||||||
|
calculateFlightDuration(abflugzeitField, ankunftszeitField, tToFField);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Laden der Piloten für die Auswahlbox
|
// Laden der Piloten für die Auswahlbox
|
||||||
Pilots pilotsData = (Pilots) XMLHelper.loadFromXML("pilots.xml");
|
Pilots pilotsData = (Pilots) XMLHelper.loadFromXML("pilots.xml");
|
||||||
List<Pilot> pilotList = pilotsData != null ? pilotsData.getPilots() : new ArrayList<>();
|
List<Pilot> pilotList = pilotsData != null ? pilotsData.getPilots() : new ArrayList<>();
|
||||||
|
|
@ -71,8 +93,9 @@ public class AddFlightScreen {
|
||||||
|
|
||||||
Button submitBtn = new Button("Hinzufügen");
|
Button submitBtn = new Button("Hinzufügen");
|
||||||
submitBtn.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;");
|
submitBtn.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;");
|
||||||
submitBtn.setOnAction(e -> handleAddFlight(datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField,
|
submitBtn.setOnAction(
|
||||||
tToFField, anzahlLandungenField, nachtflugBox.isSelected(), kommentarField, pilotComboBox));
|
e -> handleAddFlight(datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField,
|
||||||
|
tToFField, anzahlLandungenField, nachtflugBox.isSelected(), kommentarField, pilotComboBox));
|
||||||
|
|
||||||
Button backButton = new Button("Zurück");
|
Button backButton = new Button("Zurück");
|
||||||
backButton.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;");
|
backButton.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;");
|
||||||
|
|
@ -104,51 +127,84 @@ public class AddFlightScreen {
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleAddFlight(DatePicker datumField, TextField musterField, TextField abflugortField, TextField abflugzeitField,
|
private void calculateFlightDuration(TextField abflugzeitField, TextField ankunftszeitField, TextField tToFField) {
|
||||||
TextField ankunftszeitField, TextField tToFField, TextField anzahlLandungenField, boolean isNachtflug,
|
|
||||||
TextField kommentarField, ComboBox<Pilot> pilotComboBox) {
|
|
||||||
clearFieldStyles(datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField, tToFField, anzahlLandungenField, pilotComboBox);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (datumField.getValue() == null) {
|
LocalTime abflugzeit = LocalTime.parse(abflugzeitField.getText(), timeFormatter);
|
||||||
setErrorStyle(datumField);
|
LocalTime ankunftszeit = LocalTime.parse(ankunftszeitField.getText(), timeFormatter);
|
||||||
throw new IllegalArgumentException("Datum ist erforderlich.");
|
long durationInMinutes = java.time.Duration.between(abflugzeit, ankunftszeit).toMinutes();
|
||||||
|
if (durationInMinutes < 0) {
|
||||||
|
durationInMinutes += 24 * 60; // Falls über Mitternacht
|
||||||
}
|
}
|
||||||
if (musterField.getText().isEmpty()) {
|
double durationInHours = durationInMinutes / 60.0;
|
||||||
setErrorStyle(musterField);
|
String formattedDuration = String.format("%.2f", durationInHours);
|
||||||
throw new IllegalArgumentException("Muster ist erforderlich.");
|
|
||||||
}
|
tToFField.setText(formattedDuration);
|
||||||
if (abflugortField.getText().isEmpty()) {
|
} catch (DateTimeParseException e) {
|
||||||
setErrorStyle(abflugortField);
|
tToFField.setText("");
|
||||||
throw new IllegalArgumentException("Abflugort ist erforderlich.");
|
}
|
||||||
}
|
}
|
||||||
if (abflugzeitField.getText().isEmpty()) {
|
|
||||||
setErrorStyle(abflugzeitField);
|
private boolean isValidTime(String time) {
|
||||||
throw new IllegalArgumentException("Abflugzeit ist erforderlich.");
|
try {
|
||||||
}
|
LocalTime.parse(time, timeFormatter);
|
||||||
if (ankunftszeitField.getText().isEmpty()) {
|
return true;
|
||||||
setErrorStyle(ankunftszeitField);
|
} catch (DateTimeParseException e) {
|
||||||
throw new IllegalArgumentException("Ankunftszeit ist erforderlich.");
|
return false;
|
||||||
}
|
}
|
||||||
if (tToFField.getText().isEmpty()) {
|
}
|
||||||
setErrorStyle(tToFField);
|
|
||||||
throw new IllegalArgumentException("Flugdauer ist erforderlich.");
|
private void handleAddFlight(DatePicker datumField, TextField musterField, TextField abflugortField,
|
||||||
}
|
TextField abflugzeitField, TextField ankunftszeitField, TextField tToFField,
|
||||||
if (anzahlLandungenField.getText().isEmpty()) {
|
TextField anzahlLandungenField, boolean isNachtflug, TextField kommentarField,
|
||||||
setErrorStyle(anzahlLandungenField);
|
ComboBox<Pilot> pilotComboBox) {
|
||||||
throw new IllegalArgumentException("Anzahl der Landungen ist erforderlich.");
|
try {
|
||||||
}
|
clearFieldStyles(datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField,
|
||||||
if (pilotComboBox.getValue() == null) {
|
tToFField, anzahlLandungenField, kommentarField, pilotComboBox);
|
||||||
setErrorStyle(pilotComboBox);
|
|
||||||
throw new IllegalArgumentException("Pilot ist erforderlich.");
|
if (datumField.getValue() == null || musterField.getText().isEmpty() || abflugortField.getText().isEmpty()
|
||||||
|
||
|
||||||
|
abflugzeitField.getText().isEmpty() || ankunftszeitField.getText().isEmpty()
|
||||||
|
|| tToFField.getText().isEmpty() ||
|
||||||
|
anzahlLandungenField.getText().isEmpty() || pilotComboBox.getValue() == null) {
|
||||||
|
throw new IllegalArgumentException("Bitte füllen Sie alle Felder aus.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isValidTime(abflugzeitField.getText())) {
|
||||||
|
setErrorStyle(abflugzeitField);
|
||||||
|
throw new IllegalArgumentException("Ungültige Abflugzeit.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isValidTime(ankunftszeitField.getText())) {
|
||||||
|
setErrorStyle(ankunftszeitField);
|
||||||
|
throw new IllegalArgumentException("Ungültige Ankunftszeit.");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Flugdauer vor dem Parsen: " + tToFField.getText()); // Debug-Ausgabe
|
||||||
|
double flightDuration;
|
||||||
|
try {
|
||||||
|
// Ersetzen des Kommas durch einen Punkt
|
||||||
|
String flightDurationText = tToFField.getText().replace(",", ".");
|
||||||
|
flightDuration = Double.parseDouble(flightDurationText);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
setErrorStyle(tToFField);
|
||||||
|
throw new IllegalArgumentException("Flugdauer muss eine gültige Zahl sein.");
|
||||||
}
|
}
|
||||||
|
|
||||||
double flightDuration = Double.parseDouble(tToFField.getText());
|
|
||||||
int landings = Integer.parseInt(anzahlLandungenField.getText());
|
int landings = Integer.parseInt(anzahlLandungenField.getText());
|
||||||
|
|
||||||
Flight newFlight = new Flight(datumField.getValue(), musterField.getText(), abflugortField.getText(),
|
Flight newFlight = new Flight();
|
||||||
abflugzeitField.getText(), ankunftszeitField.getText(), flightDuration, landings,
|
newFlight.setDatum(datumField.getValue()); // Setzen des Datums als LocalDate
|
||||||
pilotComboBox.getValue(), isNachtflug, kommentarField.getText());
|
newFlight.setMuster(musterField.getText());
|
||||||
|
newFlight.setAbflugort(abflugortField.getText());
|
||||||
|
newFlight.setAbflugzeit(abflugzeitField.getText());
|
||||||
|
newFlight.setAnkunftszeit(ankunftszeitField.getText());
|
||||||
|
newFlight.setTToF(flightDuration);
|
||||||
|
newFlight.setAnzahlLandungen(landings);
|
||||||
|
newFlight.setPilot(pilotComboBox.getValue());
|
||||||
|
newFlight.setNachtflug(isNachtflug);
|
||||||
|
newFlight.setKommentar(kommentarField.getText());
|
||||||
|
newFlight.setDatumStr(datumField.getValue().format(DateTimeFormatter.ISO_LOCAL_DATE)); // Setzen des DatumStr
|
||||||
|
|
||||||
|
|
||||||
Flights flights = (Flights) XMLHelper.loadFromXML("flights.xml");
|
Flights flights = (Flights) XMLHelper.loadFromXML("flights.xml");
|
||||||
if (flights == null) {
|
if (flights == null) {
|
||||||
|
|
@ -159,7 +215,8 @@ public class AddFlightScreen {
|
||||||
|
|
||||||
new HomeScreen(stage).display();
|
new HomeScreen(stage).display();
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
showAlert("Ungültige Eingabe", "Bitte stellen Sie sicher, dass die Flugdauer und die Anzahl der Landungen numerisch sind.");
|
showAlert("Ungültige Eingabe",
|
||||||
|
"Bitte stellen Sie sicher, dass die Flugdauer und die Anzahl der Landungen numerisch sind.");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
showAlert("Fehlende Eingabe", e.getMessage());
|
showAlert("Fehlende Eingabe", e.getMessage());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue