Anpassung nach MVC vorgenommen
parent
5290732598
commit
489ea74b7a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
162
flights.xml
162
flights.xml
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<java version="21.0.1" class="java.beans.XMLDecoder">
|
<java version="21" class="java.beans.XMLDecoder">
|
||||||
<object class="models.Flights" id="Flights0">
|
<object class="models.Flights" id="Flights0">
|
||||||
<void property="flights">
|
<void property="flights">
|
||||||
<void method="add">
|
<void method="add">
|
||||||
|
|
@ -43,6 +43,166 @@
|
||||||
</void>
|
</void>
|
||||||
</object>
|
</object>
|
||||||
</void>
|
</void>
|
||||||
|
<void method="add">
|
||||||
|
<object class="models.Flight">
|
||||||
|
<void property="TToF">
|
||||||
|
<double>1.0</double>
|
||||||
|
</void>
|
||||||
|
<void property="abflugort">
|
||||||
|
<string>test</string>
|
||||||
|
</void>
|
||||||
|
<void property="abflugzeit">
|
||||||
|
<string>11:00</string>
|
||||||
|
</void>
|
||||||
|
<void property="ankunftszeit">
|
||||||
|
<string>12:00</string>
|
||||||
|
</void>
|
||||||
|
<void property="anzahlLandungen">
|
||||||
|
<int>2</int>
|
||||||
|
</void>
|
||||||
|
<void property="datumStr">
|
||||||
|
<string>2024-06-11</string>
|
||||||
|
</void>
|
||||||
|
<void property="kommentar">
|
||||||
|
<string>asd</string>
|
||||||
|
</void>
|
||||||
|
<void property="muster">
|
||||||
|
<string>test</string>
|
||||||
|
</void>
|
||||||
|
<void property="pilot">
|
||||||
|
<object class="models.Pilot" id="Pilot0">
|
||||||
|
<void property="adresse">
|
||||||
|
<string>sad</string>
|
||||||
|
</void>
|
||||||
|
<void property="kontaktinformationen">
|
||||||
|
<string>ads</string>
|
||||||
|
</void>
|
||||||
|
<void property="lizenzen">
|
||||||
|
<void method="add">
|
||||||
|
<string>äää</string>
|
||||||
|
</void>
|
||||||
|
<void method="add">
|
||||||
|
<string>äää</string>
|
||||||
|
</void>
|
||||||
|
</void>
|
||||||
|
<void property="name">
|
||||||
|
<string>sad</string>
|
||||||
|
</void>
|
||||||
|
</object>
|
||||||
|
</void>
|
||||||
|
</object>
|
||||||
|
</void>
|
||||||
|
<void method="add">
|
||||||
|
<object class="models.Flight">
|
||||||
|
<void property="TToF">
|
||||||
|
<double>6.75</double>
|
||||||
|
</void>
|
||||||
|
<void property="abflugort">
|
||||||
|
<string>max</string>
|
||||||
|
</void>
|
||||||
|
<void property="abflugzeit">
|
||||||
|
<string>09:15</string>
|
||||||
|
</void>
|
||||||
|
<void property="ankunftszeit">
|
||||||
|
<string>16:00</string>
|
||||||
|
</void>
|
||||||
|
<void property="anzahlLandungen">
|
||||||
|
<int>2</int>
|
||||||
|
</void>
|
||||||
|
<void property="datumStr">
|
||||||
|
<string>2024-06-14</string>
|
||||||
|
</void>
|
||||||
|
<void property="kommentar">
|
||||||
|
<string>Kommentar</string>
|
||||||
|
</void>
|
||||||
|
<void property="muster">
|
||||||
|
<string>Max</string>
|
||||||
|
</void>
|
||||||
|
<void property="pilot">
|
||||||
|
<object class="models.Pilot" id="Pilot1">
|
||||||
|
<void property="adresse">
|
||||||
|
<string>max</string>
|
||||||
|
</void>
|
||||||
|
<void property="kontaktinformationen">
|
||||||
|
<string>max</string>
|
||||||
|
</void>
|
||||||
|
<void property="lizenzen">
|
||||||
|
<void method="add">
|
||||||
|
<string>hallo</string>
|
||||||
|
</void>
|
||||||
|
<void method="add">
|
||||||
|
<string>test</string>
|
||||||
|
</void>
|
||||||
|
</void>
|
||||||
|
<void property="name">
|
||||||
|
<string>max</string>
|
||||||
|
</void>
|
||||||
|
<void property="zertifikate">
|
||||||
|
<void method="add">
|
||||||
|
<string>test</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>mannheim</string>
|
||||||
|
</void>
|
||||||
|
<void property="abflugzeit">
|
||||||
|
<string>12:00</string>
|
||||||
|
</void>
|
||||||
|
<void property="ankunftszeit">
|
||||||
|
<string>13:00</string>
|
||||||
|
</void>
|
||||||
|
<void property="anzahlLandungen">
|
||||||
|
<int>1</int>
|
||||||
|
</void>
|
||||||
|
<void property="datumStr">
|
||||||
|
<string>2024-06-14</string>
|
||||||
|
</void>
|
||||||
|
<void property="kommentar">
|
||||||
|
<string>max</string>
|
||||||
|
</void>
|
||||||
|
<void property="muster">
|
||||||
|
<string>newTest</string>
|
||||||
|
</void>
|
||||||
|
<void property="nachtflug">
|
||||||
|
<boolean>true</boolean>
|
||||||
|
</void>
|
||||||
|
<void property="pilot">
|
||||||
|
<object class="models.Pilot" id="Pilot2">
|
||||||
|
<void property="adresse">
|
||||||
|
<string>max</string>
|
||||||
|
</void>
|
||||||
|
<void property="kontaktinformationen">
|
||||||
|
<string>max</string>
|
||||||
|
</void>
|
||||||
|
<void property="lizenzen">
|
||||||
|
<void method="add">
|
||||||
|
<string>hallo</string>
|
||||||
|
</void>
|
||||||
|
<void method="add">
|
||||||
|
<string>test</string>
|
||||||
|
</void>
|
||||||
|
</void>
|
||||||
|
<void property="name">
|
||||||
|
<string>max</string>
|
||||||
|
</void>
|
||||||
|
<void property="zertifikate">
|
||||||
|
<void method="add">
|
||||||
|
<string>test</string>
|
||||||
|
</void>
|
||||||
|
</void>
|
||||||
|
</object>
|
||||||
|
</void>
|
||||||
|
</object>
|
||||||
|
</void>
|
||||||
</void>
|
</void>
|
||||||
</object>
|
</object>
|
||||||
</java>
|
</java>
|
||||||
|
|
|
||||||
28
pilots.xml
28
pilots.xml
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<java version="21.0.1" class="java.beans.XMLDecoder">
|
<java version="21" class="java.beans.XMLDecoder">
|
||||||
<object class="models.Pilots" id="Pilots0">
|
<object class="models.Pilots" id="Pilots0">
|
||||||
<void property="pilots">
|
<void property="pilots">
|
||||||
<void method="add">
|
<void method="add">
|
||||||
|
|
@ -49,6 +49,32 @@
|
||||||
</void>
|
</void>
|
||||||
</object>
|
</object>
|
||||||
</void>
|
</void>
|
||||||
|
<void method="add">
|
||||||
|
<object class="models.Pilot" id="Pilot1">
|
||||||
|
<void property="adresse">
|
||||||
|
<string>max</string>
|
||||||
|
</void>
|
||||||
|
<void property="kontaktinformationen">
|
||||||
|
<string>max</string>
|
||||||
|
</void>
|
||||||
|
<void property="lizenzen">
|
||||||
|
<void method="add">
|
||||||
|
<string>hallo</string>
|
||||||
|
</void>
|
||||||
|
<void method="add">
|
||||||
|
<string>test</string>
|
||||||
|
</void>
|
||||||
|
</void>
|
||||||
|
<void property="name">
|
||||||
|
<string>max</string>
|
||||||
|
</void>
|
||||||
|
<void property="zertifikate">
|
||||||
|
<void method="add">
|
||||||
|
<string>test</string>
|
||||||
|
</void>
|
||||||
|
</void>
|
||||||
|
</object>
|
||||||
|
</void>
|
||||||
</void>
|
</void>
|
||||||
</object>
|
</object>
|
||||||
</java>
|
</java>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,109 @@
|
||||||
|
package controllers;
|
||||||
|
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import models.Flight;
|
||||||
|
import models.Flights;
|
||||||
|
import models.Pilot;
|
||||||
|
import models.Pilots;
|
||||||
|
import utils.XMLHelper;
|
||||||
|
import views.HomeScreen;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.format.DateTimeParseException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AddFlightController {
|
||||||
|
private Stage stage;
|
||||||
|
private DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
|
||||||
|
|
||||||
|
public AddFlightController(Stage stage) {
|
||||||
|
this.stage = stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableList<Pilot> loadPilots() {
|
||||||
|
ObservableList<Pilot> pilotList = FXCollections.observableArrayList();
|
||||||
|
Pilots pilots = (Pilots) XMLHelper.loadFromXML("pilots.xml");
|
||||||
|
if (pilots != null) {
|
||||||
|
List<Pilot> pilotEntries = pilots.getPilots();
|
||||||
|
pilotList.addAll(pilotEntries);
|
||||||
|
}
|
||||||
|
return pilotList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveFlight(Flight newFlight, DatePicker datumField, TextField musterField, TextField abflugortField,
|
||||||
|
TextField abflugzeitField, TextField ankunftszeitField, TextField tToFField, TextField anzahlLandungenField,
|
||||||
|
ComboBox<Pilot> pilotComboBox, CheckBox nachtflugBox, TextField kommentarField) {
|
||||||
|
try {
|
||||||
|
double flightDuration = Double.parseDouble(tToFField.getText().replace(',', '.'));
|
||||||
|
int landings = Integer.parseInt(anzahlLandungenField.getText());
|
||||||
|
boolean isNachtflug = nachtflugBox.isSelected();
|
||||||
|
|
||||||
|
newFlight.setDatum(datumField.getValue());
|
||||||
|
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));
|
||||||
|
|
||||||
|
Flights flights = (Flights) XMLHelper.loadFromXML("flights.xml");
|
||||||
|
if (flights == null) {
|
||||||
|
flights = new Flights(new ArrayList<>());
|
||||||
|
}
|
||||||
|
flights.getFlights().add(newFlight);
|
||||||
|
XMLHelper.saveToXML(flights, "flights.xml");
|
||||||
|
|
||||||
|
new HomeScreen(stage).display();
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
showAlert("Ungültige Eingabe", "Bitte stellen Sie sicher, dass die Flugdauer und die Anzahl der Landungen numerisch sind.");
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
showAlert("Fehlende Eingabe", e.getMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
showAlert("Fehler", "Es ist ein Fehler beim Speichern des Flugs aufgetreten.");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double calculateFlightDuration(String abflugzeit, String ankunftszeit) throws DateTimeParseException {
|
||||||
|
LocalTime start = LocalTime.parse(abflugzeit, timeFormatter);
|
||||||
|
LocalTime end = LocalTime.parse(ankunftszeit, timeFormatter);
|
||||||
|
return (double) Duration.between(start, end).toMinutes() / 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValidTime(String time) {
|
||||||
|
try {
|
||||||
|
LocalTime.parse(time, timeFormatter);
|
||||||
|
return true;
|
||||||
|
} catch (DateTimeParseException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorStyle(Control field) {
|
||||||
|
field.setStyle("-fx-border-color: red;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearFieldStyles(Control... fields) {
|
||||||
|
for (Control field : fields) {
|
||||||
|
field.setStyle(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showAlert(String title, String message) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
alert.setTitle(title);
|
||||||
|
alert.setHeaderText(null);
|
||||||
|
alert.setContentText(message);
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
package controllers;
|
||||||
|
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import models.Flight;
|
||||||
|
import models.Flights;
|
||||||
|
import utils.XMLHelper;
|
||||||
|
import views.EditFlightScreen;
|
||||||
|
import views.HomeScreen;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class LogbookController {
|
||||||
|
private Stage stage;
|
||||||
|
private ObservableList<Flight> flightList;
|
||||||
|
|
||||||
|
public LogbookController(Stage stage) {
|
||||||
|
this.stage = stage;
|
||||||
|
this.flightList = FXCollections.observableArrayList();
|
||||||
|
loadFlights();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableList<Flight> getFlightList() {
|
||||||
|
return flightList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadFlights() {
|
||||||
|
Flights flights = (Flights) XMLHelper.loadFromXML("flights.xml");
|
||||||
|
if (flights != null) {
|
||||||
|
List<Flight> flightEntries = flights.getFlights();
|
||||||
|
flightList.addAll(flightEntries);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void editFlight(Flight selectedFlight) {
|
||||||
|
if (selectedFlight != null) {
|
||||||
|
new EditFlightScreen(stage, selectedFlight).display();
|
||||||
|
} else {
|
||||||
|
showAlert("Fehler", "Bitte wählen Sie einen Flug aus.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void goBack() {
|
||||||
|
new HomeScreen(stage).display();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showAlert(String title, String message) {
|
||||||
|
javafx.scene.control.Alert alert = new javafx.scene.control.Alert(javafx.scene.control.Alert.AlertType.ERROR);
|
||||||
|
alert.setTitle(title);
|
||||||
|
alert.setHeaderText(null);
|
||||||
|
alert.setContentText(message);
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,245 +1,149 @@
|
||||||
package views;
|
package views;
|
||||||
|
|
||||||
import javafx.collections.FXCollections;
|
import controllers.AddFlightController;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import models.Flight;
|
import models.Flight;
|
||||||
import models.Flights;
|
|
||||||
import models.Pilot;
|
import models.Pilot;
|
||||||
import models.Pilots;
|
|
||||||
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.List;
|
|
||||||
|
|
||||||
public class AddFlightScreen {
|
public class AddFlightScreen {
|
||||||
private Stage stage;
|
private Stage stage;
|
||||||
private DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
|
private AddFlightController controller;
|
||||||
|
|
||||||
public AddFlightScreen(Stage stage) {
|
public AddFlightScreen(Stage stage) {
|
||||||
this.stage = stage;
|
this.stage = stage;
|
||||||
|
this.controller = new AddFlightController(stage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void display() {
|
public void display() {
|
||||||
Label label = new Label("Flugdaten eingeben:");
|
Label label = new Label("Flugdaten eingeben:");
|
||||||
label.setStyle("-fx-font-size: 18px; -fx-font-weight: bold;");
|
label.setStyle("-fx-font-size: 18px; -fx-font-weight: bold;");
|
||||||
DatePicker datumField = new DatePicker();
|
|
||||||
TextField musterField = new TextField();
|
|
||||||
TextField abflugortField = new TextField();
|
|
||||||
TextField abflugzeitField = new TextField();
|
|
||||||
TextField ankunftszeitField = new TextField();
|
|
||||||
TextField tToFField = new TextField();
|
|
||||||
TextField anzahlLandungenField = new TextField();
|
|
||||||
CheckBox nachtflugBox = new CheckBox("Nachtflug");
|
|
||||||
TextField kommentarField = new TextField();
|
|
||||||
|
|
||||||
datumField.setPromptText("YYYY-MM-DD");
|
Label datumLabel = new Label("Datum:");
|
||||||
|
DatePicker datumField = new DatePicker(LocalDate.now()); // Set today's date
|
||||||
|
|
||||||
|
Label musterLabel = new Label("Muster:");
|
||||||
|
TextField musterField = new TextField();
|
||||||
musterField.setPromptText("Muster");
|
musterField.setPromptText("Muster");
|
||||||
|
|
||||||
|
Label abflugortLabel = new Label("Abflugort:");
|
||||||
|
TextField abflugortField = new TextField();
|
||||||
abflugortField.setPromptText("Abflugort");
|
abflugortField.setPromptText("Abflugort");
|
||||||
|
|
||||||
|
Label abflugzeitLabel = new Label("Abflugzeit:");
|
||||||
|
TextField abflugzeitField = new TextField();
|
||||||
abflugzeitField.setPromptText("HH:mm");
|
abflugzeitField.setPromptText("HH:mm");
|
||||||
|
|
||||||
|
Label ankunftszeitLabel = new Label("Ankunftszeit:");
|
||||||
|
TextField ankunftszeitField = new TextField();
|
||||||
ankunftszeitField.setPromptText("HH:mm");
|
ankunftszeitField.setPromptText("HH:mm");
|
||||||
|
|
||||||
|
Label tToFLabel = new Label("Flugdauer (Stunden):");
|
||||||
|
TextField tToFField = new TextField();
|
||||||
tToFField.setPromptText("Flugdauer (Stunden)");
|
tToFField.setPromptText("Flugdauer (Stunden)");
|
||||||
|
tToFField.setEditable(false); // Make the field read-only
|
||||||
|
tToFField.setStyle("-fx-control-inner-background: #E0E0E0;"); // Gray out the field
|
||||||
|
|
||||||
|
Label anzahlLandungenLabel = new Label("Anzahl der Landungen:");
|
||||||
|
TextField anzahlLandungenField = new TextField();
|
||||||
anzahlLandungenField.setPromptText("Anzahl der Landungen");
|
anzahlLandungenField.setPromptText("Anzahl der Landungen");
|
||||||
|
|
||||||
|
Label nachtflugLabel = new Label("Nachtflug:");
|
||||||
|
CheckBox nachtflugBox = new CheckBox();
|
||||||
|
|
||||||
|
Label kommentarLabel = new Label("Kommentar:");
|
||||||
|
TextField kommentarField = new TextField();
|
||||||
kommentarField.setPromptText("Kommentar");
|
kommentarField.setPromptText("Kommentar");
|
||||||
|
|
||||||
// Nur numerische Eingaben für Flugdauer und Anzahl der Landungen zulassen
|
ObservableList<Pilot> pilotList = controller.loadPilots();
|
||||||
tToFField.setEditable(false);
|
Label pilotLabel = new Label("Pilot:");
|
||||||
anzahlLandungenField.textProperty().addListener((observable, oldValue, newValue) -> {
|
ComboBox<Pilot> pilotComboBox = new ComboBox<>(pilotList);
|
||||||
if (!newValue.matches("\\d*")) {
|
|
||||||
anzahlLandungenField.setText(oldValue);
|
Button saveBtn = new Button("Speichern");
|
||||||
}
|
saveBtn.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;");
|
||||||
|
saveBtn.setOnAction(e -> {
|
||||||
|
Flight newFlight = new Flight();
|
||||||
|
controller.clearFieldStyles(datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField, tToFField, anzahlLandungenField, kommentarField);
|
||||||
|
|
||||||
|
// Save the flight with the corrected TToF value
|
||||||
|
controller.saveFlight(newFlight, datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField, tToFField, anzahlLandungenField, pilotComboBox, nachtflugBox, kommentarField);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 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
|
|
||||||
Pilots pilotsData = (Pilots) XMLHelper.loadFromXML("pilots.xml");
|
|
||||||
List<Pilot> pilotList = pilotsData != null ? pilotsData.getPilots() : new ArrayList<>();
|
|
||||||
ObservableList<Pilot> pilots = FXCollections.observableArrayList(pilotList);
|
|
||||||
|
|
||||||
ComboBox<Pilot> pilotComboBox = new ComboBox<>(pilots);
|
|
||||||
pilotComboBox.setPromptText("Pilot auswählen");
|
|
||||||
|
|
||||||
Button submitBtn = new Button("Hinzufügen");
|
|
||||||
submitBtn.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;");
|
|
||||||
submitBtn.setOnAction(
|
|
||||||
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;");
|
||||||
backButton.setOnAction(e -> new HomeScreen(stage).display());
|
backButton.setOnAction(e -> new HomeScreen(stage).display());
|
||||||
|
|
||||||
VBox vbox = new VBox(10, label, datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField,
|
// Add listeners to the time fields to update the flight duration automatically
|
||||||
tToFField, anzahlLandungenField, nachtflugBox, kommentarField, pilotComboBox, submitBtn);
|
abflugzeitField.textProperty().addListener((observable, oldValue, newValue) -> updateFlightDuration(abflugzeitField, ankunftszeitField, tToFField));
|
||||||
|
ankunftszeitField.textProperty().addListener((observable, oldValue, newValue) -> updateFlightDuration(abflugzeitField, ankunftszeitField, tToFField));
|
||||||
|
|
||||||
|
GridPane grid = new GridPane();
|
||||||
|
grid.setAlignment(Pos.CENTER);
|
||||||
|
grid.setHgap(10);
|
||||||
|
grid.setVgap(10);
|
||||||
|
grid.setPadding(new Insets(20));
|
||||||
|
|
||||||
|
grid.add(label, 0, 0, 2, 1);
|
||||||
|
|
||||||
|
grid.add(datumLabel, 0, 1);
|
||||||
|
grid.add(datumField, 1, 1);
|
||||||
|
grid.add(musterLabel, 0, 2);
|
||||||
|
grid.add(musterField, 1, 2);
|
||||||
|
grid.add(abflugortLabel, 0, 3);
|
||||||
|
grid.add(abflugortField, 1, 3);
|
||||||
|
grid.add(abflugzeitLabel, 0, 4);
|
||||||
|
grid.add(abflugzeitField, 1, 4);
|
||||||
|
grid.add(ankunftszeitLabel, 0, 5);
|
||||||
|
grid.add(ankunftszeitField, 1, 5);
|
||||||
|
grid.add(tToFLabel, 0, 6);
|
||||||
|
grid.add(tToFField, 1, 6);
|
||||||
|
grid.add(anzahlLandungenLabel, 0, 7);
|
||||||
|
grid.add(anzahlLandungenField, 1, 7);
|
||||||
|
grid.add(pilotLabel, 0, 8);
|
||||||
|
grid.add(pilotComboBox, 1, 8);
|
||||||
|
grid.add(nachtflugLabel, 0, 9);
|
||||||
|
grid.add(nachtflugBox, 1, 9);
|
||||||
|
grid.add(kommentarLabel, 0, 10);
|
||||||
|
grid.add(kommentarField, 1, 10);
|
||||||
|
|
||||||
|
HBox buttonBox = new HBox(10, saveBtn, backButton);
|
||||||
|
buttonBox.setAlignment(Pos.CENTER);
|
||||||
|
|
||||||
|
VBox vbox = new VBox(20, grid, buttonBox);
|
||||||
vbox.setAlignment(Pos.CENTER);
|
vbox.setAlignment(Pos.CENTER);
|
||||||
vbox.setPadding(new Insets(20));
|
vbox.setPadding(new Insets(20));
|
||||||
vbox.setStyle("-fx-background-color: #E6F2FF;");
|
vbox.setStyle("-fx-background-color: #E6F2FF;");
|
||||||
|
|
||||||
BorderPane borderPane = new BorderPane();
|
Scene scene = new Scene(vbox, 800, 600);
|
||||||
borderPane.setTop(backButton);
|
|
||||||
borderPane.setCenter(vbox);
|
|
||||||
BorderPane.setAlignment(backButton, Pos.TOP_LEFT);
|
|
||||||
BorderPane.setMargin(backButton, new Insets(10));
|
|
||||||
|
|
||||||
if (pilots.isEmpty()) {
|
|
||||||
Button addPilotBtn = new Button("Pilot hinzufügen");
|
|
||||||
addPilotBtn.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;");
|
|
||||||
addPilotBtn.setOnAction(e -> new ManagePilotProfileScreen(stage).display());
|
|
||||||
vbox.getChildren().add(addPilotBtn);
|
|
||||||
}
|
|
||||||
|
|
||||||
Scene scene = new Scene(borderPane, 800, 600);
|
|
||||||
scene.getStylesheets().add(getClass().getResource("/resources/styles.css").toExternalForm());
|
scene.getStylesheets().add(getClass().getResource("/resources/styles.css").toExternalForm());
|
||||||
|
|
||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculateFlightDuration(TextField abflugzeitField, TextField ankunftszeitField, TextField tToFField) {
|
private void updateFlightDuration(TextField abflugzeitField, TextField ankunftszeitField, TextField tToFField) {
|
||||||
try {
|
String abflugzeit = abflugzeitField.getText();
|
||||||
LocalTime abflugzeit = LocalTime.parse(abflugzeitField.getText(), timeFormatter);
|
String ankunftszeit = ankunftszeitField.getText();
|
||||||
LocalTime ankunftszeit = LocalTime.parse(ankunftszeitField.getText(), timeFormatter);
|
|
||||||
long durationInMinutes = java.time.Duration.between(abflugzeit, ankunftszeit).toMinutes();
|
|
||||||
if (durationInMinutes < 0) {
|
|
||||||
durationInMinutes += 24 * 60; // Falls über Mitternacht
|
|
||||||
}
|
|
||||||
double durationInHours = durationInMinutes / 60.0;
|
|
||||||
String formattedDuration = String.format("%.2f", durationInHours);
|
|
||||||
|
|
||||||
tToFField.setText(formattedDuration);
|
if (controller.isValidTime(abflugzeit) && controller.isValidTime(ankunftszeit)) {
|
||||||
} catch (DateTimeParseException e) {
|
double duration = controller.calculateFlightDuration(abflugzeit, ankunftszeit);
|
||||||
|
if (duration >= 0) {
|
||||||
|
tToFField.setText(String.valueOf(duration));
|
||||||
|
} else {
|
||||||
|
controller.showAlert("Ungültige Zeit", "Die Ankunftszeit darf nicht vor der Abflugzeit liegen.");
|
||||||
|
tToFField.setText("");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
tToFField.setText("");
|
tToFField.setText("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isValidTime(String time) {
|
|
||||||
try {
|
|
||||||
LocalTime.parse(time, timeFormatter);
|
|
||||||
return true;
|
|
||||||
} catch (DateTimeParseException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleAddFlight(DatePicker datumField, TextField musterField, TextField abflugortField,
|
|
||||||
TextField abflugzeitField, TextField ankunftszeitField, TextField tToFField,
|
|
||||||
TextField anzahlLandungenField, boolean isNachtflug, TextField kommentarField,
|
|
||||||
ComboBox<Pilot> pilotComboBox) {
|
|
||||||
try {
|
|
||||||
clearFieldStyles(datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField,
|
|
||||||
tToFField, anzahlLandungenField, kommentarField, pilotComboBox);
|
|
||||||
|
|
||||||
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.");
|
|
||||||
}
|
|
||||||
|
|
||||||
int landings = Integer.parseInt(anzahlLandungenField.getText());
|
|
||||||
|
|
||||||
Flight newFlight = new Flight();
|
|
||||||
newFlight.setDatum(datumField.getValue()); // Setzen des Datums als LocalDate
|
|
||||||
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");
|
|
||||||
if (flights == null) {
|
|
||||||
flights = new Flights(new ArrayList<>());
|
|
||||||
}
|
|
||||||
flights.getFlights().add(newFlight);
|
|
||||||
XMLHelper.saveToXML(flights, "flights.xml");
|
|
||||||
|
|
||||||
new HomeScreen(stage).display();
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
showAlert("Ungültige Eingabe",
|
|
||||||
"Bitte stellen Sie sicher, dass die Flugdauer und die Anzahl der Landungen numerisch sind.");
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
showAlert("Fehlende Eingabe", e.getMessage());
|
|
||||||
} catch (Exception e) {
|
|
||||||
showAlert("Fehler", "Es ist ein Fehler beim Speichern des Flugs aufgetreten.");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setErrorStyle(Control field) {
|
|
||||||
field.setStyle("-fx-border-color: red;");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void clearFieldStyles(Control... fields) {
|
|
||||||
for (Control field : fields) {
|
|
||||||
field.setStyle(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showAlert(String title, String message) {
|
|
||||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
|
||||||
alert.setTitle(title);
|
|
||||||
alert.setHeaderText(null);
|
|
||||||
alert.setContentText(message);
|
|
||||||
alert.showAndWait();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package views;
|
package views;
|
||||||
|
|
||||||
|
import controllers.LogbookController;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.collections.FXCollections;
|
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
|
|
@ -11,18 +11,17 @@ import javafx.scene.layout.BorderPane;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import models.Flight;
|
import models.Flight;
|
||||||
import models.Flights;
|
|
||||||
import utils.XMLHelper;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ViewLogbookScreen {
|
public class ViewLogbookScreen {
|
||||||
private Stage stage;
|
private Stage stage;
|
||||||
|
private LogbookController controller;
|
||||||
|
|
||||||
public ViewLogbookScreen(Stage stage) {
|
public ViewLogbookScreen(Stage stage) {
|
||||||
this.stage = stage;
|
this.stage = stage;
|
||||||
|
this.controller = new LogbookController(stage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void display() {
|
public void display() {
|
||||||
|
|
@ -68,28 +67,19 @@ public class ViewLogbookScreen {
|
||||||
|
|
||||||
table.getColumns().addAll(datumCol, musterCol, abflugortCol, abflugzeitCol, ankunftszeitCol, tToFCol, anzahlLandungenCol, pilotCol, nachtflugCol, kommentarCol);
|
table.getColumns().addAll(datumCol, musterCol, abflugortCol, abflugzeitCol, ankunftszeitCol, tToFCol, anzahlLandungenCol, pilotCol, nachtflugCol, kommentarCol);
|
||||||
|
|
||||||
ObservableList<Flight> flightList = FXCollections.observableArrayList();
|
ObservableList<Flight> flightList = controller.getFlightList();
|
||||||
Flights flights = (Flights) XMLHelper.loadFromXML("flights.xml");
|
|
||||||
if (flights != null) {
|
|
||||||
List<Flight> flightEntries = flights.getFlights();
|
|
||||||
flightList.addAll(flightEntries);
|
|
||||||
}
|
|
||||||
table.setItems(flightList);
|
table.setItems(flightList);
|
||||||
|
|
||||||
Button editBtn = new Button("Bearbeiten");
|
Button editBtn = new Button("Bearbeiten");
|
||||||
editBtn.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;");
|
editBtn.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;");
|
||||||
editBtn.setOnAction(e -> {
|
editBtn.setOnAction(e -> {
|
||||||
Flight selectedFlight = table.getSelectionModel().getSelectedItem();
|
Flight selectedFlight = table.getSelectionModel().getSelectedItem();
|
||||||
if (selectedFlight != null) {
|
controller.editFlight(selectedFlight);
|
||||||
new EditFlightScreen(stage, selectedFlight).display();
|
|
||||||
} else {
|
|
||||||
showAlert("Fehler", "Bitte wählen Sie einen Flug aus.");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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;");
|
||||||
backButton.setOnAction(e -> new HomeScreen(stage).display());
|
backButton.setOnAction(e -> controller.goBack());
|
||||||
|
|
||||||
VBox vbox = new VBox(20, label, table, editBtn, backButton);
|
VBox vbox = new VBox(20, label, table, editBtn, backButton);
|
||||||
vbox.setAlignment(Pos.CENTER);
|
vbox.setAlignment(Pos.CENTER);
|
||||||
|
|
@ -102,12 +92,4 @@ public class ViewLogbookScreen {
|
||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showAlert(String title, String message) {
|
|
||||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
|
||||||
alert.setTitle(title);
|
|
||||||
alert.setHeaderText(null);
|
|
||||||
alert.setContentText(message);
|
|
||||||
alert.showAndWait();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue