From 2404c18d51cf549bb31a7b99d8146791d40a2292 Mon Sep 17 00:00:00 2001 From: Sunguin Peng Date: Sun, 2 Oct 2016 16:11:52 +1300 Subject: [PATCH] Changed JSwing component in new flight path. --- res/userdb.db | Bin 8387584 -> 8387584 bytes .../seng202/group9/Controller/SceneCode.java | 3 +- .../group9/GUI/FlightRDController.java | 32 +------- .../seng202/group9/GUI/NewPathController.java | 58 ++++++++++++++ .../java/seng202/group9/GUI/NewPathPopUp.java | 75 ------------------ src/main/resources/new_flight_path.fxml | 50 ++++++++++++ 6 files changed, 113 insertions(+), 105 deletions(-) create mode 100644 src/main/java/seng202/group9/GUI/NewPathController.java delete mode 100644 src/main/java/seng202/group9/GUI/NewPathPopUp.java create mode 100644 src/main/resources/new_flight_path.fxml diff --git a/res/userdb.db b/res/userdb.db index 475b3444f6f3a237d98f3897694db685fa4d7949..ec4da796782f0ae0a32ba4a05c1cc90f14c6e99d 100644 GIT binary patch delta 749 zcmW;KJ5v*37{&4T-3_u4BW#upMnHo%yv87ch__%Aji`WPOyVU3NC=9G?s~r@js+GL zT5Y8>egr4QS~!E9pTJJL%xGmp3OoHT&&;nmGta3`0L)cE`6FDG{W^z zgW4nQf@ODGx#9V_*^-?b%iAUWRn=Im8WIXr_|Sk=XoLnoR-*}P5WreAqXjyG@VZ*v zs$rS~0o^A|)0!z3Evry)zmJ%0K1J8vKcnV*pZx8k!6zw4(!^*no|QpbML@8C$Rw+t3ZKZwGc_7j|P0qS%WVdaw_@*pEK+;{XP5 z5Q8{`!#IMYIEFZea2yGoz)1|_6iy?FGZ?{HoWpsHVhrQBfQy*GC8Tf}X=ISa6WMaroX3Or!{~c}T2LJ#7 delta 742 zcmWm6%~KL_9LMqf?V_$0C~b?8SZELQNSaw@4=$k;SqVZQ^njoymi7epU=PrEu!Dy> z?WtzCbn4P@*bW`K^%r!jE-};1>DZyk-h5|XxA*5;{@v1{qUVDO~@?mmNbFaA? zlwMJsDHMH$OlW>?Hebv{vcgbo+l zu?22yMF%|S#5Qb)7hUK^eY+F8up2(?!CvgcejLC-_;Cn5=*405;RyP16vr@t;~2yV zoWv=d#t;kya0WpPV+0|b#W{p=9;3K`i@1a_L=eR|Vu<515=deKDWq`)S8)y3k-;Rg z$YBc8n86LqB9A%T#4XHY0k?4ncX1E*Q9u!kcz}m^gvVII6FkK;Jh!}w(l5~^DW8?H zVu flightPathListView; private ObservableList 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 * to display the selected Flight paths points. Called from the MenuController. @@ -166,16 +147,9 @@ public class FlightRDController extends Controller { * 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); - flightPathListView.getItems().clear(); - flightPathListView(); - } + createPopUpStage(SceneCode.FLIGHT_PATH_ADD, 500, 240); + flightPathListView.getItems().clear(); + flightPathListView(); } /** * Removes the selected point from the table and database. diff --git a/src/main/java/seng202/group9/GUI/NewPathController.java b/src/main/java/seng202/group9/GUI/NewPathController.java new file mode 100644 index 0000000..0395f6a --- /dev/null +++ b/src/main/java/seng202/group9/GUI/NewPathController.java @@ -0,0 +1,58 @@ +package seng202.group9.GUI; + +import javafx.fxml.FXML; +import javafx.scene.control.Alert; +import javafx.scene.control.Button; +import javafx.scene.control.TextField; +import javafx.stage.Stage; +import seng202.group9.Controller.Dataset; +import seng202.group9.Controller.EntryParser; + +/** + * The controller class for new_flight_path.fxml. + * Created by Sunguin. + */ +public class NewPathController extends Controller { + @FXML + private TextField sourceAirport; + @FXML + private TextField destinationAirport; + @FXML + private Button addButton; + + private Dataset theDataSet = null; + + public void load() { + theDataSet = getParent().getCurrentDataset(); + } + + /** + * Attempts to add a new flight path. First uses the entry parser to check for valid ICAO codes. + */ + public void addPath() { + EntryParser airportCheck = new EntryParser(); + try { + airportCheck.parsePointName(sourceAirport.getText()); + airportCheck.parsePointName(destinationAirport.getText()); + theDataSet.addFlightPath(sourceAirport.getText(), destinationAirport.getText()); + + //Saying to the user that the flight path has successfully added. + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("Flight Path Add Successful"); + alert.setHeaderText("New Flight Path added!"); + alert.setContentText("Your new flight path has been successfully added into the database."); + alert.showAndWait(); + + //Closes the add form. + Stage stage = (Stage) addButton.getScene().getWindow(); + stage.close(); + } catch (Exception e) { + //Tells the user what and where the error is. + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Flight Path Data Error"); + alert.setHeaderText("Error adding a custom flight path entry."); + alert.setContentText(e.getMessage()); + alert.showAndWait(); + } + } +} diff --git a/src/main/java/seng202/group9/GUI/NewPathPopUp.java b/src/main/java/seng202/group9/GUI/NewPathPopUp.java deleted file mode 100644 index a219a9d..0000000 --- a/src/main/java/seng202/group9/GUI/NewPathPopUp.java +++ /dev/null @@ -1,75 +0,0 @@ -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 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(); - try{ - EntryParser parser = new EntryParser(); - parser.parsePointName(sourceAirport); - }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 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 { - sourceAirport = null; - destinationAirport = null; - } - } - - public String getSourceAirport() { - return sourceAirport; - } - - public String getDestinationAirport() { - return destinationAirport; - } -} - - diff --git a/src/main/resources/new_flight_path.fxml b/src/main/resources/new_flight_path.fxml new file mode 100644 index 0000000..a9c0f08 --- /dev/null +++ b/src/main/resources/new_flight_path.fxml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +