Search in sources :

Example 1 with GraphWidget

use of il.ac.technion.cs.smarthouse.applications.dashboard.model.widget.GraphWidget in project Smartcity-Smarthouse by TechnionYP5777.

the class ConfigurationController method addTimer.

private static void addTimer(String key, WidgetType type, final BasicWidget widget) {
    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).getTitle());

        @Override
        public void handle(long now) {
            if (now > lastTimerCall + 500_000_000) {
                if (isGraph)
                    GraphWidget.getDefaultSerie().getData().stream().forEach(data -> widget.updateExisting(RND.nextInt(100), data.getXValue()));
                else
                    widget.updateExisting(RND.nextDouble() * 100, null);
                lastTimerCall = now;
            }
        }
    });
    timers.put(key, where);
}
Also used : AnimationTimer(javafx.animation.AnimationTimer) Random(java.util.Random) GraphWidget(il.ac.technion.cs.smarthouse.applications.dashboard.model.widget.GraphWidget)

Aggregations

GraphWidget (il.ac.technion.cs.smarthouse.applications.dashboard.model.widget.GraphWidget)1 Random (java.util.Random)1 AnimationTimer (javafx.animation.AnimationTimer)1