diff --git a/.gitignore b/.gitignore index 2dd483e..e57e8a2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ SENG202.iml .settings/ doc/ res/session.ser +res/userdb.db \ No newline at end of file diff --git a/README.txt b/README.txt index 11e2cd8..8d001f0 100644 --- a/README.txt +++ b/README.txt @@ -16,6 +16,9 @@ Run java -jar seng202_2016_team9_phase2.jar Necessary Files: /res/userdb.db +To not have userdb.db clash problems run: +git update-index --assume-unchanged res/userdb.db + Getting started: The application is shipped with all the example data files pre loaded into the database. If the user wants add more data from a file then they can select a file to import using File -> Import where data is the type of data you are diff --git a/pom.xml b/pom.xml index f88e6ca..471603b 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + diff --git a/res/userdb.db b/res/userdb.db index 2d8e254..475b344 100644 Binary files a/res/userdb.db and b/res/userdb.db differ diff --git a/src/main/java/seng202/group9/Controller/App.java b/src/main/java/seng202/group9/Controller/App.java index 8744e05..d61cccd 100644 --- a/src/main/java/seng202/group9/Controller/App.java +++ b/src/main/java/seng202/group9/Controller/App.java @@ -1,6 +1,8 @@ package seng202.group9.Controller; import java.io.*; +import java.net.InetSocketAddress; +import java.net.Socket; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; @@ -13,10 +15,12 @@ import javafx.fxml.Initializable; import javafx.fxml.JavaFXBuilderFactory; import javafx.scene.Parent; import javafx.scene.Scene; +import javafx.scene.control.Alert; 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.*; @@ -33,23 +37,40 @@ public class App extends Application private VBox mainContainer = null; private Session session = null; private MenuController menuController = null; - - public static void main( String[] args ) - { - launch(args); - } + + public static void main( String[] args ) + { + launch(args); + } public Stage getPrimaryStage() { return primaryStage; } /** - * Starts the application - * @param primaryStage main "stage" of the program - */ + * Starts the application + * @param primaryStage main "stage" of the program + */ @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,32 +93,26 @@ public class App extends Application } catch (Exception e){ e.printStackTrace(); } - //testing out dataset - try { - currentDataset = new Dataset("test's", Dataset.getExisting); - }catch (DataException e){ - e.printStackTrace(); + if (session.getCurrentDataset() != null){ + for (int i = 0; i < datasets.size(); i ++) { + if (datasets.get(i).getName().equals(session.getCurrentDataset())) { + currentDataset = datasets.get(i); + } + } } //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(); + if (session.getSceneDisplayed() != null) { + menuController.replaceSceneContent(session.getSceneDisplayed()); + }else{ + menuController.replaceSceneContent(SceneCode.INITIAL); + } + //check if there is internet connectivity + if (!testInet("maps.google.com")){ + Alert alert = new Alert(Alert.AlertType.WARNING); + alert.setTitle("No Internet Connection."); + alert.setHeaderText("Unable to Connect to Google Maps"); + alert.setContentText("As we are unable to connect to Google Maps all applications which are supposed to display maps may not work as intended."); + alert.showAndWait(); } } @@ -139,6 +154,7 @@ public class App extends Application c.close(); } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + e.printStackTrace(); } } @@ -196,6 +212,7 @@ public class App extends Application */ public void setCurrentDataset(int index){ currentDataset = datasets.get(index); + session.setCurrentDataset(currentDataset.getName()); } /** @@ -204,6 +221,7 @@ public class App extends Application */ public void setCurrentDataset(Dataset dataset){ currentDataset = dataset; + session.setCurrentDataset(currentDataset.getName()); } /** @@ -240,4 +258,23 @@ public class App extends Application } } } + + /** + * Inet test to check if there internet connectivity + * @param site + * @return + */ + public boolean testInet(String site){ + Socket sock = new Socket(); + InetSocketAddress addr = new InetSocketAddress(site,80); + try { + sock.connect(addr,3000); + return true; + } catch (IOException e) { + return false; + } finally { + try {sock.close();} + catch (IOException e) {} + } + } } diff --git a/src/main/java/seng202/group9/Controller/Dataset.java b/src/main/java/seng202/group9/Controller/Dataset.java index 02377bb..d73e644 100644 --- a/src/main/java/seng202/group9/Controller/Dataset.java +++ b/src/main/java/seng202/group9/Controller/Dataset.java @@ -2,7 +2,9 @@ package seng202.group9.Controller; import javafx.scene.chart.PieChart; +import javafx.scene.control.Alert; import seng202.group9.Core.*; +import sun.awt.image.ImageWatched; import java.sql.Connection; import java.sql.DriverManager; @@ -23,12 +25,14 @@ public class Dataset { private ArrayList flightPaths; private ArrayList countries; private ArrayList cities; - private LinkedHashMap airlineDictionary; - private LinkedHashMap airportDictionary; - private LinkedHashMap routeDictionary; - private LinkedHashMap flightPathDictionary; - private LinkedHashMap countryDictionary; - private LinkedHashMap cityDictionary; + private LinkedHashMap airlineDictionary;//key name + private LinkedHashMap airportDictionary;//key name + private LinkedHashMap routeDictionary;//key routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip + private LinkedHashMap flightPathDictionary;//key path id + private LinkedHashMap countryDictionary;//key name + private LinkedHashMap cityDictionary;//key city name + private LinkedHashMap flightPointDictionary;//key point id + private LinkedHashMap equipmentDictionary; /** * @@ -50,6 +54,8 @@ public class Dataset { this.countryDictionary = new LinkedHashMap();; this.cityDictionary = new LinkedHashMap();; this.flightPathDictionary = new LinkedHashMap(); + this.flightPointDictionary = new LinkedHashMap(); + this.equipmentDictionary = new LinkedHashMap<>(); if (action == getExisting){ updateDataset(); //after this make connections. ie filling in the country.cities airports.routes etc @@ -204,9 +210,11 @@ public class Dataset { double flightPtTotDist = rs.getDouble("Tot_Dist"); double flightPtLatitude = rs.getDouble("Latitude"); double flightPtLongitude = rs.getDouble("Longitude"); - flightPaths.get(i).addFlightPoint(new FlightPoint(flightPtName, flightPtID, flightPtInd - , flightPtType, flightPtVia, flightPtheading, flightPtAltitude, flightPtLegDistance, flightPtTotDist, - flightPtLatitude, flightPtLongitude)); + FlightPoint flightPoint = new FlightPoint(flightPtName, flightPtID, flightPtInd + , flightPtType, flightPtVia, flightPtheading, flightPtAltitude, flightPtLegDistance, flightPtTotDist, + flightPtLatitude, flightPtLongitude); + flightPaths.get(i).addFlightPoint(flightPoint); + flightPointDictionary.put(flightPtID, flightPoint); } rs.close(); stmt.close(); @@ -375,7 +383,7 @@ public class Dataset { ArrayList airlinesToImport = parser.getResult(); //check for dup int numOfDuplicates = 0; - int nextID = -1; + int nextID = 1; //query database. Connection c = null; Statement stmt = null; @@ -448,7 +456,7 @@ public class Dataset { ArrayList countriesToImport = parser.getCountryResult(); //check for dup int numOfDuplicates = 0; - int nextID = -1; + int nextID = 1; //query database. Connection c = null; Statement stmt = null; @@ -463,7 +471,6 @@ public class Dataset { while (IDResult.next()) { nextID = Integer.parseInt(IDResult.getString("seq")) + 1;//for some reason sqlite3 stores incremental values as a string... } - System.out.println(nextID); stmt.close(); stmt = c.createStatement(); String insertAirportQuery = "INSERT INTO `" + this.name + "_Airport` (`Name`, `City`, `Country`, `IATA/FFA`," + @@ -580,7 +587,7 @@ public class Dataset { ArrayList routesToImport = parser.getResult(); //check for dup int numOfDuplicates = 0; - int nextID = -1; + int nextID = 1; //query database. Connection c = null; Statement stmt = null; @@ -654,7 +661,7 @@ public class Dataset { String message = parser.parse(); ArrayList flightPointsToImport = parser.getResult(); //check for dup - int nextID = -1; + int nextID = 1; //query database. Connection c = null; Statement stmt = null; @@ -662,15 +669,15 @@ public class Dataset { Class.forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); stmt = c.createStatement(); - String queryName = this.name.replace("'", "''"); - String IDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = '"+queryName+"_Flight_Points' LIMIT 1;"; + String queryName = this.name.replace("\"", "\"\""); + String IDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = \""+queryName+"_Flight_Points\" LIMIT 1;"; ResultSet IDResult = stmt.executeQuery(IDQuery); while(IDResult.next()){ nextID = Integer.parseInt(IDResult.getString("seq")) + 1;//for some reason sqlite3 stores incremental values as a string... } stmt.close(); stmt = c.createStatement(); - //ADDED + String firstPt = flightPointsToImport.get(0).getName(); String lastPt = flightPointsToImport.get(flightPointsToImport.size() - 1).getName(); FlightPath flightPathToAdd = new FlightPath(firstPt, lastPt); @@ -680,7 +687,7 @@ public class Dataset { stmt.execute(insertFlightPathQuery); stmt.close(); stmt = c.createStatement(); - int flightPathId = 0; + int flightPathId = 1; String getLastestIndex = "SELECT * FROM `sqlite_sequence` WHERE `name` = \"" + this.name.replace("\"", "\"\"") + "_Flight_Path\" LIMIT 1;"; ResultSet lastestIdResult = stmt.executeQuery(getLastestIndex); @@ -691,7 +698,7 @@ public class Dataset { lastestIdResult.close(); stmt = c.createStatement(); flightPathToAdd.setID(flightPathId); - //ADDED + String insertFlightPointQuery = "INSERT INTO `" + this.name + "_Flight_Points` (`Index_ID`, `Name`, `Type`," + " `Altitude`, `Latitude`, `Longitude`, `Order`) VALUES "; int numOfFlights = 0; @@ -706,7 +713,7 @@ public class Dataset { double flightLatitude = flightPointsToImport.get(i).getLatitude(); double flightLongitude = flightPointsToImport.get(i).getLongitude(); //insert import into database - if (numOfFlights > 0){ + if (numOfFlights > 0) { insertFlightPointQuery += ","; } insertFlightPointQuery += "(" + flightPathId +", \""+ flightName +"\", \"" + flightType + "\", "+ flightAltitude + ", " + @@ -717,6 +724,7 @@ public class Dataset { //this is placed after incase the database messes up flightPathToAdd.addFlightPoint(flightPointsToImport.get(i)); //routeDictionary.put(routeIdentifier, flightsToImport.get(i)); + flightPointDictionary.put(nextID, flightPointsToImport.get(i)); nextID++; numOfFlights++; //} @@ -732,6 +740,7 @@ public class Dataset { flightPathDictionary.put(flightPathToAdd.getID(), flightPathToAdd); } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + e.printStackTrace(); System.exit(0); } createDataLinks(); @@ -755,7 +764,6 @@ public class Dataset { //create Airline country link for (Airline airline: airlines){ airlineByIATA.put(airline.getIATA(), airline); - //System.out.println(airline.getAlias()); airline.setRoutes(new ArrayList()); airline.setCountry(countryDictionary.get(airline.getCountryName())); Country country = countryDictionary.get(airline.getCountryName()); @@ -778,17 +786,43 @@ public class Dataset { airport.setDepartureRoutes(new ArrayList()); airport.setArrivalRoutes(new ArrayList()); } + equipmentDictionary = new LinkedHashMap<>(); //set Airport variables for route for (Route route: routes){ + String[] equipment = route.getEquipment().split(" "); + for (String equip: equipment){ + if (equip != "" && equip != null){ + Equipment equipment1 = equipmentDictionary.get(equip); + if (equipment1 != null){ + equipment1.addRoute(route); + }else{ + equipment1 = new Equipment(equip); + equipment1.addRoute(route); + equipmentDictionary.put(equip, equipment1); + } + } + } if (route.getDepartureAirport().length() > 3){ route.setSourceAirport(airportsByICAO.get(route.getDepartureAirport())); + if (airportsByICAO.get(route.getDepartureAirport()) != null) { + airportsByICAO.get(route.getDepartureAirport()).addDepartureRoutes(route); + } }else{ route.setSourceAirport(airportsByIATA.get(route.getDepartureAirport())); + if (airportsByIATA.get(route.getDepartureAirport()) != null){ + airportsByIATA.get(route.getDepartureAirport()).addDepartureRoutes(route); + } } if (route.getArrivalAirport().length() > 3){ route.setDestinationAirport(airportsByICAO.get(route.getArrivalAirport())); + if (airportsByICAO.get(route.getArrivalAirport()) != null) { + airportsByICAO.get(route.getArrivalAirport()).addArrivalRoutes(route); + } }else{ route.setDestinationAirport(airportsByIATA.get(route.getArrivalAirport())); + if (airportsByIATA.get(route.getArrivalAirport()) != null) { + airportsByIATA.get(route.getArrivalAirport()).addArrivalRoutes(route); + } } route.setAirline(airlineByIATA.get(route.getAirlineName())); Airline airline = airlineByIATA.get(route.getAirlineName()); @@ -1148,21 +1182,22 @@ public class Dataset { String insertPathQuery = "INSERT INTO `" + this.name + "_Flight_Path` (`Path_ID`, `Source_Airport`, " + "`Destination_Airport`) VALUES ("+pathID+", \""+sourceAirport+"\", \""+destAirport+"\" )"; stmt.execute(insertPathQuery); - } catch (Exception e){ - System.err.println( e.getClass().getName() + ": " + e.getMessage() ); - System.exit(0); - } - newPath.setID(pathID); - flightPathDictionary.put(pathID, newPath); - flightPaths.add(newPath); - FlightPoint sourcePoint = new FlightPoint(sourceAirport, pathID); - FlightPoint destinationPoint = new FlightPoint(sourceAirport, pathID); - try{ + newPath.setID(pathID); + + flightPathDictionary.put(pathID, newPath); + flightPaths.add(newPath); + FlightPoint sourcePoint = new FlightPoint(sourceAirport, pathID); + FlightPoint destinationPoint = new FlightPoint(destAirport, pathID); + addFlightPointToPath(sourcePoint); addFlightPointToPath(destinationPoint); + updateFlightPath(newPath); } catch (DataException e){ System.err.println( e.getClass().getName() + ": " + e.getMessage() ); System.exit(0); + }catch (Exception e){ + System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + System.exit(0); } } @@ -1171,22 +1206,14 @@ public class Dataset { * @param id * @param name * @param type - * @param via * @param altitude * @param latitude * @param longitude - * @param heading - * @param legDist - * @param totDist */ - public void addFlightPointToPath(int id, String name, String type, String via, String altitude, String latitude, String longitude, - String heading, String legDist, String totDist , int index) throws DataException{ + public void addFlightPointToPath(int id, String name, String type, String altitude, String latitude, String longitude, int index) throws DataException{ double altitudeVal = 0.0; double latitudeVal = 0.0; double longitudeVal = 0.0; - int headingVal = 0; - double legDistVal = 0.0; - double totalDistVal = 0.0; try{ altitudeVal = Double.parseDouble(altitude); @@ -1203,20 +1230,8 @@ public class Dataset { }catch (NumberFormatException e){ throw new DataException("Longitude must be a double value"); } - try{ - headingVal = Integer.parseInt(heading); - }catch (NumberFormatException e){ - throw new DataException("Heading must be a integer value"); - } - try{ - legDistVal = Double.parseDouble(legDist); - }catch (NumberFormatException e){ - throw new DataException("Leg DIstance must be a double value"); - } - try{ - totalDistVal = Double.parseDouble(totDist); - }catch (NumberFormatException e){ - throw new DataException("Total Distance must be a double value"); + if (index == -1){ + index = flightPathDictionary.get(id).getFlightPoints().size(); } Connection c = null; Statement stmt; @@ -1225,21 +1240,20 @@ public class Dataset { c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); stmt = c.createStatement(); - String flightPointIDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = \""+this.name+"_Flight_Points\" LIMIT 1;"; - ResultSet pointIDRes= stmt.executeQuery(flightPointIDQuery); - while (pointIDRes.next()){ + String flightPointIDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = \"" + this.name + "_Flight_Points\" LIMIT 1;"; + ResultSet pointIDRes = stmt.executeQuery(flightPointIDQuery); + while (pointIDRes.next()) { pointID = Integer.parseInt(pointIDRes.getString("seq")); } stmt.close(); stmt = c.createStatement(); String insertFlightPointQuery = "INSERT INTO `" + this.name + "_Flight_Points` (`Index_ID`, `Name`, `Type`," + - " `Altitude`, `Latitude`, `Longitude`, `Heading`, `Tot_Dist`, `Leg_Dist`, `Via`, `Order`) VALUES "; + " `Altitude`, `Latitude`, `Longitude`, `Order`) VALUES "; String flightType = type.replace("\"", "\"\""); String flightName = name.replace("\"", "\"\""); insertFlightPointQuery += "(" + id +", \""+ flightName +"\", \"" + flightType + "\", "+ altitudeVal + ", " + - "" + latitudeVal + ", " + longitudeVal + ", " + headingVal + ", " + totalDistVal + ", " + legDistVal + - ", \"" + via + "\", "+index+")"; + "" + latitudeVal + ", " + longitudeVal + ", "+index+")"; stmt.execute(insertFlightPointQuery); stmt.close(); //move all the points after this forward @@ -1258,7 +1272,6 @@ public class Dataset { String query = "UPDATE `"+this.name+"_Flight_Path` SET `Source_Airport` = \""+flightName+"\" " + "WHERE `Path_ID` = "+flightPath.getID(); stmt.execute(query); - c.close(); } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); } @@ -1269,7 +1282,6 @@ public class Dataset { String query = "UPDATE `"+this.name+"_Flight_Path` SET `Destination_Airport` = \""+flightName+"\" " + "WHERE `Path_ID` = "+flightPath.getID(); stmt.execute(query); - c.close(); } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); } @@ -1281,10 +1293,10 @@ public class Dataset { System.exit(0); } - FlightPoint pointToAdd = new FlightPoint(name, pointID+1, id, type, via, headingVal, altitudeVal, legDistVal, - totalDistVal,latitudeVal, longitudeVal); - updateFlightPointInfo(flightPathDictionary.get(Integer.valueOf(id))); + FlightPoint pointToAdd = new FlightPoint(type, pointID+1, id, name, altitudeVal, latitudeVal, longitudeVal); flightPathDictionary.get(Integer.valueOf(id)).addFlightPoint(pointToAdd, index); + flightPointDictionary.put(pointID + 1, pointToAdd); + updateFlightPointInfo(flightPathDictionary.get(Integer.valueOf(id))); } /*** @@ -1294,9 +1306,8 @@ public class Dataset { * @throws DataException */ public void addFlightPointToPath(FlightPoint point, int index) throws DataException{ - addFlightPointToPath(point.getIndex(), point.getName(), point.getType(), point.getVia(), String.valueOf(point.getAltitude()), - String.valueOf( point.getLatitude()),String.valueOf(point.getLongitude()), - String.valueOf(point.getHeading()), String.valueOf(point.getLegDistance()), String.valueOf(point.getTotalDistance()), index); + addFlightPointToPath(point.getIndex(), point.getName(), point.getType(), String.valueOf(point.getAltitude()), + String.valueOf( point.getLatitude()),String.valueOf(point.getLongitude()), index); } /*** * Adds a single flight Point to an Existing FLight Path appended on the end of the list. @@ -1304,9 +1315,8 @@ public class Dataset { * @throws DataException */ public void addFlightPointToPath(FlightPoint point) throws DataException{ - addFlightPointToPath(point.getIndex(), point.getName(), point.getType(), point.getVia(), String.valueOf(point.getAltitude()), - String.valueOf( point.getLatitude()),String.valueOf(point.getLongitude()), - String.valueOf(point.getHeading()), String.valueOf(point.getLegDistance()), String.valueOf(point.getTotalDistance()), -1); + addFlightPointToPath(point.getIndex(), point.getName(), point.getType(), String.valueOf(point.getAltitude()), + String.valueOf( point.getLatitude()),String.valueOf(point.getLongitude()), -1); } /** @@ -1314,19 +1324,14 @@ public class Dataset { * @param id * @param name * @param type - * @param via * @param altitude * @param latitude * @param longitude - * @param heading - * @param legDist - * @param totDist * @throws DataException */ - public void addFlightPointToPath(int id, String name, String type, String via, String altitude, String latitude, String longitude, - String heading, String legDist, String totDist) throws DataException{ - addFlightPointToPath(id, name, type, via, altitude, latitude, longitude, heading, legDist, totDist, -1); + public void addFlightPointToPath(int id, String name, String type, String altitude, String latitude, String longitude) throws DataException{ + addFlightPointToPath(id, name, type, altitude, latitude, longitude, -1); } /** * This is called in conjunction to the App deleteDataset DO NOT CALL UNLESS THROUGH APP.DELETEDATASET @@ -1367,14 +1372,10 @@ public class Dataset { try { Class.forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); - //System.out.println(airline.getID()); - String deleteQuery = "DELETE FROM `"+this.name+"_Airline` WHERE `Airline_ID` = " + airline.getID() + ";"; + String deleteQuery = "DELETE FROM `" + this.name + "_Airline` WHERE `Airline_ID` = " + airline.getID() + ";"; stmt = c.createStatement(); - //System.out.println("Airline deleted"); stmt.execute(deleteQuery); - //System.out.println("Airline deleted"); stmt.close(); - //System.out.println("Airline deleted"); stmt = c.createStatement(); //check if number of countries that contain airlines > 0 else delete the country String countCountry = "SELECT COUNT(*) FROM `"+this.name+"_Airline` JOIN `"+this.name+"_Country` ON" + @@ -1546,7 +1547,12 @@ public class Dataset { public void deleteFlightPath(FlightPath flightPath){ //delete all flight points with the id while(flightPath.getFlightPoints().size() > 0){ - deleteFlightPoint(flightPath.getFlightPoints().get(0), flightPath); + try { + flightPointDictionary.remove(flightPath.getFlightPoints().get(0).getID()); + flightPath.getFlightPoints().remove(0); + } catch (DataException e) { + e.printStackTrace(); + } } //drop the entries Connection c = null; @@ -1587,21 +1593,41 @@ public class Dataset { * @param flightPoint */ public void deleteFlightPoint(FlightPoint flightPoint, FlightPath flightPath){ - //drop the tables - Connection c = null; - Statement stmt = null; - try { - Class.forName("org.sqlite.JDBC"); - c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); - String deleteQuery = "DELETE FROM `"+this.name+"_Flight_Points` WHERE `Point_ID` = " + flightPoint.getID() + ";"; - stmt = c.createStatement(); - stmt.execute(deleteQuery); - c.close(); - } catch ( Exception e ) { - System.err.println( e.getClass().getName() + ": " + e.getMessage() ); - System.exit(0); + if (flightPath.getFlightPoints().size() > 2){ + //drop the tables + Connection c = null; + Statement stmt = null; + try { + Class.forName("org.sqlite.JDBC"); + c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + String deleteQuery = "DELETE FROM `" + this.name + "_Flight_Points` WHERE `Point_ID` = " + flightPoint.getID() + ";"; + stmt = c.createStatement(); + stmt.execute(deleteQuery); + + stmt = c.createStatement(); + String updatePointOrderQuery = ""; + for (int i = 0; i < flightPath.getFlightPoints().size(); i++) { + updatePointOrderQuery = "UPDATE `" + this.name + "_Flight_Points` SET `Order` = " + i + " WHERE `Point_ID` = " + flightPath.getFlightPoints().get(i).getID() + ";"; + stmt.execute(updatePointOrderQuery); + } + stmt.close(); + + c.close(); + } catch (Exception e) { + System.err.println(e.getClass().getName() + ": " + e.getMessage()); + System.exit(0); + } + flightPath.getFlightPoints().remove(flightPoint); + flightPointDictionary.remove(flightPoint); + updateFlightPointInfo(flightPath); + updateFlightPath(flightPath); + }else{ + Alert cannotDelete = new Alert(Alert.AlertType.ERROR); + cannotDelete.setTitle("Flight Path Error"); + cannotDelete.setHeaderText("Cannot Delete Flight Point."); + cannotDelete.setContentText("You cannot have less than 2 Points in a Flight Path."); + cannotDelete.showAndWait(); } - flightPath.getFlightPoints().remove(flightPoint); } /** @@ -1693,6 +1719,15 @@ public class Dataset { return flightPathDictionary; } + /** + * returns a flightpoint dictionary with the flights that are associated with this dataset. + * + * @return + */ + public LinkedHashMap getFlightPointDictionary() { + return flightPointDictionary; + } + /** * returns a Country Dictionary with the COuntries that are associated with this dataset. * @return @@ -1709,6 +1744,10 @@ public class Dataset { return cityDictionary; } + public LinkedHashMap getEquipmentDictionary() { + return equipmentDictionary; + } + /** * Edits Airline and commits them to the database. * @param index @@ -1739,9 +1778,10 @@ public class Dataset { public void editAirline(Airline airline, String name, String alias, String IATA, String ICAO, String callsign, String country, String active ) throws DataException { //check the data errors EntryParser parser = new EntryParser(); + airlineDictionary.remove(airline); parser.parseAirline(name, alias, IATA,ICAO, callsign, country, active); airline.setName(name); - airline.setAlias(name); + airline.setAlias(alias); airline.setIATA(IATA); airline.setICAO(ICAO); airline.setCallSign(callsign); @@ -1753,7 +1793,7 @@ public class Dataset { Class.forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); stmt = c.createStatement(); - String query = "UPDATE `"+this.name+"_Airline` SET `Name` = \""+airline.getName().replace("\"", "\"\"")+"\", `Alias` = \""+airline.getActive().replace("\"", "\"\"")+"\", " + + String query = "UPDATE `"+this.name+"_Airline` SET `Name` = \""+airline.getName().replace("\"", "\"\"")+"\", `Alias` = \""+airline.getAlias().replace("\"", "\"\"")+"\", " + "`IATA` = \""+airline.getIATA().replace("\"", "\"\"")+"\", `ICAO` = \""+airline.getICAO().replace("\"", "\"\"")+"\" , `Callsign` = \""+airline.getCallSign().replace("\"", "\"\"")+"\", " + "`Country` = \""+airline.getCountryName().replace("\"", "\"\"")+"\", `Active` = \""+airline.getActive().replace("\"", "\"\"")+"\" WHERE `Airline_ID` = "+airline.getID(); stmt.execute(query); @@ -1762,6 +1802,7 @@ public class Dataset { } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); } + airlineDictionary.put(airline.getName(), airline); createDataLinks(); } @@ -1803,25 +1844,77 @@ public class Dataset { */ public void editAirport(Airport airport, String name, String city, String country, String IATA_FFA, String ICAO, String lat, String lng, String alt, String timezone, String DST, String olson) throws DataException { EntryParser parser = new EntryParser(); + airportDictionary.remove(airport.getName()); Airport newAirport = parser.parseAirport(name, city, country, IATA_FFA, ICAO, lat, lng, alt, timezone, DST, olson); airport.setName(name); airport.setCityName(city); - airport.getCity().setName(city); + //airport.getCity().setName(city); airport.setCountryName(country); - airport.getCountry().setName(country); + //airport.getCountry().setName(country); airport.setIATA_FFA(IATA_FFA); airport.setICAO(ICAO); airport.setLatitude(newAirport.getLatitude()); airport.setLongitude(newAirport.getLongitude()); + airport.setAltitude(newAirport.getAltitude()); airport.getCity().setTimezone(Double.parseDouble(timezone)); airport.getCountry().setDST(DST); airport.getCity().setTimeOlson(olson); Connection c = null; Statement stmt = null; + try { Class.forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + /* + //UPDATE CITY AND COUNTRIES + */ + if (cityDictionary.containsKey(city) && cityDictionary.get(city) != null){ + airport.setCity(cityDictionary.get(city)); + airport.getCity().setCountry(country); + airport.getCity().setTimezone(Double.parseDouble(timezone)); + airport.getCity().setTimeOlson(olson); + //update city in database + stmt = c.createStatement(); + String updateCityQuery = "UPDATE `"+this.name+"_City` SET `Country_Name` = \""+country+"\", " + + "`Timezone` = "+timezone+", `Olson_Timezone` = \""+olson+"\" WHERE `City_Name` = \""+city+"\""; + stmt.execute(updateCityQuery); + stmt.close(); + }else { + City newCity = new City(city, country, Double.parseDouble(timezone), olson); + airport.setCity(newCity); + airport.setCityName(city); + cities.add(newCity); + cityDictionary.put(city, newCity); + //add new City to database + stmt = c.createStatement(); + String addNewCity = "INSERT INTO `"+this.name+"_City` (`City_Name`, `Country_name`, `Timezone`, `Olson_Timezone`) VALUES " + + "(\""+city+"\", \""+country+"\", "+timezone+", \""+olson+"\")"; + stmt.execute(addNewCity); + stmt.close(); + } + + if (countryDictionary.containsKey(country) && countryDictionary.get(country) != null){ + airport.setCountry(countryDictionary.get(country)); + airport.getCountry().setDST(DST); + //update country in database + stmt = c.createStatement(); + String updateCountryQuery = "UPDATE `"+this.name+"_Country` SET `DST` = "+DST+" WHERE `Country_Name` = \""+country+"\""; + stmt.execute(updateCountryQuery); + stmt.close(); + }else{ + Country newCountry = new Country(DST, name); + airport.setCountry(newCountry); + airport.setCountryName(country); + countries.add(newCountry); + countryDictionary.put(country, newCountry); + //add new COuntry to database + stmt = c.createStatement(); + String createCountryQuery = "INSERT INTO `"+this.name+"_Country` (`Country_Name`, `DST`) VALUES (\""+country+"\", \""+DST+"\")"; + stmt.execute(createCountryQuery); + stmt.close(); + } + stmt = c.createStatement(); String query = "UPDATE `"+this.name+"_Airport` SET `Name` = \""+airport.getName().replace("\"", "\"\"")+"\", `City` = \""+airport.getCityName().replace("\"", "\"\"")+"\", " + "`Country` = \""+airport.getCountryName().replace("\"", "\"\"")+"\", `IATA/FFA` = \""+airport.getIATA_FFA().replace("\"", "\"\"")+"\", " + @@ -1833,6 +1926,7 @@ public class Dataset { } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); } + airportDictionary.put(airport.getName(), airport); createDataLinks(); } @@ -1864,6 +1958,8 @@ public class Dataset { */ public void editRoute(Route route, String airline, String source, String dest, String code, String stops, String equip) throws DataException { EntryParser entryParser = new EntryParser(); + //routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip + routeDictionary.remove(route.getAirlineName()+route.getDepartureAirport()+route.getArrivalAirport()+route.getCode()+route.getStops() + route.getEquipment()); Route newRoute = entryParser.parseRoute(airline, source, dest, code, stops, equip); route.setAirlineName(newRoute.getAirlineName()); route.setDepartureAirport(newRoute.getDepartureAirport()); @@ -1877,16 +1973,18 @@ public class Dataset { Class.forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); stmt = c.createStatement(); - String query = "UPDATE `"+this.name+"_Routes` SET `Airline` = \""+route.getAirlineName().replace("\"", "\"\"")+"\", " + - "`Source_Airport` = \""+route.getDepartureAirport().replace("\"", "\"\"")+"\", `Destination_Airport` = \""+route.getArrivalAirport().replace("\"", "\"\"")+"\", " + - "`Codeshare` = \""+route.getCode().replace("\"", "\"\"")+"\", `Stops` = "+route.getStops()+", `Equipment` = \""+route.getEquipment().replace("\"", "\"\"")+"\" " + - "WHERE `Route_ID` = "+route.getID(); + String query = "UPDATE `" + this.name + "_Routes` SET `Airline` = \"" + route.getAirlineName().replace("\"", "\"\"") + "\", " + + "`Source_Airport` = \"" + route.getDepartureAirport().replace("\"", "\"\"") + "\", `Destination_Airport` = \"" + route.getArrivalAirport().replace("\"", "\"\"") + "\", " + + "`Codeshare` = \"" + route.getCode().replace("\"", "\"\"") + "\", `Stops` = " + route.getStops() + ", `Equipment` = \"" + route.getEquipment().replace("\"", "\"\"") + "\" " + + "WHERE `Route_ID` = " + route.getID(); stmt.execute(query); stmt.close(); c.close(); } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); } + //routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip + routeDictionary.put(route.getAirlineName()+route.getDepartureAirport()+route.getArrivalAirport()+route.getCode()+route.getStops() + route.getEquipment(), route); createDataLinks(); } @@ -1915,14 +2013,14 @@ public class Dataset { * @param longitude * @throws DataException */ - public void editFlight(FlightPoint flightPoint, String name, String type, String altitude, String latitude, String longitude) throws DataException{ + public void editFlight(FlightPoint flightPoint, String name, String type, String altitude, String latitude, String longitude) throws DataException { EntryParser entryParser = new EntryParser(); - FlightPoint flightPoint1 = entryParser.parsePoint(name, type, altitude, latitude, longitude); - flightPoint.setName(flightPoint1.getName()); - flightPoint.setType(flightPoint1.getType()); - flightPoint.setAltitude(flightPoint1.getAltitude()); - flightPoint.setLatitude(flightPoint1.getLatitude()); - flightPoint.setLongitude(flightPoint1.getLongitude()); + FlightPoint parsedFlightPoint = entryParser.parsePoint(name, type, altitude, latitude, longitude); + flightPoint.setName(parsedFlightPoint.getName()); + flightPoint.setType(parsedFlightPoint.getType()); + flightPoint.setAltitude(parsedFlightPoint.getAltitude()); + flightPoint.setLatitude(parsedFlightPoint.getLatitude()); + flightPoint.setLongitude(parsedFlightPoint.getLongitude()); Connection c = null; @@ -1941,35 +2039,33 @@ public class Dataset { } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); } + updateFlightPath(flightPathDictionary.get(flightPoint.getIndex())); + createDataLinks(); + } - FlightPath flightPath = flightPathDictionary.get(flightPoint.getIndexID()); - int indexOf = flightPath.getFlightPoints().indexOf(flightPoint); - - if (indexOf == 0){ - try { - stmt = c.createStatement(); - String query = "UPDATE `"+this.name+"_Flight_Path` SET `Source_Airport` = \""+flightPoint.getName().replace("\"", "\"\"")+"\" " + - "WHERE `Path_ID` = "+flightPoint.getIndexID(); - stmt.execute(query); - c.close(); - } catch ( Exception e ) { - System.err.println( e.getClass().getName() + ": " + e.getMessage() ); - } - flightPath.setDepartureAirport(flightPoint.getName()); - }else if (indexOf == flightPath.getFlightPoints().size() - 1){ - try { - stmt = c.createStatement(); - String query = "UPDATE `"+this.name+"_Flight_Path` SET `Destination_Airport` = \""+flightPoint.getName().replace("\"", "\"\"")+"\" " + - "WHERE `Path_ID` = "+flightPoint.getIndexID(); - stmt.execute(query); - c.close(); - } catch ( Exception e ) { - System.err.println( e.getClass().getName() + ": " + e.getMessage() ); - } - flightPath.setArrivalAirport(flightPoint.getName()); + /** + * Updates the flight path to the first Point and the last point + * @param flightPath + */ + private void updateFlightPath(FlightPath flightPath){ + Connection c = null; + Statement stmt = null; + FlightPoint startPoint = flightPath.getFlightPoints().get(0); + FlightPoint endPoint = flightPath.getFlightPoints().get(flightPath.getFlightPoints().size() - 1); + try { + Class.forName("org.sqlite.JDBC"); + c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + stmt = c.createStatement(); + String query= "UPDATE `"+this.name+"_Flight_Path` SET `Source_Airport` = \""+startPoint.getName().replace("\"", "\"\"")+"\", " + + "`Destination_Airport` = \""+endPoint.getName().replace("\"", "\"\"") + "\" " + + "WHERE `Path_ID` = "+startPoint.getIndex(); + stmt.execute(query); + c.close(); + } catch ( Exception e ) { + System.err.println( e.getClass().getName() + ": " + e.getMessage() ); } - updateFlightPointInfo(flightPath); - createDataLinks(); + flightPath.setArrivalAirport(endPoint.getName()); + flightPath.setDepartureAirport(startPoint.getName()); } /** @@ -1985,9 +2081,6 @@ public class Dataset { int curIndex = flightPath.getFlightPoints().indexOf(flightPoint); flightPath.getFlightPoints().remove(flightPoint); int indexToAdd = index; - if (curIndex < index){ - indexToAdd --; - } flightPath.getFlightPoints().add(indexToAdd, flightPoint); Connection c = null; @@ -2002,30 +2095,7 @@ public class Dataset { stmt.execute(updatePointOrderQuery); } stmt.close(); - - if (index == 0){ - try { - stmt = c.createStatement(); - String query = "UPDATE `"+this.name+"_Flight_Path` SET `Source_Airport` = \""+flightPoint.getName().replace("\"", "\"\"")+"\" " + - "WHERE `Path_ID` = "+flightPoint.getIndex(); - stmt.execute(query); - c.close(); - } catch ( Exception e ) { - System.err.println( e.getClass().getName() + ": " + e.getMessage() ); - } - flightPath.setDepartureAirport(flightPoint.getName()); - }else if (index == flightPath.getFlightPoints().size() - 1){ - try { - stmt = c.createStatement(); - String query = "UPDATE `"+this.name+"_Flight_Path` SET `Destination_Airport` = \""+flightPoint.getName().replace("\"", "\"\"")+"\" " + - "WHERE `Path_ID` = "+flightPoint.getIndex(); - stmt.execute(query); - c.close(); - } catch ( Exception e ) { - System.err.println( e.getClass().getName() + ": " + e.getMessage() ); - } - flightPath.setArrivalAirport(flightPoint.getName()); - } + updateFlightPath(flightPath); c.close(); } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); @@ -2060,4 +2130,12 @@ public class Dataset { System.exit(0); } } + + /** + * Name of the dataset in the database + */ + @Override + public String toString(){ + return this.name; + } } diff --git a/src/main/java/seng202/group9/Controller/EntryParser.java b/src/main/java/seng202/group9/Controller/EntryParser.java index fbeddf2..b7e2e18 100644 --- a/src/main/java/seng202/group9/Controller/EntryParser.java +++ b/src/main/java/seng202/group9/Controller/EntryParser.java @@ -132,18 +132,26 @@ public class EntryParser { } public FlightPoint parsePoint(String name, String type, String altitude, String latitude, String longitude) throws DataException{ - //(airport) name (first and last point) + //name + name = name.toUpperCase(); if (!isLetter(name)) { - throw new DataException("Airport ICAO code must contain only letters"); - } - if (name.length() != 4) { - throw new DataException("Aiport ICAO code must be of length four"); + throw new DataException("ICAO code (name field) must contain only letters"); } //type type = type.toUpperCase(); if (!type.equals("APT") && !type.equals("VOR") && !type.equals("FIX") && !type.equals("NDB") && !type.equals("LATLON")){ throw new DataException("Type of flight must be either APT, VOR, FIX, NDB or LATLON"); } + //altitude + double alt; + try{ + alt = Double.parseDouble(altitude); + }catch (NumberFormatException e){ + throw new DataException ("Altitude must be a number"); + } + if (alt < 0 || alt > 50000){ + throw new DataException("Altitude must be between 0 and 50000ft inclusive."); + } //latitude double lat; try{ @@ -164,13 +172,7 @@ public class EntryParser { if (lng > 180 || lng < -180){ throw new DataException("Longitude must be between -180 and 180 inclusive."); } - //altitude - double alt; - try{ - alt = Double.parseDouble(altitude); - }catch (NumberFormatException e){ - throw new DataException ("Altitude must be a number"); - } + FlightPoint parseSuccess = new FlightPoint(type, name, alt, lat, lng); return parseSuccess; } diff --git a/src/main/java/seng202/group9/Controller/SceneCode.java b/src/main/java/seng202/group9/Controller/SceneCode.java index 56fd07c..4802581 100644 --- a/src/main/java/seng202/group9/Controller/SceneCode.java +++ b/src/main/java/seng202/group9/Controller/SceneCode.java @@ -5,15 +5,18 @@ 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"),ANALYSER_TAB("analyser_main_page.fxml"), CHART_ERROR("too_many_options_pie.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"), ANALYSER_TAB("analyser_main_page.fxml"), CHART_ERROR("too_many_options_pie.fxml"), BAR_GRAPH_CHOOSER("bar_graph_chooser.fxml"), PIE_GRAPH_CHOOSER("pie_graph_chooser.fxml"); + private String filePath; /** diff --git a/src/main/java/seng202/group9/Controller/Session.java b/src/main/java/seng202/group9/Controller/Session.java index 7e2c018..0d759d4 100644 --- a/src/main/java/seng202/group9/Controller/Session.java +++ b/src/main/java/seng202/group9/Controller/Session.java @@ -1,8 +1,10 @@ package seng202.group9.Controller; - +import javafx.collections.ObservableList; import seng202.group9.Core.Airline; +import seng202.group9.Core.FlightPoint; + import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; @@ -14,6 +16,9 @@ import java.util.HashMap; public class Session implements Serializable { private SceneCode sceneDisplayed; + + private int currentFlightPointID; + private int currentFlightPathID; private HashMap filteredAirlines; private HashMap filteredAirports; private HashMap filteredRoutes; @@ -63,6 +68,13 @@ public class Session implements Serializable { this.usefilter = usefilter; } + private String airlineToEdit; + private String airportToEdit; + private String routeToEdit; + + private String currentDataset; + + /** * Constructor for a new session */ @@ -79,6 +91,14 @@ public class Session implements Serializable { this.sceneDisplayed = scene; } + public String getCurrentDataset(){ + return this.currentDataset; + } + + public void setCurrentDataset(String currentDataset){ + this.currentDataset = currentDataset; + } + /** * changes the serialized scene. * @param sceneDisplayed @@ -119,4 +139,60 @@ public class Session implements Serializable { return filteredRoutes; } + + public void setAirlineToEdit(String name) { + this.airlineToEdit = name; + } + + public String getAirlineToEdit() { + return airlineToEdit; + } + + public String getAirportToEdit() { + return airportToEdit; + } + + public void setAirportToEdit(String airport) { + this.airportToEdit = airport; + } + + public String getRouteToEdit() { + return routeToEdit; + } + + public void setRouteToEdit(String route) { + this.routeToEdit = route; + } + + /** + * sets the current flight point + * @param currentFlightPointID + */ + public void setCurrentFlightPointID(int currentFlightPointID) { + this.currentFlightPointID = currentFlightPointID; + } + + /** + * gets the current flight point + * @return + */ + public int getCurrentFlightPointID() { + return currentFlightPointID; + } + /** + * sets the current flight point + * @param currentFlightPathID + */ + public void setCurrentFlightPathtID(int currentFlightPathID) { + this.currentFlightPathID = currentFlightPathID; + } + + /** + * gets the current flight point + * @return + */ + public int getCurrentFlightPathID() { + return currentFlightPathID; + } + } diff --git a/src/main/java/seng202/group9/Core/Airline.java b/src/main/java/seng202/group9/Core/Airline.java index 76f9765..820b419 100644 --- a/src/main/java/seng202/group9/Core/Airline.java +++ b/src/main/java/seng202/group9/Core/Airline.java @@ -278,7 +278,7 @@ public class Airline{ if (!this.ICAO.equals("") && this.ICAO.equals(airline.getICAO())){ throw new DataException("This ICAO Code already Exists, Please Choose Another."); } - if (!this.alias.equals("") && this.alias.equals(airline.getAlias())){ + if (!this.alias.equals("") && !this.alias.equals("\\N") && !this.alias.equals("\\n") && this.alias.equals(airline.getAlias())){ throw new DataException("This Alias already Exists, Please Choose Another."); } if (!this.callSign.equals("") && this.callSign.equals(airline.getCallSign())){ diff --git a/src/main/java/seng202/group9/Core/Airport.java b/src/main/java/seng202/group9/Core/Airport.java index b4cc7f3..76e00c0 100644 --- a/src/main/java/seng202/group9/Core/Airport.java +++ b/src/main/java/seng202/group9/Core/Airport.java @@ -426,6 +426,9 @@ public class Airport { throw new DataException("Airport ICAO already Exists, Please Choose Another."); } } + public int getTotalRoutes(){ + return departureRoutes.size() + arrivalRoutes.size(); + } /** * Information of the airport returned in String format. */ diff --git a/src/main/java/seng202/group9/Core/Equipment.java b/src/main/java/seng202/group9/Core/Equipment.java new file mode 100644 index 0000000..2a67c62 --- /dev/null +++ b/src/main/java/seng202/group9/Core/Equipment.java @@ -0,0 +1,45 @@ +package seng202.group9.Core; + +import java.util.ArrayList; +import java.util.HashMap; + +/** + * Created by fwy13 on 2/10/16. + */ +public class Equipment { + private String name; + private HashMap routesUsed; + + public Equipment(String name){ + this.name = name; + routesUsed = new HashMap<>(); + } + + public void resetRoutes(){ + routesUsed = new HashMap<>(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public void addRoute(Route route){ + routesUsed.put(routesUsed.size(), route); + } + + public HashMap getRoutesUsed() { + return routesUsed; + } + + public void setRoutesUsed(HashMap routesUsed) { + this.routesUsed = routesUsed; + } + + public int getRouteNum(){ + return routesUsed.size(); + } +} diff --git a/src/main/java/seng202/group9/Core/FlightPath.java b/src/main/java/seng202/group9/Core/FlightPath.java index 1ec0931..70539e4 100644 --- a/src/main/java/seng202/group9/Core/FlightPath.java +++ b/src/main/java/seng202/group9/Core/FlightPath.java @@ -28,7 +28,7 @@ public class FlightPath { } /** - * COnstructor for FlightPath from dataset add later the ID needs to be set from database. + * Constructor for FlightPath from dataset add later the ID needs to be set from database. * @param departureAirport * @param arrivalAirport */ @@ -216,4 +216,4 @@ public class FlightPath { flightPoints.get(i).setHeading((int)heading); } } -} +} \ No newline at end of file diff --git a/src/main/java/seng202/group9/Core/FlightPoint.java b/src/main/java/seng202/group9/Core/FlightPoint.java index d4538e7..88b0b7c 100644 --- a/src/main/java/seng202/group9/Core/FlightPoint.java +++ b/src/main/java/seng202/group9/Core/FlightPoint.java @@ -60,6 +60,24 @@ public class FlightPoint { this.longitude = longitude; } + public FlightPoint(String type, int id, int index, String name, double altitude, double latitude, double longitude){ + //extra calculations will have to be used to find heading, legdistance and total distance. If necessary + //Type 1 file the file the lecturers gave us + //indexID = flight path ID + //ID = unique Auto Increment value + this.name = name; + this.ID = id; + this.indexID = index; + this.type = type; + this.via = ""; + this.heading = 0; + this.altitude = altitude; + this.legDistance = 0.0; + this.totalDistance = 0.0; + this.latitude = latitude; + this.longitude = longitude; + } + /** * Constructor when getting points from the database. * @param name Name for the point. diff --git a/src/main/java/seng202/group9/GUI/AirlineAddController.java b/src/main/java/seng202/group9/GUI/AirlineAddController.java index 8d08691..c736075 100644 --- a/src/main/java/seng202/group9/GUI/AirlineAddController.java +++ b/src/main/java/seng202/group9/GUI/AirlineAddController.java @@ -1,6 +1,5 @@ package seng202.group9.GUI; -import javafx.collections.FXCollections; import javafx.fxml.FXML; import javafx.scene.control.Alert; import javafx.scene.control.Button; @@ -9,10 +8,12 @@ import javafx.stage.Stage; import seng202.group9.Controller.Dataset; /** - * Created by Sunguin on 2016/09/22. + * The GUI controller class for airline_add_form.fxml. + * Extends from the abstract class {@link Controller}. + * Created by Sunguin */ public class AirlineAddController extends Controller { - //Setting up text fields for adding data + //Setting up text fields for adding data. @FXML private TextField airlNameAdd; @FXML @@ -30,8 +31,16 @@ public class AirlineAddController extends Controller { @FXML private Button addButton; + //Set an empty Dataset to be assigned to the current dataset. private Dataset theDataSet = null; + /** + * Loads up the current dataset. + */ + public void load() { + theDataSet = getParent().getCurrentDataset(); + } + /** * Adds a single airline entry to the database. * Takes in values from the GUI the user has typed in. @@ -58,26 +67,23 @@ public class AirlineAddController extends Controller { airlCountryAdd.clear(); airlActiveAdd.clear(); + //Saying to the user that the airline has successfully added. Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Airline Add Successful"); alert.setHeaderText("New Airline added!"); alert.setContentText("Your new airline 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("Airline Data Error"); alert.setHeaderText("Error adding a custom airline entry."); alert.setContentText(e.getMessage()); alert.showAndWait(); } - - } - - public void load() { - theDataSet = getParent().getCurrentDataset(); } } diff --git a/src/main/java/seng202/group9/GUI/AirlineEditController.java b/src/main/java/seng202/group9/GUI/AirlineEditController.java new file mode 100644 index 0000000..545e5e4 --- /dev/null +++ b/src/main/java/seng202/group9/GUI/AirlineEditController.java @@ -0,0 +1,95 @@ +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.DataException; +import seng202.group9.Controller.Dataset; +import seng202.group9.Controller.EntryParser; +import seng202.group9.Controller.Session; +import seng202.group9.Core.Airline; + + +/** + * The GUI controller class for airline_edit_form.fxml. + * Extends from the abstract class {@link Controller}. + * Created by Sunguin + */ +public class AirlineEditController extends Controller { + //Setting up text fields for editing data. + @FXML + private TextField airlNameEdit; + @FXML + private TextField airlAliasEdit; + @FXML + private TextField airlIATAEdit; + @FXML + private TextField airlICAOEdit; + @FXML + private TextField airlCallsignEdit; + @FXML + private TextField airlCountryEdit; + @FXML + private TextField airlActiveEdit; + @FXML + private Button applyButton; + + //Sets up an empty Dataset to be assigned to the current dataset. + private Dataset theDataSet = null; + //Sets up an empty session to be assigned to the current session. + private Session currentSession = null; + //Sets up an empty airline to be assigned to the airline being edited. + private Airline toEdit = null; + + + /** + * Loads up the current dataset and current session. + * Also gets the airline to be edited from the table. + * Sets the text fields as the airline selected. + */ + public void load() { + theDataSet = getParent().getCurrentDataset(); + currentSession = getParent().getSession(); + + toEdit = theDataSet.getAirlineDictionary().get(currentSession.getAirlineToEdit()); + + airlNameEdit.setText(toEdit.getName()); + airlAliasEdit.setText(toEdit.getAlias()); + airlIATAEdit.setText(toEdit.getIATA()); + airlICAOEdit.setText(toEdit.getICAO()); + airlCallsignEdit.setText(toEdit.getCallSign()); + airlCountryEdit.setText(toEdit.getCountryName()); + airlActiveEdit.setText(toEdit.getActive()); + } + + + /** + * Edits the current airline and closes the popup window. + * Takes in the values from the text fields. + * @see Dataset + */ + public void editAirline() { + //Tries to edit an airport and comes up with a popup if successful and exits the popup. + //Otherwise an error message will pop up with what is wrong. + try { + EntryParser parser = new EntryParser(); + parser.parseAirline(airlNameEdit.getText(), airlAliasEdit.getText(), airlIATAEdit.getText(), + airlICAOEdit.getText(), airlCallsignEdit.getText(), airlCountryEdit.getText(), airlActiveEdit.getText()); + theDataSet.editAirline(toEdit, airlNameEdit.getText(), airlAliasEdit.getText(), airlIATAEdit.getText(), + airlICAOEdit.getText(), airlCallsignEdit.getText(), airlCountryEdit.getText(), airlActiveEdit.getText()); + + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("Airline Edit Successful"); + alert.setHeaderText("Airline data edited!"); + alert.setContentText("Your airline data has been successfully edited."); + alert.showAndWait(); + + Stage stage = (Stage) applyButton.getScene().getWindow(); + stage.close(); + } catch (DataException e) { + System.err.println("RIP Harambe: " + e.getMessage() + "IT WAS TOO SOON"); + } + } +} diff --git a/src/main/java/seng202/group9/GUI/AirlineFilterController.java b/src/main/java/seng202/group9/GUI/AirlineFilterController.java index 7a6b88c..b8db03f 100644 --- a/src/main/java/seng202/group9/GUI/AirlineFilterController.java +++ b/src/main/java/seng202/group9/GUI/AirlineFilterController.java @@ -17,7 +17,9 @@ import java.util.ArrayList; import java.util.HashMap; /** - * Created by Sunguin on 2016/09/22. + * The GUI controller class for airline_filter_form.fxml. + * Extends from the abstract class {@link Controller}. + * Created by Sunguin */ public class AirlineFilterController extends Controller { @@ -42,6 +44,14 @@ public class AirlineFilterController extends Controller { private Dataset theDataSet = null; private Session currentSession = null; + /** + * Loads up the current dataset and current session. + */ + public void load() { + theDataSet = getParent().getCurrentDataset(); + currentSession = getParent().getSession(); + } + /** * Filters airlines by any field. * These are specified by what the user has typed in the filter boxes. @@ -79,22 +89,17 @@ public class AirlineFilterController extends Controller { alert.setContentText("Your airline data has been successfully filtered."); alert.showAndWait(); - //currentSession.setFilteredAirlines(FXCollections.observableArrayList(filter.getFilteredData())); - + //Creates a new hashmap for airlines and fills it with airlines that fit the criteria specified by the user. + //Saves it into the current session. HashMap airlinesHM = new HashMap(); ArrayList airlines = filter.getFilteredData(); - //for (Airline airline: airlines) { for (int index = 0; index < airlines.size(); index++) { airlinesHM.put(index, airlines.get(index).getName()); } currentSession.setFilteredAirlines(airlinesHM); + //Closes the popup. Stage stage = (Stage) applyButton.getScene().getWindow(); stage.close(); } - - public void load() { - theDataSet = getParent().getCurrentDataset(); - currentSession = getParent().getSession(); - } } diff --git a/src/main/java/seng202/group9/GUI/AirlineRDController.java b/src/main/java/seng202/group9/GUI/AirlineRDController.java index 020d07d..8c161c3 100644 --- a/src/main/java/seng202/group9/GUI/AirlineRDController.java +++ b/src/main/java/seng202/group9/GUI/AirlineRDController.java @@ -49,6 +49,9 @@ public class AirlineRDController extends Controller { * Also sets up the dropdown menu options. */ public void load() { + if (!checkDataset()){ + return; + } //Sets up the table columns to be ready for use for Airline data airlIDCol.setCellValueFactory(new PropertyValueFactory("ID")); airlNameCol.setCellValueFactory(new PropertyValueFactory("Name")); @@ -69,7 +72,7 @@ public class AirlineRDController extends Controller { /** - * Opens the Airline add form. + * Opens the Airline Add form. */ public void openAdd() { createPopUpStage(SceneCode.AIRLINE_ADD, 600, 370); @@ -82,11 +85,8 @@ public class AirlineRDController extends Controller { public void openFilter() { createPopUpStage(SceneCode.AIRLINE_FILTER, 600, 370); ArrayList d = new ArrayList(); - for(int i = 0; i < theDataSet.getAirlines().size(); i++) { - if (currentSession.getFilteredAirlines().containsValue(theDataSet.getAirlines().get(i).getName()) - && currentSession.getFilteredAirlines().containsKey(i)) { - d.add(theDataSet.getAirlines().get(i)); - } + for (int key: currentSession.getFilteredAirlines().keySet()){ + d.add(theDataSet.getAirlineDictionary().get(currentSession.getFilteredAirlines().get(key))); } tableViewAirlineRD.setItems(FXCollections.observableArrayList(d)); } @@ -104,7 +104,6 @@ public class AirlineRDController extends Controller { alert.setTitle("Airline Delete Confirmation"); alert.setHeaderText("You are about to delete some data."); alert.setContentText("Are you sure you want to delete the selected airline(s)?"); - //alert.showAndWait(); Optional result = alert.showAndWait(); Airline air = null; if (result.isPresent() && result.get() == ButtonType.OK) { @@ -116,6 +115,19 @@ public class AirlineRDController extends Controller { } } + /** + * Opens the Airline Edit form. + */ + public void editAirline() { + Airline toEdit = tableViewAirlineRD.getSelectionModel().getSelectedItem(); + currentSession.setAirlineToEdit(toEdit.getName()); + createPopUpStage(SceneCode.AIRLINE_EDIT, 600, 370); + + System.out.println(toEdit.getName() + "," + toEdit.getAlias() + "," + toEdit.getIATA() + "," + toEdit.getICAO() + + "," + toEdit.getCallSign() + "," + toEdit.getCountryName() + "," + toEdit.getActive()); + + tableViewAirlineRD.refresh(); + } /** * Analyses the current data and creates a graph based on the data. @@ -125,6 +137,9 @@ public class AirlineRDController extends Controller { JOptionPane.showMessageDialog(null, "This is not Implemented yet"); } + /** + * Goes to the airline summary page. + */ public void airlineSummaryButton() { replaceSceneContent(SceneCode.AIRLINE_SUMMARY); } diff --git a/src/main/java/seng202/group9/GUI/AirlineSummaryController.java b/src/main/java/seng202/group9/GUI/AirlineSummaryController.java index 6e62b78..2f39ec7 100644 --- a/src/main/java/seng202/group9/GUI/AirlineSummaryController.java +++ b/src/main/java/seng202/group9/GUI/AirlineSummaryController.java @@ -48,6 +48,9 @@ public class AirlineSummaryController extends Controller{ * Loads initial state of the scene. */ public void load() { + if (!checkDataset()){ + return; + } //Fills the table. columnName.setCellValueFactory(new PropertyValueFactory("Name")); columnAlias.setCellValueFactory(new PropertyValueFactory("Alias")); @@ -57,10 +60,9 @@ public class AirlineSummaryController extends Controller{ currentData = getParent().getCurrentDataset(); tableView.setItems(FXCollections.observableArrayList(currentData.getAirlines())); //Sets up map. - map = new Map(mapView, new RoutePath()); tableView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { public void changed(ObservableValue observable, Airline oldValue, Airline newValue) { - Airline selectedAirline= currentData.getAirlines().get(tableView.getSelectionModel().getSelectedIndices().get(0)); + Airline selectedAirline= tableView.getSelectionModel().getSelectedItems().get(0); for (int i = 0 ; i < currentData.getAirports().size(); i ++){ if (currentData.getAirports().get(i).getCountryName().equals(selectedAirline.getCountryName())){ map.displayAirport(new RoutePath(new Position(currentData.getAirports().get(i).getLatitude(), currentData.getAirports().get(i).getLongitude()))); @@ -69,6 +71,7 @@ public class AirlineSummaryController extends Controller{ } } }); + map = new Map(mapView, new RoutePath(), tableView); } /** diff --git a/src/main/java/seng202/group9/GUI/AirportAddController.java b/src/main/java/seng202/group9/GUI/AirportAddController.java index 30f29bf..cf0514b 100644 --- a/src/main/java/seng202/group9/GUI/AirportAddController.java +++ b/src/main/java/seng202/group9/GUI/AirportAddController.java @@ -3,6 +3,7 @@ package seng202.group9.GUI; import javafx.collections.FXCollections; import javafx.fxml.FXML; import javafx.scene.control.Alert; +import javafx.scene.control.Button; import javafx.scene.control.ComboBox; import javafx.scene.control.TextField; import javafx.stage.Stage; @@ -37,7 +38,7 @@ public class AirportAddController extends Controller { @FXML private TextField airpTzAdd; @FXML - private TextField addButton; + private Button addButton; //Set an empty Dataset to be assigned later private Dataset theDataSet = null; diff --git a/src/main/java/seng202/group9/GUI/AirportEditController.java b/src/main/java/seng202/group9/GUI/AirportEditController.java new file mode 100644 index 0000000..63d507e --- /dev/null +++ b/src/main/java/seng202/group9/GUI/AirportEditController.java @@ -0,0 +1,95 @@ +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.DataException; +import seng202.group9.Controller.Dataset; +import seng202.group9.Controller.EntryParser; +import seng202.group9.Controller.Session; +import seng202.group9.Core.Airport; + +/** + * Created by Sunguin on 2016/09/24. + */ +public class AirportEditController extends Controller { + //Setting up text fields for adding data + @FXML + private TextField airpNameEdit; + @FXML + private TextField airpCityEdit; + @FXML + private TextField airpCountryEdit; + @FXML + private TextField airpIATAFAAEdit; + @FXML + private TextField airpICAOEdit; + @FXML + private TextField airpLatitudeEdit; + @FXML + private TextField airpLongitudeEdit; + @FXML + private TextField airpAltitudeEdit; + @FXML + private TextField airpTimezoneEdit; + @FXML + private TextField airpDSTEdit; + @FXML + private TextField airpTzEdit; + @FXML + private Button editButton; + + //Set an empty Dataset to be assigned later + private Dataset theDataSet = null; + + private Session currentSession = null; + + private Airport toEdit = null; + + public void editAirport() { + try { + EntryParser parser = new EntryParser(); + parser.parseAirport(airpNameEdit.getText(), airpCityEdit.getText(), airpCountryEdit.getText(), airpIATAFAAEdit.getText(), + airpICAOEdit.getText(), airpLatitudeEdit.getText(), airpLongitudeEdit.getText(), airpAltitudeEdit.getText(), + airpTimezoneEdit.getText(), airpDSTEdit.getText(), airpTzEdit.getText()); + theDataSet.editAirport(toEdit, airpNameEdit.getText(), airpCityEdit.getText(), airpCountryEdit.getText(), airpIATAFAAEdit.getText(), + airpICAOEdit.getText(), airpLatitudeEdit.getText(), airpLongitudeEdit.getText(), airpAltitudeEdit.getText(), + airpTimezoneEdit.getText(), airpDSTEdit.getText(), airpTzEdit.getText()); + + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("Airport Edit Successful"); + alert.setHeaderText("Airport data edited!"); + alert.setContentText("Your airport data has been successfully edited."); + alert.showAndWait(); + + Stage stage = (Stage) editButton.getScene().getWindow(); + stage.close(); + } catch (DataException e) { + System.err.println("RIP Harambe: " + e.getMessage() + "IT WAS TOO SOON"); + } + } + + public void load() { + if (!checkDataset()){ + return; + } + theDataSet = getParent().getCurrentDataset(); + currentSession = getParent().getSession(); + + toEdit = theDataSet.getAirportDictionary().get(currentSession.getAirportToEdit()); + + airpNameEdit.setText(toEdit.getName()); + airpCityEdit.setText(toEdit.getCityName()); + airpCountryEdit.setText(toEdit.getCountryName()); + airpIATAFAAEdit.setText(toEdit.getIATA_FFA()); + airpICAOEdit.setText(toEdit.getICAO()); + airpLatitudeEdit.setText(Double.toString(toEdit.getLatitude())); + airpLongitudeEdit.setText(Double.toString(toEdit.getLongitude())); + airpAltitudeEdit.setText(Double.toString(toEdit.getAltitude())); + airpTimezoneEdit.setText(Double.toString(toEdit.getTimezone())); + airpDSTEdit.setText(toEdit.getDST()); + airpTzEdit.setText(toEdit.getTz()); + } +} diff --git a/src/main/java/seng202/group9/GUI/AirportRDController.java b/src/main/java/seng202/group9/GUI/AirportRDController.java index 59af18c..1b4bbfd 100644 --- a/src/main/java/seng202/group9/GUI/AirportRDController.java +++ b/src/main/java/seng202/group9/GUI/AirportRDController.java @@ -59,26 +59,31 @@ public class AirportRDController extends Controller{ * Also sets up the dropdown menu options. */ public void load() { - //Sets up the table columns to be ready for use for Airport data - airpIDCol.setCellValueFactory(new PropertyValueFactory("ID")); - airpNameCol.setCellValueFactory(new PropertyValueFactory("Name")); - airpCityCol.setCellValueFactory(new PropertyValueFactory("CityName")); - airpCountryCol.setCellValueFactory(new PropertyValueFactory("CountryName")); - airpIATAFFACol.setCellValueFactory(new PropertyValueFactory("IATA_FFA")); - airpICAOCol.setCellValueFactory(new PropertyValueFactory("ICAO")); - airpLatitudeCol.setCellValueFactory(new PropertyValueFactory("Latitude")); - airpLongitudeCol.setCellValueFactory(new PropertyValueFactory("Longitude")); - airpAltitudeCol.setCellValueFactory(new PropertyValueFactory ("Altitude")); - airpTimezoneCol.setCellValueFactory(new PropertyValueFactory("Timezone")); - airpDSTCol.setCellValueFactory(new PropertyValueFactory("DST")); - airpTzCol.setCellValueFactory(new PropertyValueFactory("Tz")); - - //Assigning the Dataset to the current Dataset's airports and displaying it in a table + if (!checkDataset()){ + return; + } theDataSet = getParent().getCurrentDataset(); - currentSession = getParent().getSession(); + if (theDataSet != null) { + //Sets up the table columns to be ready for use for Airport data + airpIDCol.setCellValueFactory(new PropertyValueFactory("ID")); + airpNameCol.setCellValueFactory(new PropertyValueFactory("Name")); + airpCityCol.setCellValueFactory(new PropertyValueFactory("CityName")); + airpCountryCol.setCellValueFactory(new PropertyValueFactory("CountryName")); + airpIATAFFACol.setCellValueFactory(new PropertyValueFactory("IATA_FFA")); + airpICAOCol.setCellValueFactory(new PropertyValueFactory("ICAO")); + airpLatitudeCol.setCellValueFactory(new PropertyValueFactory("Latitude")); + airpLongitudeCol.setCellValueFactory(new PropertyValueFactory("Longitude")); + airpAltitudeCol.setCellValueFactory(new PropertyValueFactory("Altitude")); + airpTimezoneCol.setCellValueFactory(new PropertyValueFactory("Timezone")); + airpDSTCol.setCellValueFactory(new PropertyValueFactory("DST")); + airpTzCol.setCellValueFactory(new PropertyValueFactory("Tz")); + + //Assigning the Dataset to the current Dataset's airports and displaying it in a table + currentSession = getParent().getSession(); - tableViewAirportRD.setItems(observableArrayList(theDataSet.getAirports())); - tableViewAirportRD.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); + tableViewAirportRD.setItems(observableArrayList(theDataSet.getAirports())); + tableViewAirportRD.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); + } } public void openAdd() { @@ -89,11 +94,8 @@ public class AirportRDController extends Controller{ public void openFilter() { createPopUpStage(SceneCode.AIRPORT_FILTER, 600, 480); ArrayList d = new ArrayList(); - for(int i = 0; i < theDataSet.getAirports().size(); i++) { - if (currentSession.getFilteredAirports().containsValue(theDataSet.getAirports().get(i).getName()) - && currentSession.getFilteredAirports().containsKey(i)) { - d.add(theDataSet.getAirports().get(i)); - } + for (int key: currentSession.getFilteredAirports().keySet()){ + d.add(theDataSet.getAirportDictionary().get(currentSession.getFilteredAirports().get(key))); } tableViewAirportRD.setItems(FXCollections.observableArrayList(d)); } @@ -105,16 +107,11 @@ public class AirportRDController extends Controller{ */ public void deleteAirport(){ //Gets an airport from the table and deletes it before updating the table -// Airport toDelete = tableViewAirportRD.getSelectionModel().getSelectedItem(); -// theDataSet.deleteAirport(toDelete); -// tableViewAirportRD.setItems(observableArrayList(theDataSet.getAirports())); - ObservableList toDelete = tableViewAirportRD.getSelectionModel().getSelectedItems(); Alert alert = new Alert(Alert.AlertType.CONFIRMATION); alert.setTitle("Airport Delete Confirmation"); alert.setHeaderText("You are about to delete some data."); alert.setContentText("Are you sure you want to delete the selected airport(s)?"); - //alert.showAndWait(); Optional result = alert.showAndWait(); Airport air = null; if (result.isPresent() && result.get() == ButtonType.OK) { @@ -126,6 +123,12 @@ public class AirportRDController extends Controller{ } } + public void editAirport() { + Airport toEdit = tableViewAirportRD.getSelectionModel().getSelectedItem(); + currentSession.setAirportToEdit(toEdit.getName()); + createPopUpStage(SceneCode.AIRPORT_EDIT, 600, 480); + tableViewAirportRD.refresh(); + } /** * Analyses the current data and creates a graph based on the data. @@ -136,4 +139,11 @@ public class AirportRDController extends Controller{ public void airportSummaryButton() { replaceSceneContent(SceneCode.AIRPORT_SUMMARY); } + + /** + * Opens a map with the data currently being displayed in the table. + */ + public void openMap() { + + } } diff --git a/src/main/java/seng202/group9/GUI/AirportRouteMapController.java b/src/main/java/seng202/group9/GUI/AirportRouteMapController.java new file mode 100644 index 0000000..cafd34f --- /dev/null +++ b/src/main/java/seng202/group9/GUI/AirportRouteMapController.java @@ -0,0 +1,68 @@ +package seng202.group9.GUI; + +import javafx.beans.InvalidationListener; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableView; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.web.WebView; +import seng202.group9.Controller.Dataset; +import seng202.group9.Core.*; +import seng202.group9.Map.Map; + +import java.util.*; + +/** + * Created by fwy13 on 1/10/16. + */ +public class AirportRouteMapController extends Controller{ + @FXML + WebView mapView; + @FXML + TableView airportsTable; + @FXML + TableColumn airportName; + @FXML + TableColumn routes; + ObservableList airportsToDisplay; + Dataset currentDataset; + Map map; + + @Override + public void load() { + if (!checkDataset()){ + return; + } + currentDataset = getParent().getCurrentDataset(); + //Sets up map. + map = new Map(mapView, new RoutePath(), airportsTable); + airportName.setCellValueFactory(new PropertyValueFactory("Name")); + routes.setCellValueFactory(new PropertyValueFactory("TotalRoutes")); + airportsToDisplay = FXCollections.observableArrayList(); + for (Airport airport: currentDataset.getAirports()){ + if (airport.getTotalRoutes() > 0) { + airportsToDisplay.add(airport); + } + } + airportsTable.setItems(airportsToDisplay); + airportsTable.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { + public void changed(ObservableValue observable, Airport oldValue, Airport newValue) { + Airport selectedAirport= (Airport) airportsTable.getSelectionModel().getSelectedItems().get(0); + + ArrayList routePaths = new ArrayList(); + for (Route route:selectedAirport.getArrivalRoutes()){ + routePaths.add(route.getRoutePath()); + } + for (Route route:selectedAirport.getDepartureRoutes()){ + routePaths.add(route.getRoutePath()); + } + map.displayRoutes(routePaths); + } + }); + } +} diff --git a/src/main/java/seng202/group9/GUI/AirportSummaryController.java b/src/main/java/seng202/group9/GUI/AirportSummaryController.java index 08ce135..31d1857 100644 --- a/src/main/java/seng202/group9/GUI/AirportSummaryController.java +++ b/src/main/java/seng202/group9/GUI/AirportSummaryController.java @@ -1,5 +1,6 @@ package seng202.group9.GUI; +import javafx.application.Platform; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; @@ -33,9 +34,7 @@ public class AirportSummaryController extends Controller{ @FXML private TableColumn columnCountry; @FXML - private TableColumn columnAltitude; - @FXML - private TableColumn columnIATA; + private TableColumn columnTotalRoutes; //Stores required data. private Dataset currentData = null; @@ -73,21 +72,24 @@ public class AirportSummaryController extends Controller{ * Loads initial state of the scene. */ public void load() { + if (!checkDataset()){ + return; + } currentData = getParent().getCurrentDataset(); columnName.setCellValueFactory(new PropertyValueFactory("Name")); columnCity.setCellValueFactory(new PropertyValueFactory("CityName")); columnCountry.setCellValueFactory(new PropertyValueFactory("CountryName")); - columnIATA.setCellValueFactory(new PropertyValueFactory("IATA_FFA")); - columnAltitude.setCellValueFactory(new PropertyValueFactory("Altitude")); + columnTotalRoutes.setCellValueFactory(new PropertyValueFactory("TotalRoutes")); currentData = getParent().getCurrentDataset(); tableView.setItems(FXCollections.observableArrayList(currentData.getAirports())); - map = new Map(mapView, new RoutePath()); tableView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { public void changed(ObservableValue observable, Airport oldValue, Airport newValue) { - System.out.println("loading"); - Airport selectedAirport= currentData.getAirports().get(tableView.getSelectionModel().getSelectedIndices().get(0)); + Airport selectedAirport= tableView.getSelectionModel().getSelectedItems().get(0); map.displayAirport(new RoutePath( new Position(selectedAirport.getLatitude(), selectedAirport.getLongitude()))); } }); + map = new Map(mapView, new RoutePath(), tableView); + + } } \ No newline at end of file diff --git a/src/main/java/seng202/group9/GUI/Controller.java b/src/main/java/seng202/group9/GUI/Controller.java index e7d1869..e6145db 100644 --- a/src/main/java/seng202/group9/GUI/Controller.java +++ b/src/main/java/seng202/group9/GUI/Controller.java @@ -4,6 +4,7 @@ import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; import javafx.scene.Parent; import javafx.scene.Scene; +import javafx.scene.control.Alert; import javafx.scene.layout.VBox; import javafx.stage.Modality; import javafx.stage.Stage; @@ -58,6 +59,23 @@ public abstract class Controller implements Initializable{ } } + public boolean checkDataset(){ + //if the dataset is null then we want to change to the initial and give a warning. + //Also then let them selecthe data set + if (getParent().getCurrentDataset() == null) { + replaceSceneContent(SceneCode.INITIAL); + Alert alert = new Alert(Alert.AlertType.WARNING); + alert.setTitle("Missing Dataset"); + alert.setHeaderText("No Dataset is currently selected."); + alert.setContentText("Please Create a Dataset to store your Information in."); + alert.showAndWait(); + createPopUpStage(SceneCode.DATASET_CONTROLLER, 600, 400); + return false; + }else{ + return true; + } + } + /** * Creates a popup window with a specific fxml scene * @param scene @@ -113,4 +131,4 @@ public abstract class Controller implements Initializable{ } -} +} \ No newline at end of file diff --git a/src/main/java/seng202/group9/GUI/DatasetController.java b/src/main/java/seng202/group9/GUI/DatasetController.java new file mode 100644 index 0000000..3215abf --- /dev/null +++ b/src/main/java/seng202/group9/GUI/DatasetController.java @@ -0,0 +1,79 @@ +package seng202.group9.GUI; + +import javafx.beans.InvalidationListener; +import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.Alert; +import javafx.scene.control.Button; +import javafx.scene.control.ListView; +import javafx.scene.control.TextField; +import javafx.stage.Stage; +import seng202.group9.Controller.DataException; +import seng202.group9.Controller.Dataset; + +import java.util.*; + +import static javafx.collections.FXCollections.observableArrayList; + +/** + * Created by fwy13 on 30/09/16. + */ +public class DatasetController extends Controller{ + + @FXML + ListView datasetView; + @FXML + TextField datasetName; + @FXML + Button openDataset; + Dataset curDataset = null; + ObservableList datasetList = observableArrayList(); + + public void load() { + curDataset = getParent().getCurrentDataset(); + loadTable(); + } + + public void loadTable(){ + ArrayList datasets = getParent().getDatasets(); + datasetList = observableArrayList(datasets); + datasetView.setItems(datasetList); + } + + public void deleteDataset(){ + Dataset datasetToDelete = (Dataset) datasetView.getSelectionModel().getSelectedItem(); + getParent().deleteDataset(datasetToDelete); + loadTable(); + } + + public void addDataset(){ + String name = datasetName.getText(); + if (!name.equals("") && name != null) { + try { + getParent().createDataset(name); + } catch (DataException e) { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Dataset Creation Error"); + alert.setHeaderText("Error creating Dataset."); + alert.setContentText(e.getMessage()); + alert.showAndWait(); + } + }else{ + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Dataset Creation Error"); + alert.setHeaderText("Error creating Dataset."); + alert.setContentText("Dataset Name Cannot be Empty"); + alert.showAndWait(); + } + loadTable(); + } + + public void openDataset(){ + Dataset datasetToOpen = (Dataset) datasetView.getSelectionModel().getSelectedItem(); + getParent().setCurrentDataset(datasetToOpen); + loadTable(); + ((Stage) openDataset.getScene().getWindow()).close(); + } +} diff --git a/src/main/java/seng202/group9/GUI/DistCalcController.java b/src/main/java/seng202/group9/GUI/DistCalcController.java index c54f1bc..9c878d4 100644 --- a/src/main/java/seng202/group9/GUI/DistCalcController.java +++ b/src/main/java/seng202/group9/GUI/DistCalcController.java @@ -67,6 +67,9 @@ public class DistCalcController extends Controller { * Sets the initial state of the scene. */ public void load(){ + if (!checkDataset()){ + return; + } currentData = getParent().getCurrentDataset(); answerBox.textProperty().bind(bound); fill_boxes(); diff --git a/src/main/java/seng202/group9/GUI/EquipByRouteController.java b/src/main/java/seng202/group9/GUI/EquipByRouteController.java new file mode 100644 index 0000000..36c871c --- /dev/null +++ b/src/main/java/seng202/group9/GUI/EquipByRouteController.java @@ -0,0 +1,69 @@ +package seng202.group9.GUI; + +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableView; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.web.WebView; +import seng202.group9.Controller.Dataset; +import seng202.group9.Core.Airport; +import seng202.group9.Core.Equipment; +import seng202.group9.Core.Route; +import seng202.group9.Core.RoutePath; +import seng202.group9.Map.Map; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Set; + +/** + * Created by fwy13 on 2/10/16. + */ +public class EquipByRouteController extends Controller{ + @FXML + WebView mapView; + @FXML + TableView equipTable; + @FXML + TableColumn equipName; + @FXML + TableColumn routes; + ObservableList equipToDisplay; + Dataset currentDataset; + Map map; + + @Override + public void load() { + if (!checkDataset()){ + return; + } + currentDataset = getParent().getCurrentDataset(); + //Sets up map. + map = new Map(mapView, new RoutePath(), equipTable); + equipName.setCellValueFactory(new PropertyValueFactory("Name")); + routes.setCellValueFactory(new PropertyValueFactory("RouteNum")); + equipToDisplay = FXCollections.observableArrayList(); + ArrayList keys = new ArrayList<>(currentDataset.getEquipmentDictionary().keySet()); + for (int i = 0; i < currentDataset.getEquipmentDictionary().size(); i ++){ + if (currentDataset.getEquipmentDictionary().get(keys.get(i)).getRouteNum() > 0){ + equipToDisplay.add(currentDataset.getEquipmentDictionary().get(keys.get(i))); + } + } + equipTable.setItems(equipToDisplay); + equipTable.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { + public void changed(ObservableValue observable, Equipment oldValue, Equipment newValue) { + Equipment selectedEquip= (Equipment) equipTable.getSelectionModel().getSelectedItems().get(0); + ArrayList routePaths = new ArrayList(); + HashMap routes = selectedEquip.getRoutesUsed(); + for (int i = 0; i < routes.size(); i ++){ + routePaths.add(routes.get(i).getRoutePath()); + } + map.displayRoutes(routePaths); + } + }); + } +} diff --git a/src/main/java/seng202/group9/GUI/FlightAddController.java b/src/main/java/seng202/group9/GUI/FlightAddController.java new file mode 100644 index 0000000..b1f845c --- /dev/null +++ b/src/main/java/seng202/group9/GUI/FlightAddController.java @@ -0,0 +1,66 @@ +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.Session; + +/** + * Created by Sunguin on 2016/10/01. + */ +public class FlightAddController extends Controller { + //Set up text fields for adding data + @FXML + private TextField fNameAdd; + @FXML + private TextField fTypeAdd; + @FXML + private TextField fAltitudeAdd; + @FXML + private TextField fLatitudeAdd; + @FXML + private TextField fLongitudeAdd; + @FXML + private Button flightAddButton; + + //Set an empty Dataset to be assigned later + private Dataset theDataSet = null; + + private Session currentSession = null; + + public void load() { + if (!checkDataset()){ + return; + } + theDataSet = getParent().getCurrentDataset(); + currentSession = getParent().getSession(); + } + + public void addFlight() { + try { + theDataSet.addFlightPointToPath(currentSession.getCurrentFlightPathID(), + fNameAdd.getText(), + fTypeAdd.getText(), + fAltitudeAdd.getText(), + fLatitudeAdd.getText(), + fLongitudeAdd.getText()); + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("Flight Point Add Successful"); + alert.setHeaderText("New Flight Point added!"); + alert.setContentText("Your new flight point has been successfully added into the database."); + alert.showAndWait(); + + Stage stage = (Stage) flightAddButton.getScene().getWindow(); + stage.close(); + } catch ( Exception e ) { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Flight Point Data Error"); + alert.setHeaderText("Error adding a custom flight point entry."); + alert.setContentText(e.getMessage()); + alert.showAndWait(); + } + } +} diff --git a/src/main/java/seng202/group9/GUI/FlightEditorController.java b/src/main/java/seng202/group9/GUI/FlightEditorController.java new file mode 100644 index 0000000..b6e0d58 --- /dev/null +++ b/src/main/java/seng202/group9/GUI/FlightEditorController.java @@ -0,0 +1,101 @@ +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.Session; +import seng202.group9.Core.FlightPoint; + +/** + * Controller for the Flights Edit Point Pop up Scene. + * Created by Liam Beckett on 23/09/2016. + */ +public class FlightEditorController extends Controller{ + //Setting up text fields for adding data + @FXML + TextField fNameEdit; + @FXML + TextField fTypeEdit; + @FXML + TextField fAltitudeEdit; + @FXML + TextField fLatitudeEdit; + @FXML + TextField fLongitudeEdit; + @FXML + private Button flightEditButton; + + //Set an empty Dataset to be assigned later + private Dataset theDataSet = null; + + /** + * Edits a single flight entry in the database. + * Takes in values from the field the user right clicked. + * @see Dataset + */ + public void editFlight() { + //Data is pre-loaded into the text fields and any accepted changes will be implemented. + //Otherwise an error message will pop up with what is wrong with edit + try { + Session session = getParent().getSession(); + int flightPointID = session.getCurrentFlightPointID(); + + theDataSet.editFlight( + theDataSet.getFlightPointDictionary().get(flightPointID), + fNameEdit.getText(), + fTypeEdit.getText(), + fAltitudeEdit.getText(), + fLatitudeEdit.getText(), + fLongitudeEdit.getText() + ); + session.setCurrentFlightPointID(flightPointID); + + fNameEdit.clear(); + fTypeEdit.clear(); + fAltitudeEdit.clear(); + fLatitudeEdit.clear(); + fLongitudeEdit.clear(); + + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("Flight Path Edit Successful"); + alert.setHeaderText("Flight Point Edited!"); + alert.setContentText("Your flight point has been updated in the database."); + alert.showAndWait(); + + Stage stage = (Stage) flightEditButton.getScene().getWindow(); + stage.close(); + + } catch ( Exception e ) { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Flight Data Error"); + alert.setHeaderText("Error editing a flight point."); + alert.setContentText(e.getMessage()); + alert.showAndWait(); + } + } + + /** + * Loader which is used to load the selected information into the text fields for editing. + */ + public void load() { + if (!checkDataset()){ + return; + } + theDataSet = getParent().getCurrentDataset(); + + Session session = getParent().getSession(); + int flightPointID = session.getCurrentFlightPointID(); + FlightPoint flightPoint = theDataSet.getFlightPointDictionary().get(flightPointID); + + fNameEdit.setText(flightPoint.getName()); + fTypeEdit.setText(flightPoint.getType()); + fAltitudeEdit.setText(Double.toString(flightPoint.getAltitude())); + fLatitudeEdit.setText(Double.toString(flightPoint.getLatitude())); + fLongitudeEdit.setText(Double.toString(flightPoint.getLongitude())); + } + +} + diff --git a/src/main/java/seng202/group9/GUI/FlightRDController.java b/src/main/java/seng202/group9/GUI/FlightRDController.java index 7cf4e8a..e85c131 100644 --- a/src/main/java/seng202/group9/GUI/FlightRDController.java +++ b/src/main/java/seng202/group9/GUI/FlightRDController.java @@ -1,5 +1,7 @@ package seng202.group9.GUI; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.EventHandler; @@ -9,18 +11,20 @@ import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.input.MouseEvent; import seng202.group9.Controller.DataException; import seng202.group9.Controller.Dataset; +import seng202.group9.Controller.SceneCode; +import seng202.group9.Controller.Session; import seng202.group9.Core.FlightPath; import seng202.group9.Core.FlightPoint; import javax.swing.*; import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.Optional; /** * Controller for the Flights Raw Data Scene. * Created by Liam Beckett on 13/09/2016. */ - public class FlightRDController extends Controller { private Dataset theDataSet = null; @@ -36,8 +40,6 @@ public class FlightRDController extends Controller { @FXML private TableColumn flightTypeCol; @FXML - private TableColumn flightViaCol; - @FXML private TableColumn flightAltitudeCol; @FXML private TableColumn flightLatCol; @@ -54,24 +56,24 @@ 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; +// @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 @@ -81,6 +83,7 @@ public class FlightRDController extends Controller { try { ArrayList flightPaths; flightPaths = theDataSet.getFlightPaths(); + for(int i = 0; i() { - 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); - - ArrayList flightPaths; - flightPaths = theDataSet.getFlightPaths(); - ArrayList flightPoints = flightPaths.get(currentPathIndex).getFlight(); - flightTableView.setItems(FXCollections.observableArrayList(flightPoints)); - - } - }); flightPathListView.setItems(flightList); } catch (Exception e) { @@ -116,66 +102,64 @@ public class FlightRDController extends Controller { * Used to load the table for the Flight points initially from the MenuController */ public void load() { - theDataSet = getParent().getCurrentDataset(); - try { - currentPathId = theDataSet.getFlightPaths().get(0).getID(); //Sets the default to the 1st Path - } catch (DataException e) { - e.printStackTrace(); + if (!checkDataset()){ + return; } - flightIdCol.setCellValueFactory(new PropertyValueFactory("ID")); - flightNameCol.setCellValueFactory(new PropertyValueFactory("Name")); - flightTypeCol.setCellValueFactory(new PropertyValueFactory("Type")); - flightViaCol.setCellValueFactory(new PropertyValueFactory("Via")); - flightAltitudeCol.setCellValueFactory(new PropertyValueFactory("Altitude")); - flightLatCol.setCellValueFactory(new PropertyValueFactory("Latitude")); - flightLongCol.setCellValueFactory(new PropertyValueFactory("Longitude")); - flightHeadCol.setCellValueFactory(new PropertyValueFactory("Heading")); - flightLegDisCol.setCellValueFactory(new PropertyValueFactory("LegDistance")); - flightTotDisCol.setCellValueFactory(new PropertyValueFactory("totalDistance")); + theDataSet = getParent().getCurrentDataset(); + if (theDataSet != null) { + try { + try { + currentPathId = theDataSet.getFlightPaths().get(0).getID(); //Sets the default to the 1st Path + } catch (DataException e) { + e.printStackTrace(); + } + flightIdCol.setCellValueFactory(new PropertyValueFactory("ID")); + flightNameCol.setCellValueFactory(new PropertyValueFactory("Name")); + flightTypeCol.setCellValueFactory(new PropertyValueFactory("Type")); + flightAltitudeCol.setCellValueFactory(new PropertyValueFactory("Altitude")); + flightLatCol.setCellValueFactory(new PropertyValueFactory("Latitude")); + flightLongCol.setCellValueFactory(new PropertyValueFactory("Longitude")); + flightHeadCol.setCellValueFactory(new PropertyValueFactory("Heading")); + flightLegDisCol.setCellValueFactory(new PropertyValueFactory("LegDistance")); + flightTotDisCol.setCellValueFactory(new PropertyValueFactory("totalDistance")); - ArrayList flightPaths; - flightPaths = theDataSet.getFlightPaths(); - ArrayList flightPoints = flightPaths.get(0).getFlight(); - flightTableView.setItems(FXCollections.observableArrayList(flightPoints)); + ArrayList flightPaths; + flightPaths = theDataSet.getFlightPaths(); + ArrayList flightPoints = flightPaths.get(0).getFlight(); + flightTableView.setItems(FXCollections.observableArrayList(flightPoints)); + }catch(IndexOutOfBoundsException e){ + System.out.println("There is no Paths to show"); + } + flightPathListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener(){ + public void changed(ObservableValue observable, String oldValue, String newValue) { + String flightPathDisplayNameClicked = flightPathListView.getSelectionModel().getSelectedItem(); + if (flightPathDisplayNameClicked!=null) { + String[] segments = flightPathDisplayNameClicked.split("_"); + String pathIdClicked = segments[0]; + + currentPathIndex = theDataSet.getFlightPaths().indexOf(theDataSet.getFlightPathDictionary() + .get(Integer.parseInt(pathIdClicked))); + currentPathId = Integer.parseInt(pathIdClicked); + + ArrayList flightPaths; + flightPaths = theDataSet.getFlightPaths(); + ArrayList flightPoints = flightPaths.get(currentPathIndex).getFlight(); + flightTableView.setItems(FXCollections.observableArrayList(flightPoints)); + } + } + }); + } } /** * Will take the inputs from the text fields and adds the point to the current flight path. */ - public void addFlightPoint() { - ArrayList flightPaths; - flightPaths = theDataSet.getFlightPaths(); - - try { - theDataSet.addFlightPointToPath(currentPathId, - flightNameBox.getText(), - flightTypeBox.getText(), - flightViaBox.getText(), - flightAltitudeBox.getText(), - flightLatitudeBox.getText(), - flightLongitudeBox.getText(), - flightHeadingBox.getText(), - flightLegDistBox.getText(), - flightTotDistBox.getText()); - flightNameBox.clear(); - flightTypeBox.clear(); - flightViaBox.clear(); - flightAltitudeBox.clear(); - flightLatitudeBox.clear(); - flightLongitudeBox.clear(); - flightHeadingBox.clear(); - flightLegDistBox.clear(); - flightTotDistBox.clear(); - - ArrayList flightPoints = flightPaths.get(currentPathIndex).getFlight(); - flightTableView.setItems(FXCollections.observableArrayList(flightPoints)); - } catch ( Exception e ) { - Alert alert = new Alert(Alert.AlertType.ERROR); - alert.setTitle("Flight Point Data Error"); - alert.setHeaderText("Error adding a custom flight point entry."); - alert.setContentText(e.getMessage()); - - } + public void openAdd() { + Session session = getParent().getSession(); + session.setCurrentFlightPathtID(currentPathId); + createPopUpStage(SceneCode.FLIGHT_ADD, 600, 280); + //flightTableView.setItems(FXCollections.observableArrayList(theDataSet.getAirports())); + updateTable(currentPathIndex); } /** @@ -198,26 +182,51 @@ public class FlightRDController extends Controller { */ public void deletePoint() { FlightPoint toDelete = flightTableView.getSelectionModel().getSelectedItem(); - int pathID; + Alert alert = new Alert(Alert.AlertType.CONFIRMATION); + alert.setTitle("Flight Point Delete Confirmation"); + alert.setHeaderText("You are about to delete some data."); + alert.setContentText("Are you sure you want to delete the selected flight point?"); + //alert.showAndWait(); + Optional result = alert.showAndWait(); + if (result.isPresent() && result.get() == ButtonType.OK) { + int pathID; + try { + pathID = toDelete.getIndex(); + } catch (DataException e) { + e.printStackTrace(); + System.err.println("Point is Undeletable as the Index ID is not set."); + return; + } + LinkedHashMap flightPathDict = theDataSet.getFlightPathDictionary(); + FlightPath toDeletesPath = flightPathDict.get(pathID); + theDataSet.deleteFlightPoint(toDelete, toDeletesPath); + + currentPathIndex = theDataSet.getFlightPaths().indexOf(theDataSet.getFlightPathDictionary().get(pathID)); + + updateTable(currentPathIndex); + updatePaths(); + } + } + + /** + * Loads the pop up for the edit data scene and updates the table when the window is closed. + */ + public void editPoint() { + FlightPoint toEdit = flightTableView.getSelectionModel().getSelectedItem(); try { - pathID = toDelete.getIndex(); + Session session = getParent().getSession(); + session.setCurrentFlightPointID(toEdit.getID()); + session.setCurrentFlightPathtID(currentPathId); } catch (DataException e) { e.printStackTrace(); - System.out.println("Point is Undeletable as the Index ID is not set."); + System.err.println("Point is Uneditable as the Index ID is not set."); return; } - LinkedHashMap flightPathDict = theDataSet.getFlightPathDictionary(); - FlightPath toDeletesPath = flightPathDict.get(pathID); - theDataSet.deleteFlightPoint(toDelete, toDeletesPath); + createPopUpStage(SceneCode.FLIGHT_EDITOR, 600, 289); + updateTable(currentPathIndex); + updatePaths(); - currentPathIndex = theDataSet.getFlightPaths().indexOf(theDataSet.getFlightPathDictionary().get(pathID)); - - ArrayList flightPaths; - flightPaths = theDataSet.getFlightPaths(); - ArrayList flightPoints = flightPaths.get(currentPathIndex).getFlight(); - flightTableView.setItems(FXCollections.observableArrayList(flightPoints)); } - /** * Removes the selected path from the list view of paths and from the database. */ @@ -232,6 +241,80 @@ public class FlightRDController extends Controller { theDataSet.deleteFlightPath(toDeleteIndex); flightPathListView.getItems().clear(); flightPathListView(); + updatePaths(); + updateTable(0); + } + + /** + * Function for the 'Move Up' right click option on the points in the flight table. + */ + public void movePointUp(){ + FlightPoint toMove = flightTableView.getSelectionModel().getSelectedItem(); + int toMoveIndex = flightTableView.getSelectionModel().getSelectedIndex(); + try{ + if (toMoveIndex != 0) { + theDataSet.moveFlightPoint(toMove, toMoveIndex - 1); + } + } catch (DataException e) { + e.printStackTrace(); + } + updateTable(currentPathIndex); + updatePaths(); + } + + /** + * Function for the 'Move Down' right click option on the points in the flight table. + */ + public void movePointDown(){ + FlightPoint toMove = flightTableView.getSelectionModel().getSelectedItem(); + int toMoveIndex = flightTableView.getSelectionModel().getSelectedIndex(); + try{ + if (toMoveIndex != flightTableView.getItems().size()-1) { + theDataSet.moveFlightPoint(toMove, toMoveIndex + 1); + } + } catch (DataException e) { + e.printStackTrace(); + } + updateTable(currentPathIndex); + updatePaths(); + } + + /** + * Updates the table so that when the database is changed (deleted or edited) it still shows the correct data values. + * @param currentPathIndex The index of the current path in the Path array list. + */ + private void updateTable(int currentPathIndex) { + ArrayList flightPaths; + flightPaths = theDataSet.getFlightPaths(); + if (flightPaths.size() != 0) { + ArrayList flightPoints = flightPaths.get(currentPathIndex).getFlight(); + flightTableView.setItems(FXCollections.observableArrayList(flightPoints)); + flightTableView.refresh(); + }else{ + flightTableView.getItems().clear(); + flightTableView.refresh(); + } + } + + /** + * Updates the flight path list view so that it displays the correct names for the paths + */ + private void updatePaths(){ + try { + flightPathListView.getItems().clear(); + ArrayList flightPaths; + flightPaths = theDataSet.getFlightPaths(); + for(int i = 0; i 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 +57,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 +75,68 @@ 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; + + for (int i=0; i < airportList.size(); i++){ + Airport current = airportList.get(i); + 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,45 +152,65 @@ 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(); + if (flightPathDisplayNameClicked!=null) { + 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(); } } + /** * Used to load the page from the MenuController. */ public void load() { - try { - theDataSet = getParent().getCurrentDataset(); - ArrayList flightPaths = new ArrayList(); - flightPaths = theDataSet.getFlightPaths(); - for(int i = 0; i 0){ - map = new Map(mapView, theDataSet.getFlightPaths().get(0).getRoutePath()); - }else{ - map = new Map(mapView, new RoutePath()); - } - flightPathListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { - public void changed(ObservableValue observable, String oldValue, String newValue) { - int index = flightPathListView.getSelectionModel().getSelectedIndices().get(0); - if (index != -1) { - map.displayRoute(theDataSet.getFlightPaths().get(index).getRoutePath()); + theDataSet = getParent().getCurrentDataset(); + if (theDataSet != null) { + try { + ArrayList flightPaths; + flightPaths = theDataSet.getFlightPaths(); + for (int i = 0; i < flightPaths.size(); i++) { + int pathID = flightPaths.get(i).getID(); + String pathSource = flightPaths.get(i).departsFrom(); + String pathDestin = flightPaths.get(i).arrivesAt(); + String flightPathDisplayName = Integer.toString(pathID) + "_" + pathSource + "_" + pathDestin; + flightList.add(flightPathDisplayName); } + flightPathListView.setItems(flightList); + flightSummaryListView(); + } catch (Exception e) { + e.printStackTrace(); + } + if (theDataSet.getFlightPaths().size() > 0) { + map = new Map(mapView, theDataSet.getFlightPaths().get(0).getRoutePath()); + } else { + map = new Map(mapView, new RoutePath()); } - }); + flightPathListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { + public void changed(ObservableValue observable, String oldValue, String newValue) { + int index = flightPathListView.getSelectionModel().getSelectedIndices().get(0); + if (index != -1) { + map.displayRoute(theDataSet.getFlightPaths().get(index).getRoutePath()); + } + } + }); + } } + /** * Removes the selected path from the list view of paths and from the database. */ diff --git a/src/main/java/seng202/group9/GUI/GettingStartedController.java b/src/main/java/seng202/group9/GUI/GettingStartedController.java new file mode 100644 index 0000000..18741e5 --- /dev/null +++ b/src/main/java/seng202/group9/GUI/GettingStartedController.java @@ -0,0 +1,45 @@ +package seng202.group9.GUI; + +import javafx.scene.control.Alert; +import seng202.group9.Controller.SceneCode; + +/** + * Created by spe76 on 26/09/16. + */ +public class GettingStartedController extends Controller { + + public void load() { + } + + public void importAirlines() { + getParent().getMenuController().changeDatasetPrompt(); + Importer importer = new Importer(SceneCode.AIRLINE_RAW_DATA, getParent(), getParent().getPrimaryStage()); + } + + public void importAirports() { + getParent().getMenuController().changeDatasetPrompt(); + Importer importer = new Importer(SceneCode.AIRPORT_RAW_DATA, getParent(), getParent().getPrimaryStage()); + } + + public void importRoutes() { + getParent().getMenuController().changeDatasetPrompt(); + Importer importer = new Importer(SceneCode.ROUTE_RAW_DATA, getParent(), getParent().getPrimaryStage()); + } + + public void importFlightData() { + getParent().getMenuController().changeDatasetPrompt(); + Importer importer = new Importer(SceneCode.FLIGHT_RAW_DATA, getParent(), getParent().getPrimaryStage()); + } + + public void manageDatasets() { + getParent().getMenuController().openDataset(); + + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("Dataset Selected"); + alert.setHeaderText("You have decided to change the Dataset."); + alert.setContentText("You will now be taken to the airline summary page."); + alert.showAndWait(); + + replaceSceneContent(SceneCode.AIRLINE_SUMMARY); + } +} diff --git a/src/main/java/seng202/group9/GUI/HelpController.java b/src/main/java/seng202/group9/GUI/HelpController.java new file mode 100644 index 0000000..d713253 --- /dev/null +++ b/src/main/java/seng202/group9/GUI/HelpController.java @@ -0,0 +1,168 @@ +package seng202.group9.GUI; + +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.fxml.FXML; +import javafx.scene.control.TreeItem; +import javafx.scene.control.TreeView; +import javafx.scene.text.Text; +import javafx.scene.text.TextFlow; + +/** + * The GUI controller class for help.fxml. + * Extends from the abstract class {@link Controller}. + * Created by Sunguin. + */ +public class HelpController extends Controller { + @FXML + private TreeView treeView; + @FXML + private TextFlow textArea; + + Text text = new Text(); + + //The TreeItems for the TreeView. + TreeItem main_root = new TreeItem("Main Root"); + + TreeItem importing = new TreeItem("Importing Data"); + TreeItem importing_start = new TreeItem("Importing on Startup"); + TreeItem importing_after = new TreeItem("Importing after Startup"); + + TreeItem viewing = new TreeItem("Viewing Data"); + TreeItem summary_viewing = new TreeItem("Viewing Summary Data"); + TreeItem raw_viewing = new TreeItem("Viewing Raw Data"); + + TreeItem manipulating = new TreeItem("Manipulating Data"); + TreeItem adding = new TreeItem("Adding Data"); + TreeItem filter = new TreeItem("Filtering Data"); + TreeItem edit = new TreeItem("Editing Data"); + TreeItem delete = new TreeItem("Deleting Data"); + + TreeItem analysing = new TreeItem("Analysing Data"); + TreeItem graphing = new TreeItem("Graphs"); + TreeItem distance = new TreeItem("Distance Calculator"); + + /** + * Loads the TreeView and sets up the TreeView. + */ + public void load() { + treeView.setRoot(main_root); + treeView.setShowRoot(false); + + main_root.getChildren().add(importing); + importing.getChildren().add(importing_start); + importing.getChildren().add(importing_after); + + main_root.getChildren().add(viewing); + viewing.getChildren().add(summary_viewing); + viewing.getChildren().add(raw_viewing); + + main_root.getChildren().add(manipulating); + manipulating.getChildren().add(adding); + manipulating.getChildren().add(filter); + manipulating.getChildren().add(edit); + manipulating.getChildren().add(delete); + + main_root.getChildren().add(analysing); + analysing.getChildren().add(graphing); + analysing.getChildren().add(distance); + + text = new Text("Please select an option on the left side menu to display its contents."); + textArea.getChildren().add(text); + + treeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { + + public void changed(ObservableValue observable, Object oldValue, + Object newValue) { + TreeItem selectedItem = (TreeItem) newValue; + String menuValue = selectedItem.getValue(); + + if ( menuValue != null ){ + textArea.getChildren().clear(); + if (menuValue.equals("Importing on Startup")) { + text = new Text("Importing on Startup\n" + "You can import data from the first start up of the application." + + "\nTo import data, select the type of data you wish to import along the bottom of the screen." + + " Then select the file (.csv and .txt file) from the " + + "file selector. The data will be loaded into the program and taken to the " + + "corresponding summary page."); + textArea.getChildren().add(text); + + } else if (menuValue.equals("Importing after Startup")) { + text = new Text("Importing after Startup\n" + + "You can import data from the 'File' menu on the top of the screen.\n" + + "To import data, select the type of data you wish to import. " + + "Then select the file (.csv and .txt file) from the file selector. " + + "The data will be loaded into the program and taken to the corresponding summary page."); + textArea.getChildren().add(text); + + } else if (menuValue.equals("Viewing Summary Data")) { + text = new Text("Viewing Summary Data\n" + + "The summary data view consists of a reduced version of the data and a map of the currently selected value. " + + "The flight summary data also has a flight path selector to select which flight points you want to view.\n" + + "The summary views are accessible from the menu on the top of the screen under the " + + "'View' tab. You first choose which set of data you want to view and then you can select 'Summary'." + + "\nEach summary page also has buttons that lead to their corresponding raw data view and the other summary views."); + textArea.getChildren().add(text); + + } else if (menuValue.equals("Viewing Raw Data")) { + text = new Text("Viewing Raw Data\n" + + "The raw data view allows the user to view the full data table." + + "The user can also add, filter, edit and delete data values as well.\n" + + "These are accessible from the menu on the top of the screen under the " + + "'View' tab. You first choose which set of data you want to view and then you can select 'Raw Data'.\n" + + "The summary view does not have every column but provides a map of where the " + + "The raw data page also has buttons that lead to the analysis of that type of data and to go back to the" + + " corresponding summary page."); + textArea.getChildren().add(text); + + } else if (menuValue.equals("Adding Data")) { + text = new Text("Adding Data\n" + + "To add a new entry, first go to the raw data view for that data type. Then click " + + "on the add button located on the bottom of the page. Then fill out the entries in the " + + "pop-up box and click add at the bottom of the screen. " + + "When the program detects an invalid field, a message will pop up and state where the error is."); + textArea.getChildren().add(text); + + } else if (menuValue.equals("Filtering Data")) { + text = new Text("Filtering Data\n" + + "To filter all current entries, click on the filter option and a pop " + + "up will appear. Then type in the fields the values you wish to filter by and press the filter button. " + + "The table should update with the fields specified."); + textArea.getChildren().add(text); + + } else if (menuValue.equals("Editing Data")) { + text = new Text("Editing Data\n" + + "The edit function can be accessed by right clicking on the entry you wish to edit and" + + " clicking the edit option. This will lead to a pop up where you can edit the current entry." + + " When the edit has been completed, you can press the apply button on the bottom of the pop up. " + + "When the program detects an invalid field, a message will pop up and state where the error is."); + textArea.getChildren().add(text); + + } else if (menuValue.equals("Deleting Data")) { + text = new Text("Deleting Data\n" + + "The delete function is accessed by right clicking an entry and pressing the delete option. " + + "This will come up with a pop up to confirm your delete. When you press OK, the entry will be deleted " + + "from the program. The program also allows multiple deletes."); + textArea.getChildren().add(text); + + } else if (menuValue.equals("Graphs")) { + text = new Text("Graphs\n" + "The program has the ability to produce graphs according to the type of data.\n" + + "This is done by going to the raw data page for the data you wish to graph. Then press the analyse data button" + + " on the bottom of the screen. This will produce a graph specific for that type of data."); + textArea.getChildren().add(text); + + } else if (menuValue.equals("Distance Calculator")) { + text = new Text("Distance Calculator\n" + "You can calculate the distance between two airports.\n" + + "First, go to the 'Analysis' tab on the top of the menu bar. You will be taken to a page that " + + "allows them to select two airports, one from each column and press 'Calculate' to get the distance between" + + " the two airports."); + textArea.getChildren().add(text); + } else { + text = new Text("Please select an option on the left side menu to display its contents."); + textArea.getChildren().add(text); + } + } + } + }); + } +} \ No newline at end of file diff --git a/src/main/java/seng202/group9/GUI/MenuController.java b/src/main/java/seng202/group9/GUI/MenuController.java index 3dd1df1..7346706 100644 --- a/src/main/java/seng202/group9/GUI/MenuController.java +++ b/src/main/java/seng202/group9/GUI/MenuController.java @@ -1,6 +1,7 @@ package seng202.group9.GUI; import java.net.URL; +import java.util.Optional; import java.util.ResourceBundle; import javax.swing.JOptionPane; @@ -8,6 +9,8 @@ import javax.swing.JOptionPane; import javafx.fxml.Initializable; import javafx.scene.control.Alert; +import javafx.scene.control.ButtonBar; +import javafx.scene.control.ButtonType; import seng202.group9.Controller.App; import seng202.group9.Controller.Dataset; import seng202.group9.Controller.SceneCode; @@ -18,18 +21,22 @@ import seng202.group9.Controller.SceneCode; public class MenuController extends Controller{ public void importAirports(){ + changeDatasetPrompt(); Importer importer = new Importer(SceneCode.AIRPORT_RAW_DATA, getParent(), getParent().getPrimaryStage()); } public void importAirlines(){ + changeDatasetPrompt(); Importer importer = new Importer(SceneCode.AIRLINE_RAW_DATA, getParent(), getParent().getPrimaryStage()); } public void importRoutes(){ + changeDatasetPrompt(); Importer importer = new Importer(SceneCode.ROUTE_RAW_DATA, getParent(), getParent().getPrimaryStage()); } public void importFlightData(){ + changeDatasetPrompt(); Importer importer = new Importer(SceneCode.FLIGHT_RAW_DATA, getParent(), getParent().getPrimaryStage()); } @@ -62,13 +69,18 @@ public class MenuController extends Controller{ public void viewAnalyserMain() { replaceSceneContent(SceneCode.ANALYSER_TAB);} + /** + * view Routes by the Destination / Arrival Airport + */ + public void viewRouteByAirport(){ + replaceSceneContent(SceneCode.ROUTE_BY_AIRPORT); + } /** * Load Flight Summary Function. */ public void viewFlightSummary() { replaceSceneContent(SceneCode.FLIGHT_SUMMARY); } - /** * Load Flight Raw Data Function. */ @@ -76,6 +88,18 @@ public class MenuController extends Controller{ replaceSceneContent(SceneCode.FLIGHT_RAW_DATA); } + public void viewRouteByEquipment(){ + replaceSceneContent(SceneCode.ROUTE_BY_EQUIP); + } + + public void goToGettingStarted() { + replaceSceneContent(SceneCode.INITIAL); + } + + public void goToHelp() { + createPopUpStage(SceneCode.HELP, 600, 400); + } + public void load() { //nothing to load } @@ -86,5 +110,23 @@ public class MenuController extends Controller{ // TODO Auto-generated method stub } + + public void changeDatasetPrompt(){ + ButtonType yes = new ButtonType("Yes", ButtonBar.ButtonData.YES); + ButtonType no = new ButtonType("No", ButtonBar.ButtonData.NO); + Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "", yes, no); + alert.setTitle("Dataset Change?"); + alert.setHeaderText("You are about to import Data"); + alert.setContentText("Would you like to change Datasets?"); + //alert.showAndWait(); + Optional result = alert.showAndWait(); + if (result.isPresent() && result.get() == yes) { + createPopUpStage(SceneCode.DATASET_CONTROLLER, 600, 400); + } + } + + public void openDataset(){ + createPopUpStage(SceneCode.DATASET_CONTROLLER, 600, 400); + } } diff --git a/src/main/java/seng202/group9/GUI/RouteAddController.java b/src/main/java/seng202/group9/GUI/RouteAddController.java index 7a9e1ff..8af7fa1 100644 --- a/src/main/java/seng202/group9/GUI/RouteAddController.java +++ b/src/main/java/seng202/group9/GUI/RouteAddController.java @@ -74,6 +74,9 @@ public class RouteAddController extends Controller { } public void load() { + if (!checkDataset()){ + return; + } theDataSet = getParent().getCurrentDataset(); } } diff --git a/src/main/java/seng202/group9/GUI/RouteEditController.java b/src/main/java/seng202/group9/GUI/RouteEditController.java new file mode 100644 index 0000000..97c2002 --- /dev/null +++ b/src/main/java/seng202/group9/GUI/RouteEditController.java @@ -0,0 +1,76 @@ +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.DataException; +import seng202.group9.Controller.Dataset; +import seng202.group9.Controller.EntryParser; +import seng202.group9.Controller.Session; +import seng202.group9.Core.Route; + +/** + * Created by Sunguin on 2016/09/24. + */ +public class RouteEditController extends Controller { + @FXML + private TextField rAirlineEdit; + @FXML + private TextField rSourceEdit; + @FXML + private TextField rDestEdit; + @FXML + private TextField rCodeshareEdit; + @FXML + private TextField rStopsEdit; + @FXML + private TextField rEquipmentEdit; + @FXML + private Button editButton; + + private Dataset theDataSet = null; + + private Session currentSession = null; + + private Route toEdit = null; + + public void editRoute() { + try { + EntryParser parser = new EntryParser(); + parser.parseRoute(rAirlineEdit.getText(), rSourceEdit.getText(), rDestEdit.getText(), rCodeshareEdit.getText(), + rStopsEdit.getText(), rEquipmentEdit.getText()); + theDataSet.editRoute(toEdit, rAirlineEdit.getText(), rSourceEdit.getText(), rDestEdit.getText(), rCodeshareEdit.getText(), + rStopsEdit.getText(), rEquipmentEdit.getText()); + + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("Route Edit Successful"); + alert.setHeaderText("Route data edited!"); + alert.setContentText("Your route data has been successfully edited."); + alert.showAndWait(); + + Stage stage = (Stage) editButton.getScene().getWindow(); + stage.close(); + } catch (DataException e) { + System.err.println("RIP Harambe: " + e.getMessage() + "IT WAS TOO SOON"); + } + } + + public void load() { + if (!checkDataset()){ + return; + } + theDataSet = getParent().getCurrentDataset(); + currentSession = getParent().getSession(); + + toEdit = theDataSet.getRouteDictionary().get(currentSession.getRouteToEdit()); + + rAirlineEdit.setText(toEdit.getAirlineName()); + rSourceEdit.setText(toEdit.getDepartureAirport()); + rDestEdit.setText(toEdit.getArrivalAirport()); + rCodeshareEdit.setText(toEdit.getCode()); + rStopsEdit.setText(Integer.toString(toEdit.getStops())); + rEquipmentEdit.setText(toEdit.getEquipment()); + } +} diff --git a/src/main/java/seng202/group9/GUI/RouteFilterController.java b/src/main/java/seng202/group9/GUI/RouteFilterController.java index dc47ecd..8eb9bdb 100644 --- a/src/main/java/seng202/group9/GUI/RouteFilterController.java +++ b/src/main/java/seng202/group9/GUI/RouteFilterController.java @@ -72,11 +72,12 @@ public class RouteFilterController extends Controller { alert.showAndWait(); //currentSession.setFilteredAirlines(FXCollections.observableArrayList(filter.getFilteredData())); - + //routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip HashMap routesHM = new HashMap(); ArrayList routes = filter.getFilteredData(); for (int index = 0; index < routes.size(); index++) { - routesHM.put(index, routes.get(index).getAirlineName()); + routesHM.put(index, routes.get(index).getAirlineName() + routes.get(index).getDepartureAirport() + routes.get(index).getArrivalAirport() + + routes.get(index).getCode() + routes.get(index).getStops() + routes.get(index).getEquipment()); } currentSession.setFilteredRoutes(routesHM); @@ -85,6 +86,9 @@ public class RouteFilterController extends Controller { } public void load() { + if (!checkDataset()){ + return; + } theDataSet = getParent().getCurrentDataset(); currentSession = getParent().getSession(); } diff --git a/src/main/java/seng202/group9/GUI/RouteRDController.java b/src/main/java/seng202/group9/GUI/RouteRDController.java index 0a352b6..f86db83 100644 --- a/src/main/java/seng202/group9/GUI/RouteRDController.java +++ b/src/main/java/seng202/group9/GUI/RouteRDController.java @@ -51,6 +51,9 @@ public class RouteRDController extends Controller { * Also sets up the dropdown menu options. */ public void load() { + if (!checkDataset()){ + return; + } //Sets up the table columns to be ready for use for Route data rAirlineCol.setCellValueFactory(new PropertyValueFactory("AirlineName")); rAirlineIDCol.setCellValueFactory(new PropertyValueFactory("AirlineID")); @@ -77,12 +80,10 @@ public class RouteRDController extends Controller { public void openFilter() { createPopUpStage(SceneCode.ROUTE_FILTER, 600, 330); + ArrayList d = new ArrayList(); - for(int i = 0; i < theDataSet.getRoutes().size(); i++) { - if (currentSession.getFilteredRoutes().containsValue(theDataSet.getRoutes().get(i).getAirlineName()) - && currentSession.getFilteredRoutes().containsKey(i)) { - d.add(theDataSet.getRoutes().get(i)); - } + for (int key: currentSession.getFilteredRoutes().keySet()){ + d.add(theDataSet.getRouteDictionary().get(currentSession.getFilteredRoutes().get(key))); } tableViewRouteRD.setItems(FXCollections.observableArrayList(d)); } @@ -111,6 +112,18 @@ public class RouteRDController extends Controller { } } + public void editRoute() { + Route toEdit = tableViewRouteRD.getSelectionModel().getSelectedItem(); + currentSession.setRouteToEdit(toEdit.getAirlineName() + toEdit.getDepartureAirport() + toEdit.getArrivalAirport() + + toEdit.getCode() + toEdit.getStops() + toEdit.getEquipment()); + createPopUpStage(SceneCode.ROUTE_EDIT, 600, 330); + +// System.out.println(toEdit.getName() + "," + toEdit.getCity() + "," + toEdit.getCountry() + "," + toEdit.getIATA_FFA() +// + "," + toEdit.getICAO() + "," + toEdit.getLatitude() + "," + toEdit.getLongitude() + "," + toEdit.getAltitude() +// + "," + toEdit.getTimezone() + "," + toEdit.getDST() + "," + toEdit.getTz()); + + tableViewRouteRD.refresh(); + } /** * Analyses the current data and creates a graph based on the data. @@ -124,4 +137,11 @@ public class RouteRDController extends Controller { replaceSceneContent(SceneCode.ROUTE_SUMMARY); currentSession = getParent().getSession(); } + + /** + * Opens a map with the data currently being displayed in the table. + */ + public void openMap(){ + + } } diff --git a/src/main/java/seng202/group9/GUI/RouteSummaryController.java b/src/main/java/seng202/group9/GUI/RouteSummaryController.java index e84e955..d986774 100644 --- a/src/main/java/seng202/group9/GUI/RouteSummaryController.java +++ b/src/main/java/seng202/group9/GUI/RouteSummaryController.java @@ -43,6 +43,9 @@ public class RouteSummaryController extends Controller{ * Loads initial state of the scene. */ public void load() { + if (!checkDataset()){ + return; + } columnAirline.setCellValueFactory(new PropertyValueFactory("AirlineName")); columnDepart.setCellValueFactory(new PropertyValueFactory("DepartureAirport")); columnArrive.setCellValueFactory(new PropertyValueFactory("ArrivalAirport")); @@ -50,11 +53,9 @@ public class RouteSummaryController extends Controller{ columnEquipment.setCellValueFactory(new PropertyValueFactory("Equipment")); currentData = getParent().getCurrentDataset(); tableView.setItems(FXCollections.observableArrayList(currentData.getRoutes())); - map = new Map(mapView, new RoutePath()); tableView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { public void changed(ObservableValue observable, Route oldValue, Route newValue) { - System.out.println("loading"); - Route selectedRoute= currentData.getRoutes().get(tableView.getSelectionModel().getSelectedIndices().get(0)); + Route selectedRoute= tableView.getSelectionModel().getSelectedItems().get(0); if (selectedRoute.getSourceAirport() != null && selectedRoute.getDestinationAirport() != null) { map.displayRoute(new RoutePath( new Position(selectedRoute.getSourceAirport().getLatitude(), selectedRoute.getSourceAirport().getLongitude()), @@ -71,6 +72,7 @@ public class RouteSummaryController extends Controller{ } } }); + map = new Map(mapView, new RoutePath(), tableView); } /** diff --git a/src/main/java/seng202/group9/Map/Map.java b/src/main/java/seng202/group9/Map/Map.java index 95bbfcc..177c11d 100644 --- a/src/main/java/seng202/group9/Map/Map.java +++ b/src/main/java/seng202/group9/Map/Map.java @@ -3,11 +3,15 @@ package seng202.group9.Map; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.concurrent.Worker; +import javafx.scene.control.Alert; +import javafx.scene.control.TableView; import javafx.scene.web.WebEngine; import javafx.scene.web.WebView; import seng202.group9.Core.Position; import seng202.group9.Core.RoutePath; +import java.util.ArrayList; + /** * Created by fwy13 on 17/09/16. */ @@ -31,6 +35,21 @@ public class Map { }); } + public Map(WebView webView, final RoutePath newRoute, TableView table){ + this.webView = webView; + webEngine = webView.getEngine(); + initMap(); + webEngine.getLoadWorker().stateProperty().addListener( + new ChangeListener() { + public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) { + if (newState == Worker.State.SUCCEEDED){ + displayRoute(newRoute); + table.getSelectionModel().selectFirst(); + } + } + }); + } + public void initMap() { webEngine.load(getClass().getClassLoader().getResource("map.html").toExternalForm()); } @@ -45,4 +64,22 @@ public class Map { webEngine.executeScript(scriptToExecute); } + public void displayRoutes(ArrayList routes){ + String routeJSONArray = "["; + int counter = 0; + for (RoutePath route: routes){ + routeJSONArray += route.toJSONArray() + ", "; + if (counter++ > 49){ + Alert alert = new Alert(Alert.AlertType.WARNING); + alert.setTitle("Too Many Routes"); + alert.setHeaderText("Too Many Routes to display"); + alert.setContentText("As there are too many routes to display only the first\n50 will be displayed."); + alert.showAndWait(); + break; + } + } + routeJSONArray += "]"; + webEngine.executeScript("displayRoutes("+routeJSONArray+");"); + } + } diff --git a/src/main/resources/airline_edit_form.fxml b/src/main/resources/airline_edit_form.fxml new file mode 100644 index 0000000..0181fc5 --- /dev/null +++ b/src/main/resources/airline_edit_form.fxml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + diff --git a/src/main/resources/airport_edit_form.fxml b/src/main/resources/airport_edit_form.fxml new file mode 100644 index 0000000..2531b03 --- /dev/null +++ b/src/main/resources/airport_edit_form.fxml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + - - - + + + + + + + + + + + + + + - + diff --git a/src/main/resources/dataset_editor.fxml b/src/main/resources/dataset_editor.fxml new file mode 100644 index 0000000..a43b40c --- /dev/null +++ b/src/main/resources/dataset_editor.fxml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/src/main/resources/flight_editor_form.fxml b/src/main/resources/flight_editor_form.fxml new file mode 100644 index 0000000..31b0702 --- /dev/null +++ b/src/main/resources/flight_editor_form.fxml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/src/main/resources/getting_started.fxml b/src/main/resources/getting_started.fxml new file mode 100644 index 0000000..25e1d8b --- /dev/null +++ b/src/main/resources/getting_started.fxml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/help.fxml b/src/main/resources/help.fxml new file mode 100644 index 0000000..35d386b --- /dev/null +++ b/src/main/resources/help.fxml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/map.html b/src/main/resources/map.html index 3af53d2..3acdd74 100644 --- a/src/main/resources/map.html +++ b/src/main/resources/map.html @@ -90,6 +90,57 @@ repositionMap(flightPath); } + function displayRoutes(flightPaths) { + map = new google.maps.Map(document.getElementById('map'), { + center: {lat: 0, lng: 0}, + zoom: 5 + }); + for (var i = 0; i < flightPaths.length; i++) { + var tempMarker1 = null; + var tempMarker2 = null; + var tempPath = null; + + if (flightPaths[i].length < 2) { + continue; + } + + // CREATE MARKERS AT START AND FINISH + tempMarker1 = new google.maps.Marker({ + position: flightPaths[i][0], + map: map + }); + + tempMarker2 = new google.maps.Marker({ + position: flightPaths[i][flightPaths[i].length - 1], + map: map + }); + + // DRAW POLYLINE FOR ROUTE + tempPath = new google.maps.Polyline({ + path: flightPaths[i], + geodesic: true, + strokeColor: '#FF0000', + strokeOpacity: 1.0, + strokeWeight: 2 + }); + + tempPath.setMap(map); + } + repositionMapToMulti(flightPaths); + } + + function repositionMapToMulti(flightPaths){ + var bounds = new google.maps.LatLngBounds(); + + for (var i = 0; i < flightPaths.length; i++) { + for (var j = 0; j < flightPaths[i].length; j++) { + bounds.extend(flightPaths[i][j]); + } + } + + map.fitBounds(bounds); + } + function repositionMap(flightPath) { var bounds = new google.maps.LatLngBounds(); diff --git a/src/main/resources/menu.fxml b/src/main/resources/menu.fxml index f06aa5e..8005c50 100644 --- a/src/main/resources/menu.fxml +++ b/src/main/resources/menu.fxml @@ -1,16 +1,21 @@ + + + - + + + @@ -43,12 +48,24 @@ + + + + + + + + + + + + diff --git a/src/main/resources/route_add_form.fxml b/src/main/resources/route_add_form.fxml index 5be91be..2f5b6f7 100644 --- a/src/main/resources/route_add_form.fxml +++ b/src/main/resources/route_add_form.fxml @@ -53,7 +53,7 @@ -