Implemented the ablitity to manually enter flight points into the database.

main
Liam Beckett 9 years ago
parent de9cee785c
commit ff20c6435e

@ -25,7 +25,7 @@ public class Dataset {
LinkedHashMap<String, Airline> airlineDictionary;
LinkedHashMap<String, Airport> airportDictionary;
LinkedHashMap<String, Route> routeDictionary;
LinkedHashMap<String, FlightPath> flightPathDictionary;
LinkedHashMap<Integer, FlightPath> flightPathDictionary;
LinkedHashMap<String, Country> countryDictionary;
LinkedHashMap<String, City> cityDictionary;
@ -48,6 +48,7 @@ public class Dataset {
this.routeDictionary = new LinkedHashMap<String, Route>();;
this.countryDictionary = new LinkedHashMap<String, Country>();;
this.cityDictionary = new LinkedHashMap<String, City>();;
this.flightPathDictionary = new LinkedHashMap<Integer, FlightPath>();
if (action == getExisting){
updateDataset();
//after this make connections. ie filling in the country.cities airports.routes etc
@ -174,7 +175,9 @@ public class Dataset {
String flightpDepart = rs.getString("Source_Airport");
String flightpArrive = rs.getString("Destination_Airport");
//duplicates are fine so no flight dictionary is made.
flightPaths.add(new FlightPath(flightpID, flightpDepart, flightpArrive));
FlightPath flightPathToAdd = new FlightPath(flightpID, flightpDepart, flightpArrive);
flightPaths.add(flightPathToAdd);
flightPathDictionary.put(flightpID, flightPathToAdd);
}
rs.close();
stmt.close();
@ -717,6 +720,7 @@ public class Dataset {
stmt.close();
}
flightPaths.add(flightPathToAdd);
flightPathDictionary.put(flightPathToAdd.getID(), flightPathToAdd);
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
@ -1011,6 +1015,87 @@ public class Dataset {
}
}
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{
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);
}catch (NumberFormatException e){
throw new DataException("Altitude must be a double value");
}
try{
latitudeVal = Double.parseDouble(latitude);
}catch (NumberFormatException e){
throw new DataException("Latitude must be a double value");
}
try{
longitudeVal = Double.parseDouble(longitude);
}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");
}
Connection c = null;
Statement stmt;
int pointID = 0;
try {
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()){
pointID = Integer.parseInt(pointIDRes.getString("seq"));
}
stmt.close();
stmt = c.createStatement();
String insertFlightPointQuery = "INSERT INTO `" + this.name + "_Flight_Points` (`Index_ID`, `Name`, `Type`," +
" `Altitude`, `Longitude`, `Latitude`, `Heading`, `Tot_Dist`, `Leg_Dist`, `Via`) VALUES ";
String flightType = type.replace("\"", "\"\"");
String flightName = name.replace("\"", "\"\"");
insertFlightPointQuery += "(" + id +", \""+ flightName +"\", \"" + flightType + "\", "+ altitudeVal + ", " +
"" + latitudeVal + ", " + longitudeVal + ", " + headingVal + ", " + totalDistVal + ", " + legDistVal +
", \"" + via + "\")";
stmt.execute(insertFlightPointQuery);
stmt.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
FlightPoint pointToAdd = new FlightPoint(name, pointID+1, id, type, via, headingVal, altitudeVal, legDistVal,
totalDistVal,latitudeVal, longitudeVal);
flightPathDictionary.get(id).addFlightPoint(pointToAdd);
}
public ArrayList<Airline> getAirlines() {
return airlines;
}
@ -1034,4 +1119,28 @@ public class Dataset {
public ArrayList<City> getCities() {
return cities;
}
public LinkedHashMap<String, Airline> getAirlineDictionary() {
return airlineDictionary;
}
public LinkedHashMap<String, Airport> getAirportDictionary() {
return airportDictionary;
}
public LinkedHashMap<String, Route> getRouteDictionary() {
return routeDictionary;
}
public LinkedHashMap<Integer, FlightPath> getFlightPathDictionary() {
return flightPathDictionary;
}
public LinkedHashMap<String, Country> getCountryDictionary() {
return countryDictionary;
}
public LinkedHashMap<String, City> getCityDictionary() {
return cityDictionary;
}
}

