Added Routes By Airport Menu

main
YaFedImYaEatIm 9 years ago
parent b31fa6e24b
commit 236b93ed85

@ -13,7 +13,7 @@ public enum SceneCode {
AIRPORT_ADD("airport_add_form.fxml"), AIRPORT_FILTER("airport_filter_form.fxml"), ROUTE_ADD("route_add_form.fxml"),
ROUTE_FILTER("route_filter_form.fxml"), AIRLINE_EDIT("airline_edit_form.fxml"), AIRPORT_EDIT("airport_edit_form.fxml"),
ROUTE_EDIT("route_edit_form.fxml"), FLIGHT_EDITOR("flight_editor_form.fxml"), DATASET_CONTROLLER("dataset_editor.fxml"), HELP("help.fxml"),
FLIGHT_ADD("flight_add_form.fxml");
FLIGHT_ADD("flight_add_form.fxml"), ROUTE_BY_AIRPORT("airport_map_routes.fxml");
private String filePath;

@ -0,0 +1,72 @@
package seng202.group9.GUI;
import javafx.beans.InvalidationListener;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.web.WebView;
import seng202.group9.Controller.Dataset;
import seng202.group9.Core.*;
import seng202.group9.Map.Map;
import java.util.*;
/**
* Created by fwy13 on 1/10/16.
*/
public class AirportRouteMapController extends Controller{
@FXML
WebView mapView;
@FXML
TableView airportsTable;
@FXML
TableColumn<Airport, String> airportName;
@FXML
TableColumn<Airport, Integer> routes;
ObservableList<Airport> airportsToDisplay;
Dataset currentDataset;
Map map;
@Override
public void load() {
if (!checkDataset()){
return;
}
currentDataset = getParent().getCurrentDataset();
//Sets up map.
map = new Map(mapView, new RoutePath(), airportsTable);
airportName.setCellValueFactory(new PropertyValueFactory<Airport, String>("Name"));
routes.setCellValueFactory(new PropertyValueFactory<Airport, Integer>("TotalRoutes"));
airportsToDisplay = FXCollections.observableArrayList();
for (Airport airport: currentDataset.getAirports()){
if (airport.getTotalRoutes() > 0) {
airportsToDisplay.add(airport);
}
}
airportsTable.setItems(airportsToDisplay);
airportsTable.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Airport>() {
public void changed(ObservableValue<? extends Airport> observable, Airport oldValue, Airport newValue) {
Airport selectedAirport= (Airport) airportsTable.getSelectionModel().getSelectedItems().get(0);
for (int i = 0 ; i < currentDataset.getAirports().size(); i ++){
if (currentDataset.getAirports().get(i).equals(selectedAirport)){
ArrayList<RoutePath> routePaths = new ArrayList<RoutePath>();
for (Route route:currentDataset.getAirports().get(i).getArrivalRoutes()){
routePaths.add(route.getRoutePath());
}
for (Route route:currentDataset.getAirports().get(i).getDepartureRoutes()){
routePaths.add(route.getRoutePath());
}
map.displayRoutes(routePaths);
break;
}
}
}
});
}
}

@ -67,6 +67,9 @@ public class MenuController extends Controller{
replaceSceneContent(SceneCode.ROUTE_SUMMARY);
}
public void viewRouteByAirport(){
replaceSceneContent(SceneCode.ROUTE_BY_AIRPORT);
}
/**
* Load Flight Summary Function.
*/

