Blame view

src/main/kotlin/application/controller/MenuBarController.kt 1.04 KB
b350f9dfe   lsagona   import vessels an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  package application.controller
  
  import application.App
  import application.model.createVesselCollection
  import application.model.observableMessages
  import javafx.event.EventHandler
  import javafx.fxml.FXML
  import javafx.fxml.FXMLLoader
  import javafx.fxml.Initializable
  import javafx.scene.Parent
  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()
  
      override fun initialize(location: URL?, resources: ResourceBundle?) {
  
          import.onAction = EventHandler {
              val fileChooser = FileChooser()
              fileChooser.title = "Choose a file to import"
              val window = menuBar.scene.window
              val file = fileChooser.showOpenDialog(window)
              val vessels = createVesselCollection(file)
              observableMessages.vessels.clear()
              observableMessages.vessels = vessels
          }
      }
  }