Got the basic functionally done on the flight point editor. Currently will change the vaule although a few bugs in the validation aspects.

main
Liam Beckett 9 years ago
parent f7d1e688fa
commit 5f8e2f2481

@ -1,6 +1,10 @@
package seng202.group9.Controller; package seng202.group9.Controller;
import java.io.*; import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import javafx.application.Application; import javafx.application.Application;
@ -14,6 +18,7 @@ import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.Stage; import javafx.stage.Stage;
import seng202.group9.Core.FlightPath;
import seng202.group9.GUI.*; import seng202.group9.GUI.*;
/** /**
@ -28,20 +33,20 @@ public class App extends Application
private VBox mainContainer = null; private VBox mainContainer = null;
private Session session = null; private Session session = null;
private MenuController menuController = null; private MenuController menuController = null;
public static void main( String[] args ) public static void main( String[] args )
{ {
launch(args); launch(args);
} }
public Stage getPrimaryStage() { public Stage getPrimaryStage() {
return primaryStage; return primaryStage;
} }
/** /**
* Starts the application * Starts the application
* @param primaryStage main "stage" of the program * @param primaryStage main "stage" of the program
*/ */
@Override @Override
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
this.primaryStage = primaryStage; this.primaryStage = primaryStage;
@ -61,11 +66,15 @@ public class App extends Application
e.printStackTrace(); e.printStackTrace();
} }
primaryStage.show(); primaryStage.show();
//load all datasets
try{
loadAllDatasets();
} catch (Exception e){
e.printStackTrace();
}
//testing out dataset //testing out dataset
try { try {
currentDataset = new Dataset("test's", Dataset.getExisting); currentDataset = new Dataset("test's", Dataset.getExisting);
datasets.add(currentDataset);
}catch (DataException e){ }catch (DataException e){
e.printStackTrace(); e.printStackTrace();
} }
@ -107,6 +116,32 @@ public class App extends Application
e.printStackTrace(); 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. * Replace Scene Content with fxml file code from oracle.
* @param fxml * @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 * @return
*/ */
public MenuController getMenuController() { public MenuController getMenuController() {
@ -147,6 +190,22 @@ public class App extends Application
return currentDataset; 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. * Creates new dataset.
* @param datasetName * @param datasetName
@ -181,4 +240,4 @@ public class App extends Application
} }
} }
} }
} }

File diff suppressed because it is too large Load Diff

