diff --git a/res/userdb.db b/res/userdb.db index 475b344..ec4da79 100644 Binary files a/res/userdb.db and b/res/userdb.db differ diff --git a/src/main/java/seng202/group9/Controller/SceneCode.java b/src/main/java/seng202/group9/Controller/SceneCode.java index 205465d..e921a0e 100644 --- a/src/main/java/seng202/group9/Controller/SceneCode.java +++ b/src/main/java/seng202/group9/Controller/SceneCode.java @@ -13,7 +13,8 @@ public enum SceneCode { AIRPORT_ADD("airport_add_form.fxml"), AIRPORT_FILTER("airport_filter_form.fxml"), ROUTE_ADD("route_add_form.fxml"), ROUTE_FILTER("route_filter_form.fxml"), AIRLINE_EDIT("airline_edit_form.fxml"), AIRPORT_EDIT("airport_edit_form.fxml"), ROUTE_EDIT("route_edit_form.fxml"), FLIGHT_EDITOR("flight_editor_form.fxml"), DATASET_CONTROLLER("dataset_editor.fxml"), HELP("help.fxml"), - FLIGHT_ADD("flight_add_form.fxml"), ROUTE_BY_AIRPORT("airport_map_routes.fxml"), ROUTE_BY_EQUIP("route_by_equip.fxml"); + FLIGHT_ADD("flight_add_form.fxml"), ROUTE_BY_AIRPORT("airport_map_routes.fxml"), ROUTE_BY_EQUIP("route_by_equip.fxml"), + FLIGHT_PATH_ADD("new_flight_path.fxml"); private String filePath; diff --git a/src/main/java/seng202/group9/GUI/FlightRDController.java b/src/main/java/seng202/group9/GUI/FlightRDController.java index e85c131..399dfdd 100644 --- a/src/main/java/seng202/group9/GUI/FlightRDController.java +++ b/src/main/java/seng202/group9/GUI/FlightRDController.java @@ -56,25 +56,6 @@ public class FlightRDController extends Controller { ListView flightPathListView; private ObservableList flightList = FXCollections.observableArrayList(); -// @FXML -// private TextField flightNameBox; -// @FXML -// private TextField flightTypeBox; -// @FXML -// private TextField flightViaBox; -// @FXML -// private TextField flightAltitudeBox; -// @FXML -// private TextField flightLatitudeBox; -// @FXML -// private TextField flightLongitudeBox; -// @FXML -// private TextField flightHeadingBox; -// @FXML -// private TextField flightLegDistBox; -// @FXML -// private TextField flightTotDistBox; - /** * Loads the Flight paths into the List View and waits for a mouse clicked event for which it will update the table * to display the selected Flight paths points. Called from the MenuController. @@ -166,16 +147,9 @@ public class FlightRDController extends Controller { * Creates a pop up dialog which prompts the user for two ICAO airport codes which will use when creating a new path. */ public void newPath() { - NewPathPopUp dialogBox = new NewPathPopUp(); - dialogBox.display(); - String destAirport = dialogBox.getDestinationAirport(); - String sourceAirport = dialogBox.getSourceAirport(); - - if (destAirport != null && sourceAirport != null){ - theDataSet.addFlightPath(sourceAirport, destAirport); - flightPathListView.getItems().clear(); - flightPathListView(); - } + createPopUpStage(SceneCode.FLIGHT_PATH_ADD, 500, 240); + flightPathListView.getItems().clear(); + flightPathListView(); } /** * Removes the selected point from the table and database. diff --git a/src/main/java/seng202/group9/GUI/NewPathController.java b/src/main/java/seng202/group9/GUI/NewPathController.java new file mode 100644 index 0000000..0395f6a --- /dev/null +++ b/src/main/java/seng202/group9/GUI/NewPathController.java @@ -0,0 +1,58 @@ +package seng202.group9.GUI; + +import javafx.fxml.FXML; +import javafx.scene.control.Alert; +import javafx.scene.control.Button; +import javafx.scene.control.TextField; +import javafx.stage.Stage; +import seng202.group9.Controller.Dataset; +import seng202.group9.Controller.EntryParser; + +/** + * The controller class for new_flight_path.fxml. + * Created by Sunguin. + */ +public class NewPathController extends Controller { + @FXML + private TextField sourceAirport; + @FXML + private TextField destinationAirport; + @FXML + private Button addButton; + + private Dataset theDataSet = null; + + public void load() { + theDataSet = getParent().getCurrentDataset(); + } + + /** + * Attempts to add a new flight path. First uses the entry parser to check for valid ICAO codes. + */ + public void addPath() { + EntryParser airportCheck = new EntryParser(); + try { + airportCheck.parsePointName(sourceAirport.getText()); + airportCheck.parsePointName(destinationAirport.getText()); + theDataSet.addFlightPath(sourceAirport.getText(), destinationAirport.getText()); + + //Saying to the user that the flight path has successfully added. + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("Flight Path Add Successful"); + alert.setHeaderText("New Flight Path added!"); + alert.setContentText("Your new flight path has been successfully added into the database."); + alert.showAndWait(); + + //Closes the add form. + Stage stage = (Stage) addButton.getScene().getWindow(); + stage.close(); + } catch (Exception e) { + //Tells the user what and where the error is. + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Flight Path Data Error"); + alert.setHeaderText("Error adding a custom flight path entry."); + alert.setContentText(e.getMessage()); + alert.showAndWait(); + } + } +} diff --git a/src/main/java/seng202/group9/GUI/NewPathPopUp.java b/src/main/java/seng202/group9/GUI/NewPathPopUp.java deleted file mode 100644 index a219a9d..0000000 --- a/src/main/java/seng202/group9/GUI/NewPathPopUp.java +++ /dev/null @@ -1,75 +0,0 @@ -package seng202.group9.GUI; - -import javafx.scene.control.Alert; -import seng202.group9.Controller.DataException; -import seng202.group9.Controller.EntryParser; -import seng202.group9.Core.FlightPoint; - -import javax.swing.*; -import java.awt.*; - -import static java.awt.Color.red; - -/** - * Creates the pop up box where the user will enter the Source and Destination airports for the path name, will reject - * empty strings, strings of length 4 and characters that are not A-Z. Will convert lowercase to uppercase. - * Created by Liam Beckett on 17/09/2016. - */ -public class NewPathPopUp { - - private String sourceAirport = null; - private String destinationAirport = null; - // Creates and displays the pop up box for the user to input data. - public void display() { - JTextField field1 = new JTextField(); - JTextField field2 = new JTextField(); - JPanel panel = new JPanel(new GridLayout(0, 1)); - panel.add(new JLabel("Source Airport ICAO Code" )); - panel.add(field1); - panel.add(new JLabel("Destination Airport ICAO Code: ")); - panel.add(field2); - int result = JOptionPane.showConfirmDialog(null, panel, "Test", - JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); - if (result == JOptionPane.OK_OPTION) { - sourceAirport = field1.getText().toUpperCase(); - destinationAirport = field2.getText().toUpperCase(); - try{ - EntryParser parser = new EntryParser(); - parser.parsePointName(sourceAirport); - }catch (DataException e){ - sourceAirport = null; - destinationAirport = null; - Alert alert = new Alert(Alert.AlertType.ERROR); - alert.setTitle("Flight Path Name Error"); - alert.setHeaderText("Error adding the Source airport ICAO code."); - alert.setContentText(e.getMessage()); - alert.showAndWait(); - } - try{ - EntryParser parser = new EntryParser(); - parser.parsePointName(destinationAirport); - }catch (DataException e){ - sourceAirport = null; - destinationAirport = null; - Alert alert = new Alert(Alert.AlertType.ERROR); - alert.setTitle("Flight Path Name Error"); - alert.setHeaderText("Error adding the Destination airport ICAO code."); - alert.setContentText(e.getMessage()); - alert.showAndWait(); - } - } else { - sourceAirport = null; - destinationAirport = null; - } - } - - public String getSourceAirport() { - return sourceAirport; - } - - public String getDestinationAirport() { - return destinationAirport; - } -} - - diff --git a/src/main/resources/new_flight_path.fxml b/src/main/resources/new_flight_path.fxml new file mode 100644 index 0000000..a9c0f08 --- /dev/null +++ b/src/main/resources/new_flight_path.fxml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +