use of il.ac.technion.cs.smarthouse.developers_api.application_builder.StatusRegionBuilder in project Smartcity-Smarthouse by TechnionYP5777.
the class StatusRegionBuilderImpl method addTimerStatusField.
/*
* (non-Javadoc)
*
* @see il.ac.technion.cs.smarthouse.developers_api.application_builder.
* StatusRegionBuilder#addTimerStatusField(java.lang.String,
* il.ac.technion.cs.smarthouse.developers_api.application_builder.
* GuiBinderObject,
* il.ac.technion.cs.smarthouse.developers_api.application_builder.
* GuiBinderObject,
* il.ac.technion.cs.smarthouse.developers_api.application_builder.
* ColorRange)
*/
@Override
public StatusRegionBuilderImpl addTimerStatusField(String title, GuiBinderObject<Boolean> timerToggle, GuiBinderObject<Double> timerDuration, ColorRange<Double> d) {
final Label timeLabel = createStatusLabel("");
final Timeline timeline;
final GuiBinderObject<Duration> time = new GuiBinderObject<>(Duration.ZERO);
timeLabel.setText(0.0 + " [sec]");
timeline = new Timeline(new KeyFrame(Duration.millis(100), ¢ -> {
time.setData(time.getData().add(((KeyFrame) ¢.getSource()).getTime()));
timerDuration.setData(time.getData().toSeconds());
timeLabel.setText(timerDuration.getData() + " [sec]");
}));
timerToggle.addOnDataChangedListener(v -> {
if (v.getData()) {
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
} else {
timeline.stop();
time.setData(Duration.ZERO);
timerDuration.setData(time.getData().toSeconds());
timeLabel.setText(timerDuration.getData() + " [sec]");
}
});
if (d != null)
timerDuration.addOnDataChangedListener(v -> setColor(v, d, timeLabel));
addAppBuilderItem(new AppBuilderItem(title, timeLabel));
return this;
}
Aggregations