@ -36,7 +36,7 @@ public class FlightPoint {
double latitude, double longitude){
this.name = name;
this.ID = ID;
this.indexID = indexID;
this.indexID = indexID; //path
this.type = type;
this.via = via;
this.heading = heading;

@ -5,9 +5,7 @@ import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ListView;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import seng202.group9.Controller.App;
@ -24,13 +22,17 @@ import java.util.ResourceBundle;
* Controller for the Flights Raw Data Scene.
* Created by Liam Beckett on 13/09/2016.
*/
public class FlightRawDataController implements Initializable {
public class FlightRDController implements Initializable {
private Dataset theDataSet = null;
private int currentPathId = 0;
private int currentPathIndex = 0;
App parent;
public void setApp(App parent){
this.parent = parent;
theDataSet = parent.getCurrentDataset();
currentPathId = theDataSet.getFlightPaths().get(0).getID(); //Sets the default to the 1st Path
}
@FXML
@ -60,6 +62,24 @@ public class FlightRawDataController implements Initializable {
ListView<String> flightPathListView;
final ObservableList<String> 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;
/**
* Loads the Flight paths into the List View and waits for a mouse clicked event for which it will update the table
@ -67,7 +87,7 @@ public class FlightRawDataController implements Initializable {
*/
public void flightPathListView() {
try {
ArrayList<FlightPath> flightPaths = new ArrayList();
ArrayList<FlightPath> flightPaths;
flightPaths = theDataSet.getFlightPaths();
for(int i = 0; i<flightPaths.size(); i++ ) {
int pathID = flightPaths.get(i).getID();
@ -82,9 +102,13 @@ public class FlightRawDataController implements Initializable {
String[] segments = flightPathDisplayNameClicked.split("_");
String pathIdClicked = segments[0];
currentPathIndex = theDataSet.getFlightPaths().indexOf(theDataSet.getFlightPathDictionary()
.get(Integer.parseInt(pathIdClicked)));
currentPathId = Integer.parseInt(pathIdClicked);
ArrayList<FlightPath> flightPaths;
flightPaths = theDataSet.getFlightPaths();
ArrayList<FlightPoint> flightPoints = flightPaths.get(Integer.parseInt(pathIdClicked)-1).getFlight();
ArrayList<FlightPoint> flightPoints = flightPaths.get(currentPathIndex).getFlight();
flightTableView.setItems(FXCollections.observableArrayList(flightPoints));
}
@ -115,11 +139,48 @@ public class FlightRawDataController implements Initializable {
ArrayList<FlightPath> flightPaths;
flightPaths = theDataSet.getFlightPaths();
int firstID = flightPaths.get(0).getID();
//int firstID = flightPaths.get(0).getID();
ArrayList<FlightPoint> flightPoints = flightPaths.get(0).getFlight();
flightTableView.setItems(FXCollections.observableArrayList(flightPoints));
}
public void addFlightPoint() {
ArrayList<FlightPath> 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<FlightPoint> flightPoints = flightPaths.get(currentPathIndex).getFlight();
flightTableView.setItems(FXCollections.observableArrayList(flightPoints));
} catch ( Exception e ) {
//e.printStackTrace();
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();
}
}
public void initialize(URL arg0, ResourceBundle arg1) {
// TODO Auto-generated method stub

@ -2,17 +2,13 @@ package seng202.group9.GUI;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.control.TableView;
import seng202.group9.Controller.App;
import seng202.group9.Controller.Dataset;
import seng202.group9.Core.FlightPath;
import seng202.group9.Core.FlightPoint;
import java.net.URL;
import java.util.ArrayList;
@ -65,7 +61,7 @@ public class FlightSummaryController implements Initializable {
*/
public void handleRawDataButton() {
try {
FlightRawDataController rawDataController = (FlightRawDataController)
FlightRDController rawDataController = (FlightRDController)
parent.replaceSceneContent("flight_raw_data.fxml");
rawDataController.setApp(parent);
rawDataController.loadTables();

@ -6,10 +6,7 @@ import java.util.ResourceBundle;
import javax.swing.JOptionPane;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import seng202.group9.Controller.App;
public class MenuController implements Initializable{
@ -117,7 +114,7 @@ public class MenuController implements Initializable{
*/
public void viewFlightRawData() {
try {
FlightRawDataController rawDataController = (FlightRawDataController)
FlightRDController rawDataController = (FlightRDController)
parent.replaceSceneContent("flight_raw_data.fxml");
rawDataController.setApp(parent);
rawDataController.loadTables();

@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
@ -15,7 +17,7 @@
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng202.group9.GUI.FlightRawDataController">
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng202.group9.GUI.FlightRDController">
<children>
<ScrollPane hbarPolicy="NEVER" prefHeight="603.0" prefWidth="751.0" vbarPolicy="NEVER">
<content>
@ -26,49 +28,108 @@
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="193.0" minHeight="10.0" prefHeight="33.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="193.0" minHeight="10.0" prefHeight="73.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="504.0" minHeight="10.0" prefHeight="434.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="62.0" minHeight="10.0" prefHeight="62.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="193.0" minHeight="10.0" prefHeight="57.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="521.0" minHeight="10.0" prefHeight="521.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="62.0" minHeight="0.0" prefHeight="19.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<GridPane GridPane.rowIndex="2">
<GridPane GridPane.rowIndex="1">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="393.0" minWidth="10.0" prefWidth="176.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="651.0" minWidth="10.0" prefWidth="624.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="393.0" minWidth="10.0" prefWidth="162.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="651.0" minWidth="10.0" prefWidth="638.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Pane prefHeight="434.0" prefWidth="304.0">
<Pane prefHeight="434.0" prefWidth="158.0">
<children>
<ListView fx:id="flightPathListView" layoutX="25.0" layoutY="27.0" prefHeight="384.0" prefWidth="125.0" />
<Label layoutX="31.0" layoutY="4.0" text="Flight Path File(s)">
<ListView fx:id="flightPathListView" layoutX="19.0" layoutY="25.0" prefHeight="450.0" prefWidth="125.0" />
<Label layoutX="16.0" text="Flight Path File(s)">
<font>
<Font size="15.0" />
</font>
</Label>
</children>
</Pane>
<GridPane prefHeight="473.0" prefWidth="650.0" GridPane.columnIndex="1">
<GridPane prefHeight="467.0" prefWidth="638.0" GridPane.columnIndex="1">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="617.0" minWidth="10.0" prefWidth="607.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="318.0" minWidth="10.0" prefWidth="43.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="414.0" minHeight="10.0" prefHeight="374.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="137.0" minHeight="1.0" prefHeight="60.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="414.0" minHeight="10.0" prefHeight="386.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="137.0" minHeight="1.0" prefHeight="17.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="137.0" minHeight="10.0" prefHeight="62.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="137.0" minHeight="10.0" prefHeight="44.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Pane GridPane.rowIndex="1">
<ScrollPane prefHeight="52.0" prefViewportHeight="25.0" prefViewportWidth="765.0" prefWidth="601.0" GridPane.rowIndex="2">
<content>
<Pane layoutY="25.0">
<children>
<TextField fx:id="flightLatitudeBox" layoutX="440.0" prefHeight="25.0" prefWidth="100.0" promptText="Latitude">
<padding>
<Insets left="2.0" right="2.0" />
</padding>
</TextField>
<TextField fx:id="flightTypeBox" layoutX="190.0" prefHeight="25.0" prefWidth="75.0" promptText="Type">
<padding>
<Insets left="2.0" right="2.0" />
</padding>
</TextField>
<TextField fx:id="flightAltitudeBox" layoutX="365.0" prefHeight="25.0" prefWidth="75.0" promptText="Altitude">
<padding>
<Insets left="2.0" right="2.0" />
</padding>
</TextField>
<Label prefHeight="25.0" prefWidth="90.0" text="Enter Values:" />
<TextField fx:id="flightViaBox" layoutX="265.0" prefHeight="25.0" prefWidth="100.0" promptText="Via">
<padding>
<Insets left="2.0" right="2.0" />
</padding>
</TextField>
<TextField fx:id="flightHeadingBox" layoutX="640.0" prefHeight="25.0" prefWidth="100.0" promptText="Heading">
<padding>
<Insets left="2.0" right="2.0" />
</padding>
</TextField>
<TextField fx:id="flightLongitudeBox" layoutX="540.0" prefHeight="25.0" prefWidth="100.0" promptText="Longitude">
<padding>
<Insets left="2.0" right="2.0" />
</padding>
</TextField>
<TextField fx:id="flightNameBox" layoutX="90.0" prefHeight="25.0" prefWidth="100.0" promptText="Name">
<padding>
<Insets left="2.0" right="2.0" />
</padding>
</TextField>
<TextField fx:id="flightLegDistBox" layoutX="740.0" prefHeight="25.0" prefWidth="75.0" promptText="Leg Dist">
<padding>
<Insets left="2.0" right="2.0" />
</padding>
</TextField>
<TextField fx:id="flightTotDistBox" layoutX="815.0" prefHeight="25.0" prefWidth="75.0" promptText="Tot Dist">
<padding>
<Insets left="2.0" right="2.0" />
</padding>
</TextField>
</children>
<opaqueInsets>
<Insets />
</opaqueInsets>
</Pane>
</content>
</ScrollPane>
<Pane prefHeight="44.0" prefWidth="601.0" GridPane.rowIndex="3">
<children>
<Button layoutX="540.0" layoutY="10.0" mnemonicParsing="false" text="Analyse" GridPane.rowIndex="1" />
<Button layoutX="476.0" layoutY="11.0" mnemonicParsing="false" onAction="#addFlightPoint" prefHeight="25.0" prefWidth="125.0" text="Add" />
<Button layoutY="11.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="125.0" text="Analyse" />
</children>
</Pane>
<TableView fx:id="flightTableView">
<TableView fx:id="flightTableView" prefHeight="377.0" prefWidth="601.0">
<columns>
<TableColumn fx:id="flightIdCol" prefWidth="75.0" text="ID" />
<TableColumn fx:id="flightIdCol" prefWidth="90.0" text="ID" />
<TableColumn fx:id="flightNameCol" prefWidth="100.0" text="Name" />
<TableColumn fx:id="flightTypeCol" prefWidth="75.0" text="Type" />
<TableColumn fx:id="flightViaCol" prefWidth="100.0" text="Via" />
@ -84,11 +145,11 @@
</GridPane>
</children>
</GridPane>
<Pane prefHeight="135.0" prefWidth="400.0" GridPane.rowIndex="1">
<Pane prefHeight="55.0" prefWidth="800.0">
<children>
<Text layoutX="24.0" layoutY="45.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Flight Raw Data">
<Text layoutX="14.0" layoutY="42.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Flight Raw Data">
<font>
<Font size="48.0" />
<Font size="29.0" />
</font>
</Text>
</children>

Loading…
Cancel
Save