Blame view

src/main/kotlin/application/controller/MenuBarController.kt 2.95 KB
b350f9dfe   lsagona   import vessels an...
1
  package application.controller
9e952e84e   lsagona   add message clust...
2
  import application.model.State.*
b350f9dfe   lsagona   import vessels an...
3
  import application.model.createVesselCollection
9e952e84e   lsagona   add message clust...
4
  import application.model.observableState
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()
79b001037   lsagona   heat map
38
39
          observableState.state = CLUSTERED_MESSAGES
          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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
  
      private fun setOnActionAllMessageButton() {
          allMessages.onAction = EventHandler {
              observableState.state = ALL_MESSAGES
              allMessages.isSelected = true
              clusteredMessage.isSelected = false
              heatMap.isSelected = false
          }
      }
  
      private fun setOnActionClusteredMessageButton() {
          clusteredMessage.onAction = EventHandler {
              observableState.state = CLUSTERED_MESSAGES
              heatMap.isSelected = false
              allMessages.isSelected = false
              clusteredMessage.isSelected = true
          }
      }
  
      private fun setOnActionHeatMapButton() {
          heatMap.onAction = EventHandler {
              observableState.state = HEAT_MAP
              heatMap.isSelected = true
              clusteredMessage.isSelected = false
              allMessages.isSelected = false
          }
      }
b350f9dfe   lsagona   import vessels an...
94
  }