From 7d36586b04f013292b00ae83ab8b9a84e5834f33 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Wed, 5 Sep 2018 13:54:44 +0200 Subject: [PATCH] Make thumbnail size configurable Add combobox on the bottom of ThumbOverviewTab. Add integer thumbWidth to the Settings to save and restore the selected value between sessions. Set the selected value for all thumbnails on all tabs. --- CHANGELOG.md | 1 + src/main/java/ctbrec/Settings.java | 2 + src/main/java/ctbrec/ui/ThumbCell.java | 38 +++++++++++------ src/main/java/ctbrec/ui/ThumbOverviewTab.java | 42 ++++++++++++++++++- 4 files changed, 69 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9459e615..98feba2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ 1.4.3 ======================== * Added possibility to switch the video resolution for a recording +* Added selection box below the overview pages to change the thumbnail size 1.4.2 ======================== diff --git a/src/main/java/ctbrec/Settings.java b/src/main/java/ctbrec/Settings.java index fb6771eb..cf96ce5e 100644 --- a/src/main/java/ctbrec/Settings.java +++ b/src/main/java/ctbrec/Settings.java @@ -37,4 +37,6 @@ public class Settings { public String proxyPort; public String proxyUser; public String proxyPassword; + public int thumbWidth = 180; + } diff --git a/src/main/java/ctbrec/ui/ThumbCell.java b/src/main/java/ctbrec/ui/ThumbCell.java index 9579d59a..92f152aa 100644 --- a/src/main/java/ctbrec/ui/ThumbCell.java +++ b/src/main/java/ctbrec/ui/ThumbCell.java @@ -58,9 +58,7 @@ import okhttp3.Response; public class ThumbCell extends StackPane { private static final transient Logger LOG = LoggerFactory.getLogger(ThumbCell.class); - - private static final int WIDTH = 180; - private static final int HEIGHT = 135; + public static int width = 180; private static final Duration ANIMATION_DURATION = new Duration(250); // this acts like a cache, once the stream resolution for a model has been determined, we don't do it again (until ctbrec is restarted) @@ -98,18 +96,16 @@ public class ThumbCell extends StackPane { iv = new ImageView(); setImage(model.getPreview()); - iv.setFitWidth(WIDTH); - iv.setFitHeight(HEIGHT); iv.setSmooth(true); getChildren().add(iv); - nameBackground = new Rectangle(WIDTH, 20); + nameBackground = new Rectangle(); nameBackground.setFill(recording ? colorRecording : colorNormal); nameBackground.setOpacity(.7); StackPane.setAlignment(nameBackground, Pos.BOTTOM_CENTER); getChildren().add(nameBackground); - topicBackground = new Rectangle(WIDTH, 115); + topicBackground = new Rectangle(); topicBackground.setFill(Color.BLACK); topicBackground.setOpacity(0); StackPane.setAlignment(topicBackground, Pos.TOP_LEFT); @@ -138,11 +134,7 @@ public class ThumbCell extends StackPane { topic.setFont(new Font("Sansserif", 13)); topic.setTextAlignment(TextAlignment.LEFT); topic.setOpacity(0); - topic.prefHeight(110); - topic.maxHeight(110); int margin = 4; - topic.maxWidth(WIDTH-margin*2); - topic.setWrappingWidth(WIDTH-margin*2); StackPane.setMargin(topic, new Insets(margin)); StackPane.setAlignment(topic, Pos.TOP_CENTER); getChildren().add(topic); @@ -188,8 +180,7 @@ public class ThumbCell extends StackPane { } }); - setMinSize(WIDTH, HEIGHT); - setPrefSize(WIDTH, HEIGHT); + setThumbWidth(width); setRecording(recording); if(Config.getInstance().getSettings().determineResolution) { @@ -542,4 +533,25 @@ public class ThumbCell extends StackPane { return false; return true; } + + public void setThumbWidth(int width) { + int height = width * 3 / 4; + setSize(width, height); + } + + private void setSize(int w, int h) { + iv.setFitWidth(w); + iv.setFitHeight(h); + setMinSize(w, h); + setPrefSize(w, h); + nameBackground.setWidth(w); + nameBackground.setHeight(20); + topicBackground.setWidth(w); + topicBackground.setHeight(h-nameBackground.getHeight()); + topic.prefHeight(h-25); + topic.maxHeight(h-25); + int margin = 4; + topic.maxWidth(w-margin*2); + topic.setWrappingWidth(w-margin*2); + } } diff --git a/src/main/java/ctbrec/ui/ThumbOverviewTab.java b/src/main/java/ctbrec/ui/ThumbOverviewTab.java index c65311b3..db8d752e 100644 --- a/src/main/java/ctbrec/ui/ThumbOverviewTab.java +++ b/src/main/java/ctbrec/ui/ThumbOverviewTab.java @@ -22,6 +22,9 @@ import java.util.concurrent.locks.ReentrantLock; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.sun.javafx.collections.ObservableListWrapper; + +import ctbrec.Config; import ctbrec.HttpClient; import ctbrec.Model; import ctbrec.ModelParser; @@ -35,6 +38,8 @@ import javafx.geometry.Insets; import javafx.scene.Node; import javafx.scene.control.Alert; import javafx.scene.control.Button; +import javafx.scene.control.ComboBox; +import javafx.scene.control.Label; import javafx.scene.control.ScrollPane; import javafx.scene.control.Tab; import javafx.scene.control.TextField; @@ -69,6 +74,8 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener { Button pageNext = new Button("▶"); private volatile boolean updatesSuspended = false; + private ComboBox thumbWidth; + public ThumbOverviewTab(String title, String url, boolean loginRequired) { super(title); this.url = url; @@ -121,11 +128,44 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener { restartUpdateService(); }); + ThumbCell.width = Config.getInstance().getSettings().thumbWidth; + HBox thumbSizeSelector = new HBox(5); + Label l = new Label("Thumb Size"); + l.setPadding(new Insets(5,0,0,0)); + thumbSizeSelector.getChildren().add(l); + List thumbWidths = new ArrayList<>(); + thumbWidths.add(180); + thumbWidths.add(200); + thumbWidths.add(220); + thumbWidths.add(270); + thumbWidths.add(360); + thumbWidth = new ComboBox<>(new ObservableListWrapper<>(thumbWidths)); + thumbWidth.getSelectionModel().select(new Integer(ThumbCell.width)); + thumbWidth.setOnAction((e) -> { + int width = thumbWidth.getSelectionModel().getSelectedItem(); + ThumbCell.width = width; + Config.getInstance().getSettings().thumbWidth = width; + for (Node node : grid.getChildren()) { + ThumbCell cell = (ThumbCell) node; + cell.setThumbWidth(width); + } + for (ThumbCell cell : filteredThumbCells) { + cell.setThumbWidth(width); + } + }); + thumbSizeSelector.getChildren().add(thumbWidth); + BorderPane.setMargin(thumbSizeSelector, new Insets(5)); + + + BorderPane bottomPane = new BorderPane(); + bottomPane.setLeft(pagination); + bottomPane.setRight(thumbSizeSelector); + BorderPane root = new BorderPane(); root.setPadding(new Insets(5)); root.setTop(search); root.setCenter(scrollPane); - root.setBottom(pagination); + root.setBottom(bottomPane); setContent(root); }