Commit b350f9dfe4c8f6b30a7b4500ec7b3eeb86644afd

Authored by lsagona
1 parent 2f45c53df1
Exists in master and in 1 other branch dev

import vessels and display it on a ListView

Showing 17 changed files with 211 additions and 78 deletions Side-by-side Diff

build.gradle View file @ b350f9d
... ... @@ -15,14 +15,6 @@
15 15 testCompile group: 'junit', name: 'junit', version: '4.12'
16 16 }
17 17  
18   -sourceSets {
19   - main {
20   - resources {
21   - srcDirs "src/main/resources"
22   - }
23   - }
24   -}
25   -
26 18 compileKotlin {
27 19 kotlinOptions.jvmTarget = "1.8"
28 20 }
src/main/kotlin/application/App.kt View file @ b350f9d
... ... @@ -11,18 +11,14 @@
11 11  
12 12 override fun start(primaryStage: Stage?) {
13 13  
14   - val fxmlLoader = FXMLLoader(App::class.java.getResource("/gui/mainApp.fxml"))
15 14  
16   - val parent: Parent = fxmlLoader.load()
17 15  
18   -// val controller: MainAppController = fxmlLoader.getController()
19   -
  16 + val fxmlLoader = FXMLLoader(App::class.java.getResource("/gui/windows.fxml"))
  17 + val parent: Parent = fxmlLoader.load()
20 18 val scene = Scene(parent)
21 19  
22 20 primaryStage!!.scene = scene
23 21 primaryStage.title = "Maritime Visualisation"
24   - primaryStage.width = 667.0
25   - primaryStage.height = 375.0
26 22 primaryStage.show()
27 23 }
28 24  
src/main/kotlin/application/controller/ControlPanelController.kt View file @ b350f9d
  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/MenuBarController.kt View file @ b350f9d
  1 +package application.controller
  2 +
  3 +import application.App
  4 +import application.model.createVesselCollection
  5 +import application.model.observableMessages
  6 +import javafx.event.EventHandler
  7 +import javafx.fxml.FXML
  8 +import javafx.fxml.FXMLLoader
  9 +import javafx.fxml.Initializable
  10 +import javafx.scene.Parent
  11 +import javafx.scene.control.MenuBar
  12 +import javafx.scene.control.MenuItem
  13 +import javafx.stage.FileChooser
  14 +import java.net.URL
  15 +import java.util.*
  16 +
  17 +class MenuBarController : Initializable {
  18 +
  19 + @FXML
  20 + var menuBar: MenuBar = MenuBar()
  21 +
  22 + @FXML
  23 + var import: MenuItem = MenuItem()
  24 +
  25 + override fun initialize(location: URL?, resources: ResourceBundle?) {
  26 +
  27 + import.onAction = EventHandler {
  28 + val fileChooser = FileChooser()
  29 + fileChooser.title = "Choose a file to import"
  30 + val window = menuBar.scene.window
  31 + val file = fileChooser.showOpenDialog(window)
  32 + val vessels = createVesselCollection(file)
  33 + observableMessages.vessels.clear()
  34 + observableMessages.vessels = vessels
  35 + }
  36 + }
  37 +}
src/main/kotlin/application/model/Context.kt View file @ b350f9d
  1 +package application.model
  2 +
  3 +val observableMessages : ObservableVessel = ObservableVessel()
