diff --git a/src/main/kotlin/application/controller/MapPanelController.kt b/src/main/kotlin/application/controller/MapPanelController.kt index 8c7713c..d4478a7 100644 --- a/src/main/kotlin/application/controller/MapPanelController.kt +++ b/src/main/kotlin/application/controller/MapPanelController.kt @@ -16,12 +16,12 @@ class MapPanelController : Initializable { private val mapView = LeafletMapView() - override fun initialize(location: URL?, resources: ResourceBundle?) { mapView.displayMap(MapConfig()) setObservableVesselListener() setObservableSelectedVesselListener() setStateListener() + setObservableIsReplayState() observableCurrentTime() map.children.add(mapView) @@ -31,8 +31,8 @@ class MapPanelController : Initializable { private fun setStateListener() { observableMapState.listeners.add(object : StateListener { override fun onValueChanged(newValue: MapState) { - if (observableSelectedVessel.vessel.mmsi != null) { - updateMap(observableSelectedVessel.vessel.mmsi!!) + if (observableSelectedVessel.value.mmsi != null) { + updateMap(observableSelectedVessel.value.mmsi!!) } else { updateMap() } @@ -43,8 +43,8 @@ class MapPanelController : Initializable { private fun observableCurrentTime() { observableCurrentTime.listeners.add(object : CurrentTime { override fun onValueChanged(newValue: Int) { - if (observableSelectedVessel.vessel.mmsi != null) { - updateMap(observableSelectedVessel.vessel.mmsi!!) + if (observableSelectedVessel.value.mmsi != null) { + updateMap(observableSelectedVessel.value.mmsi!!) } else { updateMap() } @@ -92,6 +92,18 @@ class MapPanelController : Initializable { }) } + private fun setObservableIsReplayState() { + observableIsReplayState.listeners.add(object: ReplayState { + override fun onValueChanged(newValue: Boolean) { + if (observableSelectedVessel.value.mmsi != null) { + updateMap(observableSelectedVessel.value.mmsi!!) + } else { + updateMap() + } + } + }) + } + private fun setObservableSelectedVesselListener() { observableSelectedVessel.listeners.add(object : SelectedVesselListener { override fun onValueChanged(newValue: Vessel) { diff --git a/src/main/kotlin/application/controller/MenuBarController.kt b/src/main/kotlin/application/controller/MenuBarController.kt index 2303835..d3846b5 100644 --- a/src/main/kotlin/application/controller/MenuBarController.kt +++ b/src/main/kotlin/application/controller/MenuBarController.kt @@ -2,15 +2,13 @@ package application.controller import application.model.MapState.* import application.model.createVesselCollection +import application.model.observableIsReplayState import application.model.observableMapState import application.model.observableVessel import javafx.event.EventHandler import javafx.fxml.FXML import javafx.fxml.Initializable -import javafx.scene.control.Alert -import javafx.scene.control.CheckMenuItem -import javafx.scene.control.MenuBar -import javafx.scene.control.MenuItem +import javafx.scene.control.* import javafx.stage.FileChooser import java.net.URL import java.util.* @@ -32,6 +30,9 @@ class MenuBarController : Initializable { @FXML var heatMap: CheckMenuItem = CheckMenuItem() + @FXML + var activateReplayButton: RadioMenuItem = RadioMenuItem() + override fun initialize(location: URL?, resources: ResourceBundle?) { setOnActionImportButton() @@ -39,6 +40,7 @@ class MenuBarController : Initializable { setOnActionAllMessageButton() setOnActionClusteredMessageButton() setOnActionHeatMapButton() + setOnActionActivateReplayButton() observableMapState.state = CLUSTERED_MESSAGES allMessages.isSelected = false clusteredMessage.isSelected = true @@ -46,6 +48,12 @@ class MenuBarController : Initializable { } + private fun setOnActionActivateReplayButton() { + activateReplayButton.onAction = EventHandler { + observableIsReplayState.value = activateReplayButton.isSelected + } + } + private fun setOnActionImportButton() { import.onAction = EventHandler { val fileChooser = FileChooser() diff --git a/src/main/kotlin/application/controller/TimePanel.kt b/src/main/kotlin/application/controller/TimePanel.kt index d18583a..c197338 100644 --- a/src/main/kotlin/application/controller/TimePanel.kt +++ b/src/main/kotlin/application/controller/TimePanel.kt @@ -24,14 +24,14 @@ class TimePanel : Initializable { override fun initialize(location: URL?, resources: ResourceBundle?) { setSliderMinMax() setSliderListener() - - + disableAllButton() + setDisable() } private fun setSliderMinMax() { timeSlider.min = 0.0 timeSlider.max = 0.0 - observableVessel.listeners.add(object : MessageListener{ + observableVessel.listeners.add(object : MessageListener { override fun onValueChanged(newValue: MutableMap) { timeSlider.max = Vessel.maxTime.toDouble() timeSlider.min = Vessel.minTime.toDouble() @@ -45,4 +45,28 @@ class TimePanel : Initializable { } } + private fun disableAllButton() { + timeStop.isDisable = true + timeSlider.isDisable = true + timePlay.isDisable = true + } + + private fun unableAllButton() { + timeStop.isDisable = false + timeSlider.isDisable = false + timePlay.isDisable = false + } + + private fun setDisable() { + observableIsReplayState.listeners.add(object : ReplayState { + override fun onValueChanged(newValue: Boolean) { + if (observableIsReplayState.value) { + unableAllButton() + } else { + disableAllButton() + } + } + }) + } + } \ No newline at end of file diff --git a/src/main/kotlin/application/controller/VesselListPanelController.kt b/src/main/kotlin/application/controller/VesselListPanelController.kt index 01a316d..bbab756 100644 --- a/src/main/kotlin/application/controller/VesselListPanelController.kt +++ b/src/main/kotlin/application/controller/VesselListPanelController.kt @@ -30,9 +30,9 @@ class VesselListPanelController : Initializable, MessageListener { observableVessel.listeners.add(this) shipListView.selectionModel.selectedItemProperty().addListener { _, _, newValue -> if (newValue == null) { - observableSelectedVessel.vessel = Vessel(null) + observableSelectedVessel.value = Vessel(null) } else { - observableSelectedVessel.vessel = observableVessel.vessels[newValue]!! + observableSelectedVessel.value = observableVessel.vessels[newValue]!! } } setCellFactory() diff --git a/src/main/kotlin/application/model/ObservableReplayState.kt b/src/main/kotlin/application/model/ObservableReplayState.kt index fe1c97c..1ff8bc6 100644 --- a/src/main/kotlin/application/model/ObservableReplayState.kt +++ b/src/main/kotlin/application/model/ObservableReplayState.kt @@ -7,7 +7,7 @@ class ObservableReplayState { val listeners: MutableList = mutableListOf() var value: Boolean by Delegates.observable( - initialValue = true, + initialValue = false, onChange = { _, _, new -> run { listeners.forEach { diff --git a/src/main/kotlin/application/model/ObservableSelectedVessel.kt b/src/main/kotlin/application/model/ObservableSelectedVessel.kt index 6d8fb37..2242b25 100644 --- a/src/main/kotlin/application/model/ObservableSelectedVessel.kt +++ b/src/main/kotlin/application/model/ObservableSelectedVessel.kt @@ -5,7 +5,7 @@ import kotlin.properties.Delegates class ObservableSelectedVessel { val listeners: MutableList = mutableListOf() - var vessel: Vessel by Delegates.observable( + var value: Vessel by Delegates.observable( initialValue = Vessel(null), onChange = { _, _, new -> run { diff --git a/src/main/kotlin/application/model/ObservableVessel.kt b/src/main/kotlin/application/model/ObservableVessel.kt index 40c173d..a30ce58 100644 --- a/src/main/kotlin/application/model/ObservableVessel.kt +++ b/src/main/kotlin/application/model/ObservableVessel.kt @@ -9,7 +9,7 @@ class ObservableVessel { initialValue = mutableMapOf(), onChange = { _, _, new -> run { - observableSelectedVessel.vessel = Vessel(null) + observableSelectedVessel.value = Vessel(null) listeners.forEach { it.onValueChanged(new) } diff --git a/src/main/kotlin/map/MapDisplayer.kt b/src/main/kotlin/map/MapDisplayer.kt index f5987f1..22c17eb 100644 --- a/src/main/kotlin/map/MapDisplayer.kt +++ b/src/main/kotlin/map/MapDisplayer.kt @@ -69,9 +69,9 @@ fun displayAllMessageOnMap(map: LeafletMapView, selectedMMSI: String) { observableVessel.vessels.forEach { (_, value) -> value.messages.forEach { (_, message) -> if (selectedMMSI == message.mmsi.value) { - map.execScript("L.circleMarker([${message.latitude.value}, ${message.longitude.value}], {renderer: myRenderer, radius: 2, color: '#ff4040'}).addTo(myMap)") + map.execScript("markers.push(L.circleMarker([${message.latitude.value}, ${message.longitude.value}], {radius: 2, color: '#ff4040'}).addTo(myMap))") } else { - map.execScript("L.circleMarker([${message.latitude.value}, ${message.longitude.value}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColorStroke()}'}).addTo(myMap)") + map.execScript("markers.push(L.circleMarker([${message.latitude.value}, ${message.longitude.value}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColorStroke()}'}).addTo(myMap))") } } } @@ -113,7 +113,7 @@ fun displayClusterMessageOnMap(map: LeafletMapView, selectedMMSI: String) { observableVessel.vessels.forEach { (_, value) -> value.messages.forEach { (_, message) -> if (selectedMMSI == message.mmsi.value) { - map.execScript("L.circleMarker([${message.latitude.value}, ${message.longitude.value}], {renderer: myRenderer, radius: 2, color: '#ff4040'}).addTo(myMap);") + map.execScript("markers.push(L.circleMarker([${message.latitude.value}, ${message.longitude.value}], {radius: 2, color: '#ff4040'}).addTo(myMap));") } else { map.execScript("markerClusters.addLayer(L.circleMarker([${message.latitude.value}, ${message.longitude.value}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColorStroke()}'}));") } @@ -157,7 +157,7 @@ fun displayHeatMapOnMap(map: LeafletMapView, selectedMMSI: String) { observableVessel.vessels.forEach { (_, value) -> value.messages.forEach { (_, message) -> if (selectedMMSI == message.mmsi.value) { - map.execScript("L.circleMarker([${message.latitude.value}, ${message.longitude.value}], {renderer: myRenderer, radius: 2, color: '#ff4040'}).addTo(myMap);") + map.execScript("markers.push(L.circleMarker([${message.latitude.value}, ${message.longitude.value}], {radius: 2, color: '#ff4040'}).addTo(myMap));") } else { map.execScript("heatLayer.addLatLng([${message.latitude.value}, ${message.longitude.value}]);") } diff --git a/src/main/resources/gui/menuBar.fxml b/src/main/resources/gui/menuBar.fxml index c4543fc..7c8e4fd 100644 --- a/src/main/resources/gui/menuBar.fxml +++ b/src/main/resources/gui/menuBar.fxml @@ -2,7 +2,7 @@ - + @@ -13,11 +13,12 @@ - - - + + + +