Commit 867a0df4617a6c1355868b60f50a41b9e74d0140
1 parent
e220e082b5
Exists in
master
and in
1 other branch
populate plot when the property is selected
Showing 1 changed file with 63 additions and 44 deletions Inline Diff
src/main/kotlin/application/controller/DataPanelController.kt
View file @
867a0df
package application.controller | 1 | 1 | package application.controller | |
2 | 2 | |||
import application.model.* | 3 | 3 | import application.model.* | |
import javafx.collections.FXCollections | 4 | 4 | import javafx.collections.FXCollections | |
import javafx.collections.ObservableList | 5 | 5 | import javafx.collections.ObservableList | |
import javafx.fxml.FXML | 6 | 6 | import javafx.fxml.FXML | |
import javafx.fxml.Initializable | 7 | 7 | import javafx.fxml.Initializable | |
import javafx.scene.control.ListCell | 8 | 8 | import javafx.scene.control.ListCell | |
import javafx.scene.control.ListView | 9 | 9 | import javafx.scene.control.ListView | |
import kotlinx.coroutines.GlobalScope | 10 | 10 | import kotlinx.coroutines.GlobalScope | |
import kotlinx.coroutines.launch | 11 | 11 | import kotlinx.coroutines.launch | |
import org.charts.dataviewer.api.config.DataViewerConfiguration | 12 | 12 | import org.charts.dataviewer.api.config.DataViewerConfiguration | |
import org.charts.dataviewer.api.data.PlotData | 13 | 13 | import org.charts.dataviewer.api.data.PlotData | |
import org.charts.dataviewer.api.trace.ScatterTrace | 14 | 14 | import org.charts.dataviewer.api.trace.ScatterTrace | |
import org.charts.dataviewer.javafx.JavaFxDataViewer | 15 | 15 | import org.charts.dataviewer.javafx.JavaFxDataViewer | |
import org.charts.dataviewer.utils.TraceColour | 16 | 16 | import org.charts.dataviewer.utils.TraceColour | |
import org.charts.dataviewer.utils.TraceVisibility | 17 | 17 | import org.charts.dataviewer.utils.TraceVisibility | |
import java.net.URL | 18 | 18 | import java.net.URL | |
import java.util.* | 19 | 19 | import java.util.* | |
20 | 20 | |||
21 | 21 | |||
class DataPanelController : Initializable, SelectedVesselListener { | 22 | 22 | class DataPanelController : Initializable, SelectedVesselListener { | |
private var dataList: ObservableList<Pair<String, ArrayList<MessageData?>>> = FXCollections.observableArrayList() | 23 | 23 | private var dataList: ObservableList<Pair<String, ArrayList<MessageData?>>> = FXCollections.observableArrayList() | |
private lateinit var timeData: ArrayList<MessageData?> | 24 | 24 | private lateinit var timeData: ArrayList<MessageData?> | |
25 | 25 | |||
private val latitude: ArrayList<MessageData?> = arrayListOf() | 26 | 26 | private val latitude: ArrayList<MessageData?> = arrayListOf() | |
private val longitude: ArrayList<MessageData?> = arrayListOf() | 27 | 27 | private val longitude: ArrayList<MessageData?> = arrayListOf() | |
private val speedOverGround: ArrayList<MessageData?> = arrayListOf() | 28 | 28 | private val speedOverGround: ArrayList<MessageData?> = arrayListOf() | |
private val courseOverGround: ArrayList<MessageData?> = arrayListOf() | 29 | 29 | private val courseOverGround: ArrayList<MessageData?> = arrayListOf() | |
private val heading: ArrayList<MessageData?> = arrayListOf() | 30 | 30 | private val heading: ArrayList<MessageData?> = arrayListOf() | |
private val vesselName: ArrayList<MessageData?> = arrayListOf() | 31 | 31 | private val vesselName: ArrayList<MessageData?> = arrayListOf() | |
private val imo: ArrayList<MessageData?> = arrayListOf() | 32 | 32 | private val imo: ArrayList<MessageData?> = arrayListOf() | |
private val callSign: ArrayList<MessageData?> = arrayListOf() | 33 | 33 | private val callSign: ArrayList<MessageData?> = arrayListOf() | |
private val vesselType: ArrayList<MessageData?> = arrayListOf() | 34 | 34 | private val vesselType: ArrayList<MessageData?> = arrayListOf() | |
private val status: ArrayList<MessageData?> = arrayListOf() | 35 | 35 | private val status: ArrayList<MessageData?> = arrayListOf() | |
private val length: ArrayList<MessageData?> = arrayListOf() | 36 | 36 | private val length: ArrayList<MessageData?> = arrayListOf() | |
private val width: ArrayList<MessageData?> = arrayListOf() | 37 | 37 | private val width: ArrayList<MessageData?> = arrayListOf() | |
private val draft: ArrayList<MessageData?> = arrayListOf() | 38 | 38 | private val draft: ArrayList<MessageData?> = arrayListOf() | |
private val cargo: ArrayList<MessageData?> = arrayListOf() | 39 | 39 | private val cargo: ArrayList<MessageData?> = arrayListOf() | |
40 | 40 | |||
private var selectedItem: Pair<String, ArrayList<MessageData?>>? = null | 41 | 41 | private var selectedItem: Pair<String, ArrayList<MessageData?>>? = null | |
42 | 42 | |||
@FXML | 43 | 43 | @FXML | |
var dataListView = ListView<Pair<String, ArrayList<MessageData?>>>() | 44 | 44 | var dataListView = ListView<Pair<String, ArrayList<MessageData?>>>() | |
45 | 45 | |||
@FXML | 46 | 46 | @FXML | |
var dataViewer = JavaFxDataViewer() | 47 | 47 | var dataViewer = JavaFxDataViewer() | |
48 | 48 | |||
private val plotData = PlotData() | 49 | 49 | private val plotData = PlotData() | |
private val config = DataViewerConfiguration() | 50 | 50 | private val config = DataViewerConfiguration() | |
51 | 51 | |||
override fun initialize(location: URL?, resources: ResourceBundle?) { | 52 | 52 | override fun initialize(location: URL?, resources: ResourceBundle?) { | |
setObservableSelectedVesselListener() | 53 | 53 | setObservableSelectedVesselListener() | |
dataListView.items = dataList | 54 | 54 | dataListView.items = dataList | |
55 | 55 | |||
56 | 56 | |||
57 | 57 | |||
config.showLegend(true) | 58 | 58 | config.showLegend(false) | |
config.setLegendInsidePlot(false) | 59 | 59 | config.setLegendInsidePlot(false) | |
60 | 60 | |||
setObservableCurrentTimeListener() | 61 | 61 | setObservableCurrentTimeListener() | |
62 | 62 | |||
dataListView.setCellFactory { | 63 | 63 | dataListView.setCellFactory { | |
object : ListCell<Pair<String, ArrayList<MessageData?>>?>() { | 64 | 64 | object : ListCell<Pair<String, ArrayList<MessageData?>>?>() { | |
override fun updateItem(item: Pair<String, ArrayList<MessageData?>>?, empty: Boolean) { | 65 | 65 | override fun updateItem(item: Pair<String, ArrayList<MessageData?>>?, empty: Boolean) { | |
super.updateItem(item, empty) | 66 | 66 | super.updateItem(item, empty) | |
text = if (empty) { | 67 | 67 | text = if (empty) { | |
null | 68 | 68 | null | |
} else { | 69 | 69 | } else { | |
item?.first | 70 | 70 | item?.first | |
} | 71 | 71 | } | |
} | 72 | 72 | } | |
} | 73 | 73 | } | |
} | 74 | 74 | } | |
75 | 75 | |||
dataListView.selectionModel.selectedItemProperty().addListener { _, _, newValue -> | 76 | 76 | dataListView.selectionModel.selectedItemProperty().addListener { _, _, newValue -> | |
selectedItem = newValue | 77 | 77 | selectedItem = newValue | |
78 | updateDataList(observableSelectedVessel.value) | |||
plot(newValue) | 78 | 79 | plot(newValue) | |
} | 79 | 80 | } | |
80 | 81 | |||
plotData.allTraces.clear() | 81 | 82 | plotData.allTraces.clear() | |
config.setxAxisTitle("") | 82 | 83 | config.setxAxisTitle("") | |
config.setyAxisTitle("") | 83 | 84 | config.setyAxisTitle("") | |
config.plotTitle = "" | 84 | 85 | config.plotTitle = "" | |
dataViewer.updateConfiguration(config) | 85 | 86 | dataViewer.updateConfiguration(config) | |
dataViewer.updatePlot(plotData) | 86 | 87 | dataViewer.updatePlot(plotData) | |
initDataList() | 87 | 88 | initDataList() | |
88 | 89 | |||
89 | 90 | |||
} | 90 | 91 | } | |
91 | 92 | |||
private fun plot() { | 92 | 93 | private fun plot() { | |
if (selectedItem != null) { | 93 | 94 | if (selectedItem != null || observableSelectedVessel.value == Vessel(null)) { | |
GlobalScope.launch { | 94 | 95 | GlobalScope.launch { | |
plot(selectedItem) | 95 | 96 | plot(selectedItem) | |
} | 96 | 97 | } | |
} | 97 | 98 | } | |
} | 98 | 99 | } | |
99 | 100 | |||
private fun plot(data: Pair<String, ArrayList<MessageData?>>?) { | 100 | 101 | private fun plot(data: Pair<String, ArrayList<MessageData?>>?) { | |
if (data == null) { | 101 | 102 | if (data == null) { | |
plotData.allTraces.clear() | 102 | 103 | plotData.allTraces.clear() | |
config.setxAxisTitle("") | 103 | 104 | config.setxAxisTitle("") | |
config.setyAxisTitle("") | 104 | 105 | config.setyAxisTitle("") | |
dataViewer.updateConfiguration(config) | 105 | 106 | dataViewer.updateConfiguration(config) | |
106 | 107 | |||
dataViewer.resetPlot() | 107 | 108 | dataViewer.resetPlot() | |
108 | 109 | |||
return | 109 | 110 | return | |
} | 110 | 111 | }else if (data.second.size < timeData.size) return | |
111 | 112 | |||
val getValueVisitorX = GetValueVisitor() | 112 | 113 | val getValueVisitorX = GetValueVisitor() | |
val getValueVisitorY = GetValueVisitor() | 113 | 114 | val getValueVisitorY = GetValueVisitor() | |
114 | 115 | |||
val arrayListStringX = arrayListOf<String>() | 115 | 116 | val arrayListStringX = arrayListOf<String>() | |
// val arrayListDoubleX = arrayListOf<Double>() | 116 | 117 | // val arrayListDoubleX = arrayListOf<Double>() | |
val arrayListStringY = arrayListOf<String>() | 117 | 118 | val arrayListStringY = arrayListOf<String>() | |
val arrayListDoubleY = arrayListOf<Double>() | 118 | 119 | val arrayListDoubleY = arrayListOf<Double>() | |
119 | 120 | |||
for (x in 0 until timeData.size) { | 120 | 121 | for (x in 0 until timeData.size) { | |
timeData[x]?.accept(getValueVisitorX) | 121 | 122 | timeData[x]?.accept(getValueVisitorX) | |
data.second[x]?.accept(getValueVisitorY) | 122 | 123 | data.second[x]?.accept(getValueVisitorY) | |
123 | 124 | |||
if (getValueVisitorY.value.toDoubleOrNull() == null) { | 124 | 125 | if (getValueVisitorY.value.toDoubleOrNull() == null) { | |
arrayListStringX.add(getValueVisitorX.value) | 125 | 126 | arrayListStringX.add(getValueVisitorX.value) | |
arrayListStringY.add(getValueVisitorY.value) | 126 | 127 | arrayListStringY.add(getValueVisitorY.value) | |
} else { | 127 | 128 | } else { | |
arrayListStringX.add(getValueVisitorX.value) | 128 | 129 | arrayListStringX.add(getValueVisitorX.value) | |
arrayListDoubleY.add(getValueVisitorY.value.toDouble()) | 129 | 130 | arrayListDoubleY.add(getValueVisitorY.value.toDouble()) | |
} | 130 | 131 | } | |
} | 131 | 132 | } | |
132 | 133 | |||
val scatterTrace = ScatterTrace<Any>() | 133 | 134 | val scatterTrace = ScatterTrace<Any>() | |
scatterTrace.traceColour = TraceColour.RED | 134 | 135 | scatterTrace.traceColour = TraceColour.RED | |
scatterTrace.traceVisibility = TraceVisibility.TRUE | 135 | 136 | scatterTrace.traceVisibility = TraceVisibility.TRUE | |
136 | 137 | |||
val serieStringX: Array<String> = arrayListStringX.toTypedArray() | 137 | 138 | val serieStringX: Array<String> = arrayListStringX.toTypedArray() | |
// val serieDoubleX: Array<Double> = arrayListDoubleX.toTypedArray() | 138 | 139 | // val serieDoubleX: Array<Double> = arrayListDoubleX.toTypedArray() | |
val serieStringY: Array<String> = arrayListStringY.toTypedArray() | 139 | 140 | val serieStringY: Array<String> = arrayListStringY.toTypedArray() | |
val serieDoubleY: Array<Double> = arrayListDoubleY.toTypedArray() | 140 | 141 | val serieDoubleY: Array<Double> = arrayListDoubleY.toTypedArray() | |
141 | 142 | |||
if (getValueVisitorY.value.toDoubleOrNull() == null) { | 142 | 143 | if (getValueVisitorY.value.toDoubleOrNull() == null) { | |
scatterTrace.setxArray(serieStringX) | 143 | 144 | scatterTrace.setxArray(serieStringX) | |
scatterTrace.setyArray(serieStringY) | 144 | 145 | scatterTrace.setyArray(serieStringY) | |
} else { | 145 | 146 | } else { | |
scatterTrace.setxArray(serieStringX) | 146 | 147 | scatterTrace.setxArray(serieStringX) | |
scatterTrace.setyArray(serieDoubleY) | 147 | 148 | scatterTrace.setyArray(serieDoubleY) | |
} | 148 | 149 | } | |
149 | 150 | |||
config.plotTitle = "" | 150 | 151 | config.plotTitle = "" | |
config.setxAxisTitle("Time (s)") | 151 | 152 | config.setxAxisTitle("Time (s)") | |
config.setyAxisTitle(data.first) | 152 | 153 | config.setyAxisTitle(data.first) | |
dataViewer.resetPlot() | 153 | 154 | dataViewer.resetPlot() | |
plotData.allTraces.clear() | 154 | 155 | plotData.allTraces.clear() | |
plotData.addTrace(scatterTrace) | 155 | 156 | plotData.addTrace(scatterTrace) | |
dataViewer.updateConfiguration(config) | 156 | 157 | dataViewer.updateConfiguration(config) | |
dataViewer.updatePlot(plotData) | 157 | 158 | dataViewer.updatePlot(plotData) | |
158 | 159 | |||
} | 159 | 160 | } | |
160 | 161 | |||
161 | 162 | |||
private fun setObservableSelectedVesselListener() { | 162 | 163 | private fun setObservableSelectedVesselListener() { | |
observableSelectedVessel.listeners.add(this) | 163 | 164 | observableSelectedVessel.listeners.add(this) | |
} | 164 | 165 | } | |
165 | 166 | |||
private fun populateTime(vessel: Vessel): ArrayList<MessageData?> { | 166 | 167 | private fun populateTime(vessel: Vessel): ArrayList<MessageData?> { | |
return if (observableIsReplayState.value) { | 167 | 168 | return if (observableIsReplayState.value) { | |
vessel.getAllTimeBeforeSelectedTime() | 168 | 169 | vessel.getAllTimeBeforeSelectedTime() | |
} else { | 169 | 170 | } else { | |
vessel.getAllTime() | 170 | 171 | vessel.getAllTime() | |
} | 171 | 172 | } | |
} | 172 | 173 | } | |
173 | 174 | |||
174 | 175 | |||
private fun populateLatitude(vessel: Vessel): ArrayList<MessageData?> { | 175 | 176 | private fun populateLatitude(vessel: Vessel): ArrayList<MessageData?> { | |
return if (observableIsReplayState.value) { | 176 | 177 | return if (observableIsReplayState.value) { | |
vessel.getAllLatitudeBeforeSelectedTime() | 177 | 178 | vessel.getAllLatitudeBeforeSelectedTime() | |
} else { | 178 | 179 | } else { | |
vessel.getAllLatitude() | 179 | 180 | vessel.getAllLatitude() | |
} | 180 | 181 | } | |
} | 181 | 182 | } | |
182 | 183 | |||
private fun populateLongitude(vessel: Vessel): ArrayList<MessageData?> { | 183 | 184 | private fun populateLongitude(vessel: Vessel): ArrayList<MessageData?> { | |
return if (observableIsReplayState.value) { | 184 | 185 | return if (observableIsReplayState.value) { | |
vessel.getAllLongitudeBeforeSelectedTime() | 185 | 186 | vessel.getAllLongitudeBeforeSelectedTime() | |
} else { | 186 | 187 | } else { | |
vessel.getAllLongitude() | 187 | 188 | vessel.getAllLongitude() | |
} | 188 | 189 | } | |
} | 189 | 190 | } | |
190 | 191 | |||
private fun populateSpeedOverGround(vessel: Vessel): ArrayList<MessageData?> { | 191 | 192 | private fun populateSpeedOverGround(vessel: Vessel): ArrayList<MessageData?> { | |
return if (observableIsReplayState.value) { | 192 | 193 | return if (observableIsReplayState.value) { | |
vessel.getAllSpeedOverGroundBeforeSelectedTime() | 193 | 194 | vessel.getAllSpeedOverGroundBeforeSelectedTime() | |
} else { | 194 | 195 | } else { | |
vessel.getAllSpeedOverGround() | 195 | 196 | vessel.getAllSpeedOverGround() | |
} | 196 | 197 | } | |
} | 197 | 198 | } | |
198 | 199 | |||
private fun populateCourseOverGround(vessel: Vessel): ArrayList<MessageData?> { | 199 | 200 | private fun populateCourseOverGround(vessel: Vessel): ArrayList<MessageData?> { | |
return if (observableIsReplayState.value) { | 200 | 201 | return if (observableIsReplayState.value) { | |
vessel.getAllCourseOverGroundBeforeSelectedTime() | 201 | 202 | vessel.getAllCourseOverGroundBeforeSelectedTime() | |
} else { | 202 | 203 | } else { | |
vessel.getAllCourseOverGround() | 203 | 204 | vessel.getAllCourseOverGround() | |
} | 204 | 205 | } | |
} | 205 | 206 | } | |
206 | 207 | |||
private fun populateHeading(vessel: Vessel): ArrayList<MessageData?> { | 207 | 208 | private fun populateHeading(vessel: Vessel): ArrayList<MessageData?> { | |
return if (observableIsReplayState.value) { | 208 | 209 | return if (observableIsReplayState.value) { | |
vessel.getAllHeadingBeforeSelectedTime() | 209 | 210 | vessel.getAllHeadingBeforeSelectedTime() | |
} else { | 210 | 211 | } else { | |
vessel.getAllHeading() | 211 | 212 | vessel.getAllHeading() | |
} | 212 | 213 | } | |
} | 213 | 214 | } | |
214 | 215 | |||
private fun populateVesselName(vessel: Vessel): ArrayList<MessageData?> { | 215 | 216 | private fun populateVesselName(vessel: Vessel): ArrayList<MessageData?> { | |
return if (observableIsReplayState.value) { | 216 | 217 | return if (observableIsReplayState.value) { | |
vessel.getAllVesselNameBeforeSelectedTime() | 217 | 218 | vessel.getAllVesselNameBeforeSelectedTime() | |
} else { | 218 | 219 | } else { | |
vessel.getAllVesselName() | 219 | 220 | vessel.getAllVesselName() | |
} | 220 | 221 | } | |
} | 221 | 222 | } | |
222 | 223 | |||
private fun populateIMO(vessel: Vessel): ArrayList<MessageData?> { | 223 | 224 | private fun populateIMO(vessel: Vessel): ArrayList<MessageData?> { | |
return if (observableIsReplayState.value) { | 224 | 225 | return if (observableIsReplayState.value) { | |
vessel.getAllIMOBeforeSelectedTime() | 225 | 226 | vessel.getAllIMOBeforeSelectedTime() | |
} else { | 226 | 227 | } else { | |
vessel.getAllIMO() | 227 | 228 | vessel.getAllIMO() | |
} | 228 | 229 | } | |
} | 229 | 230 | } | |
230 | 231 | |||
private fun populateCallSign(vessel: Vessel): ArrayList<MessageData?> { | 231 | 232 | private fun populateCallSign(vessel: Vessel): ArrayList<MessageData?> { | |
return if (observableIsReplayState.value) { | 232 | 233 | return if (observableIsReplayState.value) { | |
vessel.getAllCallSignBeforeSelectedTime() | 233 | 234 | vessel.getAllCallSignBeforeSelectedTime() | |
} else { | 234 | 235 | } else { | |
vessel.getAllCallSign() | 235 | 236 | vessel.getAllCallSign() | |
} | 236 | 237 | } | |
} | 237 | 238 | } | |
238 | 239 | |||
private fun populateVesselType(vessel: Vessel): ArrayList<MessageData?> { | 239 | 240 | private fun populateVesselType(vessel: Vessel): ArrayList<MessageData?> { | |
return if (observableIsReplayState.value) { | 240 | 241 | return if (observableIsReplayState.value) { | |
vessel.getAllVesselTypeBeforeSelectedTime() | 241 | 242 | vessel.getAllVesselTypeBeforeSelectedTime() | |
} else { | 242 | 243 | } else { | |
vessel.getAllVesselType() | 243 | 244 | vessel.getAllVesselType() | |
} | 244 | 245 | } | |
} | 245 | 246 | } | |
246 | 247 | |||
private fun populateStatus(vessel: Vessel): ArrayList<MessageData?> { | 247 | 248 | private fun populateStatus(vessel: Vessel): ArrayList<MessageData?> { | |
return if (observableIsReplayState.value) { | 248 | 249 | return if (observableIsReplayState.value) { | |
vessel.getAllStatusBeforeSelectedTime() | 249 | 250 | vessel.getAllStatusBeforeSelectedTime() | |
} else { | 250 | 251 | } else { | |
vessel.getAllStatus() | 251 | 252 | vessel.getAllStatus() | |
} | 252 | 253 | } | |
} | 253 | 254 | } | |
254 | 255 | |||
private fun populateLength(vessel: Vessel): ArrayList<MessageData?> { | 255 | 256 | private fun populateLength(vessel: Vessel): ArrayList<MessageData?> { | |
return if (observableIsReplayState.value) { | 256 | 257 | return if (observableIsReplayState.value) { | |
vessel.getAllLengthBeforeSelectedTime() | 257 | 258 | vessel.getAllLengthBeforeSelectedTime() | |
} else { | 258 | 259 | } else { | |
vessel.getAllLength() | 259 | 260 | vessel.getAllLength() | |
} | 260 | 261 | } | |
} | 261 | 262 | } | |
262 | 263 | |||
private fun populateWidth(vessel: Vessel): ArrayList<MessageData?> { | 263 | 264 | private fun populateWidth(vessel: Vessel): ArrayList<MessageData?> { | |
return if (observableIsReplayState.value) { | 264 | 265 | return if (observableIsReplayState.value) { | |
vessel.getAllWidthBeforeSelectedTime() | 265 | 266 | vessel.getAllWidthBeforeSelectedTime() | |
} else { | 266 | 267 | } else { | |
vessel.getAllWidth() | 267 | 268 | vessel.getAllWidth() | |
} | 268 | 269 | } | |
} | 269 | 270 | } | |
270 | 271 | |||
private fun populateDraft(vessel: Vessel): ArrayList<MessageData?> { | 271 | 272 | private fun populateDraft(vessel: Vessel): ArrayList<MessageData?> { | |
return if (observableIsReplayState.value) { | 272 | 273 | return if (observableIsReplayState.value) { | |
vessel.getAllDraftBeforeSelectedTime() | 273 | 274 | vessel.getAllDraftBeforeSelectedTime() | |
} else { | 274 | 275 | } else { | |
vessel.getAllDraft() | 275 | 276 | vessel.getAllDraft() | |
} | 276 | 277 | } | |
} | 277 | 278 | } | |
278 | 279 | |||
private fun populateCargo(vessel: Vessel): ArrayList<MessageData?> { | 279 | 280 | private fun populateCargo(vessel: Vessel): ArrayList<MessageData?> { | |
return if (observableIsReplayState.value) { | 280 | 281 | return if (observableIsReplayState.value) { | |
vessel.getAllCargoBeforeSelectedTime() | 281 | 282 | vessel.getAllCargoBeforeSelectedTime() | |
} else { | 282 | 283 | } else { | |
vessel.getAllCargo() | 283 | 284 | vessel.getAllCargo() | |
} | 284 | 285 | } | |
} | 285 | 286 | } | |
286 | 287 | |||
private fun initDataList() { | 287 | 288 | private fun initDataList() { | |
val data = arrayListOf<Pair<String, ArrayList<MessageData?>>>() | 288 | 289 | val data = arrayListOf<Pair<String, ArrayList<MessageData?>>>() | |
289 | 290 | |||
data.add(Pair("Latitude", latitude)) | 290 | 291 | data.add(Pair("Latitude", latitude)) | |
data.add(Pair("Longitude", longitude)) | 291 | 292 | data.add(Pair("Longitude", longitude)) | |
data.add(Pair("Speed Over Ground", speedOverGround)) | 292 | 293 | data.add(Pair("Speed Over Ground", speedOverGround)) | |
data.add(Pair("Course Over Ground", courseOverGround)) | 293 | 294 | data.add(Pair("Course Over Ground", courseOverGround)) | |
data.add(Pair("Heading", heading)) | 294 | 295 | data.add(Pair("Heading", heading)) | |
data.add(Pair("Vessel Name", vesselName)) | 295 | 296 | data.add(Pair("Vessel Name", vesselName)) | |
data.add(Pair("IMO", imo)) | 296 | 297 | data.add(Pair("IMO", imo)) | |
data.add(Pair("Call Sign", callSign)) | 297 | 298 | data.add(Pair("Call Sign", callSign)) | |
data.add(Pair("Vessel Type", vesselType)) | 298 | 299 | data.add(Pair("Vessel Type", vesselType)) | |
data.add(Pair("Status", status)) | 299 | 300 | data.add(Pair("Status", status)) | |
data.add(Pair("Length", length)) | 300 | 301 | data.add(Pair("Length", length)) | |
data.add(Pair("Width", width)) | 301 | 302 | data.add(Pair("Width", width)) | |
data.add(Pair("Draft", draft)) | 302 | 303 | data.add(Pair("Draft", draft)) | |
data.add(Pair("Cargo", cargo)) | 303 | 304 | data.add(Pair("Cargo", cargo)) | |
304 | 305 | |||
dataList.addAll(data) | 305 | 306 | dataList.addAll(data) | |
} | 306 | 307 | } | |
307 | 308 | |||
private fun updateDataList(vessel: Vessel) { | 308 | 309 | private fun updateDataList(vessel: Vessel) { | |
timeData = populateTime(vessel) | 309 | 310 | timeData = populateTime(vessel) | |
310 | 311 | |||
latitude.clear() | 311 | 312 | if(dataListView.selectionModel.selectedItem == null) return | |
latitude.addAll(populateLatitude(vessel)) | 312 | |||
313 | 313 | |||
longitude.clear() | 314 | 314 | when (dataListView.selectionModel.selectedItem.first) { | |
longitude.addAll(populateLongitude(vessel)) | 315 | 315 | "Latitude" -> { | |
316 | 316 | latitude.clear() | ||
speedOverGround.clear() | 317 | 317 | latitude.addAll(populateLatitude(vessel)) | |
speedOverGround.addAll(populateSpeedOverGround(vessel)) | 318 | 318 | } | |
319 | 319 | "Longitude" -> { | ||
courseOverGround.clear() | 320 | 320 | longitude.clear() | |
courseOverGround.addAll(populateCourseOverGround(vessel)) | 321 | 321 | longitude.addAll(populateLongitude(vessel)) | |
322 | 322 | } | ||
heading.clear() | 323 | 323 | "Speed Over Ground" -> { | |
heading.addAll(populateHeading(vessel)) | 324 | 324 | speedOverGround.clear() | |
325 | 325 | speedOverGround.addAll(populateSpeedOverGround(vessel)) | ||
vesselName.clear() | 326 | 326 | } | |
vesselName.addAll(populateVesselName(vessel)) | 327 | 327 | "Course Over Ground" -> { | |
328 | 328 | courseOverGround.clear() | ||
imo.clear() | 329 | 329 | courseOverGround.addAll(populateCourseOverGround(vessel)) | |
imo.addAll(populateIMO(vessel)) | 330 | 330 | } | |
331 | 331 | "Heading" -> { | ||
callSign.clear() | 332 | 332 | heading.clear() | |
callSign.addAll(populateCallSign(vessel)) | 333 | 333 | heading.addAll(populateHeading(vessel)) | |
334 | 334 | } | ||
vesselType.clear() | 335 | 335 | "Vessel Name" -> { | |
vesselType.addAll(populateVesselType(vessel)) | 336 | 336 | vesselName.clear() | |
337 | 337 | vesselName.addAll(populateVesselName(vessel)) | ||
status.clear() | 338 | 338 | } | |
status.addAll(populateStatus(vessel)) | 339 | 339 | "IMO" -> { | |
340 | 340 | imo.clear() | ||
length.clear() | 341 | 341 | imo.addAll(populateIMO(vessel)) | |
length.addAll(populateLength(vessel)) | 342 | 342 | } | |
343 | 343 | "Call Sign" -> { | ||
width.clear() | 344 | 344 | callSign.clear() | |
width.addAll(populateWidth(vessel)) | 345 | 345 | callSign.addAll(populateCallSign(vessel)) | |
346 | 346 | } | ||
draft.clear() | 347 | 347 | "Vessel Type" -> { | |
draft.addAll(populateDraft(vessel)) | 348 | 348 | vesselType.clear() | |
349 | 349 | vesselType.addAll(populateVesselType(vessel)) | ||
cargo.clear() | 350 | 350 | } | |
cargo.addAll(populateCargo(vessel)) | 351 | 351 | "Status" -> { | |
352 | 352 | status.clear() | ||
353 | status.addAll(populateStatus(vessel)) | |||
354 | } | |||
355 | "Length" -> { | |||
356 | length.clear() | |||
357 | length.addAll(populateLength(vessel)) | |||
358 | } | |||
359 | "Width" -> { | |||
360 | width.clear() |