DataPanelController.kt
8.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
package application.controller
import application.model.*
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.fxml.FXML
import javafx.fxml.Initializable
import javafx.scene.chart.CategoryAxis
import javafx.scene.chart.NumberAxis
import javafx.scene.chart.ScatterChart
import javafx.scene.chart.XYChart.Data
import javafx.scene.chart.XYChart.Series
import javafx.scene.control.ListCell
import javafx.scene.control.ListView
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?>
@FXML
var dataListView = ListView<Pair<String, ArrayList<MessageData?>>>()
@FXML
var xaxisNumber: CategoryAxis = CategoryAxis()
@FXML
var yaxisNumber: NumberAxis = NumberAxis()
@FXML
lateinit var scatterChartNumber: ScatterChart<String, Number>
@FXML
var xaxisCategory: CategoryAxis = CategoryAxis()
@FXML
var yaxisCategory: CategoryAxis = CategoryAxis()
@FXML
lateinit var scatterChartCategory: ScatterChart<String, String>
override fun initialize(location: URL?, resources: ResourceBundle?) {
xaxisNumber.animated = false
yaxisNumber.animated = false
xaxisCategory.animated = false
yaxisCategory.animated = false
setObservableSelectedVesselListener()
dataListView.items = dataList
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 ->
if (newValue == null){
scatterChartCategory.data.clear()
scatterChartNumber.data.clear()
return@addListener
}
val serieNumber = Series<String, Number>()
val serieString = Series<String, String>()
val getValueVisitorX = GetValueVisitor()
val getValueVisitorY = GetValueVisitor()
for (x in 0 until newValue?.second?.size!!) {
timeData[x]?.accept(getValueVisitorX)
newValue.second[x]?.accept(getValueVisitorY)
if (getValueVisitorY.value.toDoubleOrNull() == null){
serieString.data.add(Data<String, String>(getValueVisitorX.value, getValueVisitorY.value))
} else{
serieNumber.data.add(Data<String, Number>(getValueVisitorX.value, getValueVisitorY.value.toDouble()))
}
}
scatterChartNumber.data.clear()
scatterChartCategory.data.clear()
if (getValueVisitorY.value.toDoubleOrNull() == null){
serieString.data.add(Data<String, String>(getValueVisitorX.value, getValueVisitorY.value))
scatterChartCategory.data.addAll(serieString)
setChartCategoryVisible()
xaxisCategory.label = "Date"
yaxisCategory.label = newValue.first
} else{
serieNumber.data.add(Data<String, Number>(getValueVisitorX.value, getValueVisitorY.value.toDouble()))
scatterChartNumber.data.addAll(serieNumber)
setChartNumberVisible()
xaxisNumber.label = "Date"
yaxisNumber.label = newValue.first
}
}
}
private fun setChartCategoryVisible(){
scatterChartCategory.isVisible = true
scatterChartNumber.isVisible = false
}
private fun setChartNumberVisible(){
scatterChartCategory.isVisible = false
scatterChartNumber.isVisible = true
}
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
}
private fun populatVesselName(vessel: Vessel): ArrayList<MessageData?> {
val allVesselName: ArrayList<MessageData?> = vessel.getAllVesselName()
allVesselName.sortBy { (it as VesselName).value }
return allVesselName
}
private fun populatIMO(vessel: Vessel): ArrayList<MessageData?> {
val allIMO: ArrayList<MessageData?> = vessel.getAllIMO()
allIMO.sortBy { (it as IMO).value }
return allIMO
}
private fun populatCallSign(vessel: Vessel): ArrayList<MessageData?> {
val allCallSign: ArrayList<MessageData?> = vessel.getAllCallSign()
allCallSign.sortBy { (it as CallSign).value }
return allCallSign
}
private fun populatVesselType(vessel: Vessel): ArrayList<MessageData?> {
val allVesselType: ArrayList<MessageData?> = vessel.getAllVesselType()
allVesselType.sortBy { (it as VesselType).value }
return allVesselType
}
private fun populatStatus(vessel: Vessel): ArrayList<MessageData?> {
val allStatus: ArrayList<MessageData?> = vessel.getAllStatus()
allStatus.sortBy { (it as Status).value }
return allStatus
}
private fun populatLength(vessel: Vessel): ArrayList<MessageData?> {
val allLength: ArrayList<MessageData?> = vessel.getAllLength()
allLength.sortBy { (it as Length).value }
return allLength
}
private fun populatWidth(vessel: Vessel): ArrayList<MessageData?> {
val allWidth: ArrayList<MessageData?> = vessel.getAllWidth()
allWidth.sortBy { (it as Width).value }
return allWidth
}
private fun populatDraft(vessel: Vessel): ArrayList<MessageData?> {
val allDraft: ArrayList<MessageData?> = vessel.getAllDraft()
allDraft.sortBy { (it as Draft).value }
return allDraft
}
private fun populatCargo(vessel: Vessel): ArrayList<MessageData?> {
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)))
data.add(Pair("Vessel Name", populatVesselName(vessel)))
data.add(Pair("IMO", populatIMO(vessel)))
data.add(Pair("Call Sign", populatCallSign(vessel)))
data.add(Pair("Vessel Type", populatVesselType(vessel)))
data.add(Pair("Status", populatStatus(vessel)))
data.add(Pair("Length", populatLength(vessel)))
data.add(Pair("Width", populatWidth(vessel)))
data.add(Pair("Draft", populatDraft(vessel)))
data.add(Pair("Cargo", populatCargo(vessel)))
dataList.addAll(data)
}
override fun onValueChanged(newValue: Vessel) {
dataList.clear()
populateDataList(newValue)
}
}