package views; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.BorderPane; import javafx.scene.layout.VBox; import javafx.stage.Stage; import models.Flight; import models.Flights; import utils.XMLHelper; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.List; public class ViewLogbookScreen { private Stage stage; public ViewLogbookScreen(Stage stage) { this.stage = stage; } public void display() { Label label = new Label("Fluglogbuch Pegasus"); label.setStyle("-fx-font-size: 32px; -fx-font-weight: bold; -fx-text-fill: #431EB9; -fx-font-family: 'Arial Black';"); TableView table = new TableView<>(); table.setStyle("-fx-font-weight: bold;"); TableColumn datumCol = new TableColumn<>("Datum"); datumCol.setCellValueFactory(cellData -> { LocalDate date = cellData.getValue().getDatum(); String formattedDate = date != null ? date.format(DateTimeFormatter.ISO_LOCAL_DATE) : ""; return new SimpleStringProperty(formattedDate); }); TableColumn musterCol = new TableColumn<>("Muster"); musterCol.setCellValueFactory(cellData -> cellData.getValue().musterProperty()); TableColumn abflugortCol = new TableColumn<>("Abflugort"); abflugortCol.setCellValueFactory(cellData -> cellData.getValue().abflugortProperty()); TableColumn abflugzeitCol = new TableColumn<>("Abflugzeit"); abflugzeitCol.setCellValueFactory(cellData -> cellData.getValue().abflugzeitProperty()); TableColumn ankunftszeitCol = new TableColumn<>("Ankunftszeit"); ankunftszeitCol.setCellValueFactory(cellData -> cellData.getValue().ankunftszeitProperty()); TableColumn tToFCol = new TableColumn<>("Flugdauer"); tToFCol.setCellValueFactory(cellData -> cellData.getValue().tToFProperty().asObject()); TableColumn anzahlLandungenCol = new TableColumn<>("Landungen"); anzahlLandungenCol.setCellValueFactory(cellData -> cellData.getValue().anzahlLandungenProperty().asObject()); TableColumn pilotCol = new TableColumn<>("Pilot"); pilotCol.setCellValueFactory(cellData -> cellData.getValue().pilotProperty().get().nameProperty()); TableColumn nachtflugCol = new TableColumn<>("Nachtflug"); nachtflugCol.setCellValueFactory(cellData -> cellData.getValue().nachtflugProperty().asObject()); TableColumn kommentarCol = new TableColumn<>("Kommentar"); kommentarCol.setCellValueFactory(cellData -> cellData.getValue().kommentarProperty()); table.getColumns().addAll(datumCol, musterCol, abflugortCol, abflugzeitCol, ankunftszeitCol, tToFCol, anzahlLandungenCol, pilotCol, nachtflugCol, kommentarCol); ObservableList flightList = FXCollections.observableArrayList(); Flights flights = (Flights) XMLHelper.loadFromXML("flights.xml"); if (flights != null) { List flightEntries = flights.getFlights(); flightList.addAll(flightEntries); } table.setItems(flightList); Button editBtn = new Button("Bearbeiten"); editBtn.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;"); editBtn.setOnAction(e -> { Flight selectedFlight = table.getSelectionModel().getSelectedItem(); if (selectedFlight != null) { new EditFlightScreen(stage, selectedFlight).display(); } else { showAlert("Fehler", "Bitte wählen Sie einen Flug aus."); } }); 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()); VBox vbox = new VBox(20, label, table, editBtn, backButton); 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 showAlert(String title, String message) { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle(title); alert.setHeaderText(null); alert.setContentText(message); alert.showAndWait(); } }