From f891b1da9a568341b4d04057577bf4de9cfc91b0 Mon Sep 17 00:00:00 2001 From: Dominik Gruntz Date: Sun, 5 Aug 2018 22:42:33 +0200 Subject: [PATCH 1/2] Updates the progress indicator to be finished By invoking updateProgress(max, max); the properties are informed that the task is completed. [this should probably be added to the former projects as well.] --- .../src/main/java/de/javafxbuch/CounterTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kapitel 9/9.3.2/progressindicator/src/main/java/de/javafxbuch/CounterTask.java b/Kapitel 9/9.3.2/progressindicator/src/main/java/de/javafxbuch/CounterTask.java index 232ba63..b869e96 100644 --- a/Kapitel 9/9.3.2/progressindicator/src/main/java/de/javafxbuch/CounterTask.java +++ b/Kapitel 9/9.3.2/progressindicator/src/main/java/de/javafxbuch/CounterTask.java @@ -18,7 +18,7 @@ protected Integer call() throws Exception { Thread.sleep(10); updateProgress(i, max); } - + updateProgress(max, max); updateMessage("READY"); return max; From c4aec2e7ebceac948f0376c127ccdead075179e2 Mon Sep 17 00:00:00 2001 From: Dominik Gruntz Date: Sun, 5 Aug 2018 23:13:49 +0200 Subject: [PATCH 2/2] Fixes a bug in tweetalot (chap 9.4) In the original version the RefreshService was declared as a local variable in the constructor and was reclaimed by the GC after creation of the timeline. The call homeTimeline.refresh() declared in the MainApp is no longer needed (was commented out). Without that code the timeline was not initialized. --- .../src/main/java/de/javafxbuch/HomeTimeline.java | 9 ++------- .../src/main/java/de/javafxbuch/MainApp.java | 1 - .../src/main/java/de/javafxbuch/RefreshService.java | 11 +++++------ 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Kapitel 9/9.4/tweetalot/src/main/java/de/javafxbuch/HomeTimeline.java b/Kapitel 9/9.4/tweetalot/src/main/java/de/javafxbuch/HomeTimeline.java index d38fcd2..38fdf57 100644 --- a/Kapitel 9/9.4/tweetalot/src/main/java/de/javafxbuch/HomeTimeline.java +++ b/Kapitel 9/9.4/tweetalot/src/main/java/de/javafxbuch/HomeTimeline.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package de.javafxbuch; import javafx.collections.ObservableList; @@ -20,12 +15,13 @@ public class HomeTimeline extends ScrollPane { private TimelineView timelineView; + private final RefreshService refreshService; public HomeTimeline() { setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); setFitToWidth(true); - RefreshService refreshService = new RefreshService(); + refreshService = new RefreshService(); refreshService.setPeriod(Duration.minutes(2)); refreshService.setRestartOnFailure(true); refreshService.setMaximumFailureCount(3); @@ -42,7 +38,6 @@ public HomeTimeline() { } public void refresh() throws TwitterException { - Twitter twitter = TwitterFactory.getSingleton(); ResponseList homeTimeline = twitter.getHomeTimeline(); ObservableTimelineList observableTimelineList = new ObservableTimelineList(homeTimeline); diff --git a/Kapitel 9/9.4/tweetalot/src/main/java/de/javafxbuch/MainApp.java b/Kapitel 9/9.4/tweetalot/src/main/java/de/javafxbuch/MainApp.java index ac1a91a..d180778 100644 --- a/Kapitel 9/9.4/tweetalot/src/main/java/de/javafxbuch/MainApp.java +++ b/Kapitel 9/9.4/tweetalot/src/main/java/de/javafxbuch/MainApp.java @@ -27,7 +27,6 @@ public void start(Stage stage) throws Exception { button.setFont(Font.font("FontAwesome", 40)); BorderPane root = new BorderPane(); final HomeTimeline homeTimeline = new HomeTimeline(); -// homeTimeline.refresh(); root.setCenter(homeTimeline); ToolBar toolBar = new ToolBar(); toolBar.setOrientation(Orientation.VERTICAL); diff --git a/Kapitel 9/9.4/tweetalot/src/main/java/de/javafxbuch/RefreshService.java b/Kapitel 9/9.4/tweetalot/src/main/java/de/javafxbuch/RefreshService.java index 51e857d..3a7f352 100644 --- a/Kapitel 9/9.4/tweetalot/src/main/java/de/javafxbuch/RefreshService.java +++ b/Kapitel 9/9.4/tweetalot/src/main/java/de/javafxbuch/RefreshService.java @@ -3,11 +3,10 @@ import javafx.concurrent.ScheduledService; import javafx.concurrent.Task; -public class RefreshService - extends ScheduledService { +public class RefreshService extends ScheduledService { - @Override - protected Task createTask() { - return new RefreshTask(); - } + @Override + protected Task createTask() { + return new RefreshTask(); + } }