Blame view

src/main/kotlin/application/controller/MenuBarController.kt 2.58 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
9e952e84e   lsagona   add message clust...
9
  import javafx.scene.control.CheckMenuItem
b350f9dfe   lsagona   import vessels an...
10
11
12
13
14
15
16
17
18
19
20
21
22
  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...
23
24
25
26
27
28
29
30
      @FXML
      var allMessages: CheckMenuItem = CheckMenuItem()
  
      @FXML
      var clusteredMessage: CheckMenuItem = CheckMenuItem()
  
      @FXML
      var heatMap: CheckMenuItem = CheckMenuItem()
b350f9dfe   lsagona   import vessels an...
31
      override fun initialize(location: URL?, resources: ResourceBundle?) {
9e952e84e   lsagona   add message clust...
32
33
34
35
36
          setOnActionImportButton()
  
          setOnActionAllMessageButton()
          setOnActionClusteredMessageButton()
          setOnActionHeatMapButton()
79b001037   lsagona   heat map
37
38
          observableState.state = CLUSTERED_MESSAGES
          allMessages.isSelected = false
9e952e84e   lsagona   add message clust...
39
          clusteredMessage.isSelected = true
79b001037   lsagona   heat map
40
          heatMap.isSelected = false
9e952e84e   lsagona   add message clust...
41
42
43
44
  
      }
  
      private fun setOnActionImportButton() {
b350f9dfe   lsagona   import vessels an...
45
46
47
48
49
          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
50
51
52
53
54
55
56
              try {
                  val vessels = createVesselCollection(file)
                  observableVessel.vessels.clear()
                  observableVessel.vessels = vessels
              } catch (ignore: IllegalStateException){
  
              }
b350f9dfe   lsagona   import vessels an...
57
58
          }
      }
9e952e84e   lsagona   add message clust...
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
  
      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...
86
  }