diff --git a/bin/models/Flight.class b/bin/models/Flight.class index d950f4a..807295d 100644 Binary files a/bin/models/Flight.class and b/bin/models/Flight.class differ diff --git a/bin/models/Pilot.class b/bin/models/Pilot.class index 9120ee5..e7b148f 100644 Binary files a/bin/models/Pilot.class and b/bin/models/Pilot.class differ diff --git a/bin/resources/icons/add_flight_icon.png b/bin/resources/icons/add_flight_icon.png index b07165d..dcb3d13 100644 Binary files a/bin/resources/icons/add_flight_icon.png and b/bin/resources/icons/add_flight_icon.png differ diff --git a/bin/resources/icons/delete_pilot_icon.png b/bin/resources/icons/delete_pilot_icon.png new file mode 100644 index 0000000..85f631a Binary files /dev/null and b/bin/resources/icons/delete_pilot_icon.png differ diff --git a/bin/resources/icons/edit_pilot_icon.png b/bin/resources/icons/edit_pilot_icon.png index 4f1c58d..80047f0 100644 Binary files a/bin/resources/icons/edit_pilot_icon.png and b/bin/resources/icons/edit_pilot_icon.png differ diff --git a/bin/resources/icons/help_icon.png b/bin/resources/icons/help_icon.png index 1dc79db..a697ea3 100644 Binary files a/bin/resources/icons/help_icon.png and b/bin/resources/icons/help_icon.png differ diff --git a/bin/resources/icons/manage_pilot_icon.png b/bin/resources/icons/manage_pilot_icon.png index 3cfe195..3189973 100644 Binary files a/bin/resources/icons/manage_pilot_icon.png and b/bin/resources/icons/manage_pilot_icon.png differ diff --git a/bin/resources/icons/view_logbook_icon.png b/bin/resources/icons/view_logbook_icon.png index ef5f13d..3050fbc 100644 Binary files a/bin/resources/icons/view_logbook_icon.png and b/bin/resources/icons/view_logbook_icon.png differ diff --git a/bin/resources/icons/view_pilot_icon.png b/bin/resources/icons/view_pilot_icon.png index 1ec354d..e24f4e2 100644 Binary files a/bin/resources/icons/view_pilot_icon.png and b/bin/resources/icons/view_pilot_icon.png differ diff --git a/bin/resources/styles.css b/bin/resources/styles.css new file mode 100644 index 0000000..6dcbb1c --- /dev/null +++ b/bin/resources/styles.css @@ -0,0 +1,22 @@ +.root { + -fx-font-family: 'Arial'; +} + +.button { + -fx-background-color: #000000; + -fx-text-fill: #FFFFFF; + -fx-font-size: 14px; + -fx-font-weight: bold; + -fx-pref-height: 40px; + -fx-pref-width: 200px; +} + +.label { + -fx-font-size: 14px; + -fx-font-weight: bold; +} + +.text-field, .date-picker, .combo-box { + -fx-pref-height: 30px; + -fx-pref-width: 250px; +} diff --git a/bin/utils/XMLHelper.class b/bin/utils/XMLHelper.class index 9f1fd64..4f4f511 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 dd69aea..bd42181 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 new file mode 100644 index 0000000..53c2289 Binary files /dev/null and b/bin/views/DeletePilotScreen.class differ diff --git a/bin/views/EditFlightScreen.class b/bin/views/EditFlightScreen.class new file mode 100644 index 0000000..0e6714b Binary files /dev/null and b/bin/views/EditFlightScreen.class differ diff --git a/bin/views/HelpScreen.class b/bin/views/HelpScreen.class index c288955..9e6b3ab 100644 Binary files a/bin/views/HelpScreen.class and b/bin/views/HelpScreen.class differ diff --git a/bin/views/HomeScreen.class b/bin/views/HomeScreen.class index ce05461..6ba4a86 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 e833e49..656ab6a 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 index e2271b0..db9216a 100644 Binary files a/bin/views/PilotView.class and b/bin/views/PilotView.class differ diff --git a/bin/views/ViewLogbookScreen.class b/bin/views/ViewLogbookScreen.class index f3bca7e..6daa3f3 100644 Binary files a/bin/views/ViewLogbookScreen.class and b/bin/views/ViewLogbookScreen.class differ diff --git a/flights.xml b/flights.xml index f17462e..0090274 100644 --- a/flights.xml +++ b/flights.xml @@ -185,6 +185,102 @@ + + + + 123.0 + + + asd + + + dsa + + + asda + + + 12 + + + 123 + + + asda + + + + + asdasdasd + + + asdasd + + + + 124312 + + + + asdasd + + + + asd + + + + + + + + + + 1.0 + + + ea + + + 11:00 + + + 12:30 + + + 2 + + + lol + + + test + + + + + asdasdasd + + + asdasd + + + + 124312 + + + + asdasd + + + + asd + + + + + + diff --git a/pilots.xml b/pilots.xml index 71cd69f..fca6cd6 100644 --- a/pilots.xml +++ b/pilots.xml @@ -5,49 +5,14 @@ - asd + sad - 23 - - - asd - - - - - - - asd - - - asd - - - - asd - - - ss - - - ddas - + ads sad - - - asd - - - asd - - - eee - - diff --git a/src/models/Flight.java b/src/models/Flight.java index ec52679..c9c96d6 100644 --- a/src/models/Flight.java +++ b/src/models/Flight.java @@ -1,121 +1,184 @@ package models; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.io.Serializable; import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import javafx.beans.property.*; public class Flight implements Serializable { private static final long serialVersionUID = 1L; - private LocalDate datum; - private String muster; - private String abflugort; - private String abflugzeit; - private String ankunftszeit; - private double tToF; // Flugdauer in Stunden - private int anzahlLandungen; - private Pilot pilot; - private boolean isNachtflug; - private String kommentar; + private transient ObjectProperty datum; + private String datumStr; + private StringProperty muster; + private StringProperty abflugort; + private StringProperty abflugzeit; + private StringProperty ankunftszeit; + private DoubleProperty tToF; + private IntegerProperty anzahlLandungen; + private ObjectProperty pilot; + private BooleanProperty nachtflug; + private StringProperty kommentar; + // Standardkonstruktor public Flight() { + this.datum = new SimpleObjectProperty<>(); + this.muster = new SimpleStringProperty(); + this.abflugort = new SimpleStringProperty(); + this.abflugzeit = new SimpleStringProperty(); + this.ankunftszeit = new SimpleStringProperty(); + this.tToF = new SimpleDoubleProperty(); + this.anzahlLandungen = new SimpleIntegerProperty(); + this.pilot = new SimpleObjectProperty<>(); + this.nachtflug = new SimpleBooleanProperty(); + this.kommentar = new SimpleStringProperty(); } - public Flight(LocalDate datum, String muster, String abflugort, String abflugzeit, String ankunftszeit, double tToF, - int anzahlLandungen, Pilot pilot, boolean isNachtflug, String kommentar) { - this.datum = datum; - this.muster = muster; - this.abflugort = abflugort; - this.abflugzeit = abflugzeit; - this.ankunftszeit = ankunftszeit; - this.tToF = tToF; - this.anzahlLandungen = anzahlLandungen; - this.pilot = pilot; - this.isNachtflug = isNachtflug; - this.kommentar = kommentar; + public Flight(LocalDate datum, String muster, String abflugort, String abflugzeit, String ankunftszeit, double tToF, int anzahlLandungen, Pilot pilot, boolean nachtflug, String kommentar) { + this.datum = new SimpleObjectProperty<>(datum); + this.datumStr = datum.format(DateTimeFormatter.ISO_LOCAL_DATE); + this.muster = new SimpleStringProperty(muster); + this.abflugort = new SimpleStringProperty(abflugort); + this.abflugzeit = new SimpleStringProperty(abflugzeit); + this.ankunftszeit = new SimpleStringProperty(ankunftszeit); + this.tToF = new SimpleDoubleProperty(tToF); + this.anzahlLandungen = new SimpleIntegerProperty(anzahlLandungen); + this.pilot = new SimpleObjectProperty<>(pilot); + this.nachtflug = new SimpleBooleanProperty(nachtflug); + this.kommentar = new SimpleStringProperty(kommentar); } - // Getter und Setter für alle Felder public LocalDate getDatum() { - return datum; + return datum.get(); } public void setDatum(LocalDate datum) { - this.datum = datum; + this.datum.set(datum); + this.datumStr = datum.format(DateTimeFormatter.ISO_LOCAL_DATE); + } + + public ObjectProperty datumProperty() { + return datum; } public String getMuster() { - return muster; + return muster.get(); } public void setMuster(String muster) { - this.muster = muster; + this.muster.set(muster); + } + + public StringProperty musterProperty() { + return muster; } public String getAbflugort() { - return abflugort; + return abflugort.get(); } public void setAbflugort(String abflugort) { - this.abflugort = abflugort; + this.abflugort.set(abflugort); + } + + public StringProperty abflugortProperty() { + return abflugort; } public String getAbflugzeit() { - return abflugzeit; + return abflugzeit.get(); } public void setAbflugzeit(String abflugzeit) { - this.abflugzeit = abflugzeit; + this.abflugzeit.set(abflugzeit); + } + + public StringProperty abflugzeitProperty() { + return abflugzeit; } public String getAnkunftszeit() { - return ankunftszeit; + return ankunftszeit.get(); } public void setAnkunftszeit(String ankunftszeit) { - this.ankunftszeit = ankunftszeit; + this.ankunftszeit.set(ankunftszeit); + } + + public StringProperty ankunftszeitProperty() { + return ankunftszeit; } public double getTToF() { - return tToF; + return tToF.get(); } public void setTToF(double tToF) { - this.tToF = tToF; + this.tToF.set(tToF); + } + + public DoubleProperty tToFProperty() { + return tToF; } public int getAnzahlLandungen() { - return anzahlLandungen; + return anzahlLandungen.get(); } public void setAnzahlLandungen(int anzahlLandungen) { - this.anzahlLandungen = anzahlLandungen; + this.anzahlLandungen.set(anzahlLandungen); + } + + public IntegerProperty anzahlLandungenProperty() { + return anzahlLandungen; } public Pilot getPilot() { - return pilot; + return pilot.get(); } public void setPilot(Pilot pilot) { - this.pilot = pilot; + this.pilot.set(pilot); + } + + public ObjectProperty pilotProperty() { + return pilot; } public boolean isNachtflug() { - return isNachtflug; + return nachtflug.get(); } public void setNachtflug(boolean nachtflug) { - isNachtflug = nachtflug; + this.nachtflug.set(nachtflug); + } + + public BooleanProperty nachtflugProperty() { + return nachtflug; } public String getKommentar() { - return kommentar; + return kommentar.get(); } public void setKommentar(String kommentar) { - this.kommentar = kommentar; + this.kommentar.set(kommentar); + } + + public StringProperty kommentarProperty() { + return kommentar; } public String getPilotInformationen() { - return pilot != null ? pilot.getInformationen() : "Kein Pilot zugewiesen"; + Pilot pilot = getPilot(); + if (pilot != null) { + return "Name: " + pilot.getName() + ", Adresse: " + pilot.getAdresse() + ", Kontaktinformationen: " + pilot.getKontaktinformationen(); + } + return "Keine Pilotinformationen verfügbar"; } + + } diff --git a/src/models/Pilot.java b/src/models/Pilot.java index e7f2221..8a6281c 100644 --- a/src/models/Pilot.java +++ b/src/models/Pilot.java @@ -3,51 +3,69 @@ package models; import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; public class Pilot implements Serializable { private static final long serialVersionUID = 1L; - private String name; - private String adresse; - private String kontaktinformationen; + private StringProperty name; + private StringProperty adresse; + private StringProperty kontaktinformationen; private List lizenzen; private List zertifikate; + // Standardkonstruktor public Pilot() { + this.name = new SimpleStringProperty(); + this.adresse = new SimpleStringProperty(); + this.kontaktinformationen = new SimpleStringProperty(); this.lizenzen = new ArrayList<>(); this.zertifikate = new ArrayList<>(); } public Pilot(String name, String adresse, String kontaktinformationen) { - this.name = name; - this.adresse = adresse; - this.kontaktinformationen = kontaktinformationen; + this.name = new SimpleStringProperty(name); + this.adresse = new SimpleStringProperty(adresse); + this.kontaktinformationen = new SimpleStringProperty(kontaktinformationen); this.lizenzen = new ArrayList<>(); this.zertifikate = new ArrayList<>(); } public String getName() { - return name; + return name.get(); } public void setName(String name) { - this.name = name; + this.name.set(name); + } + + public StringProperty nameProperty() { + return name; } public String getAdresse() { - return adresse; + return adresse.get(); } public void setAdresse(String adresse) { - this.adresse = adresse; + this.adresse.set(adresse); + } + + public StringProperty adresseProperty() { + return adresse; } public String getKontaktinformationen() { - return kontaktinformationen; + return kontaktinformationen.get(); } public void setKontaktinformationen(String kontaktinformationen) { - this.kontaktinformationen = kontaktinformationen; + this.kontaktinformationen.set(kontaktinformationen); + } + + public StringProperty kontaktinformationenProperty() { + return kontaktinformationen; } public List getLizenzen() { @@ -58,6 +76,10 @@ public class Pilot implements Serializable { this.lizenzen = lizenzen; } + public void addLizenz(String lizenz) { + this.lizenzen.add(lizenz); + } + public List getZertifikate() { return zertifikate; } @@ -66,20 +88,12 @@ public class Pilot implements Serializable { this.zertifikate = zertifikate; } - public void addLizenz(String lizenz) { - this.lizenzen.add(lizenz); - } - public void addZertifikat(String zertifikat) { this.zertifikate.add(zertifikat); } - public String getInformationen() { - return "Name: " + name + ", Adresse: " + adresse + ", Kontaktinformationen: " + kontaktinformationen; - } - @Override public String toString() { - return name; + return getName(); } } diff --git a/src/resources/icons/add_flight_icon.png b/src/resources/icons/add_flight_icon.png index b07165d..dcb3d13 100644 Binary files a/src/resources/icons/add_flight_icon.png and b/src/resources/icons/add_flight_icon.png differ diff --git a/src/resources/icons/delete_pilot_icon.png b/src/resources/icons/delete_pilot_icon.png new file mode 100644 index 0000000..85f631a Binary files /dev/null and b/src/resources/icons/delete_pilot_icon.png differ diff --git a/src/resources/icons/edit_pilot_icon.png b/src/resources/icons/edit_pilot_icon.png index 4f1c58d..80047f0 100644 Binary files a/src/resources/icons/edit_pilot_icon.png and b/src/resources/icons/edit_pilot_icon.png differ diff --git a/src/resources/icons/help_icon.png b/src/resources/icons/help_icon.png index 1dc79db..a697ea3 100644 Binary files a/src/resources/icons/help_icon.png and b/src/resources/icons/help_icon.png differ diff --git a/src/resources/icons/manage_pilot_icon.png b/src/resources/icons/manage_pilot_icon.png index 3cfe195..3189973 100644 Binary files a/src/resources/icons/manage_pilot_icon.png and b/src/resources/icons/manage_pilot_icon.png differ diff --git a/src/resources/icons/view_logbook_icon.png b/src/resources/icons/view_logbook_icon.png index ef5f13d..3050fbc 100644 Binary files a/src/resources/icons/view_logbook_icon.png and b/src/resources/icons/view_logbook_icon.png differ diff --git a/src/resources/icons/view_pilot_icon.png b/src/resources/icons/view_pilot_icon.png index 1ec354d..e24f4e2 100644 Binary files a/src/resources/icons/view_pilot_icon.png and b/src/resources/icons/view_pilot_icon.png differ diff --git a/src/resources/styles.css b/src/resources/styles.css new file mode 100644 index 0000000..6dcbb1c --- /dev/null +++ b/src/resources/styles.css @@ -0,0 +1,22 @@ +.root { + -fx-font-family: 'Arial'; +} + +.button { + -fx-background-color: #000000; + -fx-text-fill: #FFFFFF; + -fx-font-size: 14px; + -fx-font-weight: bold; + -fx-pref-height: 40px; + -fx-pref-width: 200px; +} + +.label { + -fx-font-size: 14px; + -fx-font-weight: bold; +} + +.text-field, .date-picker, .combo-box { + -fx-pref-height: 30px; + -fx-pref-width: 250px; +} diff --git a/src/utils/XMLHelper.java b/src/utils/XMLHelper.java index 0d92428..d311ceb 100644 --- a/src/utils/XMLHelper.java +++ b/src/utils/XMLHelper.java @@ -2,28 +2,24 @@ package utils; import java.beans.XMLDecoder; import java.beans.XMLEncoder; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; +import java.io.*; public class XMLHelper { - public static void saveToXML(Object data, String filename) { - try (XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(filename)))) { - encoder.writeObject(data); + public static void saveToXML(Object obj, String filePath) { + try (XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(filePath)))) { + encoder.writeObject(obj); encoder.flush(); } catch (IOException e) { e.printStackTrace(); } } - public static Object loadFromXML(String filename) { - try (XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(filename)))) { + public static Object loadFromXML(String filePath) { + try (XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(filePath)))) { return decoder.readObject(); - } catch (IOException e) { - e.printStackTrace(); + } catch (FileNotFoundException e) { + System.out.println("File not found: " + filePath); return null; } } diff --git a/src/views/AddFlightScreen.java b/src/views/AddFlightScreen.java index 95f44b6..c8fa81a 100644 --- a/src/views/AddFlightScreen.java +++ b/src/views/AddFlightScreen.java @@ -70,12 +70,12 @@ public class AddFlightScreen { pilotComboBox.setPromptText("Pilot auswählen"); Button submitBtn = new Button("Hinzufügen"); - submitBtn.setStyle("-fx-background-color: #431EB9; -fx-text-fill: #FFFFFF;"); - submitBtn.setOnAction( - e -> handleAddFlight(datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField, - tToFField, anzahlLandungenField, nachtflugBox.isSelected(), kommentarField, pilotComboBox)); + 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"); + 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(10, label, datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField, @@ -90,18 +90,24 @@ public class AddFlightScreen { BorderPane.setAlignment(backButton, Pos.TOP_LEFT); BorderPane.setMargin(backButton, new Insets(10)); - Scene scene = new Scene(borderPane, 600, 700); + 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, 700); + scene.getStylesheets().add(getClass().getResource("/resources/styles.css").toExternalForm()); stage.setScene(scene); stage.show(); } - private void handleAddFlight(DatePicker datumField, TextField musterField, TextField abflugortField, - TextField abflugzeitField, - TextField ankunftszeitField, TextField tToFField, TextField anzahlLandungenField, boolean isNachtflug, - TextField kommentarField, ComboBox pilotComboBox) { - clearFieldStyles(datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField, tToFField, - anzahlLandungenField, pilotComboBox); + private void handleAddFlight(DatePicker datumField, TextField musterField, TextField abflugortField, TextField abflugzeitField, + TextField ankunftszeitField, TextField tToFField, TextField anzahlLandungenField, boolean isNachtflug, + TextField kommentarField, ComboBox pilotComboBox) { + clearFieldStyles(datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField, tToFField, anzahlLandungenField, pilotComboBox); try { if (datumField.getValue() == null) { @@ -153,8 +159,7 @@ public class AddFlightScreen { 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."); + 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) { diff --git a/src/views/DeletePilotScreen.java b/src/views/DeletePilotScreen.java new file mode 100644 index 0000000..6866599 --- /dev/null +++ b/src/views/DeletePilotScreen.java @@ -0,0 +1,77 @@ +package views; + +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.Alert; +import javafx.scene.control.Button; +import javafx.scene.control.ComboBox; +import javafx.scene.control.Label; +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; + + public DeletePilotScreen(Stage stage) { + this.stage = stage; + } + + 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)); + 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(); + } else { + showAlert("Fehler", "Bitte wählen Sie einen Piloten 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(10, label, pilotComboBox, deleteBtn); + vbox.setAlignment(Pos.CENTER); + vbox.setPadding(new Insets(20)); + vbox.setStyle("-fx-background-color: #E6F2FF;"); + + 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 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/EditFlightScreen.java b/src/views/EditFlightScreen.java new file mode 100644 index 0000000..95efa8b --- /dev/null +++ b/src/views/EditFlightScreen.java @@ -0,0 +1,178 @@ +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)); + vbox.setStyle("-fx-background-color: #E6F2FF;"); + + 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, 700); + 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/HelpScreen.java b/src/views/HelpScreen.java index bad6795..0d5785d 100644 --- a/src/views/HelpScreen.java +++ b/src/views/HelpScreen.java @@ -35,6 +35,7 @@ public class HelpScreen { vbox.setStyle("-fx-background-color: #FFFFFF;"); Scene scene = new Scene(vbox, 400, 300); + scene.getStylesheets().add(getClass().getResource("/resources/styles.css").toExternalForm()); stage.setScene(scene); stage.show(); diff --git a/src/views/HomeScreen.java b/src/views/HomeScreen.java index 3680149..2939543 100644 --- a/src/views/HomeScreen.java +++ b/src/views/HomeScreen.java @@ -5,9 +5,14 @@ import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.Tooltip; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.GridPane; import javafx.scene.layout.VBox; +import javafx.scene.shape.Circle; import javafx.stage.Stage; import models.Pilots; import utils.XMLHelper; @@ -20,16 +25,22 @@ public class HomeScreen { } public void display() { - Button btn1 = createButton("Flug erfassen", "/resources/icons/add_flight_icon.png"); - Button btn2 = createButton("Logbuch einsehen", "/resources/icons/view_logbook_icon.png"); - Button btn3 = createButton("Pilotenprofil verwalten", "/resources/icons/manage_pilot_icon.png"); - Button helpBtn = createButton("Hilfe", "/resources/icons/help_icon.png"); - Button pilotsBtn = createButton("Alle Piloten anzeigen", "/resources/icons/view_pilot_icon.png"); - Button editPilotsBtn = createButton("Pilot bearbeiten", "/resources/icons/edit_pilot_icon.png"); + // Titel des Projekts + Label title = new Label("Fluglogbuch Pegasus"); + title.setStyle("-fx-font-size: 32px; -fx-font-weight: bold; -fx-text-fill: #000000; -fx-font-family: 'Arial Black';"); + + Button btn1 = createButton("Flug erfassen", "/resources/icons/add_flight_icon.png", "Erfassen Sie einen neuen Flug"); + Button btn2 = createButton("Logbuch einsehen", "/resources/icons/view_logbook_icon.png", "Sehen Sie das Fluglogbuch ein"); + Button btn3 = createButton("Pilotenprofil verwalten", "/resources/icons/manage_pilot_icon.png", "Verwalten Sie das Profil eines Piloten"); + Button btn4 = createButton("Piloten löschen", "/resources/icons/delete_pilot_icon.png", "Löschen Sie einen Piloten"); + Button helpBtn = createHelpButton("/resources/icons/help_icon.png", "Hilfe anzeigen"); + Button pilotsBtn = createButton("Alle Piloten anzeigen", "/resources/icons/view_pilot_icon.png", "Alle Piloten anzeigen"); + Button editPilotsBtn = createButton("Pilot bearbeiten", "/resources/icons/edit_pilot_icon.png", "Bearbeiten Sie ein Pilotenprofil"); btn1.setOnAction(e -> new AddFlightScreen(stage).display()); btn2.setOnAction(e -> new ViewLogbookScreen(stage).display()); btn3.setOnAction(e -> new ManagePilotProfileScreen(stage).display()); + btn4.setOnAction(e -> new DeletePilotScreen(stage).display()); helpBtn.setOnAction(e -> new HelpScreen(stage).display()); pilotsBtn.setOnAction(e -> new PilotView(stage).displayAllPilots()); editPilotsBtn.setOnAction(e -> { @@ -41,33 +52,63 @@ public class HomeScreen { } }); - VBox vbox = new VBox(20, btn1, btn2, btn3, helpBtn, pilotsBtn, editPilotsBtn); - vbox.setAlignment(Pos.CENTER); - vbox.setPadding(new Insets(30)); - vbox.setStyle("-fx-background-color: #E6F2FF;"); + GridPane gridPane = new GridPane(); + gridPane.setPadding(new Insets(20)); + gridPane.setHgap(20); + gridPane.setVgap(20); + gridPane.setAlignment(Pos.CENTER); + gridPane.add(btn1, 0, 0); + gridPane.add(btn2, 1, 0); + gridPane.add(btn3, 0, 1); + gridPane.add(pilotsBtn, 1, 1); + gridPane.add(editPilotsBtn, 0, 2); + gridPane.add(btn4, 1, 2); - Scene scene = new Scene(vbox, 600, 400); + VBox vbox = new VBox(20, title, gridPane); + vbox.setAlignment(Pos.CENTER); + + BorderPane borderPane = new BorderPane(); + borderPane.setCenter(vbox); + borderPane.setRight(helpBtn); + BorderPane.setAlignment(helpBtn, Pos.TOP_RIGHT); + BorderPane.setMargin(helpBtn, new Insets(10)); + + Scene scene = new Scene(borderPane, 800, 600); + scene.getStylesheets().add(getClass().getResource("/resources/styles.css").toExternalForm()); stage.setScene(scene); - stage.setTitle("Fluglogbuch"); + stage.setTitle("Fluglogbuch Pegasus"); stage.show(); } - private Button createButton(String text, String iconPath) { + private Button createButton(String text, String iconPath, String tooltipText) { Image icon = new Image(getClass().getResourceAsStream(iconPath)); - if (icon.isError()) { - System.out.println("Fehler beim Laden des Icons: " + iconPath); - } ImageView iconView = new ImageView(icon); iconView.setFitHeight(20); iconView.setFitWidth(20); Button button = new Button(text, iconView); - button.setStyle("-fx-background-color: #431EB9; -fx-text-fill: #FFFFFF;"); + button.setTooltip(new Tooltip(tooltipText)); + button.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;"); button.setPrefSize(250, 50); return button; } + private Button createHelpButton(String iconPath, String tooltipText) { + Image icon = new Image(getClass().getResourceAsStream(iconPath)); + ImageView iconView = new ImageView(icon); + iconView.setFitHeight(30); + iconView.setFitWidth(30); + + Button button = new Button("", iconView); + button.setTooltip(new Tooltip(tooltipText)); + button.setStyle("-fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-font-weight: bold;"); + button.setShape(new Circle(25)); // Set button shape to circle + button.setMinSize(50, 50); // Set the min size to ensure it remains circular + button.setMaxSize(50, 50); // Set the max size to ensure it remains circular + return button; + } + private void showAlert(String title, String message) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle(title); diff --git a/src/views/ManagePilotProfileScreen.java b/src/views/ManagePilotProfileScreen.java index 215083e..8e7a4f4 100644 --- a/src/views/ManagePilotProfileScreen.java +++ b/src/views/ManagePilotProfileScreen.java @@ -5,7 +5,6 @@ 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; @@ -56,6 +55,8 @@ public class ManagePilotProfileScreen { BorderPane.setMargin(backButton, new Insets(10)); Scene scene = new Scene(borderPane, 400, 300); + scene.getStylesheets().add(getClass().getResource("/resources/styles.css").toExternalForm()); + stage.setScene(scene); stage.show(); @@ -123,6 +124,7 @@ public class ManagePilotProfileScreen { BorderPane.setMargin(backButton, new Insets(10)); Scene scene = new Scene(borderPane, 400, 600); + scene.getStylesheets().add(getClass().getResource("/resources/styles.css").toExternalForm()); stage.setScene(scene); stage.show(); diff --git a/src/views/PilotView.java b/src/views/PilotView.java index e105958..f577445 100644 --- a/src/views/PilotView.java +++ b/src/views/PilotView.java @@ -76,6 +76,8 @@ public class PilotView { BorderPane.setMargin(backButton, new Insets(10)); Scene scene = new Scene(borderPane, 400, 300); + scene.getStylesheets().add(getClass().getResource("/resources/styles.css").toExternalForm()); + stage.setScene(scene); stage.setTitle("Alle Piloten"); stage.show(); diff --git a/src/views/ViewLogbookScreen.java b/src/views/ViewLogbookScreen.java index fe0600d..2b99472 100644 --- a/src/views/ViewLogbookScreen.java +++ b/src/views/ViewLogbookScreen.java @@ -1,14 +1,12 @@ 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.Button; -import javafx.scene.control.TableColumn; -import javafx.scene.control.TableView; -import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.control.*; import javafx.scene.layout.BorderPane; import javafx.scene.layout.VBox; import javafx.stage.Stage; @@ -16,6 +14,8 @@ 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 { @@ -26,68 +26,88 @@ public class ViewLogbookScreen { } public void display() { - Flights flightsData = (Flights) XMLHelper.loadFromXML("flights.xml"); - List flightList = flightsData != null ? flightsData.getFlights() : List.of(); + 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';"); - ObservableList flights = FXCollections.observableArrayList(flightList); + TableView table = new TableView<>(); + table.setStyle("-fx-font-weight: bold;"); - TableView tableView = new TableView<>(flights); + 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 dateColumn = new TableColumn<>("Datum"); - dateColumn.setCellValueFactory(new PropertyValueFactory<>("datum")); + TableColumn musterCol = new TableColumn<>("Muster"); + musterCol.setCellValueFactory(cellData -> cellData.getValue().musterProperty()); - TableColumn modelColumn = new TableColumn<>("Muster"); - modelColumn.setCellValueFactory(new PropertyValueFactory<>("muster")); + TableColumn abflugortCol = new TableColumn<>("Abflugort"); + abflugortCol.setCellValueFactory(cellData -> cellData.getValue().abflugortProperty()); - TableColumn departureColumn = new TableColumn<>("Abflugort"); - departureColumn.setCellValueFactory(new PropertyValueFactory<>("abflugort")); + TableColumn abflugzeitCol = new TableColumn<>("Abflugzeit"); + abflugzeitCol.setCellValueFactory(cellData -> cellData.getValue().abflugzeitProperty()); - TableColumn departureTimeColumn = new TableColumn<>("Abflugzeit"); - departureTimeColumn.setCellValueFactory(new PropertyValueFactory<>("abflugzeit")); + TableColumn ankunftszeitCol = new TableColumn<>("Ankunftszeit"); + ankunftszeitCol.setCellValueFactory(cellData -> cellData.getValue().ankunftszeitProperty()); - TableColumn arrivalTimeColumn = new TableColumn<>("Ankunftszeit"); - arrivalTimeColumn.setCellValueFactory(new PropertyValueFactory<>("ankunftszeit")); + TableColumn tToFCol = new TableColumn<>("Flugdauer"); + tToFCol.setCellValueFactory(cellData -> cellData.getValue().tToFProperty().asObject()); - TableColumn durationColumn = new TableColumn<>("Flugdauer"); - durationColumn.setCellValueFactory(new PropertyValueFactory<>("tToF")); + TableColumn anzahlLandungenCol = new TableColumn<>("Landungen"); + anzahlLandungenCol.setCellValueFactory(cellData -> cellData.getValue().anzahlLandungenProperty().asObject()); - TableColumn landingsColumn = new TableColumn<>("Anzahl der Landungen"); - landingsColumn.setCellValueFactory(new PropertyValueFactory<>("anzahlLandungen")); + TableColumn pilotCol = new TableColumn<>("Pilot"); + pilotCol.setCellValueFactory(cellData -> cellData.getValue().pilotProperty().get().nameProperty()); - TableColumn nightFlightColumn = new TableColumn<>("Nachtflug"); - nightFlightColumn.setCellValueFactory(new PropertyValueFactory<>("isNachtflug")); + TableColumn nachtflugCol = new TableColumn<>("Nachtflug"); + nachtflugCol.setCellValueFactory(cellData -> cellData.getValue().nachtflugProperty().asObject()); - TableColumn commentColumn = new TableColumn<>("Kommentar"); - commentColumn.setCellValueFactory(new PropertyValueFactory<>("kommentar")); + TableColumn kommentarCol = new TableColumn<>("Kommentar"); + kommentarCol.setCellValueFactory(cellData -> cellData.getValue().kommentarProperty()); - tableView.getColumns().add(dateColumn); - tableView.getColumns().add(modelColumn); - tableView.getColumns().add(departureColumn); - tableView.getColumns().add(departureTimeColumn); - tableView.getColumns().add(arrivalTimeColumn); - tableView.getColumns().add(durationColumn); - tableView.getColumns().add(landingsColumn); - tableView.getColumns().add(nightFlightColumn); - tableView.getColumns().add(commentColumn); + 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(tableView); + VBox vbox = new VBox(20, label, table, editBtn, backButton); vbox.setAlignment(Pos.CENTER); vbox.setPadding(new Insets(20)); - vbox.setStyle("-fx-background-color: #FFFFFF;"); + vbox.setStyle("-fx-background-color: #E6F2FF;"); - 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 scene = new Scene(vbox, 800, 600); + scene.getStylesheets().add(getClass().getResource("/resources/styles.css").toExternalForm()); stage.setScene(scene); - stage.setTitle("Fluglogbuch einsehen"); 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(); + } }