Blame view
src/main/kotlin/application/controller/MenuBarController.kt
4.03 KB
b350f9dfe import vessels an... |
1 |
package application.controller |
3b26be8f9 controle the time... |
2 |
import application.model.MapState.* |
b350f9dfe import vessels an... |
3 |
import application.model.createVesselCollection |
dd1ce7fe8 add button to swi... |
4 |
import application.model.observableIsReplayState |
3b26be8f9 controle the time... |
5 |
import application.model.observableMapState |
2bbe36a1b addd the possibil... |
6 |
import application.model.observableVessel |
b350f9dfe import vessels an... |
7 8 |
import javafx.event.EventHandler import javafx.fxml.FXML |
b350f9dfe import vessels an... |
9 |
import javafx.fxml.Initializable |
dd1ce7fe8 add button to swi... |
10 |
import javafx.scene.control.* |
b350f9dfe import vessels an... |
11 |
import javafx.stage.FileChooser |
6b2760a45 add warning messa... |
12 |
import java.io.* |
b350f9dfe import vessels an... |
13 14 |
import java.net.URL import java.util.* |
6b2760a45 add warning messa... |
15 |
|
b350f9dfe import vessels an... |
16 17 18 19 20 21 22 |
class MenuBarController : Initializable { @FXML var menuBar: MenuBar = MenuBar() @FXML var import: MenuItem = MenuItem() |
9e952e84e add message clust... |
23 24 25 26 27 28 29 30 |
@FXML var allMessages: CheckMenuItem = CheckMenuItem() @FXML var clusteredMessage: CheckMenuItem = CheckMenuItem() @FXML var heatMap: CheckMenuItem = CheckMenuItem() |
dd1ce7fe8 add button to swi... |
31 32 |
@FXML var activateReplayButton: RadioMenuItem = RadioMenuItem() |
b350f9dfe import vessels an... |
33 |
override fun initialize(location: URL?, resources: ResourceBundle?) { |
9e952e84e add message clust... |
34 35 36 37 38 |
setOnActionImportButton() setOnActionAllMessageButton() setOnActionClusteredMessageButton() setOnActionHeatMapButton() |
dd1ce7fe8 add button to swi... |
39 |
setOnActionActivateReplayButton() |
3b26be8f9 controle the time... |
40 |
observableMapState.state = CLUSTERED_MESSAGES |
79b001037 heat map |
41 |
allMessages.isSelected = false |
9e952e84e add message clust... |
42 |
clusteredMessage.isSelected = true |
79b001037 heat map |
43 |
heatMap.isSelected = false |
9e952e84e add message clust... |
44 45 |
} |
dd1ce7fe8 add button to swi... |
46 47 48 49 50 |
private fun setOnActionActivateReplayButton() { activateReplayButton.onAction = EventHandler { observableIsReplayState.value = activateReplayButton.isSelected } } |
9e952e84e add message clust... |
51 |
private fun setOnActionImportButton() { |
b350f9dfe import vessels an... |
52 53 54 55 56 |
import.onAction = EventHandler { val fileChooser = FileChooser() fileChooser.title = "Choose a file to import" val window = menuBar.scene.window val file = fileChooser.showOpenDialog(window) |
6b2760a45 add warning messa... |
57 |
|
79b001037 heat map |
58 |
try { |
07bf03cd8 add alert message... |
59 60 61 62 63 64 65 |
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() } |
79b001037 heat map |
66 |
observableVessel.vessels.clear() |
6b2760a45 add warning messa... |
67 68 69 70 71 72 |
if(toMuchVessel(file)){ observableVessel.vessels = mutableMapOf() }else { val vessels = createVesselCollection(file) observableVessel.vessels = vessels } |
07bf03cd8 add alert message... |
73 |
} catch (ignore: IllegalStateException) { |
79b001037 heat map |
74 75 |
} |
b350f9dfe import vessels an... |
76 77 |
} } |
9e952e84e add message clust... |
78 |
|
6b2760a45 add warning messa... |
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
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 } |
9e952e84e add message clust... |
95 96 |
private fun setOnActionAllMessageButton() { allMessages.onAction = EventHandler { |
3b26be8f9 controle the time... |
97 |
observableMapState.state = ALL_MESSAGES |
9e952e84e add message clust... |
98 99 100 101 102 103 104 105 |
allMessages.isSelected = true clusteredMessage.isSelected = false heatMap.isSelected = false } } private fun setOnActionClusteredMessageButton() { clusteredMessage.onAction = EventHandler { |
3b26be8f9 controle the time... |
106 |
observableMapState.state = CLUSTERED_MESSAGES |
9e952e84e add message clust... |
107 108 109 110 111 112 113 114 |
heatMap.isSelected = false allMessages.isSelected = false clusteredMessage.isSelected = true } } private fun setOnActionHeatMapButton() { heatMap.onAction = EventHandler { |
3b26be8f9 controle the time... |
115 |
observableMapState.state = HEAT_MAP |
9e952e84e add message clust... |
116 117 118 119 120 |
heatMap.isSelected = true clusteredMessage.isSelected = false allMessages.isSelected = false } } |
b350f9dfe import vessels an... |
121 |
} |