Blame view
src/main/kotlin/application/controller/DataPanelController.kt
9.16 KB
513c0341c
|
1 2 3 4 5 6 7 |
package application.controller import application.model.* import javafx.collections.FXCollections import javafx.collections.ObservableList import javafx.fxml.FXML import javafx.fxml.Initializable |
513c0341c
|
8 9 |
import javafx.scene.control.ListCell import javafx.scene.control.ListView |
f15a58907
|
10 11 |
import org.charts.dataviewer.api.config.DataViewerConfiguration import org.charts.dataviewer.api.data.PlotData |
f15a58907
|
12 13 14 |
import org.charts.dataviewer.api.trace.ScatterTrace import org.charts.dataviewer.javafx.JavaFxDataViewer import org.charts.dataviewer.utils.TraceColour |
f15a58907
|
15 |
import org.charts.dataviewer.utils.TraceVisibility |
513c0341c
|
16 17 18 19 20 21 22 |
import java.net.URL import java.util.* class DataPanelController : Initializable, SelectedVesselListener { private var dataList: ObservableList<Pair<String, ArrayList<MessageData?>>> = FXCollections.observableArrayList() private lateinit var timeData: ArrayList<MessageData?> |
513c0341c
|
23 24 |
@FXML |
f15a58907
|
25 |
var dataListView = ListView<Pair<String, ArrayList<MessageData?>>>() |
513c0341c
|
26 |
|
513c0341c
|
27 |
@FXML |
f15a58907
|
28 |
var dataViewer = JavaFxDataViewer() |
513c0341c
|
29 30 |
override fun initialize(location: URL?, resources: ResourceBundle?) { |
513c0341c
|
31 32 |
setObservableSelectedVesselListener() dataListView.items = dataList |
f15a58907
|
33 |
val plotData = PlotData() |
f15a58907
|
34 35 36 |
val config = DataViewerConfiguration() config.showLegend(true) config.setLegendInsidePlot(false) |
513c0341c
|
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
dataListView.setCellFactory { object : ListCell<Pair<String, ArrayList<MessageData?>>?>() { override fun updateItem(item: Pair<String, ArrayList<MessageData?>>?, empty: Boolean) { super.updateItem(item, empty) text = if (empty) { null } else { item?.first } } } } dataListView.selectionModel.selectedItemProperty().addListener { _, _, newValue -> |
f15a58907
|
52 53 54 55 |
if (newValue == null) { plotData.allTraces.clear() config.setxAxisTitle("") config.setyAxisTitle("") |
f39d90e60
|
56 |
dataViewer.updateConfiguration(config) |
f15a58907
|
57 |
dataViewer.resetPlot() |
513c0341c
|
58 59 |
return@addListener } |
513c0341c
|
60 61 62 |
val getValueVisitorX = GetValueVisitor() val getValueVisitorY = GetValueVisitor() |
f15a58907
|
63 64 65 66 |
val arrayListStringX = arrayListOf<String>() val arrayListDoubleX = arrayListOf<Double>() val arrayListStringY = arrayListOf<String>() val arrayListDoubleY = arrayListOf<Double>() |
513c0341c
|
67 |
|
f15a58907
|
68 |
for (x in 0 until newValue.second.size) { |
513c0341c
|
69 70 |
timeData[x]?.accept(getValueVisitorX) newValue.second[x]?.accept(getValueVisitorY) |
f15a58907
|
71 72 73 74 75 76 |
if (getValueVisitorY.value.toDoubleOrNull() == null) { arrayListStringX.add(getValueVisitorX.value) arrayListStringY.add(getValueVisitorY.value) } else { arrayListStringX.add(getValueVisitorX.value) arrayListDoubleY.add(getValueVisitorY.value.toDouble()) |
513c0341c
|
77 |
} |
513c0341c
|
78 |
} |
f15a58907
|
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
val scatterTrace = ScatterTrace<Any>() scatterTrace.traceColour = TraceColour.RED scatterTrace.traceVisibility = TraceVisibility.TRUE val serieStringX: Array<String> = arrayListStringX.toTypedArray() // val serieDoubleX: Array<Double> = arrayListDoubleX.toTypedArray() val serieStringY: Array<String> = arrayListStringY.toTypedArray() val serieDoubleY: Array<Double> = arrayListDoubleY.toTypedArray() if (getValueVisitorY.value.toDoubleOrNull() == null) { scatterTrace.setxArray(serieStringX) scatterTrace.setyArray(serieStringY) } else { scatterTrace.setxArray(serieStringX) scatterTrace.setyArray(serieDoubleY) |
513c0341c
|
94 |
} |
8108656dd
|
95 |
config.plotTitle = "" |
3b26be8f9
|
96 |
config.setxAxisTitle("Time (s)") |
f15a58907
|
97 98 99 100 101 102 |
config.setyAxisTitle(newValue.first) dataViewer.resetPlot() plotData.allTraces.clear() plotData.addTrace(scatterTrace) dataViewer.updateConfiguration(config) dataViewer.updatePlot(plotData) |
513c0341c
|
103 |
} |
f15a58907
|
104 |
plotData.allTraces.clear() |
f15a58907
|
105 106 |
config.setxAxisTitle("") config.setyAxisTitle("") |
8108656dd
|
107 |
config.plotTitle = "" |
f15a58907
|
108 109 |
dataViewer.updateConfiguration(config) dataViewer.updatePlot(plotData) |
513c0341c
|
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
} private fun setObservableSelectedVesselListener() { observableSelectedVessel.listeners.add(this) } private fun populateTime(vessel: Vessel): ArrayList<MessageData?> { val allTime: ArrayList<MessageData?> = vessel.getAllTime() allTime.sortBy { (it as Time).value } return allTime } private fun populateLatitude(vessel: Vessel): ArrayList<MessageData?> { val allLatitude: ArrayList<MessageData?> = vessel.getAllLatitude() allLatitude.sortBy { (it as Latitude).value } return allLatitude } private fun populateLongitude(vessel: Vessel): ArrayList<MessageData?> { val allLongitude: ArrayList<MessageData?> = vessel.getAllLongitude() allLongitude.sortBy { (it as Longitude).value } return allLongitude } private fun populateSpeedOverGround(vessel: Vessel): ArrayList<MessageData?> { val allSpeedOverGround: ArrayList<MessageData?> = vessel.getAllSpeedOverGround() allSpeedOverGround.sortBy { (it as SpeedOverGround).value } return allSpeedOverGround } private fun populateCourseOverGround(vessel: Vessel): ArrayList<MessageData?> { val allCourseOverGround: ArrayList<MessageData?> = vessel.getAllCourseOverGround() allCourseOverGround.sortBy { (it as CourseOverGround).value } return allCourseOverGround } private fun populateHeading(vessel: Vessel): ArrayList<MessageData?> { val allHeading: ArrayList<MessageData?> = vessel.getAllHeading() allHeading.sortBy { (it as Heading).value } return allHeading } |
f15a58907
|
157 |
private fun populateVesselName(vessel: Vessel): ArrayList<MessageData?> { |
513c0341c
|
158 159 160 161 162 |
val allVesselName: ArrayList<MessageData?> = vessel.getAllVesselName() allVesselName.sortBy { (it as VesselName).value } return allVesselName } |
f15a58907
|
163 |
private fun populateIMO(vessel: Vessel): ArrayList<MessageData?> { |
513c0341c
|
164 165 166 167 168 |
val allIMO: ArrayList<MessageData?> = vessel.getAllIMO() allIMO.sortBy { (it as IMO).value } return allIMO } |
f15a58907
|
169 |
private fun populateCallSign(vessel: Vessel): ArrayList<MessageData?> { |
513c0341c
|
170 171 172 173 174 |
val allCallSign: ArrayList<MessageData?> = vessel.getAllCallSign() allCallSign.sortBy { (it as CallSign).value } return allCallSign } |
f15a58907
|
175 |
private fun populateVesselType(vessel: Vessel): ArrayList<MessageData?> { |
513c0341c
|
176 177 178 179 180 |
val allVesselType: ArrayList<MessageData?> = vessel.getAllVesselType() allVesselType.sortBy { (it as VesselType).value } return allVesselType } |
f15a58907
|
181 |
private fun populateStatus(vessel: Vessel): ArrayList<MessageData?> { |
513c0341c
|
182 183 184 185 186 |
val allStatus: ArrayList<MessageData?> = vessel.getAllStatus() allStatus.sortBy { (it as Status).value } return allStatus } |
f15a58907
|
187 |
private fun populateLength(vessel: Vessel): ArrayList<MessageData?> { |
513c0341c
|
188 189 190 191 192 |
val allLength: ArrayList<MessageData?> = vessel.getAllLength() allLength.sortBy { (it as Length).value } return allLength } |
f15a58907
|
193 |
private fun populateWidth(vessel: Vessel): ArrayList<MessageData?> { |
513c0341c
|
194 195 196 197 198 |
val allWidth: ArrayList<MessageData?> = vessel.getAllWidth() allWidth.sortBy { (it as Width).value } return allWidth } |
f15a58907
|
199 |
private fun populateDraft(vessel: Vessel): ArrayList<MessageData?> { |
513c0341c
|
200 201 202 203 204 |
val allDraft: ArrayList<MessageData?> = vessel.getAllDraft() allDraft.sortBy { (it as Draft).value } return allDraft } |
f15a58907
|
205 |
private fun populateCargo(vessel: Vessel): ArrayList<MessageData?> { |
513c0341c
|
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
val allCargo: ArrayList<MessageData?> = vessel.getAllCargo() allCargo.sortBy { (it as Cargo).value } return allCargo } private fun populateDataList(vessel: Vessel) { val data = arrayListOf<Pair<String, ArrayList<MessageData?>>>() timeData = populateTime(vessel) data.add(Pair("Latitude", populateLatitude(vessel))) data.add(Pair("Longitude", populateLongitude(vessel))) data.add(Pair("Speed Over Ground", populateSpeedOverGround(vessel))) data.add(Pair("Course Over Ground", populateCourseOverGround(vessel))) data.add(Pair("Heading", populateHeading(vessel))) |
f15a58907
|
226 |
data.add(Pair("Vessel Name", populateVesselName(vessel))) |
513c0341c
|
227 |
|
f15a58907
|
228 |
data.add(Pair("IMO", populateIMO(vessel))) |
513c0341c
|
229 |
|
f15a58907
|
230 |
data.add(Pair("Call Sign", populateCallSign(vessel))) |
513c0341c
|
231 |
|
f15a58907
|
232 |
data.add(Pair("Vessel Type", populateVesselType(vessel))) |
513c0341c
|
233 |
|
f15a58907
|
234 |
data.add(Pair("Status", populateStatus(vessel))) |
513c0341c
|
235 |
|
f15a58907
|
236 |
data.add(Pair("Length", populateLength(vessel))) |
513c0341c
|
237 |
|
f15a58907
|
238 |
data.add(Pair("Width", populateWidth(vessel))) |
513c0341c
|
239 |
|
f15a58907
|
240 |
data.add(Pair("Draft", populateDraft(vessel))) |
513c0341c
|
241 |
|
f15a58907
|
242 |
data.add(Pair("Cargo", populateCargo(vessel))) |
513c0341c
|
243 244 245 246 247 248 249 250 251 252 253 |
dataList.addAll(data) } override fun onValueChanged(newValue: Vessel) { dataList.clear() populateDataList(newValue) } } |