Blame view

src/main/kotlin/application/controller/MenuBarController.kt 4.04 KB
b350f9dfe   lsagona   import vessels an...
1
  package application.controller
3b26be8f9   lsagona   controle the time...
2
  import application.model.MapState.*
b350f9dfe   lsagona   import vessels an...
3
  import application.model.createVesselCollection
dd1ce7fe8   lsagona   add button to swi...
4
  import application.model.observableIsReplayState
3b26be8f9   lsagona   controle the time...
5
  import application.model.observableMapState
2bbe36a1b   lsagona   addd the possibil...
6
  import application.model.observableVessel
b350f9dfe   lsagona   import vessels an...
7
8
  import javafx.event.EventHandler
  import javafx.fxml.FXML
b350f9dfe   lsagona   import vessels an...
9
  import javafx.fxml.Initializable
dd1ce7fe8   lsagona   add button to swi...
10
  import javafx.scene.control.*
b350f9dfe   lsagona   import vessels an...
11
  import javafx.stage.FileChooser
6b2760a45   lsagona   add warning messa...
12
  import java.io.*
b350f9dfe   lsagona   import vessels an...
13
14
  import java.net.URL
  import java.util.*
6b2760a45   lsagona   add warning messa...
15

b350f9dfe   lsagona   import vessels an...
16
17
18
19
20
21
22
  class MenuBarController : Initializable {
  
      @FXML
      var menuBar: MenuBar = MenuBar()
  
      @FXML
      var import: MenuItem = MenuItem()
9e952e84e   lsagona   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   lsagona   add button to swi...
31
      @FXML
862dc9b51   lsagona   rename an element...
32
      var activateTimeSliderButton: RadioMenuItem = RadioMenuItem()
dd1ce7fe8   lsagona   add button to swi...
33

b350f9dfe   lsagona   import vessels an...
34
      override fun initialize(location: URL?, resources: ResourceBundle?) {
9e952e84e   lsagona   add message clust...
35
36
37
38
39
          setOnActionImportButton()
  
          setOnActionAllMessageButton()
          setOnActionClusteredMessageButton()
          setOnActionHeatMapButton()
dd1ce7fe8   lsagona   add button to swi...
40
          setOnActionActivateReplayButton()
3b26be8f9   lsagona   controle the time...
41
          observableMapState.state = CLUSTERED_MESSAGES
79b001037   lsagona   heat map
42
          allMessages.isSelected = false
9e952e84e   lsagona   add message clust...
43
          clusteredMessage.isSelected = true
79b001037   lsagona   heat map
44
          heatMap.isSelected = false
9e952e84e   lsagona   add message clust...
45
46
  
      }
dd1ce7fe8   lsagona   add button to swi...
47
      private fun setOnActionActivateReplayButton() {
862dc9b51   lsagona   rename an element...
48
49
          activateTimeSliderButton.onAction = EventHandler {
              observableIsReplayState.value = activateTimeSliderButton.isSelected
dd1ce7fe8   lsagona   add button to swi...
50
51
          }
      }
9e952e84e   lsagona   add message clust...
52
      private fun setOnActionImportButton() {
b350f9dfe   lsagona   import vessels an...
53
54
55
56
57
          import.onAction = EventHandler {
              val fileChooser = FileChooser()
              fileChooser.title = "Choose a file to import"
              val window = menuBar.scene.window
              val file = fileChooser.showOpenDialog(window)
6b2760a45   lsagona   add warning messa...
58

79b001037   lsagona   heat map
59
              try {
07bf03cd8   lsagona   add alert message...
60
61
62
63
64
65
66
                  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   lsagona   heat map
67
                  observableVessel.vessels.clear()
6b2760a45   lsagona   add warning messa...
68
69
70
71
72
73
                  if(toMuchVessel(file)){
                      observableVessel.vessels = mutableMapOf()
                  }else {
                      val vessels = createVesselCollection(file)
                      observableVessel.vessels = vessels
                  }
07bf03cd8   lsagona   add alert message...
74
              } catch (ignore: IllegalStateException) {
79b001037   lsagona   heat map
75
76
  
              }
b350f9dfe   lsagona   import vessels an...
77
78
          }
      }
9e952e84e   lsagona   add message clust...
79

6b2760a45   lsagona   add warning messa...
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
      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   lsagona   add message clust...
96
97
      private fun setOnActionAllMessageButton() {
          allMessages.onAction = EventHandler {
3b26be8f9   lsagona   controle the time...
98
              observableMapState.state = ALL_MESSAGES
9e952e84e   lsagona   add message clust...
99
100
101
102
103
104
105
106
              allMessages.isSelected = true
              clusteredMessage.isSelected = false
              heatMap.isSelected = false
          }
      }
  
      private fun setOnActionClusteredMessageButton() {
          clusteredMessage.onAction = EventHandler {
3b26be8f9   lsagona   controle the time...
107
              observableMapState.state = CLUSTERED_MESSAGES
9e952e84e   lsagona   add message clust...
108
109
110
111
112
113
114
115
              heatMap.isSelected = false
              allMessages.isSelected = false
              clusteredMessage.isSelected = true
          }
      }
  
      private fun setOnActionHeatMapButton() {
          heatMap.onAction = EventHandler {
3b26be8f9   lsagona   controle the time...
116
              observableMapState.state = HEAT_MAP
9e952e84e   lsagona   add message clust...
117
118
119
120
121
              heatMap.isSelected = true
              clusteredMessage.isSelected = false
              allMessages.isSelected = false
          }
      }
b350f9dfe   lsagona   import vessels an...
122
  }