Search in sources :

Example 1 with BasicWidget

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;
}
Also used : InfoCollector(il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ObservableList(javafx.collections.ObservableList) BasicWidget(il.ac.technion.cs.smarthouse.system.dashboard.widget.BasicWidget)

Example 2 with BasicWidget

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;
}
Also used : HBox(javafx.scene.layout.HBox) Function(java.util.function.Function) InfoCollector(il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector) DashboardCore(il.ac.technion.cs.smarthouse.system.dashboard.DashboardCore) WidgetsRegionBuilder(il.ac.technion.cs.smarthouse.developers_api.application_builder.WidgetsRegionBuilder) SensorApi(il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorApi) Insets(javafx.geometry.Insets) ScrollPane(javafx.scene.control.ScrollPane) SensorData(il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorData) ScrollBarPolicy(javafx.scene.control.ScrollPane.ScrollBarPolicy) BasicWidget(il.ac.technion.cs.smarthouse.system.dashboard.widget.BasicWidget) Map(java.util.Map) WidgetType(il.ac.technion.cs.smarthouse.system.dashboard.WidgetType) BasicWidget(il.ac.technion.cs.smarthouse.system.dashboard.widget.BasicWidget)

Example 3 with BasicWidget

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);
}
Also used : Button(javafx.scene.control.Button) FontWeight(javafx.scene.text.FontWeight) Arrays(java.util.Arrays) URL(java.net.URL) GuiController(il.ac.technion.cs.smarthouse.gui_controller.GuiController) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) ReadOnlyFileNode(il.ac.technion.cs.smarthouse.system.file_system.FileSystem.ReadOnlyFileNode) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) Random(java.util.Random) InfoCollector(il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) ScrollPane(javafx.scene.control.ScrollPane) ResourceBundle(java.util.ResourceBundle) ComboBox(javafx.scene.control.ComboBox) AlertType(javafx.scene.control.Alert.AlertType) BasicWidget(il.ac.technion.cs.smarthouse.system.dashboard.widget.BasicWidget) Map(java.util.Map) TableView(javafx.scene.control.TableView) Tooltip(javafx.scene.control.Tooltip) FileSystemEntries(il.ac.technion.cs.smarthouse.system.file_system.FileSystemEntries) WidgetType(il.ac.technion.cs.smarthouse.system.dashboard.WidgetType) PathBuilder(il.ac.technion.cs.smarthouse.system.file_system.PathBuilder) Tile(eu.hansolo.tilesfx.Tile) Alert(javafx.scene.control.Alert) HBox(javafx.scene.layout.HBox) Color(javafx.scene.paint.Color) TextField(javafx.scene.control.TextField) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) GraphWidget(il.ac.technion.cs.smarthouse.system.dashboard.widget.GraphWidget) FileSystem(il.ac.technion.cs.smarthouse.system.file_system.FileSystem) Font(javafx.scene.text.Font) Collectors(java.util.stream.Collectors) SystemMode(il.ac.technion.cs.smarthouse.system.SystemMode) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) SystemCore(il.ac.technion.cs.smarthouse.system.SystemCore) AnimationTimer(javafx.animation.AnimationTimer) List(java.util.List) SystemGuiController(il.ac.technion.cs.smarthouse.gui.controllers.SystemGuiController) Stream(java.util.stream.Stream) Stage(javafx.stage.Stage) ListWidget(il.ac.technion.cs.smarthouse.system.dashboard.widget.ListWidget) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) AnimationTimer(javafx.animation.AnimationTimer) Random(java.util.Random) GraphWidget(il.ac.technion.cs.smarthouse.system.dashboard.widget.GraphWidget) ListWidget(il.ac.technion.cs.smarthouse.system.dashboard.widget.ListWidget)

Aggregations

InfoCollector (il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector)3 BasicWidget (il.ac.technion.cs.smarthouse.system.dashboard.widget.BasicWidget)3 WidgetType (il.ac.technion.cs.smarthouse.system.dashboard.WidgetType)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 ObservableList (javafx.collections.ObservableList)2 ScrollPane (javafx.scene.control.ScrollPane)2 Tile (eu.hansolo.tilesfx.Tile)1 WidgetsRegionBuilder (il.ac.technion.cs.smarthouse.developers_api.application_builder.WidgetsRegionBuilder)1 SystemGuiController (il.ac.technion.cs.smarthouse.gui.controllers.SystemGuiController)1 GuiController (il.ac.technion.cs.smarthouse.gui_controller.GuiController)1 SystemCore (il.ac.technion.cs.smarthouse.system.SystemCore)1 SystemMode (il.ac.technion.cs.smarthouse.system.SystemMode)1 DashboardCore (il.ac.technion.cs.smarthouse.system.dashboard.DashboardCore)1 GraphWidget (il.ac.technion.cs.smarthouse.system.dashboard.widget.GraphWidget)1 ListWidget (il.ac.technion.cs.smarthouse.system.dashboard.widget.ListWidget)1 FileSystem (il.ac.technion.cs.smarthouse.system.file_system.FileSystem)1 ReadOnlyFileNode (il.ac.technion.cs.smarthouse.system.file_system.FileSystem.ReadOnlyFileNode)1