Blame view
src/main/kotlin/application/controller/VesselListPanelController.kt
2.17 KB
b350f9dfe import vessels an... |
1 2 3 4 |
package application.controller import application.model.MessageListener import application.model.Vessel |
2bbe36a1b addd the possibil... |
5 |
import application.model.observableSelectedVessel |
f39d90e60 Select/deselect MMSI |
6 |
import application.model.observableVessel |
b350f9dfe import vessels an... |
7 8 |
import javafx.collections.FXCollections import javafx.collections.ObservableList |
f39d90e60 Select/deselect MMSI |
9 |
import javafx.event.EventHandler |
b350f9dfe import vessels an... |
10 11 |
import javafx.fxml.FXML import javafx.fxml.Initializable |
f39d90e60 Select/deselect MMSI |
12 13 |
import javafx.scene.control.* import javafx.scene.input.MouseEvent |
b350f9dfe import vessels an... |
14 15 |
import java.net.URL import java.util.* |
f39d90e60 Select/deselect MMSI |
16 |
|
2bbe36a1b addd the possibil... |
17 |
class VesselListPanelController : Initializable, MessageListener { |
b350f9dfe import vessels an... |
18 |
@FXML |
f39d90e60 Select/deselect MMSI |
19 |
var shipListView: ListView<String?> = ListView() |
b350f9dfe import vessels an... |
20 |
|
f39d90e60 Select/deselect MMSI |
21 |
private var shipList: ObservableList<String?> = FXCollections.observableArrayList() |
b350f9dfe import vessels an... |
22 23 |
override fun initialize(location: URL?, resources: ResourceBundle?) { |
f39d90e60 Select/deselect MMSI |
24 |
|
b350f9dfe import vessels an... |
25 |
shipListView.items = shipList |
2bbe36a1b addd the possibil... |
26 27 |
observableVessel.listeners.add(this) shipListView.selectionModel.selectedItemProperty().addListener { _, _, newValue -> |
f39d90e60 Select/deselect MMSI |
28 29 30 31 32 |
if (newValue == null) { observableSelectedVessel.vessel = Vessel(null) } else { observableSelectedVessel.vessel = observableVessel.vessels[newValue]!! } |
2bbe36a1b addd the possibil... |
33 |
} |
f39d90e60 Select/deselect MMSI |
34 |
setCellFactory() |
b350f9dfe import vessels an... |
35 |
} |
f39d90e60 Select/deselect MMSI |
36 |
override fun onValueChanged(newValue: MutableMap<String?, Vessel>) { |
b350f9dfe import vessels an... |
37 38 39 |
shipList.clear() shipList.addAll(newValue.keys) } |
f39d90e60 Select/deselect MMSI |
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
private fun setCellFactory() { val selectionModel: MultipleSelectionModel<String?>? = shipListView.selectionModel selectionModel?.selectionMode = SelectionMode.SINGLE shipListView.setCellFactory { val cell = ListCell<String?>() cell.textProperty().bind(cell.itemProperty()) cell.addEventFilter(MouseEvent.MOUSE_PRESSED) { event: MouseEvent -> shipListView.requestFocus() if (!cell.isEmpty) { val index = cell.index if (selectionModel!!.selectedIndices.contains(index)) { selectionModel.clearSelection() } else { selectionModel.select(index) } event.consume() } } cell } } } |