-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUiController.java
67 lines (57 loc) · 1.7 KB
/
UiController.java
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
package state;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
/**
* Created by Beka on 16.04.17.
*/
public class UiController {
private IState state = new RegularState(this);
@FXML private RadioButton regular;
@FXML private RadioButton gravel;
@FXML private RadioButton wet;
@FXML private RadioButton ice;
@FXML private Label label;
@FXML
void initialize(){
ToggleGroup g = new ToggleGroup();
regular.setToggleGroup(g);
gravel.setToggleGroup(g);
wet.setToggleGroup(g);
ice.setToggleGroup(g);
g.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
RadioButton rb = (RadioButton) newValue;
switch (rb.getId()) {
case "regular":
state = new RegularState(this);
break;
case "gravel":
state = new GravelState(this);
break;
case "wet":
state = new WetState(this);
break;
case "ice":
state = new IceState(this);
break;
}
});
}
public void onRight(ActionEvent actionEvent) {
state.onRight();
}
public void onLeft(ActionEvent actionEvent) {
state.onLeft();
}
public void onBrake(ActionEvent actionEvent) {
state.onLeft();
}
public void onAccel(ActionEvent actionEvent) {
state.onAccel();
}
public void setTitle(String title) {
label.setText(title);
}
}