From 03bac3b6dd38a1402fbc95ba36eb6475476b1550 Mon Sep 17 00:00:00 2001 From: YaFedImYaEatIm Date: Sat, 17 Sep 2016 15:08:53 +1200 Subject: [PATCH 1/3] Made it so that the session file is ignored --- .gitignore | 3 ++- res/session.ser | Bin 211 -> 0 bytes 2 files changed, 2 insertions(+), 1 deletion(-) delete mode 100644 res/session.ser diff --git a/.gitignore b/.gitignore index 2902811..2dd483e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ SENG202.iml .classpath .project .settings/ -doc/ \ No newline at end of file +doc/ +res/session.ser diff --git a/res/session.ser b/res/session.ser deleted file mode 100644 index 98ddf26d989515a3be7c9079dd872e162cfc2e7a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 211 zcmZ4UmVvdnh(WP9H80)Bz(_B>D8ID8QqMU*ucRnHCnvQ?FF3WhI5R&_ioH%+!RRO> z69c0U17C4+YF?^KW^qAIVr6Pd34^K+)Bt^m0s067^n*cao%2&ttt$%ZiWrpfSOrtb x00lw}3>8HTd|8QQiF!GSdFgttd8N6?k_9CU0*;N From cbfe40a8fddf8af81c946c967731307d42f6c2f9 Mon Sep 17 00:00:00 2001 From: YaFedImYaEatIm Date: Sat, 17 Sep 2016 15:09:21 +1200 Subject: [PATCH 2/3] Edited Session Message as Importer Error messages --- .../java/seng202/group9/Controller/App.java | 2 +- .../java/seng202/group9/GUI/Importer.java | 49 ++++++++++--------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/main/java/seng202/group9/Controller/App.java b/src/main/java/seng202/group9/Controller/App.java index 1a8ffd3..f07a6c2 100644 --- a/src/main/java/seng202/group9/Controller/App.java +++ b/src/main/java/seng202/group9/Controller/App.java @@ -130,7 +130,7 @@ public class App extends Application fileIn.close(); }catch(IOException e){ session = new Session(); - e.printStackTrace(); + System.out.println("New Session File Created"); }catch(ClassNotFoundException e){ System.out.println("Missing Session Class"); System.exit(1); diff --git a/src/main/java/seng202/group9/GUI/Importer.java b/src/main/java/seng202/group9/GUI/Importer.java index a16a9f4..3be619a 100644 --- a/src/main/java/seng202/group9/GUI/Importer.java +++ b/src/main/java/seng202/group9/GUI/Importer.java @@ -26,32 +26,33 @@ public class Importer{ "Text & .csv", "*.txt", "*.csv"); chooser.getExtensionFilters().add(filter); File file = chooser.showOpenDialog(primaryStage); - if (scene == SceneCode.AIRLINE_RAW_DATA){ - try { - showSuccessAlert(parent.getCurrentDataset().importAirline(file.getPath())); - } catch (DataException e) { - e.printStackTrace(); - } - }else if (scene == SceneCode.AIRPORT_RAW_DATA){ - try { - showSuccessAlert(parent.getCurrentDataset().importAirport(file.getPath())); - } catch (DataException e) { - e.printStackTrace(); - } - }else if (scene == SceneCode.ROUTE_RAW_DATA){ - try { - showSuccessAlert(parent.getCurrentDataset().importRoute(file.getPath())); - } catch (DataException e) { - e.printStackTrace(); - } - }else if (scene == SceneCode.FLIGHT_RAW_DATA){ - try { - showSuccessAlert(parent.getCurrentDataset().importFlight(file.getPath())); - } catch (DataException e) { - e.printStackTrace(); + if (file != null) { + if (scene == SceneCode.AIRLINE_RAW_DATA) { + try { + showSuccessAlert(parent.getCurrentDataset().importAirline(file.getPath())); + } catch (DataException e) { + e.printStackTrace(); + } + } else if (scene == SceneCode.AIRPORT_RAW_DATA) { + try { + showSuccessAlert(parent.getCurrentDataset().importAirport(file.getPath())); + } catch (DataException e) { + e.printStackTrace(); + } + } else if (scene == SceneCode.ROUTE_RAW_DATA) { + try { + showSuccessAlert(parent.getCurrentDataset().importRoute(file.getPath())); + } catch (DataException e) { + e.printStackTrace(); + } + } else if (scene == SceneCode.FLIGHT_RAW_DATA) { + try { + showSuccessAlert(parent.getCurrentDataset().importFlight(file.getPath())); + } catch (DataException e) { + e.printStackTrace(); + } } } - } public void showSuccessAlert(String message){ From 23bebdf8e31d6d8f540f2df32dfa644b72468618 Mon Sep 17 00:00:00 2001 From: Liam Beckett Date: Sat, 17 Sep 2016 15:36:00 +1200 Subject: [PATCH 3/3] Implements the button 'new' on the Flight raw data page which can be used to create a new blank path. Currently does not reload the list view of paths to include the new path. --- .../seng202/group9/Controller/Dataset.java | 49 +++++++++++- .../group9/GUI/FlightRDController.java | 27 ++++++- .../java/seng202/group9/GUI/NewPathPopUp.java | 77 +++++++++++++++++++ src/main/resources/flight_data_summary.fxml | 8 +- src/main/resources/flight_raw_data.fxml | 10 ++- 5 files changed, 159 insertions(+), 12 deletions(-) create mode 100644 src/main/java/seng202/group9/GUI/NewPathPopUp.java diff --git a/src/main/java/seng202/group9/Controller/Dataset.java b/src/main/java/seng202/group9/Controller/Dataset.java index 578b92b..064fa3c 100644 --- a/src/main/java/seng202/group9/Controller/Dataset.java +++ b/src/main/java/seng202/group9/Controller/Dataset.java @@ -731,9 +731,6 @@ public class Dataset { return message; } - - - /** * This function updates the connections between airports citys countries etc. */ @@ -1020,7 +1017,53 @@ public class Dataset { } } + /** + * Adds a path to the database and to the path dictionary + * @param sourceAirport + * @param destAirport + */ + public void addFlightPath(String sourceAirport, String destAirport){ + FlightPath newPath = new FlightPath(sourceAirport, destAirport); + Connection c; + Statement stmt; + int pathID = 0; + try { + c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + stmt = c.createStatement(); + String flightPathIDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = \""+this.name+"_Flight_Path\" LIMIT 1;"; + ResultSet pathIDRes= stmt.executeQuery(flightPathIDQuery); + while (pathIDRes.next()){ + pathID = Integer.parseInt(pathIDRes.getString("seq")); + } + pathID +=1; + stmt.close(); + + stmt = c.createStatement(); + String insertPathQuery = "INSERT INTO `" + this.name + "_Flight_Path` (`Path_ID`, `Source_Airport`, " + + "`Destination_Airport`) VALUES ("+pathID+", \""+sourceAirport+"\", \""+destAirport+"\" )"; + stmt.execute(insertPathQuery); + } catch (Exception e){ + System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + System.exit(0); + } + newPath.setID(pathID); + flightPathDictionary.put(pathID, newPath); + } + + /** + * Adds a flight point to a given path woth the given id + * @param id + * @param name + * @param type + * @param via + * @param altitude + * @param latitude + * @param longitude + * @param heading + * @param legDist + * @param totDist + */ 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; diff --git a/src/main/java/seng202/group9/GUI/FlightRDController.java b/src/main/java/seng202/group9/GUI/FlightRDController.java index 30ea8b4..26e5ffa 100644 --- a/src/main/java/seng202/group9/GUI/FlightRDController.java +++ b/src/main/java/seng202/group9/GUI/FlightRDController.java @@ -13,6 +13,7 @@ import seng202.group9.Controller.Dataset; import seng202.group9.Core.FlightPath; import seng202.group9.Core.FlightPoint; +import javax.swing.*; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; @@ -115,7 +116,7 @@ public class FlightRDController extends Controller { } /** - * Function used to load the table for the Flight points initially from the MenuController + * Used to load the table for the Flight points initially from the MenuController */ public void load() { theDataSet = getParent().getCurrentDataset(); @@ -133,11 +134,13 @@ public class FlightRDController extends Controller { ArrayList flightPaths; flightPaths = theDataSet.getFlightPaths(); - //int firstID = flightPaths.get(0).getID(); ArrayList flightPoints = flightPaths.get(0).getFlight(); flightTableView.setItems(FXCollections.observableArrayList(flightPoints)); } + /** + * Will take the inputs from the text fields and adds the point to the current flight path. + */ public void addFlightPoint() { ArrayList flightPaths; flightPaths = theDataSet.getFlightPaths(); @@ -171,10 +174,28 @@ public class FlightRDController extends Controller { alert.setTitle("Flight Point Data Error"); alert.setHeaderText("Error adding a custom flight point entry."); alert.setContentText(e.getMessage()); - alert.showAndWait(); + + } + } + + /** + * Creates a pop up dialog which prompts the user for two ICAO airport codes which will use when creating a new path + */ + public void newPath() { + NewPathPopUp dialogBox = new NewPathPopUp(); + dialogBox.display(); + String destAirport = dialogBox.getDestinationAirport(); + String sourceAirport = dialogBox.getSourceAirport(); + + if (destAirport != null && sourceAirport != null){ + theDataSet.addFlightPath(sourceAirport, destAirport); } } + public void flightAnalyser(){ + JOptionPane.showMessageDialog(null, "This is not Implemented yet"); + } + @Override public void loadOnce(){ flightPathListView(); diff --git a/src/main/java/seng202/group9/GUI/NewPathPopUp.java b/src/main/java/seng202/group9/GUI/NewPathPopUp.java new file mode 100644 index 0000000..ea2d1c2 --- /dev/null +++ b/src/main/java/seng202/group9/GUI/NewPathPopUp.java @@ -0,0 +1,77 @@ +package seng202.group9.GUI; + +import javax.swing.*; +import java.awt.*; + +import static java.awt.Color.red; + +/** + * Creates the pop up box where the user will enter the Source and Destination airports for the path name, will reject + * empty strings, strings of length 4 and characters that are not A-Z. Will convert lowercase to uppercase. + * Created by Liam Beckett on 17/09/2016. + */ +public class NewPathPopUp { + + private String sourceAirport = null; + private String destinationAirport = null; + + // Creates and displays the pop up box for the user to input data. + public void display() { + JTextField field1 = new JTextField(); + JTextField field2 = new JTextField(); + JPanel panel = new JPanel(new GridLayout(0, 1)); + panel.add(new JLabel("Source Airport ICAO Code" )); + panel.add(field1); + panel.add(new JLabel("Destination Airport ICAO Code: ")); + panel.add(field2); + int result = JOptionPane.showConfirmDialog(null, panel, "Test", + JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); + if (result == JOptionPane.OK_OPTION) { + sourceAirport = field1.getText().toUpperCase(); + destinationAirport = field2.getText().toUpperCase(); + if (validate(sourceAirport) != true && validate(destinationAirport) != true){ + sourceAirport = null; + destinationAirport = null; + JOptionPane.showMessageDialog(null, "Enter a vaild ICAO Code!"); + return; + } + } else { + sourceAirport = null; + destinationAirport = null; + } + } + + // 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() { + return sourceAirport; + } + + public String getDestinationAirport() { + return destinationAirport; + } +} + + diff --git a/src/main/resources/flight_data_summary.fxml b/src/main/resources/flight_data_summary.fxml index b8c936c..9b71da3 100644 --- a/src/main/resources/flight_data_summary.fxml +++ b/src/main/resources/flight_data_summary.fxml @@ -84,22 +84,22 @@ - - - -