src/main/kotlin/application/model/Message.kt View file @ b350f9d
  1 +package application.model
  2 +
  3 +import java.time.LocalDateTime
  4 +
  5 +class Message(split: List<String>) {
  6 + val mmsi: Int? = split[0].toIntOrNull()
  7 + val time: LocalDateTime = LocalDateTime.parse(split[1])
  8 + val latitude: Double? = split[2].toDoubleOrNull()
  9 + val longitude: Double? = split[3].toDoubleOrNull()
  10 + val speedOverGround: Double? = split[4].toDoubleOrNull()
  11 + val courseOverGround: Double? = split[5].toDoubleOrNull()
  12 + val heading: Int? = split[6].toIntOrNull()
  13 + val vesselName: String? = split[7]
  14 + val imo: String? = split[8]
  15 + val callSign: String? = split[9]
  16 + val vesselType: Int? = split[10].toIntOrNull()
  17 + val status: String? = split[11]
  18 + val length: Double? = split[12].toDoubleOrNull()
  19 + val width: Double? = split[13].toDoubleOrNull()
  20 + val draft: Double? = split[14].toDoubleOrNull()
  21 + val cargo: Int? = split[15].toIntOrNull()
  22 +
  23 +}
src/main/kotlin/application/model/MessageListener.kt View file @ b350f9d
  1 +package application.model
  2 +
  3 +interface MessageListener {
  4 + fun onValueChanged(newValue: MutableMap<Int?, Vessel>)
  5 +}
src/main/kotlin/application/model/ObservableVessel.kt View file @ b350f9d
  1 +package application.model
  2 +
  3 +import kotlin.properties.Delegates
  4 +
  5 +class ObservableVessel {
  6 + val listeners: MutableList<MessageListener> = mutableListOf()
  7 +
  8 + var vessels: MutableMap<Int?, Vessel> by Delegates.observable(
  9 + initialValue = mutableMapOf(),
  10 + onChange = {
  11 + _, _, new ->
  12 + run {
  13 + listeners.forEach {
  14 + it.onValueChanged(new)
  15 + }
  16 + }
  17 + }
  18 + )
  19 +
  20 +}
src/main/kotlin/application/model/Vessel.kt View file @ b350f9d
  1 +package application.model
  2 +
  3 +import java.time.LocalDateTime
  4 +
  5 +
  6 +class Vessel() {
  7 + val messages: MutableMap<LocalDateTime, Message> = mutableMapOf()
  8 +}
src/main/kotlin/application/model/VesselGenerator.kt View file @ b350f9d
  1 +package application.model
  2 +
  3 +import java.io.File
  4 +
  5 +fun createVesselCollection(file: File) : MutableMap<Int?, Vessel> {
  6 + val messages : ArrayList<Message> = arrayListOf()
  7 + val vessels: MutableMap<Int?, Vessel> = mutableMapOf()
  8 +
  9 + file.forEachLine {
  10 + val arrayMessage = it.split(",")
  11 + if (arrayMessage[0].toIntOrNull() !== null) {
  12 + val message = Message(arrayMessage)
  13 + messages.add(message)
  14 + if (!vessels.containsKey(message.mmsi)){
  15 + vessels[message.mmsi] = Vessel()
  16 + }
  17 + vessels[message.mmsi]?.messages?.set(message.time, message)
  18 + }
  19 +
  20 + }
  21 +
  22 + return vessels
  23 +}
