Atempting to get the editor to work for the flight raw data points (Currently broken)

This commit is contained in:
Liam Beckett
2016-09-23 14:45:51 +12:00
parent c1b338e35c
commit 3d6dd0c2cb
8 changed files with 221 additions and 18 deletions
@@ -1863,8 +1863,9 @@ public class Dataset {
* @param longitude
* @throws DataException
*/
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);
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);
}
/**
@@ -1877,7 +1878,8 @@ 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 editFlightPoint(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());
@@ -132,18 +132,25 @@ 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
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 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 +171,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;
}
@@ -9,7 +9,7 @@ public enum SceneCode {
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");
AIRPORT_DIST_CALC("airport_dist_calc.fxml"), FLIGHT_EDITOR("flight_editor_form.fxml");
private String filePath;
@@ -1,9 +1,17 @@
package seng202.group9.GUI;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import seng202.group9.Controller.App;
import seng202.group9.Controller.SceneCode;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ResourceBundle;
@@ -50,6 +58,45 @@ public abstract class Controller implements Initializable{
}
}
/**
* Creates a popup window with a specific fxml scene
* @param scene
* @param width
* @param height
*/
public Stage createPopUpStage(SceneCode scene, int width, int height) {
FXMLLoader loader = new FXMLLoader();
InputStream in = getClass().getClassLoader().getResourceAsStream(scene.getFilePath());
Parent page = null;
try {
page = loader.load(in);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//set contorller and call default calls
Controller controller = (Controller) loader.getController();
controller.setApp(parent);
controller.load();
controller.loadOnce();
//create a new stage to popup
Stage popupStage = new Stage();
popupStage.initModality(Modality.APPLICATION_MODAL);
//inner layout constraints
VBox container = new VBox();
container.getChildren().add(page);
Scene popupScene = new Scene(container, width, height);
//show
popupStage.setScene(popupScene);
popupStage.showAndWait();
return popupStage;
}
/**
* Functions here will only load once and after the load function.
*/
@@ -66,4 +113,4 @@ public abstract class Controller implements Initializable{
}
}
}
@@ -0,0 +1,70 @@
package seng202.group9.GUI;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.TextField;
import seng202.group9.Controller.Dataset;
import seng202.group9.Core.FlightPoint;
/**
* 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;
//Set an empty Dataset to be assigned later
private Dataset theDataSet = null;
/**
* Adds a single airport entry in the database.
* Takes in values from the GUI the user has typed in.
* @see Dataset
*/
public void editFlight(FlightPoint flightPoint) {
//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()));
theDataSet.editFlightPoint(
flightPoint,
fNameEdit.getText(),
fTypeEdit.getText(),
fAltitudeEdit.getText(),
fLatitudeEdit.getText(),
fLongitudeEdit.getText()
);
fNameEdit.clear();
fTypeEdit.clear();
fAltitudeEdit.clear();
fLatitudeEdit.clear();
fLongitudeEdit.clear();
} 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();
}
}
public void load() {
theDataSet = getParent().getCurrentDataset();
}
}
@@ -9,6 +9,7 @@ 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.Core.FlightPath;
import seng202.group9.Core.FlightPoint;
@@ -174,7 +175,6 @@ public class FlightRDController extends Controller {
alert.setTitle("Flight Point Data Error");
alert.setHeaderText("Error adding a custom flight point entry.");
alert.setContentText(e.getMessage());
}
}
@@ -218,6 +218,21 @@ public class FlightRDController extends Controller {
flightTableView.setItems(FXCollections.observableArrayList(flightPoints));
}
public void editPoint() {
FlightPoint toEdit = flightTableView.getSelectionModel().getSelectedItem();
int pathID;
try {
pathID = toEdit.getIndex();
} 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()));
}
/**
* Removes the selected path from the list view of paths and from the database.
*/