use of il.ac.technion.cs.smarthouse.applications.dashboard.model.widget.BasicWidget in project Smartcity-Smarthouse by TechnionYP5777.
the class Controller method updateTile.
private void updateTile(WidgetType type, final String path, Integer position) {
log.info("creating tile for: type=[" + type + "], path=[" + path + "], pos=[" + position + "]");
final BasicWidget w;
try {
w = (BasicWidget) type.getImplementingClass().getConstructor(type.getClass()).newInstance(type);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
e.printStackTrace();
return;
}
Tile tile = w.getTile();
setTileEventHandlers(tile, position);
pane.getChildren().set(position, tile);
if (path == null || "".equals(path))
return;
fileSystem.subscribe((rPath, data) -> {
log.info("dashbord rquested to be notified on " + path + " got notified on (p,d)=(" + rPath + "," + data + ").");
if (rPath.equals(path))
w.updateExisting(Double.valueOf((String) data), path);
}, path);
}
use of il.ac.technion.cs.smarthouse.applications.dashboard.model.widget.BasicWidget in project Smartcity-Smarthouse by TechnionYP5777.
the class ConfigurationController method initialize.
@Override
public void initialize(URL location, ResourceBundle resources) {
button.setOnMouseClicked(e -> {
if (callback != null)
Platform.runLater(callback);
timers.values().stream().filter(l -> l != null).flatMap(l -> l.stream()).forEach(t -> t.stop());
((Stage) button.getScene().getWindow()).close();
widgets.values().stream().filter(l -> l != null).flatMap(l -> l.stream()).forEach(w -> w.getTile().setForegroundBaseColor(normalTileColor));
});
pane.setPadding(new Insets(5));
pane.setBackground(new Background(new BackgroundFill(Tile.BACKGROUND.darker(), CornerRadii.EMPTY, Insets.EMPTY)));
types.setItems(FXCollections.observableArrayList(widgets.keySet()));
types.getSelectionModel().selectedItemProperty().addListener((options, oldValue, newValue) -> {
Optional.ofNullable(timers.get(newValue)).ifPresent(l -> l.stream().forEach(t -> t.start()));
pane.getChildren().setAll(widgets.get(newValue).stream().map(BasicWidget::getTile).collect(Collectors.toList()));
Optional.ofNullable(timers.get(oldValue)).ifPresent(l -> l.stream().forEach(t -> t.stop()));
Optional.ofNullable(widgets.get(oldValue)).ifPresent(l -> l.stream().forEach(w -> w.getTile().setForegroundBaseColor(normalTileColor)));
});
types.getSelectionModel().select(3);
;
// sPane.setHbarPolicy(ScrollBarPolicy.ALWAYS);
// sPane.setVbarPolicy(ScrollBarPolicy.NEVER);
// sPane.setContent(pane);
}
use of il.ac.technion.cs.smarthouse.applications.dashboard.model.widget.BasicWidget in project Smartcity-Smarthouse by TechnionYP5777.
the class ConfigurationController method initWidgets.
private static Map<String, List<BasicWidget>> initWidgets() {
Map<String, List<BasicWidget>> widgets = new HashMap<>();
Stream.of(WidgetType.values()).forEach(t -> {
try {
BasicWidget widget = null;
Class implClass = t.getImplementingClass();
switch(t) {
case BAR_CHART:
BarChartItem[] bItems = (BarChartItem[]) ListWidget.getDefaultBarItems().toArray();
widget = (BasicWidget) implClass.getConstructor(t.getClass(), bItems.getClass()).newInstance(t, bItems);
break;
case LEAD_CHART:
LeaderBoardItem[] lItems = (LeaderBoardItem[]) ListWidget.getDefaultBoardItems().toArray();
widget = (BasicWidget) implClass.getConstructor(t.getClass(), lItems.getClass()).newInstance(t, lItems);
break;
default:
widget = (BasicWidget) implClass.getConstructor(t.getClass()).newInstance(t);
break;
}
List<BasicWidget> newlist = widgets.getOrDefault(widget.getTitle(), new ArrayList<>());
newlist.add(widget);
widgets.put(widget.getTitle(), newlist);
addTimer(widget.getTitle(), t, widget);
setListeners(widget);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
log.error("Failed to instantiate new widget tile. Got error:" + e);
}
});
// todo:not do it so uglyly
BasicWidget.setDefaultTileSize(220);
return widgets;
}
Aggregations