TimePanel.kt
1.76 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package application.controller
import application.model.*
import javafx.fxml.FXML
import javafx.fxml.Initializable
import javafx.scene.control.Button
import javafx.scene.control.Slider
import java.net.URL
import java.util.*
class TimePanel : Initializable {
@FXML
var timeSlider = Slider()
@FXML
var timeStop = Button()
@FXML
var timePlay = Button()
override fun initialize(location: URL?, resources: ResourceBundle?) {
setSliderMinMax()
setSliderListener()
disableAllButton()
setDisable()
}
private fun setSliderMinMax() {
timeSlider.min = 0.0
timeSlider.max = 0.0
observableVessel.listeners.add(object : MessageListener {
override fun onValueChanged(newValue: MutableMap<String?, Vessel>) {
timeSlider.max = Vessel.maxTime.toDouble()
timeSlider.min = Vessel.minTime.toDouble()
}
})
}
private fun setSliderListener() {
timeSlider.valueProperty().addListener { _, _, newValue ->
observableCurrentTime.value = newValue.toInt()
}
}
private fun disableAllButton() {
timeStop.isDisable = true
timeSlider.isDisable = true
timePlay.isDisable = true
}
private fun unableAllButton() {
timeStop.isDisable = false
timeSlider.isDisable = false
timePlay.isDisable = false
}
private fun setDisable() {
observableIsReplayState.listeners.add(object : ReplayState {
override fun onValueChanged(newValue: Boolean) {
if (observableIsReplayState.value) {
unableAllButton()
} else {
disableAllButton()
}
}
})
}
}