use of il.ac.technion.cs.smarthouse.system.dashboard.widget.BasicWidget in project Smartcity-Smarthouse by TechnionYP5777.
the class ConfigConsumer method initWidgets.
// ------------------ private helper methods ------------------------------
private Map<String, List<BasicWidget>> initWidgets() {
final Map<String, List<BasicWidget>> allWidgets = new HashMap<>();
final InfoCollector info = new InfoCollector().addInfoEntry("path.to.foo", "foo").addInfoEntry("path.to.bar", "bar").setUnit("m/s");
final Double tileSize = 150.0;
Stream.of(WidgetType.values()).forEach(type -> {
final Optional<BasicWidget> nullableWidget = Optional.ofNullable(type.createWidget(tileSize, info));
nullableWidget.ifPresent(widget -> {
final List<BasicWidget> newlist = allWidgets.getOrDefault(widget.getTitle(), new ArrayList<>());
newlist.add(widget);
allWidgets.put(widget.getTitle(), newlist);
addWidgetTimer(widget);
setWidgetColorListeners(widget);
});
});
return allWidgets;
}
use of il.ac.technion.cs.smarthouse.system.dashboard.widget.BasicWidget in project Smartcity-Smarthouse by TechnionYP5777.
the class WidgetsRegionBuilderImpl method addWidget.
/*
* (non-Javadoc)
*
* @see il.ac.technion.cs.smarthouse.developers_api.application_builder.
* WidgetsRegionBuilder#addWidget(il.ac.technion.cs.smarthouse.system.
* dashboard.WidgetType,
* il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector,
* il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorApi,
* java.util.function.Function)
*/
@Override
public <T extends SensorData> WidgetsRegionBuilder addWidget(final WidgetType t, final InfoCollector c, final SensorApi<T> a, final Function<T, Map<String, Object>> sensorProcessor) {
if (!canAdd())
return this;
BasicWidget bw = t.createWidget(tileSize, c);
a.subscribe(data -> sensorProcessor.apply(data).forEach((path, val) -> bw.update(val, path)));
widgetsHbox.getChildren().add(core.createWidget(bw).get());
return this;
}
use of il.ac.technion.cs.smarthouse.system.dashboard.widget.BasicWidget in project Smartcity-Smarthouse by TechnionYP5777.
the class ConfigConsumer method addWidgetTimer.
private void addWidgetTimer(final BasicWidget w) {
final String key = w.getTitle();
final List<AnimationTimer> where = timers.getOrDefault(key, new ArrayList<>());
where.add(new AnimationTimer() {
private long lastTimerCall;
final Random RND = new Random();
final Boolean isGraph = key.equals(new GraphWidget(WidgetType.AREA_GRAPH, w.getTileSize(), w.getInitalInfo()).getTitle());
final Boolean isList = key.equals(new ListWidget(WidgetType.BAR_CHART, w.getTileSize(), w.getInitalInfo()).getTitle());
@Override
public void handle(final long now) {
if (now <= lastTimerCall + 500_000_000)
return;
if (isGraph) {
final GraphWidget realW = (GraphWidget) w;
realW.getUpdateKeys().forEach(updateKey -> realW.update(RND.nextInt(100) + 0.0, updateKey));
} else if (!isList)
w.update(100 * RND.nextDouble(), null);
else {
final ListWidget realW = (ListWidget) w;
realW.getUpdateKeys().forEach(updateKey -> realW.update(RND.nextInt(100) + 0.0, updateKey));
}
lastTimerCall = now;
}
});
timers.put(key, where);
}
Aggregations