Blame view

src/main/kotlin/application/controller/DataPanelController.kt 11.1 KB
513c0341c   lsagona   add chart
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   lsagona   add chart
8
9
  import javafx.scene.control.ListCell
  import javafx.scene.control.ListView
f15a58907   lsagona   add better chart
10
11
12
13
14
15
16
17
18
  import javafx.scene.layout.StackPane
  import org.charts.dataviewer.api.config.DataViewerConfiguration
  import org.charts.dataviewer.api.data.PlotData
  import org.charts.dataviewer.api.trace.LineTrace
  import org.charts.dataviewer.api.trace.ScatterTrace
  import org.charts.dataviewer.javafx.JavaFxDataViewer
  import org.charts.dataviewer.utils.TraceColour
  import org.charts.dataviewer.utils.TraceMode
  import org.charts.dataviewer.utils.TraceVisibility
513c0341c   lsagona   add chart
19
20
21
22
23
24
25
  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   lsagona   add chart
26
27
  
      @FXML
f15a58907   lsagona   add better chart
28
      var dataListView = ListView<Pair<String, ArrayList<MessageData?>>>()
513c0341c   lsagona   add chart
29

f15a58907   lsagona   add better chart
30
31
  //    @FXML
  //    var stackPanePlot = StackPane()
513c0341c   lsagona   add chart
32
33
  
      @FXML
f15a58907   lsagona   add better chart
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
      var dataViewer = JavaFxDataViewer()
  
  //    @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>
513c0341c   lsagona   add chart
53
54
  
      override fun initialize(location: URL?, resources: ResourceBundle?) {
f15a58907   lsagona   add better chart
55
56
57
58
  //        xaxisNumber.animated = false
  //        yaxisNumber.animated = false
  //        xaxisCategory.animated = false
  //        yaxisCategory.animated = false
513c0341c   lsagona   add chart
59
60
          setObservableSelectedVesselListener()
          dataListView.items = dataList
f15a58907   lsagona   add better chart
61
62
63
64
65
          val plotData = PlotData()
          plotData.addTrace(createScatterTrace())
          val config = DataViewerConfiguration()
          config.showLegend(true)
          config.setLegendInsidePlot(false)
513c0341c   lsagona   add chart
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  
          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   lsagona   add better chart
81
82
83
84
85
              if (newValue == null) {
                  plotData.allTraces.clear()
                  config.setxAxisTitle("")
                  config.setyAxisTitle("")
                  dataViewer.resetPlot()
513c0341c   lsagona   add chart
86
87
                  return@addListener
              }
513c0341c   lsagona   add chart
88
89
90
  
              val getValueVisitorX = GetValueVisitor()
              val getValueVisitorY = GetValueVisitor()
f15a58907   lsagona   add better chart
91
92
93
94
              val arrayListStringX = arrayListOf<String>()
              val arrayListDoubleX = arrayListOf<Double>()
              val arrayListStringY = arrayListOf<String>()
              val arrayListDoubleY = arrayListOf<Double>()
513c0341c   lsagona   add chart
95

f15a58907   lsagona   add better chart
96
              for (x in 0 until newValue.second.size) {
513c0341c   lsagona   add chart
97
98
                  timeData[x]?.accept(getValueVisitorX)
                  newValue.second[x]?.accept(getValueVisitorY)
f15a58907   lsagona   add better chart
99
100
101
102
103
104
                  if (getValueVisitorY.value.toDoubleOrNull() == null) {
                      arrayListStringX.add(getValueVisitorX.value)
                      arrayListStringY.add(getValueVisitorY.value)
                  } else {
                      arrayListStringX.add(getValueVisitorX.value)
                      arrayListDoubleY.add(getValueVisitorY.value.toDouble())
513c0341c   lsagona   add chart
105
                  }
513c0341c   lsagona   add chart
106
              }
f15a58907   lsagona   add better chart
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
              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   lsagona   add chart
122
              }
f15a58907   lsagona   add better chart
123
124
125
126
127
128
129
              config.setxAxisTitle("Date")
              config.setyAxisTitle(newValue.first)
              dataViewer.resetPlot()
              plotData.allTraces.clear()
              plotData.addTrace(scatterTrace)
              dataViewer.updateConfiguration(config)
              dataViewer.updatePlot(plotData)
513c0341c   lsagona   add chart
130
          }
f15a58907   lsagona   add better chart
131
132
133
134
135
136
137
138
139
          plotData.allTraces.clear()
  //        plotData.addTrace(createScatterTrace())
          config.setxAxisTitle("")
          config.setyAxisTitle("")
          config.plotTitle = "No data selected"
          dataViewer.updateConfiguration(config)
          dataViewer.updatePlot(plotData)
  
  //        stackPanePlot.children.add(dataViewer)
513c0341c   lsagona   add chart
140
      }
f15a58907   lsagona   add better chart
141
142
143
144
145
146
147
148
      private fun createScatterTrace(): ScatterTrace<*>? {
          val scatterTrace = ScatterTrace<Any>()
          scatterTrace.setxArray(arrayOf("asdf", "fdsa", "asdfffe", "asdfe", "asfee3"))
          scatterTrace.setyArray(arrayOf("pppp", "koojoi", "pp", "ii", "rty", "ert"))
          scatterTrace.traceName = "MyScatterTrace"
          scatterTrace.traceColour = TraceColour.PURPLE
          scatterTrace.traceMode = TraceMode.MARKERS
          return scatterTrace
513c0341c   lsagona   add chart
149
      }
