Merge branch 'WIP_Flight_fixes' into 'master'

flight fixes



See merge request !15
main
Liam Beckett 9 years ago
commit c1b338e35c

@ -37,8 +37,14 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>3.8.1</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

@ -1150,6 +1150,15 @@ public class Dataset {
newPath.setID(pathID); newPath.setID(pathID);
flightPathDictionary.put(pathID, newPath); flightPathDictionary.put(pathID, newPath);
flightPaths.add(newPath); flightPaths.add(newPath);
FlightPoint sourcePoint = new FlightPoint(sourceAirport, pathID);
FlightPoint destinationPoint = new FlightPoint(sourceAirport, pathID);
try{
addFlightPointToPath(sourcePoint);
addFlightPointToPath(destinationPoint);
} catch (DataException e){
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
} }
/** /**

@ -132,6 +132,14 @@ public class EntryParser {
} }
public FlightPoint parsePoint(String name, String type, String altitude, String latitude, String longitude) throws DataException{ public FlightPoint parsePoint(String name, String type, String altitude, String latitude, String longitude) throws DataException{
//(airport) name (first and last point)
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");
}
//type
type = type.toUpperCase(); type = type.toUpperCase();
if (!type.equals("APT") && !type.equals("VOR") && !type.equals("FIX") && !type.equals("NDB") && !type.equals("LATLON")){ 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"); throw new DataException("Type of flight must be either APT, VOR, FIX, NDB or LATLON");
@ -167,4 +175,31 @@ public class EntryParser {
return parseSuccess; return parseSuccess;
} }
/**
* Throws an exception if the point name is not a valid AIRPORT ICAO code.
* @param name
* @throws DataException
*/
public void parsePointName(String name)throws DataException{
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!");
}
}
/*
* Cycles through a string to make sure all the characters are letters
*/
private static boolean isLetter(String string){
char[] chars = string.toCharArray();
for (char element : chars) {
if(!Character.isLetter(element)) {
return false;
}
}
return true;
}
} }

