Commit b350f9dfe4c8f6b30a7b4500ec7b3eeb86644afd
1 parent
2f45c53df1
Exists in
master
and in
1 other branch
import vessels and display it on a ListView
Showing 17 changed files with 211 additions and 78 deletions Inline Diff
- build.gradle
- src/main/kotlin/application/App.kt
- src/main/kotlin/application/controller/ControlPanelController.kt
- src/main/kotlin/application/controller/MenuBarController.kt
- src/main/kotlin/application/model/Context.kt
- src/main/kotlin/application/model/Message.kt
- src/main/kotlin/application/model/MessageListener.kt
- src/main/kotlin/application/model/ObservableVessel.kt
- src/main/kotlin/application/model/Vessel.kt
- src/main/kotlin/application/model/VesselGenerator.kt
- src/main/kotlin/application/ui/MenuBar.kt
- src/main/kotlin/application/ui/ShipList.kt
- src/main/resources/gui/controlPanel.fxml
- src/main/resources/gui/mainApp.fxml
- src/main/resources/gui/menuBar.fxml
- src/main/resources/gui/shipList.fxml
- src/main/resources/gui/windows.fxml
build.gradle
View file @
b350f9d
plugins { | 1 | 1 | plugins { | |
id 'java' | 2 | 2 | id 'java' | |
id 'org.jetbrains.kotlin.jvm' version '1.3.72' | 3 | 3 | id 'org.jetbrains.kotlin.jvm' version '1.3.72' | |
} | 4 | 4 | } | |
5 | 5 | |||
group 'marivisu' | 6 | 6 | group 'marivisu' | |
version '1.0-SNAPSHOT' | 7 | 7 | version '1.0-SNAPSHOT' | |
8 | 8 | |||
repositories { | 9 | 9 | repositories { | |
mavenCentral() | 10 | 10 | mavenCentral() | |
} | 11 | 11 | } | |
12 | 12 | |||
dependencies { | 13 | 13 | dependencies { | |
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" | 14 | 14 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" | |
testCompile group: 'junit', name: 'junit', version: '4.12' | 15 | 15 | testCompile group: 'junit', name: 'junit', version: '4.12' | |
} | 16 | 16 | } | |
17 | 17 | |||
sourceSets { | 18 | |||
main { | 19 | |||
resources { | 20 | |||
srcDirs "src/main/resources" | 21 | |||
} | 22 | |||
} | 23 | |||
} | 24 | |||
25 | ||||
compileKotlin { | 26 | 18 | compileKotlin { |
src/main/kotlin/application/App.kt
View file @
b350f9d
package application | 1 | 1 | package application | |
2 | 2 | |||
import javafx.application.Application | 3 | 3 | import javafx.application.Application | |
import javafx.fxml.FXMLLoader | 4 | 4 | import javafx.fxml.FXMLLoader | |
import javafx.scene.Parent | 5 | 5 | import javafx.scene.Parent | |
import javafx.scene.Scene | 6 | 6 | import javafx.scene.Scene | |
import javafx.stage.Stage | 7 | 7 | import javafx.stage.Stage | |
8 | 8 | |||
class App : Application() { | 9 | 9 | class App : Application() { | |
10 | 10 | |||
11 | 11 | |||
override fun start(primaryStage: Stage?) { | 12 | 12 | override fun start(primaryStage: Stage?) { | |
13 | 13 | |||
val fxmlLoader = FXMLLoader(App::class.java.getResource("/gui/mainApp.fxml")) | 14 | |||
15 | 14 | |||
val parent: Parent = fxmlLoader.load() | 16 | |||
17 | 15 | |||
// val controller: MainAppController = fxmlLoader.getController() | 18 | 16 | val fxmlLoader = FXMLLoader(App::class.java.getResource("/gui/windows.fxml")) | |
19 | 17 | val parent: Parent = fxmlLoader.load() | ||
val scene = Scene(parent) | 20 | 18 | val scene = Scene(parent) | |
21 | 19 | |||
primaryStage!!.scene = scene | 22 | 20 | primaryStage!!.scene = scene | |
primaryStage.title = "Maritime Visualisation" | 23 | 21 | primaryStage.title = "Maritime Visualisation" | |
primaryStage.width = 667.0 | 24 | |||
primaryStage.height = 375.0 | 25 | |||
primaryStage.show() | 26 | 22 | primaryStage.show() | |
} | 27 | 23 | } |
src/main/kotlin/application/controller/ControlPanelController.kt
View file @
b350f9d
File was created | 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 | } |
src/main/kotlin/application/controller/MenuBarController.kt
View file @
b350f9d
File was created | 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) |
src/main/kotlin/application/model/Context.kt
View file @
b350f9d
File was created | 1 | package application.model | ||
2 |
src/main/kotlin/application/model/Message.kt
View file @
b350f9d
File was created | 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() |
src/main/kotlin/application/model/MessageListener.kt
View file @
b350f9d
File was created | 1 | package application.model | ||
2 | ||||
3 | interface MessageListener { | |||
4 | fun onValueChanged(newValue: MutableMap<Int?, Vessel>) |
src/main/kotlin/application/model/ObservableVessel.kt
View file @
b350f9d
File was created | 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 | } |
src/main/kotlin/application/model/Vessel.kt
View file @
b350f9d
File was created | 1 | package application.model | ||
2 | ||||
3 | import java.time.LocalDateTime | |||
4 | ||||
5 |
src/main/kotlin/application/model/VesselGenerator.kt
View file @
b350f9d
File was created | 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 | } |
src/main/kotlin/application/ui/MenuBar.kt
View file @
b350f9d
package application.ui | 1 | File was deleted | ||
2 | ||||
import javafx.fxml.FXML | 3 | |||
4 | ||||
class MenuBar { | 5 | |||
6 | ||||
@FXML | 7 |
src/main/kotlin/application/ui/ShipList.kt
View file @
b350f9d
package application.ui | 1 | File was deleted | ||
2 | ||||
class ShipList { | 3 |
src/main/resources/gui/controlPanel.fxml
View file @
b350f9d
File was created | 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> |
src/main/resources/gui/mainApp.fxml
View file @
b350f9d
<?xml version="1.0" encoding="UTF-8"?> | 1 | File was deleted | ||
2 | ||||
3 | ||||
<?import javafx.scene.control.ListView?> | 4 | |||
<?import javafx.scene.control.SplitPane?> | 5 | |||
<?import javafx.scene.layout.*?> | 6 | |||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" | 7 | |||
prefWidth="600.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="shipList.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 |
src/main/resources/gui/menuBar.fxml
View file @
b350f9d
<?xml version="1.0" encoding="UTF-8"?> | 1 | 1 | <?xml version="1.0" encoding="UTF-8"?> | |
2 | 2 | |||
<?import javafx.scene.control.MenuBar?> | 3 | 3 | <?import javafx.scene.control.*?> | |
<?import javafx.scene.control.Menu?> | 4 | 4 | <MenuBar prefHeight="25.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.2-internal" | |
<?import javafx.scene.control.MenuItem?> | 5 | 5 | xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.controller.MenuBarController" fx:id="menuBar"> | |
<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"> | 6 | |||
<menus> | 7 | 6 | <menus> | |
<Menu mnemonicParsing="false" text="File"> | 8 | 7 | <Menu mnemonicParsing="false" text="File"> | |
<items> | 9 | 8 | <items> | |
<MenuItem mnemonicParsing="false" text="Close"/> | 10 | 9 | <MenuItem fx:id="import" mnemonicParsing="false" text="Import"/> | |
</items> | 11 | 10 | </items> | |
</Menu> | 12 | 11 | </Menu> | |
<Menu mnemonicParsing="false" text="Edit"> | 13 | 12 | <Menu mnemonicParsing="false" text="Edit"> | |
<items> | 14 | 13 | <items> | |
<MenuItem mnemonicParsing="false" text="Delete"/> | 15 | 14 | <MenuItem mnemonicParsing="false" text="Delete"/> | |
</items> | 16 | 15 | </items> | |
</Menu> | 17 | 16 | </Menu> | |
<Menu mnemonicParsing="false" text="Help"> | 18 | 17 | <Menu mnemonicParsing="false" text="Help"> | |
<items> | 19 | 18 | <items> | |
<MenuItem mnemonicParsing="false" text="About"/> | 20 | 19 | <MenuItem mnemonicParsing="false" text="About"/> | |
</items> | 21 | 20 | </items> | |
</Menu> | 22 | 21 | </Menu> | |
</menus> | 23 | 22 | </menus> | |
</MenuBar> | 24 | 23 | </MenuBar> | |
25 | 24 | |||
src/main/resources/gui/shipList.fxml
View file @
b350f9d
<?xml version="1.0" encoding="UTF-8"?> | 1 | File was deleted | ||
2 | ||||
<?import javafx.scene.control.ListView?> | 3 | |||
<?import javafx.scene.layout.AnchorPane?> | 4 | |||
<ListView prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" | 5 | |||
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" | 6 |
src/main/resources/gui/windows.fxml
View file @
b350f9d
File was created | 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> |