Commit 2bbe36a1be826b47c824114b471c6a1e5de02983
1 parent
52321443a8
Exists in
master
and in
1 other branch
addd the possibility to select a ship
Showing 13 changed files with 112 additions and 68 deletions Side-by-side Diff
- src/main/kotlin/application/controller/ControlPanelController.kt
- src/main/kotlin/application/controller/MapPanelController.kt
- src/main/kotlin/application/controller/MenuBarController.kt
- src/main/kotlin/application/controller/VesselListPanelController.kt
- src/main/kotlin/application/model/Context.kt
- src/main/kotlin/application/model/ObservableSelectedVessel.kt
- src/main/kotlin/application/model/SelectedVesselListener.kt
- src/main/kotlin/application/model/Vessel.kt
- src/main/kotlin/application/model/VesselGenerator.kt
- src/main/kotlin/map/CircleMarkerGenerator.kt
- src/main/resources/gui/controlPanel.fxml
- src/main/resources/gui/vesselListPanel.fxml
- src/main/resources/gui/windows.fxml
src/main/kotlin/application/controller/ControlPanelController.kt
View file @
2bbe36a
1 | -package application.controller | |
2 | - | |
3 | -import application.model.MessageListener | |
4 | -import application.model.Vessel | |
5 | -import application.model.observableMessages | |
6 | -import javafx.collections.FXCollections | |
7 | -import javafx.collections.ObservableList | |
8 | -import javafx.event.EventHandler | |
9 | -import javafx.fxml.FXML | |
10 | -import javafx.fxml.Initializable | |
11 | -import javafx.scene.control.Button | |
12 | -import javafx.scene.control.ListView | |
13 | -import java.net.URL | |
14 | -import java.util.* | |
15 | - | |
16 | -class ControlPanelController : Initializable, MessageListener { | |
17 | - @FXML | |
18 | - var shipListView: ListView<Int> = ListView() | |
19 | - | |
20 | - | |
21 | - var shipList: ObservableList<Int> = FXCollections.observableArrayList() | |
22 | - | |
23 | - override fun initialize(location: URL?, resources: ResourceBundle?) { | |
24 | - shipListView.items = shipList | |
25 | - observableMessages.listeners.add(this) | |
26 | - } | |
27 | - | |
28 | - override fun onValueChanged(newValue: MutableMap<Int?, Vessel>) { | |
29 | - shipList.clear() | |
30 | - shipList.addAll(newValue.keys) | |
31 | - } | |
32 | - | |
33 | -} |
src/main/kotlin/application/controller/MapPanelController.kt
View file @
2bbe36a
1 | 1 | package application.controller |
2 | 2 | |
3 | -import application.model.MessageListener | |
4 | -import application.model.Vessel | |
5 | -import application.model.observableMessages | |
3 | +import application.model.* | |
6 | 4 | import javafx.concurrent.Worker |
7 | 5 | import javafx.fxml.FXML |
8 | 6 | import javafx.fxml.Initializable |
... | ... | @@ -14,7 +12,7 @@ |
14 | 12 | import java.util.* |
15 | 13 | import java.util.concurrent.CompletableFuture |
16 | 14 | |
17 | -class MapPanelController : Initializable, MessageListener { | |
15 | +class MapPanelController : Initializable { | |
18 | 16 | |
19 | 17 | @FXML |
20 | 18 | private lateinit var map: StackPane |
21 | 19 | |
22 | 20 | |
... | ... | @@ -24,18 +22,24 @@ |
24 | 22 | |
25 | 23 | override fun initialize(location: URL?, resources: ResourceBundle?) { |
26 | 24 | val completeFutureMap: CompletableFuture<Worker.State> = mapView.displayMap(MapConfig()) |
27 | - observableMessages.listeners.add(this) | |
25 | + observableVessel.listeners.add(object : MessageListener { | |
26 | + override fun onValueChanged(newValue: MutableMap<Int?, Vessel>) { | |
27 | + displayMessageOnMap(mapView) | |
28 | + } | |
29 | + }) | |
28 | 30 | |
31 | + observableSelectedVessel.listeners.add(object : SelectedVesselListener { | |
32 | + override fun onValueChanged(newValue: Vessel) { | |
33 | + displayMessageOnMap(mapView, newValue.mmsi!!) | |
34 | + } | |
35 | + }) | |
36 | + | |
29 | 37 | /*completeFutureMap.whenComplete{ |
30 | 38 | workerState, _ -> |
31 | 39 | if (workerState == Worker.State.SUCCEEDED) { |
32 | 40 | } |
33 | 41 | }*/ |
34 | 42 | map.children.add(mapView) |
35 | - } | |
36 | - | |
37 | - override fun onValueChanged(newValue: MutableMap<Int?, Vessel>) { | |
38 | - displayMessageOnMap(mapView) | |
39 | 43 | } |
40 | 44 | |
41 | 45 |
src/main/kotlin/application/controller/MenuBarController.kt
View file @
2bbe36a
1 | 1 | package application.controller |
2 | 2 | |
3 | 3 | import application.model.createVesselCollection |
4 | -import application.model.observableMessages | |
4 | +import application.model.observableVessel | |
5 | 5 | import javafx.event.EventHandler |
6 | 6 | import javafx.fxml.FXML |
7 | 7 | import javafx.fxml.Initializable |
... | ... | @@ -27,8 +27,8 @@ |
27 | 27 | val window = menuBar.scene.window |
28 | 28 | val file = fileChooser.showOpenDialog(window) |
29 | 29 | val vessels = createVesselCollection(file) |
30 | - observableMessages.vessels.clear() | |
31 | - observableMessages.vessels = vessels | |
30 | + observableVessel.vessels.clear() | |
31 | + observableVessel.vessels = vessels | |
32 | 32 | } |
33 | 33 | } |
34 | 34 | } |
src/main/kotlin/application/controller/VesselListPanelController.kt
View file @
2bbe36a
1 | +package application.controller | |
2 | + | |
3 | +import application.model.MessageListener | |
4 | +import application.model.Vessel | |
5 | +import application.model.observableVessel | |
6 | +import application.model.observableSelectedVessel | |
7 | +import javafx.collections.FXCollections | |
8 | +import javafx.collections.ObservableList | |
9 | +import javafx.fxml.FXML | |
10 | +import javafx.fxml.Initializable | |
11 | +import javafx.scene.control.ListView | |
12 | +import java.net.URL | |
13 | +import java.util.* | |
14 | + | |
15 | +class VesselListPanelController : Initializable, MessageListener { | |
16 | + @FXML | |
17 | + var shipListView: ListView<Int> = ListView() | |
18 | + | |
19 | + | |
20 | + var shipList: ObservableList<Int> = FXCollections.observableArrayList() | |
21 | + | |
22 | + override fun initialize(location: URL?, resources: ResourceBundle?) { | |
23 | + shipListView.items = shipList | |
24 | + observableVessel.listeners.add(this) | |
25 | + shipListView.selectionModel.selectedItemProperty().addListener { _, _, newValue -> | |
26 | + observableSelectedVessel.vessel = observableVessel.vessels[newValue]!! | |
27 | + } | |
28 | + } | |
29 | + | |
30 | + override fun onValueChanged(newValue: MutableMap<Int?, Vessel>) { | |
31 | + shipList.clear() | |
32 | + shipList.addAll(newValue.keys) | |
33 | + } | |
34 | + | |
35 | +} |
src/main/kotlin/application/model/Context.kt
View file @
2bbe36a
src/main/kotlin/application/model/ObservableSelectedVessel.kt
View file @
2bbe36a
1 | +package application.model | |
2 | + | |
3 | +import kotlin.properties.Delegates | |
4 | + | |
5 | +class ObservableSelectedVessel { | |
6 | + val listeners: MutableList<SelectedVesselListener> = mutableListOf() | |
7 | + | |
8 | + var vessel: Vessel by Delegates.observable( | |
9 | + initialValue = Vessel(null), | |
10 | + onChange = { _, _, new -> | |
11 | + run { | |
12 | + listeners.forEach { | |
13 | + it.onValueChanged(new) | |
14 | + } | |
15 | + } | |
16 | + } | |
17 | + ) | |
18 | +} |
src/main/kotlin/application/model/SelectedVesselListener.kt
View file @
2bbe36a
src/main/kotlin/application/model/Vessel.kt
View file @
2bbe36a
src/main/kotlin/application/model/VesselGenerator.kt
View file @
2bbe36a
... | ... | @@ -14,7 +14,7 @@ |
14 | 14 | val message = Message(arrayMessage) |
15 | 15 | messages.add(message) |
16 | 16 | if (!vessels.containsKey(message.mmsi)){ |
17 | - vessels[message.mmsi] = Vessel() | |
17 | + vessels[message.mmsi] = Vessel(message.mmsi!!) | |
18 | 18 | } |
19 | 19 | vessels[message.mmsi]?.messages?.set(message.time, message) |
20 | 20 | } |
src/main/kotlin/map/CircleMarkerGenerator.kt
View file @
2bbe36a
1 | 1 | package map |
2 | 2 | |
3 | -import application.model.observableMessages | |
3 | +import application.model.observableVessel | |
4 | 4 | |
5 | 5 | fun clearMapCanvas(map: LeafletMapView) { |
6 | 6 | map.execScript(""" |
7 | 7 | |
... | ... | @@ -11,9 +11,22 @@ |
11 | 11 | |
12 | 12 | fun displayMessageOnMap(map: LeafletMapView) { |
13 | 13 | clearMapCanvas(map) |
14 | - observableMessages.vessels.forEach { (_, value) -> | |
14 | + observableVessel.vessels.forEach { (_, value) -> | |
15 | 15 | value.messages.forEach { (_, message) -> |
16 | 16 | map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColor()}'}).addTo(myMap)") |
17 | + } | |
18 | + } | |
19 | +} | |
20 | + | |
21 | +fun displayMessageOnMap(map: LeafletMapView, selectedMMSI: Int) { | |
22 | + clearMapCanvas(map) | |
23 | + observableVessel.vessels.forEach { (_, value) -> | |
24 | + value.messages.forEach { (_, message) -> | |
25 | + if(selectedMMSI == message.mmsi){ | |
26 | + map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 4, color: '#ff001e'}).addTo(myMap)") | |
27 | + }else{ | |
28 | + map.execScript("L.circleMarker([${message.latitude}, ${message.longitude}], {renderer: myRenderer, radius: 0.01, color: '#${message.getHexColor()}'}).addTo(myMap)") | |
29 | + } | |
17 | 30 | } |
18 | 31 | } |
19 | 32 | } |
src/main/resources/gui/controlPanel.fxml
View file @
2bbe36a
1 | -<?xml version="1.0" encoding="UTF-8"?> | |
2 | - | |
3 | -<?import javafx.scene.control.*?> | |
4 | -<?import javafx.scene.layout.*?> | |
5 | - | |
6 | -<BorderPane prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.controller.ControlPanelController"> | |
7 | - | |
8 | - <top> | |
9 | - <AnchorPane prefHeight="33.0" prefWidth="200.0" BorderPane.alignment="CENTER"> | |
10 | - <children> | |
11 | - <Button layoutX="74.0" layoutY="2.0" mnemonicParsing="false" text="Button" fx:id="buton" /> | |
12 | - </children></AnchorPane> | |
13 | - </top> | |
14 | - <center> | |
15 | - <ListView fx:id="shipListView" prefHeight="105.0" prefWidth="200.0" /> | |
16 | - </center> | |
17 | -</BorderPane> |
src/main/resources/gui/vesselListPanel.fxml
View file @
2bbe36a
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | + | |
3 | +<?import javafx.scene.control.*?> | |
4 | +<?import javafx.scene.layout.*?> | |
5 | + | |
6 | +<BorderPane prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.controller.VesselListPanelController"> | |
7 | + | |
8 | + <top> | |
9 | + <AnchorPane prefHeight="33.0" prefWidth="200.0" BorderPane.alignment="CENTER"> | |
10 | + <children> | |
11 | + <Button layoutX="74.0" layoutY="2.0" mnemonicParsing="false" text="Button" fx:id="buton" /> | |
12 | + </children></AnchorPane> | |
13 | + </top> | |
14 | + <center> | |
15 | + <ListView fx:id="shipListView" prefHeight="105.0" prefWidth="200.0" /> | |
16 | + </center> | |
17 | +</BorderPane> |
src/main/resources/gui/windows.fxml
View file @
2bbe36a
... | ... | @@ -11,7 +11,7 @@ |
11 | 11 | <items> |
12 | 12 | <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"> |
13 | 13 | <children> |
14 | - <fx:include source="controlPanel.fxml" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" /> | |
14 | + <fx:include source="vesselListPanel.fxml" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" /> | |
15 | 15 | </children> |
16 | 16 | </AnchorPane> |
17 | 17 | <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"> |