Blame view

src/main/kotlin/application/controller/MenuBarController.kt 2.97 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
3b26be8f9   lsagona   controle the time...
4
  import application.model.observableMapState
2bbe36a1b   lsagona   addd the possibil...
5
  import application.model.observableVessel
b350f9dfe   lsagona   import vessels an...
6
7
  import javafx.event.EventHandler
  import javafx.fxml.FXML
b350f9dfe   lsagona   import vessels an...
8
  import javafx.fxml.Initializable
07bf03cd8   lsagona   add alert message...
9
  import javafx.scene.control.Alert
9e952e84e   lsagona   add message clust...
10
  import javafx.scene.control.CheckMenuItem
b350f9dfe   lsagona   import vessels an...
11
12
13
14
15
16
17
18
19
20
21
22
23
  import javafx.scene.control.MenuBar
  import javafx.scene.control.MenuItem
  import javafx.stage.FileChooser
  import java.net.URL
  import java.util.*
  
  class MenuBarController : Initializable {
  
      @FXML
      var menuBar: MenuBar = MenuBar()
  
      @FXML
      var import: MenuItem = MenuItem()
9e952e84e   lsagona   add message clust...
24
25
26
27
28
29
30
31
      @FXML
      var allMessages: CheckMenuItem = CheckMenuItem()
  
      @FXML
      var clusteredMessage: CheckMenuItem = CheckMenuItem()
  
      @FXML
      var heatMap: CheckMenuItem = CheckMenuItem()
b350f9dfe   lsagona   import vessels an...
32
      override fun initialize(location: URL?, resources: ResourceBundle?) {
9e952e84e   lsagona   add message clust...
33
34
35
36
37
          setOnActionImportButton()
  
          setOnActionAllMessageButton()
          setOnActionClusteredMessageButton()
          setOnActionHeatMapButton()
3b26be8f9   lsagona   controle the time...
38
          observableMapState.state = CLUSTERED_MESSAGES
79b001037   lsagona   heat map
39
          allMessages.isSelected = false
9e952e84e   lsagona   add message clust...
40
          clusteredMessage.isSelected = true
79b001037   lsagona   heat map
41
          heatMap.isSelected = false
9e952e84e   lsagona   add message clust...
42
43
44
45
  
      }
  
      private fun setOnActionImportButton() {
b350f9dfe   lsagona   import vessels an...
46
47
48
49
50
          import.onAction = EventHandler {
              val fileChooser = FileChooser()
              fileChooser.title = "Choose a file to import"
              val window = menuBar.scene.window
              val file = fileChooser.showOpenDialog(window)
79b001037   lsagona   heat map
51
              try {
07bf03cd8   lsagona   add alert message...
52
53
54
55
56
57
58
                  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
59
60
61
                  val vessels = createVesselCollection(file)
                  observableVessel.vessels.clear()
                  observableVessel.vessels = vessels
07bf03cd8   lsagona   add alert message...
62
              } catch (ignore: IllegalStateException) {
79b001037   lsagona   heat map
63
64
  
              }
b350f9dfe   lsagona   import vessels an...
65
66
          }
      }
9e952e84e   lsagona   add message clust...
67
68
69
  
      private fun setOnActionAllMessageButton() {
          allMessages.onAction = EventHandler {
3b26be8f9   lsagona   controle the time...
70
              observableMapState.state = ALL_MESSAGES
9e952e84e   lsagona   add message clust...
71
72
73
74
75
76
77
78
              allMessages.isSelected = true
              clusteredMessage.isSelected = false
              heatMap.isSelected = false
          }
      }
  
      private fun setOnActionClusteredMessageButton() {
          clusteredMessage.onAction = EventHandler {
3b26be8f9   lsagona   controle the time...
79
              observableMapState.state = CLUSTERED_MESSAGES
9e952e84e   lsagona   add message clust...
80
81
82
83
84
85
86
87
              heatMap.isSelected = false
              allMessages.isSelected = false
              clusteredMessage.isSelected = true
          }
      }
  
      private fun setOnActionHeatMapButton() {
          heatMap.onAction = EventHandler {
3b26be8f9   lsagona   controle the time...
88
              observableMapState.state = HEAT_MAP
9e952e84e   lsagona   add message clust...
89
90
91
92
93
              heatMap.isSelected = true
              clusteredMessage.isSelected = false
              allMessages.isSelected = false
          }
      }
b350f9dfe   lsagona   import vessels an...
94
  }