diff --git a/Pegasus b/Pegasus new file mode 160000 index 0000000..489ea74 --- /dev/null +++ b/Pegasus @@ -0,0 +1 @@ +Subproject commit 489ea74b7a7a3b9f156fd899a1015e63e77b4f2f diff --git a/bin/controllers/AddFlightController.class b/bin/controllers/AddFlightController.class index d83822d..d8dc47d 100644 Binary files a/bin/controllers/AddFlightController.class and b/bin/controllers/AddFlightController.class differ diff --git a/bin/controllers/DeletePilotController.class b/bin/controllers/DeletePilotController.class new file mode 100644 index 0000000..e2997b8 Binary files /dev/null and b/bin/controllers/DeletePilotController.class differ diff --git a/bin/controllers/FlightController.class b/bin/controllers/FlightController.class deleted file mode 100644 index 43dc06a..0000000 Binary files a/bin/controllers/FlightController.class and /dev/null differ diff --git a/bin/controllers/LogbookController.class b/bin/controllers/LogbookController.class index 73380b2..bb6b17c 100644 Binary files a/bin/controllers/LogbookController.class and b/bin/controllers/LogbookController.class differ diff --git a/bin/controllers/ManagePilotProfileController.class b/bin/controllers/ManagePilotProfileController.class new file mode 100644 index 0000000..a658357 Binary files /dev/null and b/bin/controllers/ManagePilotProfileController.class differ diff --git a/bin/controllers/PilotController.class b/bin/controllers/PilotController.class deleted file mode 100644 index ee8b650..0000000 Binary files a/bin/controllers/PilotController.class and /dev/null differ diff --git a/bin/models/Flight.class b/bin/models/Flight.class index d365ae0..7afafe4 100644 Binary files a/bin/models/Flight.class and b/bin/models/Flight.class differ diff --git a/bin/models/Flights.class b/bin/models/Flights.class index 2f55ca3..68304fb 100644 Binary files a/bin/models/Flights.class and b/bin/models/Flights.class differ diff --git a/bin/utils/XMLHelper.class b/bin/utils/XMLHelper.class index 4f4f511..6dcd31a 100644 Binary files a/bin/utils/XMLHelper.class and b/bin/utils/XMLHelper.class differ diff --git a/bin/views/AddFlightScreen.class b/bin/views/AddFlightScreen.class index 57928db..31b0db3 100644 Binary files a/bin/views/AddFlightScreen.class and b/bin/views/AddFlightScreen.class differ diff --git a/bin/views/DeletePilotScreen.class b/bin/views/DeletePilotScreen.class index e660159..04fa178 100644 Binary files a/bin/views/DeletePilotScreen.class and b/bin/views/DeletePilotScreen.class differ diff --git a/bin/views/EditFlightScreen.class b/bin/views/EditFlightScreen.class deleted file mode 100644 index 1de65f9..0000000 Binary files a/bin/views/EditFlightScreen.class and /dev/null differ diff --git a/bin/views/FlightView.class b/bin/views/FlightView.class deleted file mode 100644 index a8b88b9..0000000 Binary files a/bin/views/FlightView.class and /dev/null differ diff --git a/bin/views/HomeScreen.class b/bin/views/HomeScreen.class index 91a52f9..3efe2bd 100644 Binary files a/bin/views/HomeScreen.class and b/bin/views/HomeScreen.class differ diff --git a/bin/views/ManagePilotProfileScreen.class b/bin/views/ManagePilotProfileScreen.class index 943f243..5097e37 100644 Binary files a/bin/views/ManagePilotProfileScreen.class and b/bin/views/ManagePilotProfileScreen.class differ diff --git a/bin/views/PilotView.class b/bin/views/PilotView.class deleted file mode 100644 index 40c74d6..0000000 Binary files a/bin/views/PilotView.class and /dev/null differ diff --git a/bin/views/ViewLogbookScreen.class b/bin/views/ViewLogbookScreen.class index 826879f..53a44d2 100644 Binary files a/bin/views/ViewLogbookScreen.class and b/bin/views/ViewLogbookScreen.class differ diff --git a/flights.xml b/flights.xml index 577780f..acc82e1 100644 --- a/flights.xml +++ b/flights.xml @@ -1,11 +1,11 @@ - + - 2.0 + 1.0 123 @@ -14,132 +14,39 @@ 12:00 - 14:00 + 13:00 - 2 + 12 - 2024-06-10 + 2024-06-17 asd - asdasd - - - - - sad - - - ads - - - sad - - - - - - - - - 1.0 - - - test - - - 11:00 - - - 12:00 - - - 2 - - - 2024-06-11 - - asd - - test - - sad + asd - ads + asd - äää - - - äää + dasd - sad - - - - - - - - - 6.75 - - - max - - - 09:15 - - - 16:00 - - - 2 - - - 2024-06-14 - - - Kommentar - - - Max - - - - - max - - - max - - - - hallo - - - test - - - - max + asdaa - test + asdasd @@ -152,7 +59,7 @@ 1.0 - mannheim + 12322 12:00 @@ -164,39 +71,84 @@ 1 - 2024-06-14 + 2024-06-17 - max + asd - newTest + asdtest - - true + + + + asd + + + asd + + + + dasd + + + + asdaa + + + + asdasd + + + + + + + + + + 1.0 + + + 12322 + + + 12:00 + + + 13:00 + + + 1 + + + 2024-06-17 + + + asd + + + asdtest - max + asd - max + asd - hallo - - - test + dasd - max + asdaa - test + asdasd diff --git a/pilots.xml b/pilots.xml index d645733..3c70075 100644 --- a/pilots.xml +++ b/pilots.xml @@ -1,77 +1,53 @@ - + - sad + asd - ads + asd - sad - - - - - - - asdasd - - - asdasd - - - sad + asd - sad + asd - ads + asd - äää - - - äää + dasd - sad + asdaa + + + + asdasd + - + - max + s - max - - - - hallo - - - test - + d - max - - - - test - + a diff --git a/src/controllers/AddFlightController.java b/src/controllers/AddFlightController.java index 682d2df..2fa5518 100644 --- a/src/controllers/AddFlightController.java +++ b/src/controllers/AddFlightController.java @@ -19,11 +19,13 @@ import java.util.ArrayList; import java.util.List; public class AddFlightController { + private Flights flights; private Stage stage; private DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm"); public AddFlightController(Stage stage) { this.stage = stage; + loadFlights(); } public ObservableList loadPilots() { @@ -74,6 +76,27 @@ public class AddFlightController { } } + public void saveFlight(Flight flight){ + if(flights == null){ + flights = new Flights(new ArrayList<>()); + } + + boolean flightExists = false; + for (int i = 0; i < flights.getFlights().size(); i++) { + if (flights.getFlights().get(i).getMuster().equals(flight.getMuster())) { + flights.getFlights().set(i, flight); + flightExists = true; + break; + } + } + + if (!flightExists) { + flights.getFlights().add(flight); + } + + XMLHelper.saveToXML(flights, "flights.xml"); + } + public double calculateFlightDuration(String abflugzeit, String ankunftszeit) throws DateTimeParseException { LocalTime start = LocalTime.parse(abflugzeit, timeFormatter); LocalTime end = LocalTime.parse(ankunftszeit, timeFormatter); @@ -93,12 +116,7 @@ public class AddFlightController { 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); @@ -106,4 +124,8 @@ public class AddFlightController { alert.setContentText(message); alert.showAndWait(); } + + public void loadFlights() { + flights = (Flights) XMLHelper.loadFromXML("flights.xml"); + } } diff --git a/src/controllers/DeletePilotController.java b/src/controllers/DeletePilotController.java new file mode 100644 index 0000000..daf9b4f --- /dev/null +++ b/src/controllers/DeletePilotController.java @@ -0,0 +1,42 @@ +package controllers; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import models.Pilot; +import models.Pilots; +import utils.XMLHelper; + +import java.util.List; + +public class DeletePilotController { + private ObservableList pilotsList; + + public DeletePilotController() { + loadPilots(); + } + + public ObservableList getPilotsList() { + return pilotsList; + } + + public void loadPilots() { + Pilots pilotsData = (Pilots) XMLHelper.loadFromXML("pilots.xml"); + List pilotList = pilotsData != null ? pilotsData.getPilots() : new java.util.ArrayList<>(); + pilotsList = FXCollections.observableArrayList(pilotList); + } + + public boolean deletePilot(Pilot pilot) { + if (pilot != null) { + // Create a new list to avoid modifying the observable list directly + List updatedList = new java.util.ArrayList<>(pilotsList); + // Remove the selected pilot from the list + updatedList.remove(pilot); + // Save the updated list back to the XML file + XMLHelper.saveToXML(new Pilots(updatedList), "pilots.xml"); + // Reload the pilots list to update the observable list + loadPilots(); + return true; + } + return false; + } +} diff --git a/src/controllers/FlightController.java b/src/controllers/FlightController.java deleted file mode 100644 index c640bf5..0000000 --- a/src/controllers/FlightController.java +++ /dev/null @@ -1,46 +0,0 @@ -package controllers; - -import java.time.Duration; -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; - -import javafx.scene.control.Alert; -import javafx.scene.control.Control; - -public class FlightController { - private DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm"); - - 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(); - } -} diff --git a/src/controllers/LogbookController.java b/src/controllers/LogbookController.java index bff54f0..797509d 100644 --- a/src/controllers/LogbookController.java +++ b/src/controllers/LogbookController.java @@ -6,10 +6,8 @@ import javafx.stage.Stage; import models.Flight; import models.Flights; import utils.XMLHelper; -import views.EditFlightScreen; import views.HomeScreen; - -import java.util.List; +import views.ViewLogbookScreen; public class LogbookController { private Stage stage; @@ -17,7 +15,6 @@ public class LogbookController { public LogbookController(Stage stage) { this.stage = stage; - this.flightList = FXCollections.observableArrayList(); loadFlights(); } @@ -28,28 +25,34 @@ public class LogbookController { private void loadFlights() { Flights flights = (Flights) XMLHelper.loadFromXML("flights.xml"); if (flights != null) { - List flightEntries = flights.getFlights(); - flightList.addAll(flightEntries); + flightList = FXCollections.observableArrayList(flights.getFlights()); + } else { + flightList = FXCollections.observableArrayList(); } } - 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 editFlight(Flight flight) { + if (flight != null) { + new EditFlightScreen(stage, flight, this).display(); } + } */ + + public void updateFlight(Flight updatedFlight) { + for (int i = 0; i < flightList.size(); i++) { + if (flightList.get(i).getId().equals(updatedFlight.getId())) { + flightList.set(i, updatedFlight); + break; + } + } + saveFlights(); + } + + private void saveFlights() { + Flights flights = new Flights(flightList); + XMLHelper.saveToXML(flights, "flights.xml"); } 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(); - } } diff --git a/src/controllers/ManagePilotProfileController.java b/src/controllers/ManagePilotProfileController.java new file mode 100644 index 0000000..3092004 --- /dev/null +++ b/src/controllers/ManagePilotProfileController.java @@ -0,0 +1,56 @@ +package controllers; + +import models.Pilot; +import models.Pilots; +import utils.XMLHelper; + +import java.util.ArrayList; +import java.util.List; + +public class ManagePilotProfileController { + private Pilots pilots; + + public ManagePilotProfileController() { + loadPilots(); + } + + public List getPilotsList() { + return pilots != null ? pilots.getPilots() : new ArrayList<>(); + } + + public Pilot getPilot(String name) { + if (pilots != null) { + for (Pilot pilot : pilots.getPilots()) { + if (pilot.getName().equals(name)) { + return pilot; + } + } + } + return null; + } + + public void savePilot(Pilot pilot) throws Exception { + if (pilots == null) { + pilots = new Pilots(new ArrayList<>()); + } + + boolean pilotExists = false; + for (int i = 0; i < pilots.getPilots().size(); i++) { + if (pilots.getPilots().get(i).getName().equals(pilot.getName())) { + pilots.getPilots().set(i, pilot); + pilotExists = true; + break; + } + } + + if (!pilotExists) { + pilots.getPilots().add(pilot); + } + + XMLHelper.saveToXML(pilots, "pilots.xml"); + } + + public void loadPilots() { + pilots = (Pilots) XMLHelper.loadFromXML("pilots.xml"); + } +} diff --git a/src/controllers/PilotController.java b/src/controllers/PilotController.java deleted file mode 100644 index 6db6a12..0000000 --- a/src/controllers/PilotController.java +++ /dev/null @@ -1,26 +0,0 @@ -package controllers; - -import models.Pilot; -import views.PilotView; - -public class PilotController { - private Pilot model; - private PilotView view; - - public PilotController(Pilot model, PilotView view) { - this.model = model; - this.view = view; - } - - public void setPilotName(String name) { - model.setName(name); - } - - public String getPilotName() { - return model.getName(); - } - - public void updateView() { - view.displayPilotDetails(model); - } -} diff --git a/src/models/Flight.java b/src/models/Flight.java index 1fd8a10..b7bd469 100644 --- a/src/models/Flight.java +++ b/src/models/Flight.java @@ -6,11 +6,13 @@ import java.io.ObjectOutputStream; import java.io.Serializable; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.util.UUID; import javafx.beans.property.*; public class Flight implements Serializable { private static final long serialVersionUID = 1L; + private String id; // Neue ID für jeden Flug private String datumStr; // String zur Speicherung des Datums in XML private transient ObjectProperty datum; // transient, um die direkte Serialization zu vermeiden private StringProperty muster; @@ -27,6 +29,7 @@ public class Flight implements Serializable { // Standardkonstruktor public Flight() { + this.id = UUID.randomUUID().toString(); // Generiere eine eindeutige ID this.datum = new SimpleObjectProperty<>(); this.muster = new SimpleStringProperty(); this.abflugort = new SimpleStringProperty(); @@ -39,18 +42,10 @@ public class Flight implements Serializable { 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); + // Getter und Setter Methoden + + public String getId() { + return id; } public LocalDate getDatum() { @@ -62,17 +57,17 @@ public class Flight implements Serializable { this.datumStr = datum != null ? datum.format(formatter) : null; } - public ObjectProperty 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); + this.datum = datumStr != null ? new SimpleObjectProperty<>(LocalDate.parse(datumStr, formatter)) : new SimpleObjectProperty<>(); + } + + public ObjectProperty datumProperty() { + return datum; } public String getMuster() { @@ -194,17 +189,13 @@ public class Flight implements Serializable { // Custom Serialization private void writeObject(ObjectOutputStream oos) throws IOException { oos.defaultWriteObject(); - oos.writeObject(datum.get() != null ? datum.get().format(formatter) : null); + oos.writeObject(datumStr); } // 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<>(); - } + datumStr = (String) ois.readObject(); + datum = datumStr != null ? new SimpleObjectProperty<>(LocalDate.parse(datumStr, formatter)) : new SimpleObjectProperty<>(); } } diff --git a/src/models/Flights.java b/src/models/Flights.java index 9b5a722..42006f6 100644 --- a/src/models/Flights.java +++ b/src/models/Flights.java @@ -8,7 +8,7 @@ public class Flights implements Serializable { private List flights; public Flights() { - this.flights = new ArrayList<>(); + flights = new ArrayList<>(); } public Flights(List flights) { @@ -22,4 +22,20 @@ public class Flights implements Serializable { public void setFlights(List flights) { this.flights = flights; } + + public void addFlight(Flight flight) { + flights.add(flight); + } + + public int size() { + return flights.size(); + } + + public Flight get(int index) { + return flights.get(index); + } + + public void set(int index, Flight flight) { + flights.set(index, flight); + } } diff --git a/src/utils/XMLHelper.java b/src/utils/XMLHelper.java index d311ceb..9c6c66d 100644 --- a/src/utils/XMLHelper.java +++ b/src/utils/XMLHelper.java @@ -4,8 +4,22 @@ import java.beans.XMLDecoder; import java.beans.XMLEncoder; import java.io.*; +import models.Flight; +import models.Flights; + public class XMLHelper { + private static final String FLIGHTS_XML = "flights.xml"; + + /* public static Flights loadFlights() { + // Implement loading flights from XML + return (Flights) loadFromXML(FLIGHTS_XML); + } + + public static void saveFlights(Flights flights) { + saveToXML(flights, FLIGHTS_XML); + } */ + public static void saveToXML(Object obj, String filePath) { try (XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(filePath)))) { encoder.writeObject(obj); diff --git a/src/views/AddFlightScreen.java b/src/views/AddFlightScreen.java index ed790ed..6c144cc 100644 --- a/src/views/AddFlightScreen.java +++ b/src/views/AddFlightScreen.java @@ -11,16 +11,33 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; import models.Flight; +import models.Flights; import models.Pilot; +import utils.XMLHelper; import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; public class AddFlightScreen { private Stage stage; private AddFlightController controller; + private Flight flight; + + private DatePicker datumField; + private TextField musterField; + private TextField abflugortField; + private TextField abflugzeitField; + private TextField ankunftszeitField; + private TextField tToFField; + private TextField anzahlLandungenField; + private CheckBox nachtflugBox; + private TextField kommentarField; + private ComboBox pilotComboBox; - public AddFlightScreen(Stage stage) { + public AddFlightScreen(Stage stage, Flight flight) { this.stage = stage; + this.flight = flight; this.controller = new AddFlightController(stage); } @@ -29,54 +46,49 @@ public class AddFlightScreen { 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 + datumField = new DatePicker(LocalDate.now()); Label musterLabel = new Label("Muster:"); - TextField musterField = new TextField(); + musterField = new TextField(); musterField.setPromptText("Muster"); Label abflugortLabel = new Label("Abflugort:"); - TextField abflugortField = new TextField(); + abflugortField = new TextField(); abflugortField.setPromptText("Abflugort"); Label abflugzeitLabel = new Label("Abflugzeit:"); - TextField abflugzeitField = new TextField(); + abflugzeitField = new TextField(); abflugzeitField.setPromptText("HH:mm"); Label ankunftszeitLabel = new Label("Ankunftszeit:"); - TextField ankunftszeitField = new TextField(); + ankunftszeitField = new TextField(); ankunftszeitField.setPromptText("HH:mm"); Label tToFLabel = new Label("Flugdauer (Stunden):"); - TextField tToFField = new 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 = new TextField(); anzahlLandungenField.setPromptText("Anzahl der Landungen"); Label nachtflugLabel = new Label("Nachtflug:"); - CheckBox nachtflugBox = new CheckBox(); + nachtflugBox = new CheckBox(); Label kommentarLabel = new Label("Kommentar:"); - TextField kommentarField = new TextField(); + kommentarField = new TextField(); kommentarField.setPromptText("Kommentar"); ObservableList pilotList = controller.loadPilots(); Label pilotLabel = new Label("Pilot:"); - ComboBox pilotComboBox = new ComboBox<>(pilotList); + 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); - }); + saveBtn.setOnAction(e -> saveFlight(flight, datumField, musterField, abflugortField, abflugzeitField, + ankunftszeitField, tToFField, anzahlLandungenField, pilotComboBox, nachtflugBox, kommentarField));//todo: saveFlight in Controller Button backButton = new Button("Zurück"); backButton.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;"); @@ -128,6 +140,11 @@ public class AddFlightScreen { stage.setScene(scene); stage.show(); + + if (flight != null) { + populateFieldsWithFlight(flight); + } + } private void updateFlightDuration(TextField abflugzeitField, TextField ankunftszeitField, TextField tToFField) { @@ -146,4 +163,57 @@ public class AddFlightScreen { tToFField.setText(""); } } + + private void populateFieldsWithFlight(Flight flight) { + datumField.setValue(LocalDate.parse(flight.getDatumStr())); + musterField.setText(flight.getMuster()); + abflugortField.setText(flight.getAbflugort()); + abflugzeitField.setText(flight.getAbflugzeit()); + ankunftszeitField.setText(flight.getAnkunftszeit()); + tToFField.setText(Double.toString(flight.getTToF())); + anzahlLandungenField.setText(Integer.toString(flight.getAnzahlLandungen())); + nachtflugBox.setSelected(flight.isNachtflug()); + kommentarField.setText(flight.getKommentar()); + pilotComboBox.setValue(flight.getPilot()); + } + + private void saveFlight(Flight newFlight, DatePicker datumField, TextField musterField, TextField abflugortField, + TextField abflugzeitField, TextField ankunftszeitField, TextField tToFField, TextField anzahlLandungenField, + ComboBox 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)); + + controller.saveFlight(newFlight); + + 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 showAlert(String title, String message) { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle(title); + alert.setHeaderText(null); + alert.setContentText(message); + alert.showAndWait(); + } } diff --git a/src/views/DeletePilotScreen.java b/src/views/DeletePilotScreen.java index baf69fd..5438e1a 100644 --- a/src/views/DeletePilotScreen.java +++ b/src/views/DeletePilotScreen.java @@ -1,5 +1,6 @@ package views; +import controllers.DeletePilotController; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; @@ -11,35 +12,30 @@ import javafx.scene.layout.BorderPane; import javafx.scene.layout.VBox; import javafx.stage.Stage; import models.Pilot; -import models.Pilots; -import utils.XMLHelper; - -import java.util.List; public class DeletePilotScreen { private Stage stage; + private DeletePilotController controller; public DeletePilotScreen(Stage stage) { this.stage = stage; + this.controller = new DeletePilotController(); } public void display() { Label label = new Label("Piloten löschen"); label.setStyle("-fx-font-size: 18px; -fx-font-weight: bold;"); - Pilots pilotsData = (Pilots) XMLHelper.loadFromXML("pilots.xml"); - List pilotList = pilotsData != null ? pilotsData.getPilots() : new java.util.ArrayList<>(); - ComboBox pilotComboBox = new ComboBox<>(javafx.collections.FXCollections.observableArrayList(pilotList)); + ComboBox pilotComboBox = new ComboBox<>(controller.getPilotsList()); pilotComboBox.setPromptText("Pilot auswählen"); Button deleteBtn = new Button("Löschen"); deleteBtn.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;"); deleteBtn.setOnAction(e -> { Pilot selectedPilot = pilotComboBox.getValue(); - if (selectedPilot != null) { - pilotList.remove(selectedPilot); - XMLHelper.saveToXML(new Pilots(pilotList), "pilots.xml"); - new HomeScreen(stage).display(); + if (selectedPilot != null && controller.deletePilot(selectedPilot)) { + showAlert("Erfolg", "Der Pilot wurde erfolgreich gelöscht."); + pilotComboBox.setItems(controller.getPilotsList()); // Refresh the combo box } else { showAlert("Fehler", "Bitte wählen Sie einen Piloten aus."); } @@ -52,7 +48,6 @@ public class DeletePilotScreen { VBox vbox = new VBox(10, label, pilotComboBox, deleteBtn); vbox.setAlignment(Pos.CENTER); vbox.setPadding(new Insets(20)); - BorderPane borderPane = new BorderPane(); borderPane.setTop(backButton); @@ -68,7 +63,7 @@ public class DeletePilotScreen { } private void showAlert(String title, String message) { - Alert alert = new Alert(Alert.AlertType.ERROR); + Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle(title); alert.setHeaderText(null); alert.setContentText(message); diff --git a/src/views/EditFlightScreen.java b/src/views/EditFlightScreen.java deleted file mode 100644 index 0c3b638..0000000 --- a/src/views/EditFlightScreen.java +++ /dev/null @@ -1,178 +0,0 @@ -package views; - -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.util.List; - -public class EditFlightScreen { - private Stage stage; - private Flight flight; - - public EditFlightScreen(Stage stage, Flight flight) { - this.stage = stage; - this.flight = flight; - } - - public void display() { - Label label = new Label("Flugdaten bearbeiten:"); - label.setStyle("-fx-font-size: 18px; -fx-font-weight: bold;"); - DatePicker datumField = new DatePicker(flight.getDatum()); - TextField musterField = new TextField(flight.getMuster()); - TextField abflugortField = new TextField(flight.getAbflugort()); - TextField abflugzeitField = new TextField(flight.getAbflugzeit()); - TextField ankunftszeitField = new TextField(flight.getAnkunftszeit()); - TextField tToFField = new TextField(String.valueOf(flight.getTToF())); - TextField anzahlLandungenField = new TextField(String.valueOf(flight.getAnzahlLandungen())); - CheckBox nachtflugBox = new CheckBox("Nachtflug"); - nachtflugBox.setSelected(flight.isNachtflug()); - TextField kommentarField = new TextField(flight.getKommentar()); - - datumField.setPromptText("YYYY-MM-DD"); - musterField.setPromptText("Muster"); - abflugortField.setPromptText("Abflugort"); - abflugzeitField.setPromptText("HH:MM"); - ankunftszeitField.setPromptText("HH:MM"); - tToFField.setPromptText("Flugdauer (Stunden)"); - anzahlLandungenField.setPromptText("Anzahl der Landungen"); - kommentarField.setPromptText("Kommentar"); - - // Nur numerische Eingaben für Flugdauer und Anzahl der Landungen zulassen - tToFField.textProperty().addListener((observable, oldValue, newValue) -> { - if (!newValue.matches("\\d*\\.?\\d*")) { - tToFField.setText(oldValue); - } - }); - - anzahlLandungenField.textProperty().addListener((observable, oldValue, newValue) -> { - 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 -> handleSaveFlight(datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField, - tToFField, anzahlLandungenField, nachtflugBox.isSelected(), 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 ViewLogbookScreen(stage).display()); - - VBox vbox = new VBox(10, label, datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField, - tToFField, anzahlLandungenField, nachtflugBox, kommentarField, saveBtn); - vbox.setAlignment(Pos.CENTER); - vbox.setPadding(new Insets(20)); - - - BorderPane borderPane = new BorderPane(); - borderPane.setTop(backButton); - borderPane.setCenter(vbox); - BorderPane.setAlignment(backButton, Pos.TOP_LEFT); - BorderPane.setMargin(backButton, new Insets(10)); - - Scene scene = new Scene(borderPane, 800, 600); - scene.getStylesheets().add(getClass().getResource("/resources/styles.css").toExternalForm()); - - stage.setScene(scene); - stage.show(); - } - - private void handleSaveFlight(DatePicker datumField, TextField musterField, TextField abflugortField, TextField abflugzeitField, - TextField ankunftszeitField, TextField tToFField, TextField anzahlLandungenField, boolean isNachtflug, - TextField kommentarField) { - clearFieldStyles(datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField, tToFField, anzahlLandungenField); - - try { - if (datumField.getValue() == null) { - setErrorStyle(datumField); - throw new IllegalArgumentException("Datum ist erforderlich."); - } - if (musterField.getText().isEmpty()) { - setErrorStyle(musterField); - throw new IllegalArgumentException("Muster ist erforderlich."); - } - if (abflugortField.getText().isEmpty()) { - setErrorStyle(abflugortField); - throw new IllegalArgumentException("Abflugort ist erforderlich."); - } - if (abflugzeitField.getText().isEmpty()) { - setErrorStyle(abflugzeitField); - throw new IllegalArgumentException("Abflugzeit ist erforderlich."); - } - if (ankunftszeitField.getText().isEmpty()) { - setErrorStyle(ankunftszeitField); - throw new IllegalArgumentException("Ankunftszeit ist erforderlich."); - } - if (tToFField.getText().isEmpty()) { - setErrorStyle(tToFField); - throw new IllegalArgumentException("Flugdauer ist erforderlich."); - } - if (anzahlLandungenField.getText().isEmpty()) { - setErrorStyle(anzahlLandungenField); - throw new IllegalArgumentException("Anzahl der Landungen ist erforderlich."); - } - - double flightDuration = Double.parseDouble(tToFField.getText()); - int landings = Integer.parseInt(anzahlLandungenField.getText()); - - flight.setDatum(datumField.getValue()); - flight.setMuster(musterField.getText()); - flight.setAbflugort(abflugortField.getText()); - flight.setAbflugzeit(abflugzeitField.getText()); - flight.setAnkunftszeit(ankunftszeitField.getText()); - flight.setTToF(flightDuration); - flight.setAnzahlLandungen(landings); - flight.setNachtflug(isNachtflug); - flight.setKommentar(kommentarField.getText()); - - Flights flights = (Flights) XMLHelper.loadFromXML("flights.xml"); - if (flights != null) { - List flightEntries = flights.getFlights(); - for (int i = 0; i < flightEntries.size(); i++) { - if (flightEntries.get(i).equals(flight)) { - flightEntries.set(i, flight); - break; - } - } - XMLHelper.saveToXML(flights, "flights.xml"); - } - - new ViewLogbookScreen(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(); - } -} diff --git a/src/views/FlightView.java b/src/views/FlightView.java deleted file mode 100644 index 17b645e..0000000 --- a/src/views/FlightView.java +++ /dev/null @@ -1,27 +0,0 @@ -package views; - -import models.Flight; - -import java.util.List; - -public class FlightView { - public void displayFlightDetails(Flight flight) { - System.out.println("Flight Details: "); - System.out.println("Datum: " + flight.getDatum()); - System.out.println("Muster: " + flight.getMuster()); - System.out.println("Abflugort: " + flight.getAbflugort()); - System.out.println("Abflugzeit: " + flight.getAbflugzeit()); - System.out.println("Ankunftszeit: " + flight.getAnkunftszeit()); - System.out.println("Flugdauer: " + flight.getTToF()); - System.out.println("Anzahl der Landungen: " + flight.getAnzahlLandungen()); - System.out.println("Pilotinformationen: " + flight.getPilotInformationen()); - System.out.println("Nachtflug: " + (flight.isNachtflug() ? "Ja" : "Nein")); - System.out.println("Kommentar: " + flight.getKommentar()); - } - - public void displayAllFlights(List flights) { - for (Flight flight : flights) { - displayFlightDetails(flight); - } - } -} diff --git a/src/views/HomeScreen.java b/src/views/HomeScreen.java index ba2ebca..59b3e8f 100644 --- a/src/views/HomeScreen.java +++ b/src/views/HomeScreen.java @@ -36,7 +36,7 @@ public class HomeScreen { Button helpBtn = createHelpButton("/resources/icons/help_icon.png", "Hilfe anzeigen"); Button editPilotsBtn = createButton("Pilot bearbeiten", "/resources/icons/manage_pilot_icon.png", "Bearbeiten Sie ein Pilotenprofil"); - btn1.setOnAction(e -> new AddFlightScreen(stage).display()); + btn1.setOnAction(e -> new AddFlightScreen(stage, null).display()); btn2.setOnAction(e -> new ViewLogbookScreen(stage).display()); btn3.setOnAction(e -> new ManagePilotProfileScreen(stage).display()); btn4.setOnAction(e -> new DeletePilotScreen(stage).display()); @@ -44,7 +44,7 @@ public class HomeScreen { editPilotsBtn.setOnAction(e -> { Pilots pilots = (Pilots) XMLHelper.loadFromXML("pilots.xml"); if (pilots != null && !pilots.getPilots().isEmpty()) { - new ManagePilotProfileScreen(stage).displayEditSelection(pilots); // Aufruf mit Pilotenliste + new ManagePilotProfileScreen(stage).displayEditSelection(); // Aufruf mit Pilotenliste } else { showAlert("Keine Piloten", "Es sind keine Piloten zum Bearbeiten verfügbar."); } diff --git a/src/views/ManagePilotProfileScreen.java b/src/views/ManagePilotProfileScreen.java index 253c5b3..0c3c6d2 100644 --- a/src/views/ManagePilotProfileScreen.java +++ b/src/views/ManagePilotProfileScreen.java @@ -1,33 +1,35 @@ package views; +import controllers.ManagePilotProfileController; 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.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; import models.Pilot; -import models.Pilots; -import utils.XMLHelper; import java.util.ArrayList; public class ManagePilotProfileScreen { private Stage stage; + private ManagePilotProfileController controller; public ManagePilotProfileScreen(Stage stage) { this.stage = stage; + this.controller = new ManagePilotProfileController(); } public void display() { display(null); } - public void displayEditSelection(Pilots pilots) { + public void displayEditSelection() { Label label = new Label("Wählen Sie einen Piloten zum Bearbeiten aus:"); ComboBox pilotComboBox = new ComboBox<>(); - pilotComboBox.getItems().addAll(pilots.getPilots()); + pilotComboBox.getItems().addAll(controller.getPilotsList()); pilotComboBox.setPromptText("Pilot auswählen"); Button selectBtn = new Button("Auswählen"); @@ -46,7 +48,6 @@ public class ManagePilotProfileScreen { VBox vbox = new VBox(10, label, pilotComboBox, selectBtn); vbox.setAlignment(Pos.CENTER); vbox.setPadding(new Insets(20)); - BorderPane borderPane = new BorderPane(); borderPane.setTop(backButton); @@ -57,65 +58,69 @@ public class ManagePilotProfileScreen { Scene scene = new Scene(borderPane, 800, 600); scene.getStylesheets().add(getClass().getResource("/resources/styles.css").toExternalForm()); - stage.setScene(scene); stage.show(); } public void display(Pilot pilot) { - Label label = new Label(pilot == null ? "Pilotendaten eingeben:" : "Pilotendaten bearbeiten:"); - TextField nameField = new TextField(pilot != null ? pilot.getName() : ""); - TextField adresseField = new TextField(pilot != null ? pilot.getAdresse() : ""); - TextField kontaktinformationenField = new TextField(pilot != null ? pilot.getKontaktinformationen() : ""); - TextField lizenzField = new TextField(); - TextField zertifikatField = new TextField(); + Label label = new Label(pilot == null ? "Neuen Piloten anlegen" : "Pilotenprofil bearbeiten"); + label.setStyle("-fx-font-size: 18px; -fx-font-weight: bold;"); + TextField nameField = new TextField(); nameField.setPromptText("Name"); + TextField adresseField = new TextField(); adresseField.setPromptText("Adresse"); + TextField kontaktinformationenField = new TextField(); kontaktinformationenField.setPromptText("Kontaktinformationen"); - lizenzField.setPromptText("Neue Lizenz"); - zertifikatField.setPromptText("Neues Zertifikat"); - - ListView lizenzListView = new ListView<>(); - ListView zertifikatListView = new ListView<>(); if (pilot != null) { - lizenzListView.getItems().addAll(pilot.getLizenzen()); - zertifikatListView.getItems().addAll(pilot.getZertifikate()); + nameField.setText(pilot.getName()); + adresseField.setText(pilot.getAdresse()); + kontaktinformationenField.setText(pilot.getKontaktinformationen()); } - Button addLizenzBtn = new Button("Lizenz hinzufügen"); - addLizenzBtn.setOnAction(e -> { - if (!lizenzField.getText().isEmpty()) { - lizenzListView.getItems().add(lizenzField.getText()); + ListView lizenzListView = new ListView<>(); + lizenzListView.getItems().addAll(pilot != null ? pilot.getLizenzen() : new ArrayList<>()); + + TextField lizenzField = new TextField(); + lizenzField.setPromptText("Neue Lizenz hinzufügen"); + Button addLizenzButton = new Button("Hinzufügen"); + addLizenzButton.setOnAction(e -> { + String lizenz = lizenzField.getText(); + if (!lizenz.isEmpty()) { + lizenzListView.getItems().add(lizenz); lizenzField.clear(); } }); - Button addZertifikatBtn = new Button("Zertifikat hinzufügen"); - addZertifikatBtn.setOnAction(e -> { - if (!zertifikatField.getText().isEmpty()) { - zertifikatListView.getItems().add(zertifikatField.getText()); + ListView zertifikatListView = new ListView<>(); + zertifikatListView.getItems().addAll(pilot != null ? pilot.getZertifikate() : new ArrayList<>()); + + TextField zertifikatField = new TextField(); + zertifikatField.setPromptText("Neues Zertifikat hinzufügen"); + Button addZertifikatButton = new Button("Hinzufügen"); + addZertifikatButton.setOnAction(e -> { + String zertifikat = zertifikatField.getText(); + if (!zertifikat.isEmpty()) { + zertifikatListView.getItems().add(zertifikat); zertifikatField.clear(); } }); - Button submitBtn = new Button(pilot == null ? "Hinzufügen" : "Speichern"); - - submitBtn.setOnAction(e -> handleSaveProfile(pilot, nameField, adresseField, kontaktinformationenField, - lizenzListView, zertifikatListView)); - - Button viewPilotsBtn = new Button("Alle Piloten anzeigen"); - viewPilotsBtn.setOnAction(e -> new PilotView(stage).displayAllPilots()); + Button saveBtn = new Button("Speichern"); + saveBtn.setOnAction(e -> savePilot(pilot, nameField, adresseField, kontaktinformationenField, lizenzListView, zertifikatListView)); Button backButton = new Button("Zurück"); backButton.setOnAction(e -> new HomeScreen(stage).display()); - VBox vbox = new VBox(10, label, nameField, adresseField, kontaktinformationenField, lizenzField, addLizenzBtn, - lizenzListView, zertifikatField, addZertifikatBtn, zertifikatListView, submitBtn, viewPilotsBtn); + VBox lizenzBox = new VBox(10, new Label("Lizenzen"), lizenzListView, lizenzField, addLizenzButton); + lizenzBox.setAlignment(Pos.CENTER); + VBox zertifikatBox = new VBox(10, new Label("Zertifikate"), zertifikatListView, zertifikatField, addZertifikatButton); + zertifikatBox.setAlignment(Pos.CENTER); + + VBox vbox = new VBox(10, label, nameField, adresseField, kontaktinformationenField, lizenzBox, zertifikatBox, saveBtn); vbox.setAlignment(Pos.CENTER); vbox.setPadding(new Insets(20)); - BorderPane borderPane = new BorderPane(); borderPane.setTop(backButton); @@ -130,8 +135,8 @@ public class ManagePilotProfileScreen { stage.show(); } - private void handleSaveProfile(Pilot pilot, TextField nameField, TextField adresseField, - TextField kontaktinformationenField, ListView lizenzListView, ListView zertifikatListView) { + private void savePilot(Pilot pilot, TextField nameField, TextField adresseField, TextField kontaktinformationenField, + ListView lizenzListView, ListView zertifikatListView) { clearFieldStyles(nameField, adresseField, kontaktinformationenField); try { @@ -159,16 +164,7 @@ public class ManagePilotProfileScreen { pilot.setLizenzen(new ArrayList<>(lizenzListView.getItems())); pilot.setZertifikate(new ArrayList<>(zertifikatListView.getItems())); - Pilots pilots = (Pilots) XMLHelper.loadFromXML("pilots.xml"); - if (pilots == null) { - pilots = new Pilots(new ArrayList<>()); - } - - if (!pilots.getPilots().contains(pilot)) { - pilots.getPilots().add(pilot); - } - - XMLHelper.saveToXML(pilots, "pilots.xml"); + controller.savePilot(pilot); new HomeScreen(stage).display(); } catch (IllegalArgumentException e) { diff --git a/src/views/PilotView.java b/src/views/PilotView.java deleted file mode 100644 index 20ce787..0000000 --- a/src/views/PilotView.java +++ /dev/null @@ -1,83 +0,0 @@ -package views; - -import javafx.geometry.Insets; -import javafx.geometry.Pos; -import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.control.ScrollPane; -import javafx.scene.layout.BorderPane; -import javafx.scene.layout.VBox; -import javafx.stage.Stage; -import models.Pilot; -import models.Pilots; -import utils.XMLHelper; - -import java.util.List; - -public class PilotView { - private Stage stage; - - public PilotView(Stage stage) { - this.stage = stage; - } - - public void displayPilotDetails(Pilot pilot) { - Label nameLabel = new Label("Name: " + pilot.getName()); - Label adresseLabel = new Label("Adresse: " + pilot.getAdresse()); - Label kontaktLabel = new Label("Kontaktinformationen: " + pilot.getKontaktinformationen()); - Label lizenzenLabel = new Label("Lizenzen: " + String.join(", ", pilot.getLizenzen())); - Label zertifikateLabel = new Label("Zertifikate: " + String.join(", ", pilot.getZertifikate())); - - VBox vbox = new VBox(10, nameLabel, adresseLabel, kontaktLabel, lizenzenLabel, zertifikateLabel); - vbox.setAlignment(Pos.CENTER); - vbox.setPadding(new Insets(20)); - - - Button backButton = new Button("Zurück"); - backButton.setOnAction(e -> new HomeScreen(stage).display()); - - BorderPane borderPane = new BorderPane(); - borderPane.setTop(backButton); - borderPane.setCenter(vbox); - BorderPane.setAlignment(backButton, Pos.TOP_LEFT); - BorderPane.setMargin(backButton, new Insets(10)); - - Scene scene = new Scene(borderPane, 800, 600); // Fenstergröße angepasst - scene.getStylesheets().add(getClass().getResource("/resources/styles.css").toExternalForm()); - stage.setScene(scene); - stage.setTitle("Pilot Details"); - stage.show(); - } - - public void displayAllPilots() { - Pilots pilotsData = (Pilots) XMLHelper.loadFromXML("pilots.xml"); - List pilots = pilotsData != null ? pilotsData.getPilots() : List.of(); - - VBox vbox = new VBox(10); - vbox.setPadding(new Insets(20)); - - for (Pilot pilot : pilots) { - Label pilotLabel = new Label(pilot.getName()); - vbox.getChildren().add(pilotLabel); - } - - ScrollPane scrollPane = new ScrollPane(vbox); // ScrollPane hinzugefügt - scrollPane.setFitToWidth(true); - scrollPane.setFitToHeight(true); - - Button backButton = new Button("Zurück"); - backButton.setOnAction(e -> new HomeScreen(stage).display()); - - BorderPane borderPane = new BorderPane(); - borderPane.setTop(backButton); - borderPane.setCenter(scrollPane); // ScrollPane anstelle von VBox hinzugefügt - BorderPane.setAlignment(backButton, Pos.TOP_LEFT); - BorderPane.setMargin(backButton, new Insets(10)); - - Scene scene = new Scene(borderPane, 800, 600); // Fenstergröße angepasst - stage.setScene(scene); - stage.setTitle("Alle Piloten"); - stage.show(); - } -} diff --git a/src/views/ViewLogbookScreen.java b/src/views/ViewLogbookScreen.java index 39eb5cf..2a2623b 100644 --- a/src/views/ViewLogbookScreen.java +++ b/src/views/ViewLogbookScreen.java @@ -1,5 +1,6 @@ package views; +import controllers.AddFlightController; import controllers.LogbookController; import javafx.beans.property.SimpleStringProperty; import javafx.collections.ObservableList; @@ -18,6 +19,7 @@ import java.time.format.DateTimeFormatter; public class ViewLogbookScreen { private Stage stage; private LogbookController controller; + private AddFlightController addFlightController; public ViewLogbookScreen(Stage stage) { this.stage = stage; @@ -26,7 +28,8 @@ public class ViewLogbookScreen { 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';"); + 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;"); @@ -65,16 +68,31 @@ public class ViewLogbookScreen { TableColumn kommentarCol = new TableColumn<>("Kommentar"); kommentarCol.setCellValueFactory(cellData -> cellData.getValue().kommentarProperty()); - 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 flightList = controller.getFlightList(); 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(); + * controller.editFlight(selectedFlight); + * }); + */ + 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(); - controller.editFlight(selectedFlight); + if (selectedFlight != null) { + AddFlightScreen addFlightScreen = new AddFlightScreen(stage, selectedFlight); + addFlightScreen.display(); + } }); Button backButton = new Button("Zurück");