Got the basic functionally done on the flight point editor. Currently will change the vaule although a few bugs in the validation aspects.
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package seng202.group9.Controller;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javafx.application.Application;
|
||||
@@ -14,6 +18,7 @@ import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import seng202.group9.Core.FlightPath;
|
||||
import seng202.group9.GUI.*;
|
||||
|
||||
/**
|
||||
@@ -61,11 +66,15 @@ public class App extends Application
|
||||
e.printStackTrace();
|
||||
}
|
||||
primaryStage.show();
|
||||
|
||||
//load all datasets
|
||||
try{
|
||||
loadAllDatasets();
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
//testing out dataset
|
||||
try {
|
||||
currentDataset = new Dataset("test's", Dataset.getExisting);
|
||||
datasets.add(currentDataset);
|
||||
}catch (DataException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -107,6 +116,32 @@ public class App extends Application
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all dataset in the current User Database.
|
||||
*/
|
||||
public void loadAllDatasets(){
|
||||
Connection c = null;
|
||||
Statement stmt = null;
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
|
||||
stmt = c.createStatement();
|
||||
String loadAllDatasetsQuery = "SELECT * FROM `Datasets`";
|
||||
ResultSet datasetsLoaded = stmt.executeQuery(loadAllDatasetsQuery);
|
||||
while (datasetsLoaded.next()){
|
||||
Dataset newDataset = new Dataset(datasetsLoaded.getString("Dataset_Name"), Dataset.getExisting);
|
||||
System.out.println("Loaded Dataset "+ datasetsLoaded.getString("Dataset_Name"));
|
||||
datasets.add(newDataset);
|
||||
}
|
||||
datasetsLoaded.close();
|
||||
stmt.close();
|
||||
c.close();
|
||||
} catch ( Exception e ) {
|
||||
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace Scene Content with fxml file code from oracle.
|
||||
* @param fxml
|
||||
@@ -132,7 +167,15 @@ public class App extends Application
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Menu COntroller of the App.
|
||||
* Gets the current session.
|
||||
* @return
|
||||
*/
|
||||
public Session getSession() {
|
||||
return this.session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Menu Controller of the App.
|
||||
* @return
|
||||
*/
|
||||
public MenuController getMenuController() {
|
||||
@@ -147,6 +190,22 @@ public class App extends Application
|
||||
return currentDataset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current Dataset to another Dataset by its index in the datasets arraylist
|
||||
* @param index
|
||||
*/
|
||||
public void setCurrentDataset(int index){
|
||||
currentDataset = datasets.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current Dataset to another Dataset.
|
||||
* @param dataset
|
||||
*/
|
||||
public void setCurrentDataset(Dataset dataset){
|
||||
currentDataset = dataset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new dataset.
|
||||
* @param datasetName
|
||||
|
||||
@@ -27,11 +27,11 @@ public class Dataset {
|
||||
private LinkedHashMap<String, Airport> airportDictionary;
|
||||
private LinkedHashMap<String, Route> routeDictionary;
|
||||
private LinkedHashMap<Integer, FlightPath> flightPathDictionary;
|
||||
private LinkedHashMap<Integer, FlightPoint> flightPointDictionary;
|
||||
private LinkedHashMap<String, Country> countryDictionary;
|
||||
private LinkedHashMap<String, City> cityDictionary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name Name of the database
|
||||
* @param action either Dataset.getExisting or Dataset.createNew
|
||||
* @throws DataException Throws an exception if there is some error ie databases with the same name
|
||||
@@ -45,11 +45,16 @@ public class Dataset {
|
||||
this.cities = new ArrayList<City>();
|
||||
this.countries = new ArrayList<Country>();
|
||||
this.airlineDictionary = new LinkedHashMap<String, Airline>();
|
||||
this.airportDictionary = new LinkedHashMap<String, Airport>();;
|
||||
this.routeDictionary = new LinkedHashMap<String, Route>();;
|
||||
this.countryDictionary = new LinkedHashMap<String, Country>();;
|
||||
this.cityDictionary = new LinkedHashMap<String, City>();;
|
||||
this.airportDictionary = new LinkedHashMap<String, Airport>();
|
||||
;
|
||||
this.routeDictionary = new LinkedHashMap<String, Route>();
|
||||
;
|
||||
this.countryDictionary = new LinkedHashMap<String, Country>();
|
||||
;
|
||||
this.cityDictionary = new LinkedHashMap<String, City>();
|
||||
;
|
||||
this.flightPathDictionary = new LinkedHashMap<Integer, FlightPath>();
|
||||
this.flightPointDictionary = new LinkedHashMap<Integer, FlightPoint>();
|
||||
if (action == getExisting) {
|
||||
updateDataset();
|
||||
//after this make connections. ie filling in the country.cities airports.routes etc
|
||||
@@ -60,6 +65,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Updates Dataset Arrays from Database.
|
||||
*
|
||||
* @throws DataException
|
||||
*/
|
||||
public void updateDataset() throws DataException {
|
||||
@@ -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
|
||||
FlightPoint flightPoint = new FlightPoint(flightPtName, flightPtID, flightPtInd
|
||||
, flightPtType, flightPtVia, flightPtheading, flightPtAltitude, flightPtLegDistance, flightPtTotDist,
|
||||
flightPtLatitude, flightPtLongitude));
|
||||
flightPtLatitude, flightPtLongitude);
|
||||
flightPaths.get(i).addFlightPoint(flightPoint);
|
||||
flightPointDictionary.put(flightPtID, flightPoint);
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
@@ -245,6 +253,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Creates new Dataset with empty data tables etc
|
||||
*
|
||||
* @throws DataException
|
||||
*/
|
||||
public void createTables() throws DataException {
|
||||
@@ -359,6 +368,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Imports Airline files to the dataset
|
||||
*
|
||||
* @param filePath
|
||||
* @return Success Message
|
||||
* @throws DataException
|
||||
@@ -371,7 +381,7 @@ public class Dataset {
|
||||
ArrayList<Airline> airlinesToImport = parser.getResult();
|
||||
//check for dup
|
||||
int numOfDuplicates = 0;
|
||||
int nextID = -1;
|
||||
int nextID = 1;
|
||||
//query database.
|
||||
Connection c = null;
|
||||
Statement stmt = null;
|
||||
@@ -428,8 +438,10 @@ public class Dataset {
|
||||
createDataLinks();
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports Airport files to the dataset
|
||||
*
|
||||
* @param filePath
|
||||
* @return Success Message
|
||||
* @throws DataException
|
||||
@@ -444,7 +456,7 @@ public class Dataset {
|
||||
ArrayList<Country> countriesToImport = parser.getCountryResult();
|
||||
//check for dup
|
||||
int numOfDuplicates = 0;
|
||||
int nextID = -1;
|
||||
int nextID = 1;
|
||||
//query database.
|
||||
Connection c = null;
|
||||
Statement stmt = null;
|
||||
@@ -459,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`," +
|
||||
@@ -564,6 +575,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Imports Route files to dataset
|
||||
*
|
||||
* @param filePath
|
||||
* @return Success Message
|
||||
* @throws DataException
|
||||
@@ -576,7 +588,7 @@ public class Dataset {
|
||||
ArrayList<Route> routesToImport = parser.getResult();
|
||||
//check for dup
|
||||
int numOfDuplicates = 0;
|
||||
int nextID = -1;
|
||||
int nextID = 1;
|
||||
//query database.
|
||||
Connection c = null;
|
||||
Statement stmt = null;
|
||||
@@ -639,6 +651,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Imports Flight files to dataset
|
||||
*
|
||||
* @param filePath
|
||||
* @return Success Message
|
||||
* @throws DataException
|
||||
@@ -651,7 +664,7 @@ public class Dataset {
|
||||
ArrayList<FlightPoint> flightPointsToImport = parser.getResult();
|
||||
//check for dup
|
||||
int numOfDuplicates = 0;
|
||||
int nextID = -1;
|
||||
int nextID = 1;
|
||||
//query database.
|
||||
Connection c = null;
|
||||
Statement stmt = null;
|
||||
@@ -667,7 +680,7 @@ public class Dataset {
|
||||
}
|
||||
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);
|
||||
@@ -677,7 +690,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);
|
||||
@@ -688,7 +701,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`) VALUES ";
|
||||
int numOfFlights = 0;
|
||||
@@ -713,7 +726,7 @@ public class Dataset {
|
||||
//add data to dataset array.
|
||||
//this is placed after incase the database messes up
|
||||
flightPathToAdd.addFlightPoint(flightPointsToImport.get(i));
|
||||
//routeDictionary.put(routeIdentifier, flightsToImport.get(i));
|
||||
flightPointDictionary.put(flightPointsToImport.get(i).getID(), flightPointsToImport.get(i));
|
||||
nextID++;
|
||||
numOfFlights++;
|
||||
//}
|
||||
@@ -750,7 +763,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<Route>());
|
||||
airline.setCountry(countryDictionary.get(airline.getCountryName()));
|
||||
Country country = countryDictionary.get(airline.getCountryName());
|
||||
@@ -762,7 +774,6 @@ public class Dataset {
|
||||
HashMap<String, Airport> airportsByIATA = new HashMap<String, Airport>(); //this is used later for connecting the routes
|
||||
HashMap<String, Airport> airportsByICAO = new HashMap<String, Airport>(); //this is used later for connecting the routes
|
||||
for (Airport airport : airports) {
|
||||
//System.out.println(airport.getIATA_FFA());
|
||||
airportsByIATA.put(airport.getIATA_FFA(), airport);
|
||||
airportsByICAO.put(airport.getICAO(), airport);
|
||||
airport.setCountry(countryDictionary.get(airport.getCountryName()));
|
||||
@@ -796,6 +807,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Addes Single Airline to Program and Database.
|
||||
*
|
||||
* @param name
|
||||
* @param alias
|
||||
* @param IATA
|
||||
@@ -821,6 +833,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Adds a Single Airline from the Program to the Database
|
||||
*
|
||||
* @param airlineToAdd
|
||||
* @throws DataException
|
||||
*/
|
||||
@@ -873,6 +886,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Adds a single Airport from the Program to the Database
|
||||
*
|
||||
* @param name
|
||||
* @param city
|
||||
* @param country
|
||||
@@ -914,6 +928,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* gets the name of the dataset.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
@@ -922,6 +937,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Adds an Airport to the database and dataset.
|
||||
*
|
||||
* @param airportToAdd
|
||||
* @throws DataException
|
||||
*/
|
||||
@@ -976,6 +992,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Adds a city to the dataset and database
|
||||
*
|
||||
* @param city
|
||||
*/
|
||||
private void addCity(City city) {
|
||||
@@ -1006,6 +1023,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Adds a Country to the dataset and database
|
||||
*
|
||||
* @param country
|
||||
*/
|
||||
private void addCountry(Country country) {
|
||||
@@ -1035,6 +1053,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Adds one single route to the program.
|
||||
*
|
||||
* @param airline
|
||||
* @param sourceAirport
|
||||
* @param destAirport
|
||||
@@ -1059,6 +1078,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Adds a single route the dataset and database.
|
||||
*
|
||||
* @param routeToAdd
|
||||
* @throws DataException
|
||||
*/
|
||||
@@ -1119,6 +1139,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Adds a path to the database and to the path dictionary
|
||||
*
|
||||
* @param sourceAirport
|
||||
* @param destAirport
|
||||
*/
|
||||
@@ -1163,6 +1184,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Adds a flight point to a given path woth the given id
|
||||
*
|
||||
* @param id
|
||||
* @param name
|
||||
* @param type
|
||||
@@ -1237,8 +1259,6 @@ public class Dataset {
|
||||
", \"" + via + "\")";
|
||||
stmt.execute(insertFlightPointQuery);
|
||||
stmt.close();
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getClass().getName() + ": " + e.getMessage());
|
||||
System.exit(0);
|
||||
@@ -1246,20 +1266,22 @@ public class Dataset {
|
||||
|
||||
FlightPoint pointToAdd = new FlightPoint(name, pointID + 1, id, type, via, headingVal, altitudeVal, legDistVal,
|
||||
totalDistVal, latitudeVal, longitudeVal);
|
||||
flightPointDictionary.put(pointID + 1, pointToAdd);
|
||||
flightPathDictionary.get(Integer.valueOf(id)).addFlightPoint(pointToAdd, index);
|
||||
}
|
||||
|
||||
/***
|
||||
* Adds a single flight Point to an Existing FLight Path.
|
||||
* Adds a single flight Point to an Existing Flight Path.
|
||||
* @param point
|
||||
* @param index
|
||||
* @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);
|
||||
String.valueOf(point.getLatitude()), String.valueOf(point.getLongitude()), String.valueOf(point.getHeading()),
|
||||
String.valueOf(point.getLegDistance()), String.valueOf(point.getTotalDistance()), index);
|
||||
}
|
||||
|
||||
/***
|
||||
* Adds a single flight Point to an Existing FLight Path appended on the end of the list.
|
||||
* @param point
|
||||
@@ -1267,12 +1289,13 @@ public class Dataset {
|
||||
*/
|
||||
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);
|
||||
String.valueOf(point.getLatitude()), String.valueOf(point.getLongitude()), String.valueOf(point.getHeading()),
|
||||
String.valueOf(point.getLegDistance()), String.valueOf(point.getTotalDistance()), -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a single flight Point to an Existing FLight Path appended on the end of the list.
|
||||
*
|
||||
* @param id
|
||||
* @param name
|
||||
* @param type
|
||||
@@ -1290,6 +1313,7 @@ public class Dataset {
|
||||
String heading, String legDist, String totDist) throws DataException {
|
||||
addFlightPointToPath(id, name, type, via, altitude, latitude, longitude, heading, legDist, totDist, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called in conjunction to the App deleteDataset DO NOT CALL UNLESS THROUGH APP.DELETEDATASET
|
||||
*/
|
||||
@@ -1320,6 +1344,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* deletes an airline from the dataset.
|
||||
*
|
||||
* @param airline
|
||||
*/
|
||||
public void deleteAirline(Airline airline) {
|
||||
@@ -1329,14 +1354,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() + ";";
|
||||
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" +
|
||||
@@ -1380,6 +1401,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Deletes an AIrline from the dataset and database based on it index
|
||||
*
|
||||
* @param index
|
||||
*/
|
||||
public void deleteAirline(int index) {
|
||||
@@ -1388,6 +1410,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* deletes an airport from the dataset.
|
||||
*
|
||||
* @param airport
|
||||
*/
|
||||
public void deleteAirport(Airport airport) {
|
||||
@@ -1463,13 +1486,16 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Deletes an Airport from the dataset and database based on it index.
|
||||
*
|
||||
* @param index
|
||||
*/
|
||||
public void deleteAirport(int index) {
|
||||
deleteAirport(airports.get(index));
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes an route from the dataset.
|
||||
*
|
||||
* @param route
|
||||
*/
|
||||
public void deleteRoute(Route route) {
|
||||
@@ -1496,13 +1522,16 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Deletes a Route from the dataset and database based on its index
|
||||
*
|
||||
* @param index
|
||||
*/
|
||||
public void deleteRoute(int index) {
|
||||
deleteRoute(routes.get(index));
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes an airline from the dataset.
|
||||
*
|
||||
* @param flightPath
|
||||
*/
|
||||
public void deleteFlightPath(FlightPath flightPath) {
|
||||
@@ -1538,6 +1567,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Deletes a flight path from the database based on its index.
|
||||
*
|
||||
* @param index
|
||||
*/
|
||||
public void deleteFlightPath(int index) {
|
||||
@@ -1546,6 +1576,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* deletes an airline from the dataset.
|
||||
*
|
||||
* @param flightPoint
|
||||
*/
|
||||
public void deleteFlightPoint(FlightPoint flightPoint, FlightPath flightPath) {
|
||||
@@ -1564,10 +1595,16 @@ public class Dataset {
|
||||
System.exit(0);
|
||||
}
|
||||
flightPath.getFlightPoints().remove(flightPoint);
|
||||
try {
|
||||
flightPointDictionary.remove(flightPoint.getID());
|
||||
} catch (DataException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes a single flight point from a given path.
|
||||
*
|
||||
* @param pathIndex
|
||||
* @param pointIndex
|
||||
*/
|
||||
@@ -1577,6 +1614,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* returns the airlines that are part of this dataset.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<Airline> getAirlines() {
|
||||
@@ -1585,6 +1623,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* returns the airports that are associated with this dataset.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<Airport> getAirports() {
|
||||
@@ -1593,6 +1632,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* returns the routes that are associated with this dataset.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<Route> getRoutes() {
|
||||
@@ -1601,6 +1641,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* returns the flight paths that are associated with this dataset.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<FlightPath> getFlightPaths() {
|
||||
@@ -1609,6 +1650,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* returns the countries that are associated with this dataset.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<Country> getCountries() {
|
||||
@@ -1617,6 +1659,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* returns the cities that are associate wit hthis dataset.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<City> getCities() {
|
||||
@@ -1625,6 +1668,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* returns a dictionary with the airlines that are associated with this datatset.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public LinkedHashMap<String, Airline> getAirlineDictionary() {
|
||||
@@ -1633,6 +1677,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* returns a dictionary with the airports that are associated with this dataset.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public LinkedHashMap<String, Airport> getAirportDictionary() {
|
||||
@@ -1641,6 +1686,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* returns a route dictionary with the routes that are associated wit hthis dataset.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public LinkedHashMap<String, Route> getRouteDictionary() {
|
||||
@@ -1649,14 +1695,25 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* returns a flightpath dictionary with the flights that are associated with this dataset.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public LinkedHashMap<Integer, FlightPath> getFlightPathDictionary() {
|
||||
return flightPathDictionary;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a flightpoint dictionary with the flights that are associated with this dataset.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public LinkedHashMap<Integer, FlightPoint> getFlightPointDictionary() {
|
||||
return flightPointDictionary;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a Country Dictionary with the COuntries that are associated with this dataset.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public LinkedHashMap<String, Country> getCountryDictionary() {
|
||||
@@ -1665,6 +1722,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* returns a City Dictionary with the Cities that are associated with this datatset.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public LinkedHashMap<String, City> getCityDictionary() {
|
||||
@@ -1673,6 +1731,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Edits Airline and commits them to the database.
|
||||
*
|
||||
* @param index
|
||||
* @param name
|
||||
* @param alias
|
||||
@@ -1686,8 +1745,10 @@ public class Dataset {
|
||||
public void editAirline(int index, String name, String alias, String IATA, String ICAO, String callsign, String country, String active) throws DataException {
|
||||
editAirline(airlines.get(index), name, alias, IATA, ICAO, callsign, country, active);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits Airline and commits them to the database.
|
||||
*
|
||||
* @param airline
|
||||
* @param name
|
||||
* @param alias
|
||||
@@ -1729,6 +1790,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Edits the Airport in the dataset then commits it to the database.
|
||||
*
|
||||
* @param index
|
||||
* @param name
|
||||
* @param city
|
||||
@@ -1749,6 +1811,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Edits the Airport in the dataset then commits it to the database.
|
||||
*
|
||||
* @param airport
|
||||
* @param name
|
||||
* @param city
|
||||
@@ -1800,6 +1863,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Edits the ROutes in the dataset and commits it to the database.
|
||||
*
|
||||
* @param index
|
||||
* @param airline
|
||||
* @param source
|
||||
@@ -1815,6 +1879,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Edits the ROutes in the dataset and then commits it to the database.
|
||||
*
|
||||
* @param route
|
||||
* @param airline
|
||||
* @param source
|
||||
@@ -1854,6 +1919,7 @@ public class Dataset {
|
||||
|
||||
/**
|
||||
* Edits a flight Point in the dataset then commits it to the database.
|
||||
*
|
||||
* @param flightPath
|
||||
* @param index
|
||||
* @param name
|
||||
@@ -1863,13 +1929,13 @@ public class Dataset {
|
||||
* @param longitude
|
||||
* @throws DataException
|
||||
*/
|
||||
public void editFlightPath(FlightPath flightPath, int index, String name, String type, String altitude, String latitude,
|
||||
String longitude) throws DataException{
|
||||
editFlightPoint(flightPath.getFlightPoints().get(index), name, type, altitude, latitude, longitude);
|
||||
public void editFlight(FlightPath flightPath, int index, String name, String type, String altitude, String latitude, String longitude) throws DataException {
|
||||
editFlight(flightPath.getFlightPoints().get(index), name, type, altitude, latitude, longitude);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits a flight Point in the dataset then commits it to the database.
|
||||
*
|
||||
* @param flightPoint
|
||||
* @param name
|
||||
* @param type
|
||||
@@ -1878,8 +1944,7 @@ public class Dataset {
|
||||
* @param longitude
|
||||
* @throws DataException
|
||||
*/
|
||||
public void editFlightPoint(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());
|
||||
@@ -1905,8 +1970,7 @@ public class Dataset {
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getClass().getName() + ": " + e.getMessage());
|
||||
}
|
||||
|
||||
FlightPath flightPath = flightPathDictionary.get(flightPoint.getIndexID());
|
||||
FlightPath flightPath = flightPathDictionary.get(flightPoint.getIndex());
|
||||
int indexOf = flightPath.getFlightPoints().indexOf(flightPoint);
|
||||
|
||||
if (indexOf == 0) {
|
||||
@@ -1919,6 +1983,7 @@ public class Dataset {
|
||||
} 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();
|
||||
@@ -1929,8 +1994,36 @@ public class Dataset {
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getClass().getName() + ": " + e.getMessage());
|
||||
}
|
||||
flightPath.setArrivalAirport(flightPoint.getName());
|
||||
}
|
||||
|
||||
updateFlightPointInfo(flightPath);
|
||||
createDataLinks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the Leg Distance, Total Distance and Bearing(Heading) of the Flight points in the flight path.
|
||||
* @param flightPath
|
||||
*/
|
||||
public void updateFlightPointInfo(FlightPath flightPath){
|
||||
flightPath.updateFlightPointInfo();
|
||||
Connection c = null;
|
||||
Statement stmt;
|
||||
try {
|
||||
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
|
||||
//move all the points after this forward
|
||||
for (FlightPoint flightPoint: flightPath.getFlightPoints()){
|
||||
stmt = c.createStatement();
|
||||
String updatePointQuery = "UPDATE `"+this.name+"_Flight_Points` SET `Heading` = "+flightPoint.getHeading()+", " +
|
||||
"`Tot_Dist` = "+flightPoint.getTotalDistance()+", `Leg_Dist` = "+flightPoint.getLegDistance()+" WHERE `POINT_ID` = " +
|
||||
"" + flightPoint.getID();
|
||||
stmt.execute(updatePointQuery);
|
||||
stmt.close();
|
||||
}
|
||||
c.close();
|
||||
} catch ( Exception e ) {
|
||||
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||
e.printStackTrace();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package seng202.group9.Controller;
|
||||
|
||||
import seng202.group9.Core.FlightPoint;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@@ -8,6 +10,8 @@ import java.io.Serializable;
|
||||
*/
|
||||
public class Session implements Serializable {
|
||||
private SceneCode sceneDisplayed;
|
||||
private int currentFlightPointID;
|
||||
private int currentFlightPathID;
|
||||
|
||||
/**
|
||||
* Constructor for a new session
|
||||
@@ -40,4 +44,36 @@ public class Session implements Serializable {
|
||||
public SceneCode getSceneDisplayed() {
|
||||
return sceneDisplayed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -183,4 +183,37 @@ public class FlightPath {
|
||||
}
|
||||
return routePath;
|
||||
}
|
||||
public void updateFlightPointInfo(){
|
||||
if (flightPoints.size() == 0){
|
||||
return;
|
||||
}
|
||||
FlightPoint startPoint = flightPoints.get(0);
|
||||
startPoint.setLegDistance(0);
|
||||
startPoint.setTotalDistance(0);
|
||||
startPoint.setHeading(0);
|
||||
for (int i = 1; i < flightPoints.size(); i ++){
|
||||
double distance = 0;
|
||||
double dLong = flightPoints.get(i - 1).getLongitude() - flightPoints.get(i).getLongitude();
|
||||
double dLat = flightPoints.get(i - 1).getLatitude() - flightPoints.get(i).getLatitude();
|
||||
dLong = Math.toRadians(dLong);
|
||||
dLat = Math.toRadians(dLat);
|
||||
double a = Math.pow((Math.sin(dLat/2)), 2) + Math.cos(Math.toRadians(flightPoints.get(i).getLatitude())) * Math.cos(Math.toRadians(flightPoints.get(i - 1).getLatitude())) * Math.pow(Math.sin(dLong/2), 2);
|
||||
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
||||
distance = 6371 * c;
|
||||
//convert distance from km to nautical mile
|
||||
distance = distance * 0.53995680345572;
|
||||
flightPoints.get(i).setLegDistance(distance);
|
||||
flightPoints.get(i).setTotalDistance(distance + flightPoints.get(i).getTotalDistance());
|
||||
//calculate bearing
|
||||
double lat1 = Math.toRadians(flightPoints.get(i - 1).getLatitude());
|
||||
double lat2 = Math.toRadians(flightPoints.get(i).getLatitude());
|
||||
double lng1 = Math.toRadians(flightPoints.get(i - 1).getLongitude());
|
||||
double lng2 = Math.toRadians(flightPoints.get(i).getLongitude());
|
||||
double y = Math.sin(dLong) * Math.cos(lat2);
|
||||
double x = Math.cos(lat1) * Math.sin(lat2);
|
||||
x -= Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLong);
|
||||
double heading = 360 - Math.toDegrees(Math.atan2(y, x));
|
||||
flightPoints.get(i).setHeading((int)heading);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,11 @@ package seng202.group9.GUI;
|
||||
import javafx.event.ActionEvent;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -22,7 +25,8 @@ public class FlightEditorController extends Controller{
|
||||
TextField fLatitudeEdit;
|
||||
@FXML
|
||||
TextField fLongitudeEdit;
|
||||
|
||||
@FXML
|
||||
private Button flightEditButton;
|
||||
|
||||
//Set an empty Dataset to be assigned later
|
||||
private Dataset theDataSet = null;
|
||||
@@ -32,30 +36,41 @@ public class FlightEditorController extends Controller{
|
||||
* Takes in values from the GUI the user has typed in.
|
||||
* @see Dataset
|
||||
*/
|
||||
public void editFlight(FlightPoint flightPoint) {
|
||||
public void editFlight() {
|
||||
//Tries to add a new airport and clears the fields to their initial state if successful.
|
||||
//Otherwise an error message will pop up with what is wrong with the manual data.
|
||||
try {
|
||||
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()));
|
||||
Session session = getParent().getSession();
|
||||
int flightPointID = session.getCurrentFlightPointID();
|
||||
int flightPathID = session.getCurrentFlightPathID();
|
||||
|
||||
theDataSet.editFlightPoint(
|
||||
flightPoint,
|
||||
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 ) {
|
||||
e.printStackTrace();
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setTitle("Flight Data Error");
|
||||
alert.setHeaderText("Error editing a flight point.");
|
||||
@@ -64,8 +79,22 @@ public class FlightEditorController extends Controller{
|
||||
}
|
||||
}
|
||||
|
||||
public void loadValues(){
|
||||
|
||||
}
|
||||
|
||||
public void load() {
|
||||
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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ 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;
|
||||
|
||||
@@ -144,8 +145,6 @@ public class FlightRDController extends Controller {
|
||||
* Will take the inputs from the text fields and adds the point to the current flight path.
|
||||
*/
|
||||
public void addFlightPoint() {
|
||||
ArrayList<FlightPath> flightPaths;
|
||||
flightPaths = theDataSet.getFlightPaths();
|
||||
|
||||
try {
|
||||
theDataSet.addFlightPointToPath(currentPathId,
|
||||
@@ -168,8 +167,7 @@ public class FlightRDController extends Controller {
|
||||
flightLegDistBox.clear();
|
||||
flightTotDistBox.clear();
|
||||
|
||||
ArrayList<FlightPoint> flightPoints = flightPaths.get(currentPathIndex).getFlight();
|
||||
flightTableView.setItems(FXCollections.observableArrayList(flightPoints));
|
||||
updateTable(currentPathIndex);
|
||||
} catch ( Exception e ) {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setTitle("Flight Point Data Error");
|
||||
@@ -212,25 +210,22 @@ public class FlightRDController extends Controller {
|
||||
|
||||
currentPathIndex = theDataSet.getFlightPaths().indexOf(theDataSet.getFlightPathDictionary().get(pathID));
|
||||
|
||||
ArrayList<FlightPath> flightPaths;
|
||||
flightPaths = theDataSet.getFlightPaths();
|
||||
ArrayList<FlightPoint> flightPoints = flightPaths.get(currentPathIndex).getFlight();
|
||||
flightTableView.setItems(FXCollections.observableArrayList(flightPoints));
|
||||
updateTable(currentPathIndex);
|
||||
}
|
||||
|
||||
public void editPoint() {
|
||||
FlightPoint toEdit = flightTableView.getSelectionModel().getSelectedItem();
|
||||
int pathID;
|
||||
try {
|
||||
pathID = toEdit.getIndex();
|
||||
Session session = getParent().getSession();
|
||||
session.setCurrentFlightPointID(toEdit.getID());
|
||||
session.setCurrentFlightPathtID(currentPathId);
|
||||
} catch (DataException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Point is Uneditable as the Index ID is not set.");
|
||||
return;
|
||||
}
|
||||
ArrayList<FlightPath> flightPaths = theDataSet.getFlightPaths();
|
||||
createPopUpStage(SceneCode.FLIGHT_EDITOR, 600, 289);
|
||||
flightTableView.setItems(FXCollections.observableArrayList(flightPaths.get(currentPathIndex).getFlight()));
|
||||
updateTable(currentPathIndex);
|
||||
|
||||
}
|
||||
/**
|
||||
@@ -249,6 +244,14 @@ public class FlightRDController extends Controller {
|
||||
flightPathListView();
|
||||
}
|
||||
|
||||
public void updateTable(int currentPathIndex) {
|
||||
ArrayList<FlightPath> flightPaths;
|
||||
flightPaths = theDataSet.getFlightPaths();
|
||||
ArrayList<FlightPoint> flightPoints = flightPaths.get(currentPathIndex).getFlight();
|
||||
flightTableView.setItems(FXCollections.observableArrayList(flightPoints));
|
||||
flightTableView.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Will link to the flight analyser when implemented.
|
||||
*/
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<Button fx:id="editButton" mnemonicParsing="false" onAction="#editFlight" text="Edit Flight" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="6" />
|
||||
<Button fx:id="flightEditButton" mnemonicParsing="false" onAction="#editFlight" text="Edit Flight" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="6" />
|
||||
<TextField fx:id="fNameEdit" prefHeight="31.0" prefWidth="432.0" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="1" />
|
||||
<TextField fx:id="fTypeEdit" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="2" />
|
||||
<TextField fx:id="fAltitudeEdit" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="3" />
|
||||
|
||||
@@ -153,8 +153,8 @@
|
||||
<contextMenu>
|
||||
<ContextMenu>
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" onAction="#deletePoint" text="Delete" />
|
||||
<MenuItem mnemonicParsing="false" onAction="#editPoint" text="Edit" />
|
||||
<MenuItem mnemonicParsing="false" onAction="#deletePoint" text="Delete" />
|
||||
</items>
|
||||
</ContextMenu>
|
||||
</contextMenu>
|
||||
|
||||
Reference in New Issue
Block a user