src/main/kotlin/application/ui/MenuBar.kt View file @ b350f9d
1   -package application.ui
2   -
3   -import javafx.fxml.FXML
4   -
5   -class MenuBar {
6   -
7   - @FXML
8   - fun initialize() {
9   - }
10   -
11   -}
src/main/kotlin/application/ui/ShipList.kt View file @ b350f9d
1   -package application.ui
2   -
3   -class ShipList {
4   -}
src/main/resources/gui/controlPanel.fxml View file @ b350f9d
  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/mainApp.fxml View file @ b350f9d
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -
3   -
4   -<?import javafx.scene.control.ListView?>
5   -<?import javafx.scene.control.SplitPane?>
6   -<?import javafx.scene.layout.*?>
7   -<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
8   - prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.241" xmlns:fx="http://javafx.com/fxml/1">
9   - <children>
10   - <fx:include source="menuBar.fxml" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
11   - AnchorPane.topAnchor="0.0"/>
12   - <SplitPane dividerPositions="0.29797979797979796" layoutY="25.0" prefHeight="379.0" prefWidth="594.0"
13   - AnchorPane.bottomAnchor="-4.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="6.0"
14   - AnchorPane.topAnchor="25.0">
15   - <items>
16   - <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
17   - <children>
18   - <fx:include source="shipList.fxml" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
19   - AnchorPane.topAnchor="0.0"/>
20   - </children>
21   - </AnchorPane>
22   - <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
23   - <children>
24   - <SplitPane dividerPositions="0.5" layoutX="127.0" layoutY="74.0" orientation="VERTICAL"
25   - prefHeight="200.0" prefWidth="160.0" AnchorPane.bottomAnchor="0.0"
26   - AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
27   - <items>
28   - <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0"/>
29   - <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0"/>
30   - </items>
31   - </SplitPane>
32   - </children>
33   - </AnchorPane>
34   - </items>
35   - </SplitPane>
36   - </children>
37   -</AnchorPane>
src/main/resources/gui/menuBar.fxml View file @ b350f9d
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2  
3   -<?import javafx.scene.control.MenuBar?>
4   -<?import javafx.scene.control.Menu?>
5   -<?import javafx.scene.control.MenuItem?>
6   -<MenuBar prefHeight="25.0" prefWidth="600.0" fx:controller="application.ui.MenuBar" xmlns="http://javafx.com/javafx/8.0.241" xmlns:fx="http://javafx.com/fxml/1">
  3 +<?import javafx.scene.control.*?>
  4 +<MenuBar prefHeight="25.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.2-internal"
  5 + xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.controller.MenuBarController" fx:id="menuBar">
7 6 <menus>
8 7 <Menu mnemonicParsing="false" text="File">
9 8 <items>
10   - <MenuItem mnemonicParsing="false" text="Close"/>
  9 + <MenuItem fx:id="import" mnemonicParsing="false" text="Import"/>
11 10 </items>
12 11 </Menu>
13 12 <Menu mnemonicParsing="false" text="Edit">
src/main/resources/gui/shipList.fxml View file @ b350f9d
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -
3   -<?import javafx.scene.control.ListView?>
4   -<?import javafx.scene.layout.AnchorPane?>
5   -<ListView prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0"
6   - AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"
7   - fx:controller="application.ui.ShipList" xmlns="http://javafx.com/javafx/8.0.241" xmlns:fx="http://javafx.com/fxml/1"/>
src/main/resources/gui/windows.fxml View file @ b350f9d
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +
  3 +
  4 +<?import javafx.scene.control.SplitPane?>
  5 +<?import javafx.scene.layout.*?>
  6 +<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="900.0"
  7 + prefWidth="1200.0" xmlns="http://javafx.com/javafx/8.0.241" xmlns:fx="http://javafx.com/fxml/1">
  8 + <children>
  9 + <fx:include source="menuBar.fxml" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
  10 + AnchorPane.topAnchor="0.0"/>
  11 + <SplitPane dividerPositions="0.29797979797979796" layoutY="25.0" prefHeight="379.0" prefWidth="594.0"
  12 + AnchorPane.bottomAnchor="-4.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="6.0"
  13 + AnchorPane.topAnchor="25.0">
  14 + <items>
  15 + <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
  16 + <children>
  17 + <fx:include source="controlPanel.fxml" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
  18 + AnchorPane.topAnchor="0.0"/>
  19 + </children>
  20 + </AnchorPane>
  21 + <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
  22 + <children>
  23 + <SplitPane dividerPositions="0.5" layoutX="127.0" layoutY="74.0" orientation="VERTICAL"
  24 + prefHeight="200.0" prefWidth="160.0" AnchorPane.bottomAnchor="0.0"
  25 + AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
  26 + <items>
  27 + <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0"/>
  28 + <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0"/>
  29 + </items>
  30 + </SplitPane>
  31 + </children>
  32 + </AnchorPane>
  33 + </items>
  34 + </SplitPane>
  35 + </children>
  36 +</AnchorPane>