150 lines
6.0 KiB
Java
150 lines
6.0 KiB
Java
package views;
|
|
|
|
import controllers.AddFlightController;
|
|
import javafx.collections.ObservableList;
|
|
import javafx.geometry.Insets;
|
|
import javafx.geometry.Pos;
|
|
import javafx.scene.Scene;
|
|
import javafx.scene.control.*;
|
|
import javafx.scene.layout.GridPane;
|
|
import javafx.scene.layout.HBox;
|
|
import javafx.scene.layout.VBox;
|
|
import javafx.stage.Stage;
|
|
import models.Flight;
|
|
import models.Pilot;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
public class AddFlightScreen {
|
|
private Stage stage;
|
|
private AddFlightController controller;
|
|
|
|
public AddFlightScreen(Stage stage) {
|
|
this.stage = stage;
|
|
this.controller = new AddFlightController(stage);
|
|
}
|
|
|
|
public void display() {
|
|
Label label = new Label("Flugdaten eingeben:");
|
|
label.setStyle("-fx-font-size: 18px; -fx-font-weight: bold;");
|
|
|
|
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");
|
|
|
|
Label abflugortLabel = new Label("Abflugort:");
|
|
TextField abflugortField = new TextField();
|
|
abflugortField.setPromptText("Abflugort");
|
|
|
|
Label abflugzeitLabel = new Label("Abflugzeit:");
|
|
TextField abflugzeitField = new TextField();
|
|
abflugzeitField.setPromptText("HH:mm");
|
|
|
|
Label ankunftszeitLabel = new Label("Ankunftszeit:");
|
|
TextField ankunftszeitField = new TextField();
|
|
ankunftszeitField.setPromptText("HH:mm");
|
|
|
|
Label tToFLabel = new Label("Flugdauer (Stunden):");
|
|
TextField tToFField = new TextField();
|
|
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");
|
|
|
|
Label nachtflugLabel = new Label("Nachtflug:");
|
|
CheckBox nachtflugBox = new CheckBox();
|
|
|
|
Label kommentarLabel = new Label("Kommentar:");
|
|
TextField kommentarField = new TextField();
|
|
kommentarField.setPromptText("Kommentar");
|
|
|
|
ObservableList<Pilot> pilotList = controller.loadPilots();
|
|
Label pilotLabel = new Label("Pilot:");
|
|
ComboBox<Pilot> pilotComboBox = new ComboBox<>(pilotList);
|
|
|
|
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);
|
|
});
|
|
|
|
Button backButton = new Button("Zurück");
|
|
backButton.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;");
|
|
backButton.setOnAction(e -> new HomeScreen(stage).display());
|
|
|
|
// Add listeners to the time fields to update the flight duration automatically
|
|
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.setPadding(new Insets(20));
|
|
vbox.setStyle("-fx-background-color: #E6F2FF;");
|
|
|
|
Scene scene = new Scene(vbox, 800, 600);
|
|
scene.getStylesheets().add(getClass().getResource("/resources/styles.css").toExternalForm());
|
|
|
|
stage.setScene(scene);
|
|
stage.show();
|
|
}
|
|
|
|
private void updateFlightDuration(TextField abflugzeitField, TextField ankunftszeitField, TextField tToFField) {
|
|
String abflugzeit = abflugzeitField.getText();
|
|
String ankunftszeit = ankunftszeitField.getText();
|
|
|
|
if (controller.isValidTime(abflugzeit) && controller.isValidTime(ankunftszeit)) {
|
|
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("");
|
|
}
|
|
}
|
|
}
|