f15a58907   lsagona   add better chart
150
151
152
153
154
155
156
      fun createLineTrace(): LineTrace<*>? {
          val lineTrace = LineTrace<Any>()
          lineTrace.setxArray(arrayOf("asdf", "fdsa", "asdfffe", "asdfe", "asfee3"))
          lineTrace.setyArray(arrayOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0))
          lineTrace.traceName = "MyLineTrace"
          lineTrace.traceColour = TraceColour.PURPLE
          return lineTrace
513c0341c   lsagona   add chart
157
      }
f15a58907   lsagona   add better chart
158
159
160
161
162
163
164
165
166
  //    private fun setChartCategoryVisible() {
  //        scatterChartCategory.isVisible = true
  //        scatterChartNumber.isVisible = false
  //    }
  //
  //    private fun setChartNumberVisible() {
  //        scatterChartCategory.isVisible = false
  //        scatterChartNumber.isVisible = true
  //    }
513c0341c   lsagona   add chart
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
      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   lsagona   add better chart
212
      private fun populateVesselName(vessel: Vessel): ArrayList<MessageData?> {
513c0341c   lsagona   add chart
213
214
215
216
217
          val allVesselName: ArrayList<MessageData?> = vessel.getAllVesselName()
          allVesselName.sortBy { (it as VesselName).value }
  
          return allVesselName
      }
f15a58907   lsagona   add better chart
218
      private fun populateIMO(vessel: Vessel): ArrayList<MessageData?> {
513c0341c   lsagona   add chart
219
220
221
222
223
          val allIMO: ArrayList<MessageData?> = vessel.getAllIMO()
          allIMO.sortBy { (it as IMO).value }
  
          return allIMO
      }
f15a58907   lsagona   add better chart
224
      private fun populateCallSign(vessel: Vessel): ArrayList<MessageData?> {
513c0341c   lsagona   add chart
225
226
227
228
229
          val allCallSign: ArrayList<MessageData?> = vessel.getAllCallSign()
          allCallSign.sortBy { (it as CallSign).value }
  
          return allCallSign
      }
f15a58907   lsagona   add better chart
230
      private fun populateVesselType(vessel: Vessel): ArrayList<MessageData?> {
513c0341c   lsagona   add chart
231
232
233
234
235
          val allVesselType: ArrayList<MessageData?> = vessel.getAllVesselType()
          allVesselType.sortBy { (it as VesselType).value }
  
          return allVesselType
      }
f15a58907   lsagona   add better chart
236
      private fun populateStatus(vessel: Vessel): ArrayList<MessageData?> {
513c0341c   lsagona   add chart
237
238
239
240
241
          val allStatus: ArrayList<MessageData?> = vessel.getAllStatus()
          allStatus.sortBy { (it as Status).value }
  
          return allStatus
      }
f15a58907   lsagona   add better chart
242
      private fun populateLength(vessel: Vessel): ArrayList<MessageData?> {
513c0341c   lsagona   add chart
243
244
245
246
247
          val allLength: ArrayList<MessageData?> = vessel.getAllLength()
          allLength.sortBy { (it as Length).value }
  
          return allLength
      }
f15a58907   lsagona   add better chart
248
      private fun populateWidth(vessel: Vessel): ArrayList<MessageData?> {
513c0341c   lsagona   add chart
249
250
251
252
253
          val allWidth: ArrayList<MessageData?> = vessel.getAllWidth()
          allWidth.sortBy { (it as Width).value }
  
          return allWidth
      }
f15a58907   lsagona   add better chart
254
      private fun populateDraft(vessel: Vessel): ArrayList<MessageData?> {
513c0341c   lsagona   add chart
255
256
257
258
259
          val allDraft: ArrayList<MessageData?> = vessel.getAllDraft()
          allDraft.sortBy { (it as Draft).value }
  
          return allDraft
      }
f15a58907   lsagona   add better chart
260
      private fun populateCargo(vessel: Vessel): ArrayList<MessageData?> {
513c0341c   lsagona   add chart
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
          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   lsagona   add better chart
281
          data.add(Pair("Vessel Name", populateVesselName(vessel)))
513c0341c   lsagona   add chart
282

f15a58907   lsagona   add better chart
283
          data.add(Pair("IMO", populateIMO(vessel)))
513c0341c   lsagona   add chart
284

f15a58907   lsagona   add better chart
285
          data.add(Pair("Call Sign", populateCallSign(vessel)))
513c0341c   lsagona   add chart
286

f15a58907   lsagona   add better chart
287
          data.add(Pair("Vessel Type", populateVesselType(vessel)))
513c0341c   lsagona   add chart
288

f15a58907   lsagona   add better chart
289
          data.add(Pair("Status", populateStatus(vessel)))
513c0341c   lsagona   add chart
290

f15a58907   lsagona   add better chart
291
          data.add(Pair("Length", populateLength(vessel)))
513c0341c   lsagona   add chart
292

f15a58907   lsagona   add better chart
293
          data.add(Pair("Width", populateWidth(vessel)))
513c0341c   lsagona   add chart
294

f15a58907   lsagona   add better chart
295
          data.add(Pair("Draft", populateDraft(vessel)))
513c0341c   lsagona   add chart
296

f15a58907   lsagona   add better chart
297
          data.add(Pair("Cargo", populateCargo(vessel)))
513c0341c   lsagona   add chart
298
299
300
301
302
303
304
305
306
307
308
  
          dataList.addAll(data)
      }
  
      override fun onValueChanged(newValue: Vessel) {
          dataList.clear()
          populateDataList(newValue)
  
      }
  
  }