MenuBarController.kt
4.04 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
package application.controller
import application.model.MapState.*
import application.model.createVesselCollection
import application.model.observableIsReplayState
import application.model.observableMapState
import application.model.observableVessel
import javafx.event.EventHandler
import javafx.fxml.FXML
import javafx.fxml.Initializable
import javafx.scene.control.*
import javafx.stage.FileChooser
import java.io.*
import java.net.URL
import java.util.*
class MenuBarController : Initializable {
@FXML
var menuBar: MenuBar = MenuBar()
@FXML
var import: MenuItem = MenuItem()
@FXML
var allMessages: CheckMenuItem = CheckMenuItem()
@FXML
var clusteredMessage: CheckMenuItem = CheckMenuItem()
@FXML
var heatMap: CheckMenuItem = CheckMenuItem()
@FXML
var activateTimeSliderButton: RadioMenuItem = RadioMenuItem()
override fun initialize(location: URL?, resources: ResourceBundle?) {
setOnActionImportButton()
setOnActionAllMessageButton()
setOnActionClusteredMessageButton()
setOnActionHeatMapButton()
setOnActionActivateReplayButton()
observableMapState.state = CLUSTERED_MESSAGES
allMessages.isSelected = false
clusteredMessage.isSelected = true
heatMap.isSelected = false
}
private fun setOnActionActivateReplayButton() {
activateTimeSliderButton.onAction = EventHandler {
observableIsReplayState.value = activateTimeSliderButton.isSelected
}
}
private fun setOnActionImportButton() {
import.onAction = EventHandler {
val fileChooser = FileChooser()
fileChooser.title = "Choose a file to import"
val window = menuBar.scene.window
val file = fileChooser.showOpenDialog(window)
try {
if (file.extension != "csv") {
val alert = Alert(Alert.AlertType.WARNING)
alert.title = "Warning Alert"
alert.headerText = "Wrong file format."
alert.contentText = "Please choose à .csv file."
alert.showAndWait()
}
observableVessel.vessels.clear()
if(toMuchVessel(file)){
observableVessel.vessels = mutableMapOf()
}else {
val vessels = createVesselCollection(file)
observableVessel.vessels = vessels
}
} catch (ignore: IllegalStateException) {
}
}
}
private fun toMuchVessel(file: File): Boolean {
val nbLine = file.readLines().size
if (nbLine > 50000) {
val alert = Alert(Alert.AlertType.CONFIRMATION)
alert.title = "Warning!!"
alert.headerText = "Warning: This file contain a lot of messages."
alert.contentText = "Are you sure you want to continue."
val buttonTypeYes = ButtonType("Yes")
val buttonTypeNo = ButtonType("No ")
alert.buttonTypes.setAll(buttonTypeYes, buttonTypeNo)
val result = alert.showAndWait()
return result.get() != buttonTypeYes
}
return false
}
private fun setOnActionAllMessageButton() {
allMessages.onAction = EventHandler {
observableMapState.state = ALL_MESSAGES
allMessages.isSelected = true
clusteredMessage.isSelected = false
heatMap.isSelected = false
}
}
private fun setOnActionClusteredMessageButton() {
clusteredMessage.onAction = EventHandler {
observableMapState.state = CLUSTERED_MESSAGES
heatMap.isSelected = false
allMessages.isSelected = false
clusteredMessage.isSelected = true
}
}
private fun setOnActionHeatMapButton() {
heatMap.onAction = EventHandler {
observableMapState.state = HEAT_MAP
heatMap.isSelected = true
clusteredMessage.isSelected = false
allMessages.isSelected = false
}
}
}