From 97d3be0b98914a8e71e79b90deace59140236fac Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Tue, 20 Nov 2018 14:35:06 +0100 Subject: [PATCH] Add setting to diable thumbnail updates This is a feature for people who have bandwidth / contingent restrictions. It can also help keeping the CPU usage down. --- .../src/main/java/ctbrec/ui/SettingsTab.java | 9 +++++++ client/src/main/java/ctbrec/ui/ThumbCell.java | 27 ++++++++++--------- common/src/main/java/ctbrec/Settings.java | 1 + 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/client/src/main/java/ctbrec/ui/SettingsTab.java b/client/src/main/java/ctbrec/ui/SettingsTab.java index 87ecf4b9..ea3b47ea 100644 --- a/client/src/main/java/ctbrec/ui/SettingsTab.java +++ b/client/src/main/java/ctbrec/ui/SettingsTab.java @@ -67,6 +67,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { private CheckBox secureCommunication = new CheckBox(); private CheckBox chooseStreamQuality = new CheckBox(); private CheckBox multiplePlayers = new CheckBox(); + private CheckBox updateThumbnails = new CheckBox(); private RadioButton recordLocal; private RadioButton recordRemote; private ToggleGroup recordLocation; @@ -334,6 +335,14 @@ public class SettingsTab extends Tab implements TabSelectionListener { GridPane.setMargin(chooseStreamQuality, new Insets(CHECKBOX_MARGIN, 0, 0, CHECKBOX_MARGIN)); layout.add(chooseStreamQuality, 1, row++); + l = new Label("Update thumbnails"); + layout.add(l, 0, row); + updateThumbnails.setSelected(Config.getInstance().getSettings().updateThumbnails); + updateThumbnails.setOnAction((e) -> Config.getInstance().getSettings().updateThumbnails = updateThumbnails.isSelected()); + GridPane.setMargin(l, new Insets(CHECKBOX_MARGIN, 0, 0, 0)); + GridPane.setMargin(updateThumbnails, new Insets(CHECKBOX_MARGIN, 0, 0, CHECKBOX_MARGIN)); + layout.add(updateThumbnails, 1, row++); + l = new Label("Maximum resolution (0 = unlimited)"); layout.add(l, 0, row); List resolutionOptions = new ArrayList<>(); diff --git a/client/src/main/java/ctbrec/ui/ThumbCell.java b/client/src/main/java/ctbrec/ui/ThumbCell.java index 146cd680..8b563344 100644 --- a/client/src/main/java/ctbrec/ui/ThumbCell.java +++ b/client/src/main/java/ctbrec/ui/ThumbCell.java @@ -262,20 +262,23 @@ public class ThumbCell extends StackPane { private void setImage(String url) { if(!Objects.equals(System.getenv("CTBREC_DEV"), "1")) { - Image img = new Image(url, true); + boolean updateThumbs = Config.getInstance().getSettings().updateThumbnails; + if(updateThumbs || iv.getImage() == null) { + Image img = new Image(url, true); - // wait for the image to load, otherwise the ImageView replaces the current image with an "empty" image, - // which causes to show the grey background until the image is loaded - img.progressProperty().addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observable, Number oldValue, Number newValue) { - if(newValue.doubleValue() == 1.0) { - //imgAspectRatio = img.getHeight() / img.getWidth(); - iv.setImage(img); - setThumbWidth(Config.getInstance().getSettings().thumbWidth); + // wait for the image to load, otherwise the ImageView replaces the current image with an "empty" image, + // which causes to show the grey background until the image is loaded + img.progressProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, Number oldValue, Number newValue) { + if(newValue.doubleValue() == 1.0) { + //imgAspectRatio = img.getHeight() / img.getWidth(); + iv.setImage(img); + setThumbWidth(Config.getInstance().getSettings().thumbWidth); + } } - } - }); + }); + } } } diff --git a/common/src/main/java/ctbrec/Settings.java b/common/src/main/java/ctbrec/Settings.java index 7e4a7136..d3895b3c 100644 --- a/common/src/main/java/ctbrec/Settings.java +++ b/common/src/main/java/ctbrec/Settings.java @@ -63,6 +63,7 @@ public class Settings { public String proxyUser; public String proxyPassword; public int thumbWidth = 180; + public boolean updateThumbnails = true; public int windowWidth = 1340; public int windowHeight = 800; public boolean windowMaximized = false;