1 package autolaskuri.event;
3 import static fi.jyu.mit.fxgui.Functions.getNode;
4 import static fi.jyu.mit.fxgui.Functions.getNodes;
7 import java.util.ArrayList;
9 import java.util.ResourceBundle;
11 import javafx.beans.property.SimpleIntegerProperty;
12 import javafx.fxml.FXML;
13 import javafx.fxml.Initializable;
14 import javafx.scene.Node;
15 import javafx.scene.control.Button;
16 import javafx.scene.control.Label;
17 import javafx.scene.control.ProgressBar;
29 @SuppressWarnings(
"javadoc")
30 public static class
Laskettava extends SimpleIntegerProperty {
32 public int inc() {
set(
get()+1);
return get(); }
33 public int reset() {
set(0);
return get(); }
36 @SuppressWarnings(
"javadoc")
38 private List<Laskettava> alkiot =
new ArrayList<>();
40 public void reset() { alkiot.forEach(l -> l.reset()); }
48 public void initialize(URL location, ResourceBundle resources) {
50 List<Label> laskurit = getNodes(parent, Label.class,
51 n -> n.getStyleClass().contains(
"laskuri"),
true);
53 for (Label laskuri: laskurit) {
54 String
id = laskuri.getId();
55 if (
id == null ||
id.length() < 1 )
continue;
57 laskuri.textProperty().bind(laskettava.asString());
59 laskuri.setOnMouseClicked(e -> laskettava.
inc());
60 laskuri.setOnTouchPressed(e -> laskettava.
inc());
61 Button button =
getNode(parent, Button.class, n ->
id.equals(n.getId()),
true);
62 if ( button != null ) button.setOnAction(e -> laskettava.
inc());
63 ProgressBar bar =
getNode(parent, ProgressBar.class, n ->
id.equals(n.getId()),
true);
64 if ( bar != null ) bar.progressProperty().bind(laskettava.divide(20.0));