@ -16,7 +16,26 @@ public class FlightPoint {
private double longitude; private double longitude;
/** /**
* Constructor for FLight POint before set by the database. * Constructor for Flight Point when creating a new path
* @param name
* @param indexID
*/
public FlightPoint(String name, int indexID) {
this.name = name;
this.ID = -1;
this.indexID = indexID;
this.type = "";
this.via = "";
this.heading = 0;
this.altitude = 0.0;
this.legDistance = 0;
this.totalDistance = 0;
this.latitude = 0.0;
this.longitude = 0.0;
}
/**
* Constructor for Flight Point before set by the database.
* @param type * @param type
* @param name * @param name
* @param altitude * @param altitude

@ -4,22 +4,17 @@ import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import seng202.group9.Controller.App;
import seng202.group9.Controller.DataException; import seng202.group9.Controller.DataException;
import seng202.group9.Controller.Dataset; import seng202.group9.Controller.Dataset;
import seng202.group9.Core.FlightPath; import seng202.group9.Core.FlightPath;
import seng202.group9.Core.FlightPoint; import seng202.group9.Core.FlightPoint;
import javax.swing.*; import javax.swing.*;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.ResourceBundle;
/** /**
* Controller for the Flights Raw Data Scene. * Controller for the Flights Raw Data Scene.
@ -57,7 +52,7 @@ public class FlightRDController extends Controller {
@FXML @FXML
ListView<String> flightPathListView; ListView<String> flightPathListView;
final ObservableList<String> flightList = FXCollections.observableArrayList(); private ObservableList<String> flightList = FXCollections.observableArrayList();
@FXML @FXML
private TextField flightNameBox; private TextField flightNameBox;
@ -82,7 +77,7 @@ public class FlightRDController extends Controller {
* Loads the Flight paths into the List View and waits for a mouse clicked event for which it will update the table * 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. * to display the selected Flight paths points. Called from the MenuController.
*/ */
public void flightPathListView() { private void flightPathListView() {
try { try {
ArrayList<FlightPath> flightPaths; ArrayList<FlightPath> flightPaths;
flightPaths = theDataSet.getFlightPaths(); flightPaths = theDataSet.getFlightPaths();
@ -135,8 +130,8 @@ public class FlightRDController extends Controller {
flightLatCol.setCellValueFactory(new PropertyValueFactory<FlightPoint, String>("Latitude")); flightLatCol.setCellValueFactory(new PropertyValueFactory<FlightPoint, String>("Latitude"));
flightLongCol.setCellValueFactory(new PropertyValueFactory<FlightPoint, String>("Longitude")); flightLongCol.setCellValueFactory(new PropertyValueFactory<FlightPoint, String>("Longitude"));
flightHeadCol.setCellValueFactory(new PropertyValueFactory<FlightPoint, String>("Heading")); flightHeadCol.setCellValueFactory(new PropertyValueFactory<FlightPoint, String>("Heading"));
flightLegDisCol.setCellValueFactory(new PropertyValueFactory<FlightPoint, String>("Leg_Dist")); flightLegDisCol.setCellValueFactory(new PropertyValueFactory<FlightPoint, String>("LegDistance"));
flightTotDisCol.setCellValueFactory(new PropertyValueFactory<FlightPoint, String>("Tot_Dist")); flightTotDisCol.setCellValueFactory(new PropertyValueFactory<FlightPoint, String>("totalDistance"));
ArrayList<FlightPath> flightPaths; ArrayList<FlightPath> flightPaths;
flightPaths = theDataSet.getFlightPaths(); flightPaths = theDataSet.getFlightPaths();
@ -175,7 +170,6 @@ public class FlightRDController extends Controller {
ArrayList<FlightPoint> flightPoints = flightPaths.get(currentPathIndex).getFlight(); ArrayList<FlightPoint> flightPoints = flightPaths.get(currentPathIndex).getFlight();
flightTableView.setItems(FXCollections.observableArrayList(flightPoints)); flightTableView.setItems(FXCollections.observableArrayList(flightPoints));
} catch ( Exception e ) { } catch ( Exception e ) {
//e.printStackTrace();
Alert alert = new Alert(Alert.AlertType.ERROR); Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Flight Point Data Error"); alert.setTitle("Flight Point Data Error");
alert.setHeaderText("Error adding a custom flight point entry."); alert.setHeaderText("Error adding a custom flight point entry.");
@ -204,7 +198,7 @@ public class FlightRDController extends Controller {
*/ */
public void deletePoint() { public void deletePoint() {
FlightPoint toDelete = flightTableView.getSelectionModel().getSelectedItem(); FlightPoint toDelete = flightTableView.getSelectionModel().getSelectedItem();
int pathID = 0; int pathID;
try { try {
pathID = toDelete.getIndex(); pathID = toDelete.getIndex();
} catch (DataException e) { } catch (DataException e) {

@ -124,7 +124,6 @@ public class FlightSummaryController extends Controller {
} }
}); });
} }
/** /**
* Removes the selected path from the list view of paths and from the database. * Removes the selected path from the list view of paths and from the database.
*/ */

@ -1,5 +1,10 @@
package seng202.group9.GUI; package seng202.group9.GUI;
import javafx.scene.control.Alert;
import seng202.group9.Controller.DataException;
import seng202.group9.Controller.EntryParser;
import seng202.group9.Core.FlightPoint;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -14,7 +19,6 @@ public class NewPathPopUp {
private String sourceAirport = null; private String sourceAirport = null;
private String destinationAirport = null; private String destinationAirport = null;
// Creates and displays the pop up box for the user to input data. // Creates and displays the pop up box for the user to input data.
public void display() { public void display() {
JTextField field1 = new JTextField(); JTextField field1 = new JTextField();
@ -29,11 +33,29 @@ public class NewPathPopUp {
if (result == JOptionPane.OK_OPTION) { if (result == JOptionPane.OK_OPTION) {
sourceAirport = field1.getText().toUpperCase(); sourceAirport = field1.getText().toUpperCase();
destinationAirport = field2.getText().toUpperCase(); destinationAirport = field2.getText().toUpperCase();
if (validate(sourceAirport) != true && validate(destinationAirport) != true){ try{
EntryParser parser = new EntryParser();
parser.parsePointName(sourceAirport);
}catch (DataException e){
sourceAirport = null; sourceAirport = null;
destinationAirport = null; destinationAirport = null;
JOptionPane.showMessageDialog(null, "Enter a vaild ICAO Code!"); Alert alert = new Alert(Alert.AlertType.ERROR);
return; alert.setTitle("Flight Path Name Error");
alert.setHeaderText("Error adding the Source airport ICAO code.");
alert.setContentText(e.getMessage());
alert.showAndWait();
}
try{
EntryParser parser = new EntryParser();
parser.parsePointName(destinationAirport);
}catch (DataException e){
sourceAirport = null;
destinationAirport = null;
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Flight Path Name Error");
alert.setHeaderText("Error adding the Destination airport ICAO code.");
alert.setContentText(e.getMessage());
alert.showAndWait();
} }
} else { } else {
sourceAirport = null; sourceAirport = null;
@ -41,30 +63,6 @@ public class NewPathPopUp {
} }
} }
// Checks the users entered string to make sure it is a 4 letter valid code.
private static boolean validate(String airportCode){
if(airportCode == ""){
return false;
} else if(airportCode.length() != 4){
return false;
} else if(!isLetter(airportCode)){
return false;
}
return true;
}
// Used by the validate() method to cycle through the string looking for non letter characters.
private static boolean isLetter(String airportCode){
char[] chars = airportCode.toCharArray();
for (char element : chars) {
if(!Character.isLetter(element)) {
return false;
}
}
return true;
}
public String getSourceAirport() { public String getSourceAirport() {
return sourceAirport; return sourceAirport;
} }

Loading…
Cancel
Save