diff --git a/res/.nfs00000000024418ac000000c5 b/res/.nfs00000000024418ac000000c5 new file mode 100644 index 0000000..dafa4b3 Binary files /dev/null and b/res/.nfs00000000024418ac000000c5 differ diff --git a/src/main/java/seng202/group9/Controller/App.java b/src/main/java/seng202/group9/Controller/App.java index b9e6c68..f7f39b2 100644 --- a/src/main/java/seng202/group9/Controller/App.java +++ b/src/main/java/seng202/group9/Controller/App.java @@ -17,6 +17,7 @@ import javafx.scene.control.Menu; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.BorderPane; import javafx.scene.layout.VBox; +import javafx.stage.Modality; import javafx.stage.Stage; import seng202.group9.Core.FlightPath; import seng202.group9.GUI.*; @@ -50,6 +51,23 @@ public class App extends Application @Override public void start(Stage primaryStage) { this.primaryStage = primaryStage; + //after all loading then load the previous session + try{ + FileInputStream fileIn = new FileInputStream("res/session.ser"); + ObjectInputStream objectIn = new ObjectInputStream(fileIn); + session = (Session) objectIn.readObject(); + objectIn.close(); + fileIn.close(); + }catch(IOException e){ + session = new Session(); + System.out.println("New Session File Created"); + }catch(ClassNotFoundException e){ + System.out.println("Missing Session Class"); + System.exit(1); + } catch (Exception e) { + session = new Session(); + e.printStackTrace(); + } //load the menu and the first container try { FXMLLoader loader = new FXMLLoader(); @@ -72,40 +90,25 @@ public class App extends Application } catch (Exception e){ e.printStackTrace(); } - //after all loading then load the previous session - try{ - FileInputStream fileIn = new FileInputStream("res/session.ser"); - ObjectInputStream objectIn = new ObjectInputStream(fileIn); - session = (Session) objectIn.readObject(); - Controller controller = (Controller) replaceSceneContent(session.getSceneDisplayed()); - controller.setApp(this); - controller.load(); - controller.loadOnce(); - objectIn.close(); - fileIn.close(); - }catch(IOException e){ - session = new Session(); - System.out.println("New Session File Created"); - }catch(ClassNotFoundException e){ - System.out.println("Missing Session Class"); - System.exit(1); - } catch (Exception e) { - session = new Session(); - e.printStackTrace(); - } //testing out dataset try { if (session.getCurrentDataset() != null) { currentDataset = new Dataset(session.getCurrentDataset(), Dataset.getExisting); }else{ - menuController.createPopUpStage(SceneCode.DATASET_CONTROLLER, 600, 400); + createPopUpStage(SceneCode.DATASET_CONTROLLER, 600, 400); } }catch (DataException e){ - menuController.createPopUpStage(SceneCode.DATASET_CONTROLLER, 600, 400); + createPopUpStage(SceneCode.DATASET_CONTROLLER, 600, 400); }catch (NullPointerException e){ - menuController.createPopUpStage(SceneCode.DATASET_CONTROLLER, 600, 400); + createPopUpStage(SceneCode.DATASET_CONTROLLER, 600, 400); }catch (Exception e){ - menuController.createPopUpStage(SceneCode.DATASET_CONTROLLER, 600, 400); + createPopUpStage(SceneCode.DATASET_CONTROLLER, 600, 400); + } + //after all loading then load the previous session + if (session.getSceneDisplayed() != null) { + menuController.replaceSceneContent(session.getSceneDisplayed()); + }else{ + menuController.replaceSceneContent(SceneCode.INITIAL); } } @@ -251,4 +254,37 @@ public class App extends Application } } } + + public Stage createPopUpStage(SceneCode scene, int width, int height) { + FXMLLoader loader = new FXMLLoader(); + InputStream in = getClass().getClassLoader().getResourceAsStream(scene.getFilePath()); + Parent page = null; + try { + page = loader.load(in); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + //set contorller and call default calls + Controller controller = (Controller) loader.getController(); + controller.setApp(this); + controller.load(); + controller.loadOnce(); + //create a new stage to popup + Stage popupStage = new Stage(); + popupStage.initModality(Modality.WINDOW_MODAL); + //inner layout constraints + VBox container = new VBox(); + container.getChildren().add(page); + Scene popupScene = new Scene(container, width, height); + //show + popupStage.setScene(popupScene); + popupStage.showAndWait(); + return popupStage; + } } diff --git a/src/main/java/seng202/group9/Controller/SceneCode.java b/src/main/java/seng202/group9/Controller/SceneCode.java index d1ae151..cdbd254 100644 --- a/src/main/java/seng202/group9/Controller/SceneCode.java +++ b/src/main/java/seng202/group9/Controller/SceneCode.java @@ -5,14 +5,14 @@ package seng202.group9.Controller; * SceneCode enum is used for Serialization of sessions as well as changing the GUI state from one to the other. */ public enum SceneCode { - INITIAL(""), AIRLINE_SUMMARY("airline_summary.fxml"), AIRLINE_RAW_DATA("airline_raw_data.fxml"), + INITIAL("getting_started.fxml"), AIRLINE_SUMMARY("airline_summary.fxml"), AIRLINE_RAW_DATA("airline_raw_data.fxml"), AIRPORT_SUMMARY("airport_summary.fxml"), AIRPORT_RAW_DATA("airport_raw_data.fxml"), ROUTE_SUMMARY("routes_summary.fxml"), ROUTE_RAW_DATA("route_raw_data.fxml"), FLIGHT_SUMMARY("flight_data_summary.fxml"), FLIGHT_RAW_DATA("flight_raw_data.fxml"), AIRPORT_ANALYSER("airport_analyser.fxml"), ROUTE_ANALYSER("route_analyser.fxml"), AIRPORT_DIST_CALC("airport_dist_calc.fxml"), AIRLINE_ADD("airline_add_form.fxml"), AIRLINE_FILTER("airline_filter_form.fxml"), 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"); + ROUTE_EDIT("route_edit_form.fxml"), FLIGHT_EDITOR("flight_editor_form.fxml"), DATASET_CONTROLLER("dataset_editor.fxml"), HELP("help.fxml"); private String filePath; diff --git a/src/main/java/seng202/group9/GUI/FlightEditorController.java b/src/main/java/seng202/group9/GUI/FlightEditorController.java index 78f0b77..6282cd5 100644 --- a/src/main/java/seng202/group9/GUI/FlightEditorController.java +++ b/src/main/java/seng202/group9/GUI/FlightEditorController.java @@ -69,7 +69,6 @@ public class FlightEditorController extends Controller{ stage.close(); } catch ( Exception e ) { - e.printStackTrace(); Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("Flight Data Error"); alert.setHeaderText("Error editing a flight point."); diff --git a/src/main/java/seng202/group9/GUI/FlightSummaryController.java b/src/main/java/seng202/group9/GUI/FlightSummaryController.java index c15cf63..4be3376 100644 --- a/src/main/java/seng202/group9/GUI/FlightSummaryController.java +++ b/src/main/java/seng202/group9/GUI/FlightSummaryController.java @@ -13,8 +13,10 @@ import javafx.scene.control.ListView; import javafx.scene.input.MouseEvent; import javafx.scene.web.WebView; import seng202.group9.Controller.App; +import seng202.group9.Controller.DataException; import seng202.group9.Controller.Dataset; import seng202.group9.Controller.SceneCode; +import seng202.group9.Core.Airport; import seng202.group9.Core.FlightPath; import seng202.group9.Core.RoutePath; import seng202.group9.Map.Map; @@ -22,6 +24,7 @@ import seng202.group9.Core.FlightPoint; import java.net.URL; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.ResourceBundle; /** @@ -31,9 +34,8 @@ import java.util.ResourceBundle; public class FlightSummaryController extends Controller { private Dataset theDataSet = null; - private int currentPathId = 0; - private int currentPathIndex = 0; + private int currentPathIndex = 0; @FXML private Button flightRawData; @@ -43,6 +45,9 @@ public class FlightSummaryController extends Controller { @FXML ListView flightPathListView; final ObservableList flightList = FXCollections.observableArrayList(); + @FXML + ListView flightSummaryListView; + final ObservableList infoList = FXCollections.observableArrayList(); /** * Changes to the Flight Raw Data Scene when the Raw Data Button is clicked. @@ -54,7 +59,9 @@ public class FlightSummaryController extends Controller { /** * Changes to the Airport Summary Scene when the Airport is clicked. */ - public void airportSummaryButton() { replaceSceneContent(SceneCode.AIRPORT_SUMMARY); } + public void airportSummaryButton() { + replaceSceneContent(SceneCode.AIRPORT_SUMMARY); + } /** * Changes to the Route Summary Scene when the Route Button is clicked. @@ -70,6 +77,73 @@ public class FlightSummaryController extends Controller { replaceSceneContent(SceneCode.AIRLINE_SUMMARY); } + /** + * Loads the current flight paths summary information into the ListView panel. The summary data includes the distance + * and the name of the source and destination airports pulled from the Airport array list. + */ + public void flightSummaryListView() { + try { + currentPathId = theDataSet.getFlightPaths().get(0).getID(); //Sets the default to the 1st Path + + FlightPath currentPath = theDataSet.getFlightPathDictionary().get(currentPathId); + ArrayList flightPoints = currentPath.getFlightPoints(); + FlightPoint firstPoint = flightPoints.get(0); + String firstPointICAO = firstPoint.getName(); + FlightPoint lastPoint = flightPoints.get(flightPoints.size()-1); + String lastPointICAO = lastPoint.getName(); + + ArrayList airportList = theDataSet.getAirports(); + Airport sourceAirport = null; + Airport destinationAirport = null; + + System.out.println(firstPointICAO); + System.out.println(lastPointICAO); + + for (int i=0; i < airportList.size(); i++){ + Airport current = airportList.get(i); + System.out.println(current.getICAO()); + if(current.getICAO().equals(firstPointICAO)){ + sourceAirport = current; + } + if(current.getICAO().equals(lastPointICAO)){ + destinationAirport = current; + } + } + + String source = "Not Available"; + String destination = "Not Available"; + double distance = 0.0; + if(sourceAirport != null){ + source = sourceAirport.getName(); + } + if(destinationAirport != null){ + destination = destinationAirport.getName(); + } + if(destination != "Not Available" && source != "Not Available"){ + distance = sourceAirport.calculateDistance(destinationAirport); + } + + infoList.add(" Flight Path Summary Information"); + infoList.add(""); + infoList.add("Total Distance of Flight:"); + infoList.add(Double.toString(distance)); + infoList.add("Source Airport:"); + infoList.add(source); + infoList.add("Destination Airport:"); + infoList.add(destination); + if(sourceAirport == null || destinationAirport == null){ + infoList.add(""); + infoList.add("Missing Data is due to first or last points"); + infoList.add("ICAO codes not being present in the Airline"); + infoList.add("Database!"); + } + + flightSummaryListView.setItems(infoList); + } catch(Exception e) { + e.printStackTrace(); + } + } + /** * 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. @@ -85,6 +159,17 @@ public class FlightSummaryController extends Controller { String flightPathDisplayName = Integer.toString(pathID) + "_" + pathSource + "_" + pathDestin; flightList.add(flightPathDisplayName); } + flightPathListView.setOnMouseClicked(new EventHandler() { + public void handle(MouseEvent event) { + String flightPathDisplayNameClicked = flightPathListView.getSelectionModel().getSelectedItem(); + String[] segments = flightPathDisplayNameClicked.split("_"); + String pathIdClicked = segments[0]; + + currentPathIndex = theDataSet.getFlightPaths().indexOf(theDataSet.getFlightPathDictionary() + .get(Integer.parseInt(pathIdClicked))); + currentPathId = Integer.parseInt(pathIdClicked); + } + }); flightPathListView.setItems(flightList); } catch (Exception e) { e.printStackTrace(); @@ -96,7 +181,7 @@ public class FlightSummaryController extends Controller { public void load() { try { theDataSet = getParent().getCurrentDataset(); - ArrayList flightPaths = new ArrayList(); + ArrayList flightPaths; flightPaths = theDataSet.getFlightPaths(); for(int i = 0; i - + @@ -85,28 +85,28 @@ - - + + - + - - - - + + + + + + + + + diff --git a/src/main/resources/help.fxml b/src/main/resources/help.fxml new file mode 100644 index 0000000..6f1d0bd --- /dev/null +++ b/src/main/resources/help.fxml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/menu.fxml b/src/main/resources/menu.fxml index e6d61d5..cb7dd6d 100644 --- a/src/main/resources/menu.fxml +++ b/src/main/resources/menu.fxml @@ -1,12 +1,15 @@ + + + - + @@ -49,6 +52,12 @@ + + + + + + diff --git a/src/main/resources/route_raw_data.fxml b/src/main/resources/route_raw_data.fxml index 80775bf..3a7a3ce 100644 --- a/src/main/resources/route_raw_data.fxml +++ b/src/main/resources/route_raw_data.fxml @@ -1,5 +1,10 @@ + + + + + @@ -13,7 +18,7 @@ - + @@ -80,5 +85,18 @@ + +