Commit 07bf03cd80598b25566ae0f71c157a3232cabae9
1 parent
79b001037b
Exists in
master
and in
1 other branch
add alert message when a non csv file is selected
Showing 2 changed files with 9 additions and 2 deletions Inline Diff
src/main/kotlin/application/controller/MenuBarController.kt
View file @
07bf03c
package application.controller | 1 | 1 | package application.controller | |
2 | 2 | |||
import application.model.State.* | 3 | 3 | import application.model.State.* | |
import application.model.createVesselCollection | 4 | 4 | import application.model.createVesselCollection | |
import application.model.observableState | 5 | 5 | import application.model.observableState | |
import application.model.observableVessel | 6 | 6 | import application.model.observableVessel | |
import javafx.event.EventHandler | 7 | 7 | import javafx.event.EventHandler | |
import javafx.fxml.FXML | 8 | 8 | import javafx.fxml.FXML | |
import javafx.fxml.Initializable | 9 | 9 | import javafx.fxml.Initializable | |
10 | import javafx.scene.control.Alert | |||
import javafx.scene.control.CheckMenuItem | 10 | 11 | import javafx.scene.control.CheckMenuItem | |
import javafx.scene.control.MenuBar | 11 | 12 | import javafx.scene.control.MenuBar | |
import javafx.scene.control.MenuItem | 12 | 13 | import javafx.scene.control.MenuItem | |
import javafx.stage.FileChooser | 13 | 14 | import javafx.stage.FileChooser | |
import java.net.URL | 14 | 15 | import java.net.URL | |
import java.util.* | 15 | 16 | import java.util.* | |
16 | 17 | |||
class MenuBarController : Initializable { | 17 | 18 | class MenuBarController : Initializable { | |
18 | 19 | |||
@FXML | 19 | 20 | @FXML | |
var menuBar: MenuBar = MenuBar() | 20 | 21 | var menuBar: MenuBar = MenuBar() | |
21 | 22 | |||
@FXML | 22 | 23 | @FXML | |
var import: MenuItem = MenuItem() | 23 | 24 | var import: MenuItem = MenuItem() | |
24 | 25 | |||
@FXML | 25 | 26 | @FXML | |
var allMessages: CheckMenuItem = CheckMenuItem() | 26 | 27 | var allMessages: CheckMenuItem = CheckMenuItem() | |
27 | 28 | |||
@FXML | 28 | 29 | @FXML | |
var clusteredMessage: CheckMenuItem = CheckMenuItem() | 29 | 30 | var clusteredMessage: CheckMenuItem = CheckMenuItem() | |
30 | 31 | |||
@FXML | 31 | 32 | @FXML | |
var heatMap: CheckMenuItem = CheckMenuItem() | 32 | 33 | var heatMap: CheckMenuItem = CheckMenuItem() | |
33 | 34 | |||
override fun initialize(location: URL?, resources: ResourceBundle?) { | 34 | 35 | override fun initialize(location: URL?, resources: ResourceBundle?) { | |
35 | 36 | |||
setOnActionImportButton() | 36 | 37 | setOnActionImportButton() | |
37 | 38 | |||
setOnActionAllMessageButton() | 38 | 39 | setOnActionAllMessageButton() | |
setOnActionClusteredMessageButton() | 39 | 40 | setOnActionClusteredMessageButton() | |
setOnActionHeatMapButton() | 40 | 41 | setOnActionHeatMapButton() | |
observableState.state = CLUSTERED_MESSAGES | 41 | 42 | observableState.state = CLUSTERED_MESSAGES | |
allMessages.isSelected = false | 42 | 43 | allMessages.isSelected = false | |
clusteredMessage.isSelected = true | 43 | 44 | clusteredMessage.isSelected = true | |
heatMap.isSelected = false | 44 | 45 | heatMap.isSelected = false | |
45 | 46 | |||
} | 46 | 47 | } | |
47 | 48 | |||
private fun setOnActionImportButton() { | 48 | 49 | private fun setOnActionImportButton() { | |
import.onAction = EventHandler { | 49 | 50 | import.onAction = EventHandler { | |
val fileChooser = FileChooser() | 50 | 51 | val fileChooser = FileChooser() | |
fileChooser.title = "Choose a file to import" | 51 | 52 | fileChooser.title = "Choose a file to import" | |
val window = menuBar.scene.window | 52 | 53 | val window = menuBar.scene.window | |
val file = fileChooser.showOpenDialog(window) | 53 | 54 | val file = fileChooser.showOpenDialog(window) | |
try { | 54 | 55 | try { | |
56 | if (file.extension != "csv") { | |||
57 | val alert = Alert(Alert.AlertType.WARNING) | |||
58 | alert.title = "Warning Alert" | |||
59 | alert.headerText = "Wrong file format." | |||
60 | alert.contentText = "Please choose à .csv file." | |||
61 | alert.showAndWait() | |||
62 | } | |||
val vessels = createVesselCollection(file) | 55 | 63 | val vessels = createVesselCollection(file) | |
observableVessel.vessels.clear() | 56 | 64 | observableVessel.vessels.clear() | |
observableVessel.vessels = vessels | 57 | 65 | observableVessel.vessels = vessels | |
} catch (ignore: IllegalStateException){ | 58 | 66 | } catch (ignore: IllegalStateException) { | |
59 | 67 | |||
} | 60 | 68 | } | |
} | 61 | 69 | } | |
} | 62 | 70 | } | |
63 | 71 | |||
private fun setOnActionAllMessageButton() { | 64 | 72 | private fun setOnActionAllMessageButton() { | |
allMessages.onAction = EventHandler { | 65 | 73 | allMessages.onAction = EventHandler { | |
observableState.state = ALL_MESSAGES | 66 | 74 | observableState.state = ALL_MESSAGES | |
allMessages.isSelected = true | 67 | 75 | allMessages.isSelected = true | |
clusteredMessage.isSelected = false | 68 | 76 | clusteredMessage.isSelected = false | |
heatMap.isSelected = false | 69 | 77 | heatMap.isSelected = false | |
} | 70 | 78 | } | |
} | 71 | 79 | } | |
72 | 80 | |||
private fun setOnActionClusteredMessageButton() { | 73 | 81 | private fun setOnActionClusteredMessageButton() { | |
clusteredMessage.onAction = EventHandler { | 74 | 82 | clusteredMessage.onAction = EventHandler { | |
observableState.state = CLUSTERED_MESSAGES | 75 | 83 | observableState.state = CLUSTERED_MESSAGES |
src/main/kotlin/map/MapDisplayer.kt
View file @
07bf03c
package map | 1 | 1 | package map | |
2 | 2 | |||
import application.model.observableVessel | 3 | 3 | import application.model.observableVessel | |
4 | 4 | |||
fun clearMap(map: LeafletMapView) { | 5 | 5 | fun clearMap(map: LeafletMapView) { | |
clearMapCanvas(map) | 6 | 6 | clearMapCanvas(map) | |
clearMapCluster(map) | 7 | 7 | clearMapCluster(map) | |
clearHeatMap(map) | 8 | 8 | clearHeatMap(map) | |
} | 9 | 9 | } | |
10 | 10 | |||
fun clearMapCluster(map: LeafletMapView) { | 11 | 11 | fun clearMapCluster(map: LeafletMapView) { | |
map.execScript( | 12 | 12 | map.execScript( | |
""" | 13 | 13 | """ | |
|myMap.removeLayer(markerClusters); | 14 | 14 | |myMap.removeLayer(markerClusters); | |
|var markerClusters = L.markerClusterGroup({spiderfyOnMaxZoom: false, disableClusteringAtZoom: 10}); | 15 | 15 | |var markerClusters = L.markerClusterGroup({spiderfyOnMaxZoom: false, disableClusteringAtZoom: 10}); | |
""".trimMargin() | 16 | 16 | """.trimMargin() | |
) | 17 | 17 | ) | |
} | 18 | 18 | } | |
19 | 19 | |||
fun clearMapCanvas(map: LeafletMapView) { | 20 | 20 | fun clearMapCanvas(map: LeafletMapView) { | |
map.execScript( | 21 | 21 | map.execScript( | |
""" | 22 | 22 | """ | |
|myRenderer.removeFrom(myMap); | 23 | 23 | |myRenderer.removeFrom(myMap); | |
|var myRenderer = L.canvas({ padding: 0.5 }); | 24 | 24 | |var myRenderer = L.canvas({ padding: 0.5 }); | |
""".trimMargin() | 25 | 25 | """.trimMargin() | |
) | 26 | 26 | ) | |
} | 27 | 27 | } | |
28 | 28 | |||
fun clearHeatMap(map: LeafletMapView) { | 29 | 29 | fun clearHeatMap(map: LeafletMapView) { | |
map.execScript( | 30 | 30 | map.execScript( | |
""" | 31 | 31 | """ | |
|heatLayer.removeFrom(myMap); | 32 | 32 | |heatLayer.removeFrom(myMap); | |
|var heatLayer = L.heatLayer([]).addTo(myMap); | 33 | 33 | |var heatLayer = L.heatLayer([]).addTo(myMap); | |
""".trimMargin() | 34 | 34 | """.trimMargin() | |
) | 35 | 35 | ) | |
} | 36 | 36 | } | |
37 | 37 | |||
fun displayAllMessageOnMap(map: LeafletMapView) { | 38 | 38 | fun displayAllMessageOnMap(map: LeafletMapView) { | |
clearMap(map) | 39 | 39 | clearMap(map) | |
observableVessel.vessels.forEach { (_, value) -> | 40 | 40 | observableVessel.vessels.forEach { (_, value) -> | |
value.messages.forEach { (_, message) -> | 41 | 41 | value.messages.forEach { (_, message) -> | |
map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColorStroke()}'}).addTo(myMap)") | 42 | 42 | map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColorStroke()}'}).addTo(myMap)") | |
} | 43 | 43 | } | |
} | 44 | 44 | } | |
} | 45 | 45 | } | |
46 | 46 | |||
fun displayAllMessageOnMap(map: LeafletMapView, selectedMMSI: Int) { | 47 | 47 | fun displayAllMessageOnMap(map: LeafletMapView, selectedMMSI: Int) { | |
clearMap(map) | 48 | 48 | clearMap(map) | |
observableVessel.vessels.forEach { (_, value) -> | 49 | 49 | observableVessel.vessels.forEach { (_, value) -> | |
value.messages.forEach { (_, message) -> | 50 | 50 | value.messages.forEach { (_, message) -> | |
if (selectedMMSI == message.mmsi) { | 51 | 51 | if (selectedMMSI == message.mmsi) { | |
map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 2, color: '#ff4040'}).addTo(myMap)") | 52 | 52 | map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 2, color: '#ff4040'}).addTo(myMap)") | |
} else { | 53 | 53 | } else { | |
map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColorStroke()}'}).addTo(myMap)") | 54 | 54 | map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColorStroke()}'}).addTo(myMap)") | |
} | 55 | 55 | } | |
} | 56 | 56 | } | |
} | 57 | 57 | } | |
} | 58 | 58 | } | |
59 | 59 | |||
fun displayClusterMessageOnMap(map: LeafletMapView) { | 60 | 60 | fun displayClusterMessageOnMap(map: LeafletMapView) { | |
clearMap(map) | 61 | 61 | clearMap(map) | |
observableVessel.vessels.forEach { (_, value) -> | 62 | 62 | observableVessel.vessels.forEach { (_, value) -> | |
value.messages.forEach { (_, message) -> | 63 | 63 | value.messages.forEach { (_, message) -> | |
map.execScript("markerClusters.addLayer(L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColorStroke()}'}));") | 64 | 64 | map.execScript("markerClusters.addLayer(L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColorStroke()}'}));") | |
} | 65 | 65 | } | |
} | 66 | 66 | } | |
map.execScript("myMap.addLayer(markerClusters);") | 67 | 67 | map.execScript("myMap.addLayer(markerClusters);") | |
} | 68 | 68 | } | |
69 | 69 | |||
fun displayClusterMessageOnMap(map: LeafletMapView, selectedMMSI: Int) { | 70 | 70 | fun displayClusterMessageOnMap(map: LeafletMapView, selectedMMSI: Int) { | |
clearMap(map) | 71 | 71 | clearMap(map) | |
observableVessel.vessels.forEach { (_, value) -> | 72 | 72 | observableVessel.vessels.forEach { (_, value) -> | |
value.messages.forEach { (_, message) -> | 73 | 73 | value.messages.forEach { (_, message) -> | |
if (selectedMMSI == message.mmsi) { | 74 | 74 | if (selectedMMSI == message.mmsi) { | |
map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 2, color: '#ff4040'}).addTo(myMap);") | 75 | 75 | map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 2, color: '#ff4040'}).addTo(myMap);") | |
} else { | 76 | 76 | } else { | |
map.execScript("markerClusters.addLayer(L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColorStroke()}'}));") | 77 | 77 | map.execScript("markerClusters.addLayer(L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColorStroke()}'}));") | |
} | 78 | 78 | } | |
} | 79 | 79 | } | |
} | 80 | 80 | } | |
map.execScript("myMap.addLayer(markerClusters);") | 81 | 81 | map.execScript("myMap.addLayer(markerClusters);") | |
} | 82 | 82 | } | |
83 | 83 | |||
fun displayHeatMapOnMap(map: LeafletMapView) { | 84 | 84 | fun displayHeatMapOnMap(map: LeafletMapView) { | |
clearMap(map) | 85 | 85 | clearMap(map) | |
observableVessel.vessels.forEach { (_, value) -> | 86 | 86 | observableVessel.vessels.forEach { (_, value) -> | |
value.messages.forEach { (_, message) -> | 87 | 87 | value.messages.forEach { (_, message) -> | |
map.execScript("heatLayer.addLatLng([${message.latitude}, ${message.longitude}]);") | 88 | 88 | map.execScript("heatLayer.addLatLng([${message.latitude}, ${message.longitude}]);") | |
} | 89 | 89 | } | |
} | 90 | 90 | } | |
91 | ||||
} | 92 | 91 | } | |
93 | 92 | |||
fun displayHeatMapOnMap(map: LeafletMapView, selectedMMSI: Int) { | 94 | 93 | fun displayHeatMapOnMap(map: LeafletMapView, selectedMMSI: Int) { |