@ -1,5 +1,7 @@
package seng202.group9.Controller; package seng202.group9.Controller;
import seng202.group9.Core.FlightPoint;
import java.io.Serializable; import java.io.Serializable;
/** /**
@ -8,6 +10,8 @@ import java.io.Serializable;
*/ */
public class Session implements Serializable { public class Session implements Serializable {
private SceneCode sceneDisplayed; private SceneCode sceneDisplayed;
private int currentFlightPointID;
private int currentFlightPathID;
/** /**
* Constructor for a new session * Constructor for a new session
@ -40,4 +44,36 @@ public class Session implements Serializable {
public SceneCode getSceneDisplayed() { public SceneCode getSceneDisplayed() {
return sceneDisplayed; 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; 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.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.stage.Stage;
import seng202.group9.Controller.Dataset; import seng202.group9.Controller.Dataset;
import seng202.group9.Controller.Session;
import seng202.group9.Core.FlightPoint; import seng202.group9.Core.FlightPoint;
/** /**
@ -22,7 +25,8 @@ public class FlightEditorController extends Controller{
TextField fLatitudeEdit; TextField fLatitudeEdit;
@FXML @FXML
TextField fLongitudeEdit; TextField fLongitudeEdit;
@FXML
private Button flightEditButton;
//Set an empty Dataset to be assigned later //Set an empty Dataset to be assigned later
private Dataset theDataSet = null; private Dataset theDataSet = null;
@ -32,30 +36,41 @@ public class FlightEditorController extends Controller{
* Takes in values from the GUI the user has typed in. * Takes in values from the GUI the user has typed in.
* @see Dataset * @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. //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. //Otherwise an error message will pop up with what is wrong with the manual data.
try { try {
fNameEdit.setText(flightPoint.getName()); Session session = getParent().getSession();
fTypeEdit.setText(flightPoint.getType()); int flightPointID = session.getCurrentFlightPointID();
fAltitudeEdit.setText(Double.toString(flightPoint.getAltitude())); int flightPathID = session.getCurrentFlightPathID();
fLatitudeEdit.setText(Double.toString(flightPoint.getLatitude()));
fLongitudeEdit.setText(Double.toString(flightPoint.getLongitude())); theDataSet.editFlight(
theDataSet.getFlightPointDictionary().get(flightPointID),
theDataSet.editFlightPoint(
flightPoint,
fNameEdit.getText(), fNameEdit.getText(),
fTypeEdit.getText(), fTypeEdit.getText(),
fAltitudeEdit.getText(), fAltitudeEdit.getText(),
fLatitudeEdit.getText(), fLatitudeEdit.getText(),
fLongitudeEdit.getText() fLongitudeEdit.getText()
); );
session.setCurrentFlightPointID(flightPointID);
fNameEdit.clear(); fNameEdit.clear();
fTypeEdit.clear(); fTypeEdit.clear();
fAltitudeEdit.clear(); fAltitudeEdit.clear();
fLatitudeEdit.clear(); fLatitudeEdit.clear();
fLongitudeEdit.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 ) { } catch ( Exception e ) {
e.printStackTrace();
Alert alert = new Alert(Alert.AlertType.ERROR); Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Flight Data Error"); alert.setTitle("Flight Data Error");
alert.setHeaderText("Error editing a flight point."); alert.setHeaderText("Error editing a flight point.");
@ -64,8 +79,22 @@ public class FlightEditorController extends Controller{
} }
} }
public void loadValues(){
}
public void load() { public void load() {
theDataSet = getParent().getCurrentDataset(); 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.DataException;
import seng202.group9.Controller.Dataset; import seng202.group9.Controller.Dataset;
import seng202.group9.Controller.SceneCode; import seng202.group9.Controller.SceneCode;
import seng202.group9.Controller.Session;
import seng202.group9.Core.FlightPath; import seng202.group9.Core.FlightPath;
import seng202.group9.Core.FlightPoint; 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. * Will take the inputs from the text fields and adds the point to the current flight path.
*/ */
public void addFlightPoint() { public void addFlightPoint() {
ArrayList<FlightPath> flightPaths;
flightPaths = theDataSet.getFlightPaths();
try { try {
theDataSet.addFlightPointToPath(currentPathId, theDataSet.addFlightPointToPath(currentPathId,
@ -168,8 +167,7 @@ public class FlightRDController extends Controller {
flightLegDistBox.clear(); flightLegDistBox.clear();
flightTotDistBox.clear(); flightTotDistBox.clear();
ArrayList<FlightPoint> flightPoints = flightPaths.get(currentPathIndex).getFlight(); updateTable(currentPathIndex);
flightTableView.setItems(FXCollections.observableArrayList(flightPoints));
} catch ( Exception e ) { } catch ( Exception e ) {
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");
@ -212,25 +210,22 @@ public class FlightRDController extends Controller {
currentPathIndex = theDataSet.getFlightPaths().indexOf(theDataSet.getFlightPathDictionary().get(pathID)); currentPathIndex = theDataSet.getFlightPaths().indexOf(theDataSet.getFlightPathDictionary().get(pathID));
ArrayList<FlightPath> flightPaths; updateTable(currentPathIndex);
flightPaths = theDataSet.getFlightPaths();
ArrayList<FlightPoint> flightPoints = flightPaths.get(currentPathIndex).getFlight();
flightTableView.setItems(FXCollections.observableArrayList(flightPoints));
} }
public void editPoint() { public void editPoint() {
FlightPoint toEdit = flightTableView.getSelectionModel().getSelectedItem(); FlightPoint toEdit = flightTableView.getSelectionModel().getSelectedItem();
int pathID;
try { try {
pathID = toEdit.getIndex(); Session session = getParent().getSession();
session.setCurrentFlightPointID(toEdit.getID());
session.setCurrentFlightPathtID(currentPathId);
} catch (DataException e) { } catch (DataException e) {
e.printStackTrace(); e.printStackTrace();
System.out.println("Point is Uneditable as the Index ID is not set."); System.out.println("Point is Uneditable as the Index ID is not set.");
return; return;
} }
ArrayList<FlightPath> flightPaths = theDataSet.getFlightPaths();
createPopUpStage(SceneCode.FLIGHT_EDITOR, 600, 289); 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(); 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. * 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" /> <Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</GridPane.margin> </GridPane.margin>
</Label> </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="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="fTypeEdit" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="2" />
<TextField fx:id="fAltitudeEdit" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="3" /> <TextField fx:id="fAltitudeEdit" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="3" />

@ -153,8 +153,8 @@
<contextMenu> <contextMenu>
<ContextMenu> <ContextMenu>
<items> <items>
<MenuItem mnemonicParsing="false" onAction="#deletePoint" text="Delete" />
<MenuItem mnemonicParsing="false" onAction="#editPoint" text="Edit" /> <MenuItem mnemonicParsing="false" onAction="#editPoint" text="Edit" />
<MenuItem mnemonicParsing="false" onAction="#deletePoint" text="Delete" />
</items> </items>
</ContextMenu> </ContextMenu>
</contextMenu> </contextMenu>

Loading…
Cancel
Save