@ -3,11 +3,14 @@ package seng202.group9.Map;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.scene.control.TableView;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import seng202.group9.Core.Position;
import seng202.group9.Core.RoutePath;
import java.util.ArrayList;
/**
* Created by fwy13 on 17/09/16.
*/
@ -31,6 +34,21 @@ public class Map {
});
}
public Map(WebView webView, final RoutePath newRoute, TableView table){
this.webView = webView;
webEngine = webView.getEngine();
initMap();
webEngine.getLoadWorker().stateProperty().addListener(
new ChangeListener<Worker.State>() {
public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) {
if (newState == Worker.State.SUCCEEDED){
displayRoute(newRoute);
table.getSelectionModel().selectFirst();
}
}
});
}
public void initMap() {
webEngine.load(getClass().getClassLoader().getResource("map.html").toExternalForm());
}
@ -45,4 +63,17 @@ public class Map {
webEngine.executeScript(scriptToExecute);
}
public void displayRoutes(ArrayList<RoutePath> routes){
String routeJSONArray = "[";
int counter = 0;
for (RoutePath route: routes){
routeJSONArray += route.toJSONArray() + ", ";
if (counter++ > 99){
break;
}
}
routeJSONArray += "]";
webEngine.executeScript("displayRoutes("+routeJSONArray+");");
}
}

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.web.*?>
<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<GridPane alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="568.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng202.group9.GUI.AirportRouteMapController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="205.0" minWidth="10.0" prefWidth="197.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="686.0" minWidth="10.0" prefWidth="603.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="50.0" minHeight="0.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="520.0" minHeight="10.0" prefHeight="20.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="520.0" minHeight="10.0" prefHeight="500.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Routes By Airport">
<font>
<Font size="36.0" />
</font>
<GridPane.margin>
<Insets left="15.0" />
</GridPane.margin>
</Text>
<Label text="Airports" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="TOP">
<font>
<Font size="15.0" />
</font>
<GridPane.margin>
<Insets left="15.0" />
</GridPane.margin>
</Label>
<WebView fx:id="mapView" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.rowSpan="2">
<GridPane.margin>
<Insets bottom="15.0" left="15.0" right="15.0" top="20.0" />
</GridPane.margin>
</WebView>
<TableView fx:id="airportsTable" prefHeight="471.0" prefWidth="142.0" GridPane.rowIndex="2">
<columns>
<TableColumn fx:id="airportName" prefWidth="88.0" text="Airport" />
<TableColumn fx:id="routes" prefWidth="62.0" text="Routes" />
</columns>
<GridPane.margin>
<Insets bottom="15.0" left="15.0" right="15.0" />
</GridPane.margin>
</TableView>
</children>
</GridPane>

@ -90,6 +90,57 @@
repositionMap(flightPath);
}
function displayRoutes(flightPaths) {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 0, lng: 0},
zoom: 5
});
for (var i = 0; i < flightPaths.length; i++) {
var tempMarker1 = null;
var tempMarker2 = null;
var tempPath = null;
if (flightPaths[i].length < 2) {
continue;
}
// CREATE MARKERS AT START AND FINISH
tempMarker1 = new google.maps.Marker({
position: flightPaths[i][0],
map: map
});
tempMarker2 = new google.maps.Marker({
position: flightPaths[i][flightPaths[i].length - 1],
map: map
});
// DRAW POLYLINE FOR ROUTE
tempPath = new google.maps.Polyline({
path: flightPaths[i],
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
tempPath.setMap(map);
}
repositionMapToMulti(flightPaths);
}
function repositionMapToMulti(flightPaths){
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < flightPaths.length; i++) {
for (var j = 0; j < flightPaths[i].length; j++) {
bounds.extend(flightPaths[i][j]);
}
}
map.fitBounds(bounds);
}
function repositionMap(flightPath) {
var bounds = new google.maps.LatLngBounds();

@ -49,6 +49,12 @@
<MenuItem mnemonicParsing="false" onAction="#viewFlightRawData" text="Raw Data" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Maps">
<items>
<MenuItem mnemonicParsing="false" onAction="#viewRouteByAirport" text="Route By Airport" />
<MenuItem mnemonicParsing="false" text="Unspecified Action" />
</items>
</Menu>
</items></Menu>
<Menu mnemonicParsing="false" text="Analysis">
<items>

Loading…
Cancel
Save