commit 56ffec8a54add49eaf2362b08f7e4dbe9c994d30 Author: Maximilian Date: Thu Jun 13 11:36:10 2024 +0200 Initial commit diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..297fd39 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,22 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "java", + "name": "Current File", + "request": "launch", + "mainClass": "${file}" + }, + { + "type": "java", + "name": "Main", + "request": "launch", + "vmArgs": "--module-path C:/Sources/javafx-sdk-22.0.1/lib --add-modules javafx.controls,javafx.fxml", + "mainClass": "program.Main", + "projectName": "Pegasus_606a3a68" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a5f7a57 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,15 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar", + "c:\\Sources\\javafx-sdk-22.0.1\\lib\\javafx.base.jar", + "c:\\Sources\\javafx-sdk-22.0.1\\lib\\javafx.controls.jar", + "c:\\Sources\\javafx-sdk-22.0.1\\lib\\javafx.fxml.jar", + "c:\\Sources\\javafx-sdk-22.0.1\\lib\\javafx.graphics.jar", + "c:\\Sources\\javafx-sdk-22.0.1\\lib\\javafx.media.jar", + "c:\\Sources\\javafx-sdk-22.0.1\\lib\\javafx.swing.jar", + "c:\\Sources\\javafx-sdk-22.0.1\\lib\\javafx.web.jar", + "c:\\Sources\\javafx-sdk-22.0.1\\lib\\javafx-swt.jar" + ] +} diff --git a/bin/controllers/FlightController.class b/bin/controllers/FlightController.class new file mode 100644 index 0000000..520767c Binary files /dev/null and b/bin/controllers/FlightController.class differ diff --git a/bin/controllers/PilotController.class b/bin/controllers/PilotController.class new file mode 100644 index 0000000..ee8b650 Binary files /dev/null and b/bin/controllers/PilotController.class differ diff --git a/bin/models/Flight.class b/bin/models/Flight.class new file mode 100644 index 0000000..d950f4a Binary files /dev/null and b/bin/models/Flight.class differ diff --git a/bin/models/Flights.class b/bin/models/Flights.class new file mode 100644 index 0000000..2f55ca3 Binary files /dev/null and b/bin/models/Flights.class differ diff --git a/bin/models/Pilot.class b/bin/models/Pilot.class new file mode 100644 index 0000000..9120ee5 Binary files /dev/null and b/bin/models/Pilot.class differ diff --git a/bin/models/Pilots.class b/bin/models/Pilots.class new file mode 100644 index 0000000..c613304 Binary files /dev/null and b/bin/models/Pilots.class differ diff --git a/bin/program/Main.class b/bin/program/Main.class new file mode 100644 index 0000000..5b6814a Binary files /dev/null and b/bin/program/Main.class differ diff --git a/bin/resources/icons/add_flight_icon.png b/bin/resources/icons/add_flight_icon.png new file mode 100644 index 0000000..b07165d Binary files /dev/null and b/bin/resources/icons/add_flight_icon.png differ diff --git a/bin/resources/icons/edit_pilot_icon.png b/bin/resources/icons/edit_pilot_icon.png new file mode 100644 index 0000000..4f1c58d Binary files /dev/null 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 new file mode 100644 index 0000000..1dc79db Binary files /dev/null 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 new file mode 100644 index 0000000..3cfe195 Binary files /dev/null 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 new file mode 100644 index 0000000..ef5f13d Binary files /dev/null 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 new file mode 100644 index 0000000..1ec354d Binary files /dev/null and b/bin/resources/icons/view_pilot_icon.png differ diff --git a/bin/utils/XMLHelper.class b/bin/utils/XMLHelper.class new file mode 100644 index 0000000..9f1fd64 Binary files /dev/null and b/bin/utils/XMLHelper.class differ diff --git a/bin/views/AddFlightScreen.class b/bin/views/AddFlightScreen.class new file mode 100644 index 0000000..dd69aea Binary files /dev/null and b/bin/views/AddFlightScreen.class differ diff --git a/bin/views/FlightView.class b/bin/views/FlightView.class new file mode 100644 index 0000000..a8b88b9 Binary files /dev/null and b/bin/views/FlightView.class differ diff --git a/bin/views/HelpScreen.class b/bin/views/HelpScreen.class new file mode 100644 index 0000000..c288955 Binary files /dev/null and b/bin/views/HelpScreen.class differ diff --git a/bin/views/HomeScreen.class b/bin/views/HomeScreen.class new file mode 100644 index 0000000..f2c8598 Binary files /dev/null and b/bin/views/HomeScreen.class differ diff --git a/bin/views/ManagePilotProfileScreen.class b/bin/views/ManagePilotProfileScreen.class new file mode 100644 index 0000000..e833e49 Binary files /dev/null and b/bin/views/ManagePilotProfileScreen.class differ diff --git a/bin/views/PilotView.class b/bin/views/PilotView.class new file mode 100644 index 0000000..e2271b0 Binary files /dev/null and b/bin/views/PilotView.class differ diff --git a/bin/views/ViewLogbookScreen.class b/bin/views/ViewLogbookScreen.class new file mode 100644 index 0000000..f3bca7e Binary files /dev/null and b/bin/views/ViewLogbookScreen.class differ diff --git a/flights.xml b/flights.xml new file mode 100644 index 0000000..f17462e --- /dev/null +++ b/flights.xml @@ -0,0 +1,190 @@ + + + + + + + + 2.0 + + + ea + + + 2 + + + 2 + + + 1 + + + 2 + + + aed + + + + + asd + + + asd + + + + asd + + + ss + + + ddas + + + + sad + + + + asd + + + asd + + + eee + + + + + + + + + + 2.0 + + + asd + + + 11:00 + + + 12:00 + + + 2 + + + asd + + + asd + + + + + asd + + + asd + + + + asd + + + ss + + + ddas + + + + sad + + + + asd + + + asd + + + eee + + + + + + + + + + 123.0 + + + sad + + + 123 + + + 123 + + + 123 + + + 123 + + + asd + + + true + + + + + asd + + + asd + + + + asd + + + ss + + + ddas + + + + sad + + + + asd + + + asd + + + eee + + + + + + + + + diff --git a/pilots.xml b/pilots.xml new file mode 100644 index 0000000..71cd69f --- /dev/null +++ b/pilots.xml @@ -0,0 +1,55 @@ + + + + + + + + asd + + + 23 + + + asd + + + + + + + asd + + + asd + + + + asd + + + ss + + + ddas + + + + sad + + + + asd + + + asd + + + eee + + + + + + + diff --git a/src/controllers/FlightController.java b/src/controllers/FlightController.java new file mode 100644 index 0000000..47fd6d4 --- /dev/null +++ b/src/controllers/FlightController.java @@ -0,0 +1,28 @@ +package controllers; + +import java.time.LocalDate; + +import models.Flight; +import views.FlightView; + +public class FlightController { + private Flight model; + private FlightView view; + + public FlightController(Flight model, FlightView view) { + this.model = model; + this.view = view; + } + + public void setFlightDatum(LocalDate datum) { + model.setDatum(datum); + } + + public LocalDate getFlightDatum() { + return model.getDatum(); + } + + public void updateView() { + view.displayFlightDetails(model); + } +} diff --git a/src/controllers/PilotController.java b/src/controllers/PilotController.java new file mode 100644 index 0000000..6db6a12 --- /dev/null +++ b/src/controllers/PilotController.java @@ -0,0 +1,26 @@ +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 new file mode 100644 index 0000000..ec52679 --- /dev/null +++ b/src/models/Flight.java @@ -0,0 +1,121 @@ +package models; + +import java.io.Serializable; +import java.time.LocalDate; + +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; + + public Flight() { + } + + 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; + } + + // Getter und Setter für alle Felder + public LocalDate getDatum() { + return datum; + } + + public void setDatum(LocalDate datum) { + this.datum = datum; + } + + public String getMuster() { + return muster; + } + + public void setMuster(String muster) { + this.muster = muster; + } + + public String getAbflugort() { + return abflugort; + } + + public void setAbflugort(String abflugort) { + this.abflugort = abflugort; + } + + public String getAbflugzeit() { + return abflugzeit; + } + + public void setAbflugzeit(String abflugzeit) { + this.abflugzeit = abflugzeit; + } + + public String getAnkunftszeit() { + return ankunftszeit; + } + + public void setAnkunftszeit(String ankunftszeit) { + this.ankunftszeit = ankunftszeit; + } + + public double getTToF() { + return tToF; + } + + public void setTToF(double tToF) { + this.tToF = tToF; + } + + public int getAnzahlLandungen() { + return anzahlLandungen; + } + + public void setAnzahlLandungen(int anzahlLandungen) { + this.anzahlLandungen = anzahlLandungen; + } + + public Pilot getPilot() { + return pilot; + } + + public void setPilot(Pilot pilot) { + this.pilot = pilot; + } + + public boolean isNachtflug() { + return isNachtflug; + } + + public void setNachtflug(boolean nachtflug) { + isNachtflug = nachtflug; + } + + public String getKommentar() { + return kommentar; + } + + public void setKommentar(String kommentar) { + this.kommentar = kommentar; + } + + public String getPilotInformationen() { + return pilot != null ? pilot.getInformationen() : "Kein Pilot zugewiesen"; + } +} diff --git a/src/models/Flights.java b/src/models/Flights.java new file mode 100644 index 0000000..9b5a722 --- /dev/null +++ b/src/models/Flights.java @@ -0,0 +1,25 @@ +package models; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +public class Flights implements Serializable { + private List flights; + + public Flights() { + this.flights = new ArrayList<>(); + } + + public Flights(List flights) { + this.flights = flights; + } + + public List getFlights() { + return flights; + } + + public void setFlights(List flights) { + this.flights = flights; + } +} diff --git a/src/models/Pilot.java b/src/models/Pilot.java new file mode 100644 index 0000000..e7f2221 --- /dev/null +++ b/src/models/Pilot.java @@ -0,0 +1,85 @@ +package models; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +public class Pilot implements Serializable { + private static final long serialVersionUID = 1L; + + private String name; + private String adresse; + private String kontaktinformationen; + private List lizenzen; + private List zertifikate; + + public Pilot() { + 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.lizenzen = new ArrayList<>(); + this.zertifikate = new ArrayList<>(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAdresse() { + return adresse; + } + + public void setAdresse(String adresse) { + this.adresse = adresse; + } + + public String getKontaktinformationen() { + return kontaktinformationen; + } + + public void setKontaktinformationen(String kontaktinformationen) { + this.kontaktinformationen = kontaktinformationen; + } + + public List getLizenzen() { + return lizenzen; + } + + public void setLizenzen(List lizenzen) { + this.lizenzen = lizenzen; + } + + public List getZertifikate() { + return zertifikate; + } + + public void setZertifikate(List zertifikate) { + 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; + } +} diff --git a/src/models/Pilots.java b/src/models/Pilots.java new file mode 100644 index 0000000..88c3ef6 --- /dev/null +++ b/src/models/Pilots.java @@ -0,0 +1,25 @@ +package models; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +public class Pilots implements Serializable { + private List pilots; + + public Pilots() { + this.pilots = new ArrayList<>(); + } + + public Pilots(List pilots) { + this.pilots = pilots; + } + + public List getPilots() { + return pilots; + } + + public void setPilots(List pilots) { + this.pilots = pilots; + } +} diff --git a/src/program/Main.java b/src/program/Main.java new file mode 100644 index 0000000..1045456 --- /dev/null +++ b/src/program/Main.java @@ -0,0 +1,17 @@ +package program; + +import javafx.application.Application; +import javafx.stage.Stage; +import views.HomeScreen; + +public class Main extends Application { + @Override + public void start(Stage primaryStage) { + HomeScreen homeScreen = new HomeScreen(primaryStage); + homeScreen.display(); + } + + public static void main(String[] args) { + launch(args); + } +} diff --git a/src/resources/icons/add_flight_icon.png b/src/resources/icons/add_flight_icon.png new file mode 100644 index 0000000..b07165d Binary files /dev/null and b/src/resources/icons/add_flight_icon.png differ diff --git a/src/resources/icons/edit_pilot_icon.png b/src/resources/icons/edit_pilot_icon.png new file mode 100644 index 0000000..4f1c58d Binary files /dev/null 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 new file mode 100644 index 0000000..1dc79db Binary files /dev/null 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 new file mode 100644 index 0000000..3cfe195 Binary files /dev/null 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 new file mode 100644 index 0000000..ef5f13d Binary files /dev/null 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 new file mode 100644 index 0000000..1ec354d Binary files /dev/null and b/src/resources/icons/view_pilot_icon.png differ diff --git a/src/utils/XMLHelper.java b/src/utils/XMLHelper.java new file mode 100644 index 0000000..0d92428 --- /dev/null +++ b/src/utils/XMLHelper.java @@ -0,0 +1,30 @@ +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; + +public class XMLHelper { + + public static void saveToXML(Object data, String filename) { + try (XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(filename)))) { + encoder.writeObject(data); + encoder.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static Object loadFromXML(String filename) { + try (XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(filename)))) { + return decoder.readObject(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/src/views/AddFlightScreen.java b/src/views/AddFlightScreen.java new file mode 100644 index 0000000..95f44b6 --- /dev/null +++ b/src/views/AddFlightScreen.java @@ -0,0 +1,183 @@ +package views; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; +import models.Flight; +import models.Flights; +import models.Pilot; +import models.Pilots; +import utils.XMLHelper; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +public class AddFlightScreen { + private Stage stage; + + public AddFlightScreen(Stage stage) { + this.stage = stage; + } + + public void display() { + Label label = new Label("Flugdaten eingeben:"); + label.setStyle("-fx-font-size: 18px; -fx-font-weight: bold;"); + DatePicker datumField = new DatePicker(); + TextField musterField = new TextField(); + TextField abflugortField = new TextField(); + TextField abflugzeitField = new TextField(); + TextField ankunftszeitField = new TextField(); + TextField tToFField = new TextField(); + TextField anzahlLandungenField = new TextField(); + CheckBox nachtflugBox = new CheckBox("Nachtflug"); + TextField kommentarField = new TextField(); + + datumField.setPromptText("YYYY-MM-DD"); + 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); + } + }); + + // Laden der Piloten für die Auswahlbox + Pilots pilotsData = (Pilots) XMLHelper.loadFromXML("pilots.xml"); + List pilotList = pilotsData != null ? pilotsData.getPilots() : new ArrayList<>(); + ObservableList pilots = FXCollections.observableArrayList(pilotList); + + ComboBox pilotComboBox = new ComboBox<>(pilots); + 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)); + + Button backButton = new Button("Zurück"); + backButton.setOnAction(e -> new HomeScreen(stage).display()); + + VBox vbox = new VBox(10, label, datumField, musterField, abflugortField, abflugzeitField, ankunftszeitField, + tToFField, anzahlLandungenField, nachtflugBox, kommentarField, pilotComboBox, submitBtn); + 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, 600, 700); + + 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); + + 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."); + } + if (pilotComboBox.getValue() == null) { + setErrorStyle(pilotComboBox); + throw new IllegalArgumentException("Pilot ist erforderlich."); + } + + double flightDuration = Double.parseDouble(tToFField.getText()); + int landings = Integer.parseInt(anzahlLandungenField.getText()); + + Flight newFlight = new Flight(datumField.getValue(), musterField.getText(), abflugortField.getText(), + abflugzeitField.getText(), ankunftszeitField.getText(), flightDuration, landings, + pilotComboBox.getValue(), isNachtflug, kommentarField.getText()); + + Flights flights = (Flights) XMLHelper.loadFromXML("flights.xml"); + if (flights == null) { + flights = new Flights(new ArrayList<>()); + } + flights.getFlights().add(newFlight); + XMLHelper.saveToXML(flights, "flights.xml"); + + new HomeScreen(stage).display(); + } catch (NumberFormatException e) { + showAlert("Ungültige Eingabe", + "Bitte stellen Sie sicher, dass die Flugdauer und die Anzahl der Landungen numerisch sind."); + } catch (IllegalArgumentException e) { + showAlert("Fehlende Eingabe", e.getMessage()); + } catch (Exception e) { + showAlert("Fehler", "Es ist ein Fehler beim Speichern des Flugs aufgetreten."); + e.printStackTrace(); + } + } + + private void setErrorStyle(Control field) { + field.setStyle("-fx-border-color: red;"); + } + + private void clearFieldStyles(Control... fields) { + for (Control field : fields) { + field.setStyle(null); + } + } + + private void showAlert(String title, String message) { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle(title); + alert.setHeaderText(null); + alert.setContentText(message); + alert.showAndWait(); + } +} diff --git a/src/views/FlightView.java b/src/views/FlightView.java new file mode 100644 index 0000000..17b645e --- /dev/null +++ b/src/views/FlightView.java @@ -0,0 +1,27 @@ +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/HelpScreen.java b/src/views/HelpScreen.java new file mode 100644 index 0000000..bad6795 --- /dev/null +++ b/src/views/HelpScreen.java @@ -0,0 +1,42 @@ +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.TextArea; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; + +public class HelpScreen { + private Stage stage; + + public HelpScreen(Stage stage) { + this.stage = stage; + } + + public void display() { + Label label = new Label("Hilfe"); + TextArea helpText = new TextArea(); + helpText.setText("Flug erfassen: Hier können Sie einen neuen Flug hinzufügen.\n" + + "Logbuch einsehen: Hier können Sie das Fluglogbuch einsehen.\n" + + "Pilotenprofil verwalten: Hier können Sie Ihr Pilotenprofil verwalten.\n" + + "Hilfe: Zeigt diese Hilfeseite an."); + helpText.setEditable(false); + + Button backBtn = new Button("Zurück"); + backBtn.setStyle("-fx-background-color: #431EB9; -fx-text-fill: #FFFFFF;"); + backBtn.setOnAction(e -> new HomeScreen(stage).display()); + + VBox vbox = new VBox(10, label, helpText, backBtn); + vbox.setAlignment(Pos.CENTER); + vbox.setPadding(new Insets(20)); + vbox.setStyle("-fx-background-color: #FFFFFF;"); + + Scene scene = new Scene(vbox, 400, 300); + + stage.setScene(scene); + stage.show(); + } +} diff --git a/src/views/HomeScreen.java b/src/views/HomeScreen.java new file mode 100644 index 0000000..301c09e --- /dev/null +++ b/src/views/HomeScreen.java @@ -0,0 +1,79 @@ +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.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; +import models.Pilots; +import utils.XMLHelper; + +public class HomeScreen { + private Stage stage; + + public HomeScreen(Stage stage) { + this.stage = stage; + } + + 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"); + + btn1.setOnAction(e -> new AddFlightScreen(stage).display()); + btn2.setOnAction(e -> new ViewLogbookScreen(stage).display()); + btn3.setOnAction(e -> new ManagePilotProfileScreen(stage).display()); + helpBtn.setOnAction(e -> new HelpScreen(stage).display()); + pilotsBtn.setOnAction(e -> new PilotView(stage).displayAllPilots()); + editPilotsBtn.setOnAction(e -> { + Pilots pilots = (Pilots) XMLHelper.loadFromXML("pilots.xml"); + if (pilots != null && !pilots.getPilots().isEmpty()) { + new ManagePilotProfileScreen(stage).displayEditSelection(pilots); // Aufruf mit Pilotenliste + } else { + showAlert("Keine Piloten", "Es sind keine Piloten zum Bearbeiten verfügbar."); + } + }); + + 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;"); + + Scene scene = new Scene(vbox, 600, 400); + scene.getStylesheets().add(getClass().getResource("/resources/style.css").toExternalForm()); + + stage.setScene(scene); + stage.setTitle("Fluglogbuch"); + stage.show(); + } + + private Button createButton(String text, String iconPath) { + 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.setPrefSize(250, 50); + return button; + } + + private void showAlert(String title, String message) { + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle(title); + alert.setHeaderText(null); + alert.setContentText(message); + alert.showAndWait(); + } +} diff --git a/src/views/ManagePilotProfileScreen.java b/src/views/ManagePilotProfileScreen.java new file mode 100644 index 0000000..215083e --- /dev/null +++ b/src/views/ManagePilotProfileScreen.java @@ -0,0 +1,196 @@ +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.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; + + public ManagePilotProfileScreen(Stage stage) { + this.stage = stage; + } + + public void display() { + display(null); + } + + public void displayEditSelection(Pilots pilots) { + Label label = new Label("Wählen Sie einen Piloten zum Bearbeiten aus:"); + ComboBox pilotComboBox = new ComboBox<>(); + pilotComboBox.getItems().addAll(pilots.getPilots()); + pilotComboBox.setPromptText("Pilot auswählen"); + + Button selectBtn = new Button("Auswählen"); + selectBtn.setOnAction(e -> { + Pilot selectedPilot = pilotComboBox.getValue(); + if (selectedPilot != null) { + display(selectedPilot); + } else { + showAlert("Keine Auswahl", "Bitte wählen Sie einen Piloten aus der Liste aus."); + } + }); + + Button backButton = new Button("Zurück"); + backButton.setOnAction(e -> new HomeScreen(stage).display()); + + VBox vbox = new VBox(10, label, pilotComboBox, selectBtn); + vbox.setAlignment(Pos.CENTER); + vbox.setPadding(new Insets(20)); + vbox.setStyle("-fx-background-color: #FFFFFF;"); + + 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, 400, 300); + + 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(); + + nameField.setPromptText("Name"); + adresseField.setPromptText("Adresse"); + 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()); + } + + Button addLizenzBtn = new Button("Lizenz hinzufügen"); + addLizenzBtn.setOnAction(e -> { + if (!lizenzField.getText().isEmpty()) { + lizenzListView.getItems().add(lizenzField.getText()); + lizenzField.clear(); + } + }); + + Button addZertifikatBtn = new Button("Zertifikat hinzufügen"); + addZertifikatBtn.setOnAction(e -> { + if (!zertifikatField.getText().isEmpty()) { + zertifikatListView.getItems().add(zertifikatField.getText()); + zertifikatField.clear(); + } + }); + + Button submitBtn = new Button(pilot == null ? "Hinzufügen" : "Speichern"); + submitBtn.setStyle("-fx-background-color: #431EB9; -fx-text-fill: #FFFFFF;"); + 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 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.setAlignment(Pos.CENTER); + vbox.setPadding(new Insets(20)); + vbox.setStyle("-fx-background-color: #FFFFFF;"); + + 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, 400, 600); + + stage.setScene(scene); + stage.show(); + } + + private void handleSaveProfile(Pilot pilot, TextField nameField, TextField adresseField, + TextField kontaktinformationenField, ListView lizenzListView, ListView zertifikatListView) { + clearFieldStyles(nameField, adresseField, kontaktinformationenField); + + try { + if (nameField.getText().isEmpty()) { + setErrorStyle(nameField); + throw new IllegalArgumentException("Name ist erforderlich."); + } + if (adresseField.getText().isEmpty()) { + setErrorStyle(adresseField); + throw new IllegalArgumentException("Adresse ist erforderlich."); + } + if (kontaktinformationenField.getText().isEmpty()) { + setErrorStyle(kontaktinformationenField); + throw new IllegalArgumentException("Kontaktinformationen sind erforderlich."); + } + + if (pilot == null) { + pilot = new Pilot(nameField.getText(), adresseField.getText(), kontaktinformationenField.getText()); + } else { + pilot.setName(nameField.getText()); + pilot.setAdresse(adresseField.getText()); + pilot.setKontaktinformationen(kontaktinformationenField.getText()); + } + + 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"); + + new HomeScreen(stage).display(); + } catch (IllegalArgumentException e) { + showAlert("Fehlende Eingabe", e.getMessage()); + } catch (Exception e) { + showAlert("Fehler", "Es ist ein Fehler beim Speichern des Piloten aufgetreten."); + } + } + + 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/PilotView.java b/src/views/PilotView.java new file mode 100644 index 0000000..e105958 --- /dev/null +++ b/src/views/PilotView.java @@ -0,0 +1,83 @@ +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.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)); + vbox.setStyle("-fx-background-color: #FFFFFF;"); + + 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, 400, 300); + 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.setAlignment(Pos.CENTER); + vbox.setPadding(new Insets(20)); + vbox.setStyle("-fx-background-color: #FFFFFF;"); + + for (Pilot pilot : pilots) { + Label nameLabel = new Label("Name: " + pilot.getName()); + vbox.getChildren().add(nameLabel); + + Button detailButton = new Button("Details anzeigen"); + detailButton.setOnAction(e -> displayPilotDetails(pilot)); + vbox.getChildren().add(detailButton); + } + + 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, 400, 300); + stage.setScene(scene); + stage.setTitle("Alle Piloten"); + stage.show(); + } +} diff --git a/src/views/ViewLogbookScreen.java b/src/views/ViewLogbookScreen.java new file mode 100644 index 0000000..fe0600d --- /dev/null +++ b/src/views/ViewLogbookScreen.java @@ -0,0 +1,93 @@ +package views; + +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.layout.BorderPane; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; +import models.Flight; +import models.Flights; +import utils.XMLHelper; + +import java.util.List; + +public class ViewLogbookScreen { + private Stage stage; + + public ViewLogbookScreen(Stage stage) { + this.stage = stage; + } + + public void display() { + Flights flightsData = (Flights) XMLHelper.loadFromXML("flights.xml"); + List flightList = flightsData != null ? flightsData.getFlights() : List.of(); + + ObservableList flights = FXCollections.observableArrayList(flightList); + + TableView tableView = new TableView<>(flights); + + TableColumn dateColumn = new TableColumn<>("Datum"); + dateColumn.setCellValueFactory(new PropertyValueFactory<>("datum")); + + TableColumn modelColumn = new TableColumn<>("Muster"); + modelColumn.setCellValueFactory(new PropertyValueFactory<>("muster")); + + TableColumn departureColumn = new TableColumn<>("Abflugort"); + departureColumn.setCellValueFactory(new PropertyValueFactory<>("abflugort")); + + TableColumn departureTimeColumn = new TableColumn<>("Abflugzeit"); + departureTimeColumn.setCellValueFactory(new PropertyValueFactory<>("abflugzeit")); + + TableColumn arrivalTimeColumn = new TableColumn<>("Ankunftszeit"); + arrivalTimeColumn.setCellValueFactory(new PropertyValueFactory<>("ankunftszeit")); + + TableColumn durationColumn = new TableColumn<>("Flugdauer"); + durationColumn.setCellValueFactory(new PropertyValueFactory<>("tToF")); + + TableColumn landingsColumn = new TableColumn<>("Anzahl der Landungen"); + landingsColumn.setCellValueFactory(new PropertyValueFactory<>("anzahlLandungen")); + + TableColumn nightFlightColumn = new TableColumn<>("Nachtflug"); + nightFlightColumn.setCellValueFactory(new PropertyValueFactory<>("isNachtflug")); + + TableColumn commentColumn = new TableColumn<>("Kommentar"); + commentColumn.setCellValueFactory(new PropertyValueFactory<>("kommentar")); + + 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); + + Button backButton = new Button("Zurück"); + backButton.setOnAction(e -> new HomeScreen(stage).display()); + + VBox vbox = new VBox(tableView); + vbox.setAlignment(Pos.CENTER); + vbox.setPadding(new Insets(20)); + vbox.setStyle("-fx-background-color: #FFFFFF;"); + + 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); + + stage.setScene(scene); + stage.setTitle("Fluglogbuch einsehen"); + stage.show(); + } +}