Search in sources :

Example 1 with BasicWidget

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);
}
Also used : Tile(eu.hansolo.tilesfx.Tile) BasicWidget(il.ac.technion.cs.smarthouse.applications.dashboard.model.widget.BasicWidget) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with BasicWidget

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);
}
Also used : Button(javafx.scene.control.Button) Initializable(javafx.fxml.Initializable) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) Random(java.util.Random) BarChartItem(eu.hansolo.tilesfx.skins.BarChartItem) ArrayList(java.util.ArrayList) Insets(javafx.geometry.Insets) ResourceBundle(java.util.ResourceBundle) ComboBox(javafx.scene.control.ComboBox) BackgroundFill(javafx.scene.layout.BackgroundFill) Map(java.util.Map) Tile(eu.hansolo.tilesfx.Tile) ListWidget(il.ac.technion.cs.smarthouse.applications.dashboard.model.widget.ListWidget) Color(javafx.scene.paint.Color) TextField(javafx.scene.control.TextField) Logger(org.slf4j.Logger) GraphWidget(il.ac.technion.cs.smarthouse.applications.dashboard.model.widget.GraphWidget) Collectors(java.util.stream.Collectors) Background(javafx.scene.layout.Background) InvocationTargetException(java.lang.reflect.InvocationTargetException) FXML(javafx.fxml.FXML) Platform(javafx.application.Platform) AnimationTimer(javafx.animation.AnimationTimer) List(java.util.List) Stream(java.util.stream.Stream) FlowPane(javafx.scene.layout.FlowPane) Stage(javafx.stage.Stage) Optional(java.util.Optional) WidgetType(il.ac.technion.cs.smarthouse.applications.dashboard.model.WidgetType) BasicWidget(il.ac.technion.cs.smarthouse.applications.dashboard.model.widget.BasicWidget) LeaderBoardItem(eu.hansolo.tilesfx.skins.LeaderBoardItem) CornerRadii(javafx.scene.layout.CornerRadii) Insets(javafx.geometry.Insets) Background(javafx.scene.layout.Background) BackgroundFill(javafx.scene.layout.BackgroundFill) Stage(javafx.stage.Stage) BasicWidget(il.ac.technion.cs.smarthouse.applications.dashboard.model.widget.BasicWidget)

Example 3 with BasicWidget

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;
}
Also used : HashMap(java.util.HashMap) BarChartItem(eu.hansolo.tilesfx.skins.BarChartItem) BasicWidget(il.ac.technion.cs.smarthouse.applications.dashboard.model.widget.BasicWidget) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArrayList(java.util.ArrayList) List(java.util.List) LeaderBoardItem(eu.hansolo.tilesfx.skins.LeaderBoardItem)

Aggregations

BasicWidget (il.ac.technion.cs.smarthouse.applications.dashboard.model.widget.BasicWidget)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Tile (eu.hansolo.tilesfx.Tile)2 BarChartItem (eu.hansolo.tilesfx.skins.BarChartItem)2 LeaderBoardItem (eu.hansolo.tilesfx.skins.LeaderBoardItem)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 WidgetType (il.ac.technion.cs.smarthouse.applications.dashboard.model.WidgetType)1 GraphWidget (il.ac.technion.cs.smarthouse.applications.dashboard.model.widget.GraphWidget)1 ListWidget (il.ac.technion.cs.smarthouse.applications.dashboard.model.widget.ListWidget)1 URL (java.net.URL)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Random (java.util.Random)1 ResourceBundle (java.util.ResourceBundle)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 AnimationTimer (javafx.animation.AnimationTimer)1 Platform (javafx.application.Platform)1