forked from j62/ctbrec
1
0
Fork 0

Code cleanup

This commit is contained in:
0xb00bface 2020-11-28 19:12:18 +01:00
parent 267e3394b5
commit cc277022f0
9 changed files with 187 additions and 250 deletions

View File

@ -1,30 +1,28 @@
package ctbrec.ui.controls; package ctbrec.ui.controls;
import static javafx.scene.control.ButtonType.*;
import java.io.InputStream;
import java.util.Optional;
import ctbrec.ui.AutosizeAlert; import ctbrec.ui.AutosizeAlert;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Alert; import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.layout.Region; import javafx.scene.layout.Region;
import javafx.stage.Modality; import javafx.stage.Modality;
import javafx.stage.Stage; import javafx.stage.Stage;
import java.io.InputStream;
import java.util.Optional;
import static javafx.scene.control.ButtonType.*;
public class Dialogs { public class Dialogs {
private Dialogs() {} private Dialogs() {}
// TODO reduce calls to this method and use Dialogs.showError(Scene parent, String header, String text, Throwable t) instead // TODO reduce calls to this method and use Dialogs.showError(Scene parent, String header, String text, Throwable t) instead
@Deprecated
public static void showError(String header, String text, Throwable t) { public static void showError(String header, String text, Throwable t) {
showError(null, header, text, t); showError(null, header, text, t);
} }

View File

@ -1,15 +1,7 @@
package ctbrec.ui.news; package ctbrec.ui.news;
import static ctbrec.io.HttpConstants.*;
import java.io.IOException;
import java.util.Objects;
import org.json.JSONObject;
import com.squareup.moshi.JsonAdapter; import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.Moshi; import com.squareup.moshi.Moshi;
import ctbrec.io.HttpException; import ctbrec.io.HttpException;
import ctbrec.ui.CamrecApplication; import ctbrec.ui.CamrecApplication;
import ctbrec.ui.controls.Dialogs; import ctbrec.ui.controls.Dialogs;
@ -22,10 +14,15 @@ import javafx.scene.control.Tab;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import org.json.JSONObject;
import java.io.IOException;
import java.util.Objects;
import static ctbrec.io.HttpConstants.USER_AGENT;
public class NewsTab extends Tab implements TabSelectionListener { public class NewsTab extends Tab implements TabSelectionListener {
private static final String ACCESS_TOKEN = "a2804d73a89951a22e0f8483a6fcec8943afd88b7ba17c459c095aa9e6f94fd0"; private static final String ACCESS_TOKEN = "a2804d73a89951a22e0f8483a6fcec8943afd88b7ba17c459c095aa9e6f94fd0";
//private static final String URL = "https://mastodon.cloud/api/v1/timelines/home?limit=50";
private static final String URL = "https://mastodon.cloud/api/v1/accounts/480960/statuses?limit=20&exclude_replies=true"; private static final String URL = "https://mastodon.cloud/api/v1/accounts/480960/statuses?limit=20&exclude_replies=true";
private VBox layout = new VBox(); private VBox layout = new VBox();
@ -64,7 +61,7 @@ public class NewsTab extends Tab implements TabSelectionListener {
} }
} }
} catch (IOException e) { } catch (IOException e) {
Dialogs.showError("News", "Couldn't load news from mastodon", e); Dialogs.showError(getTabPane().getScene(), "News", "Couldn't load news from mastodon", e);
} }
} }

View File

@ -1,25 +1,18 @@
package ctbrec.ui.settings; package ctbrec.ui.settings;
import ctbrec.recorder.postprocessing.*;
import ctbrec.ui.controls.Dialogs;
import ctbrec.ui.settings.api.Preferences;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.layout.Region;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import ctbrec.Config;
import ctbrec.recorder.postprocessing.CreateContactSheet;
import ctbrec.recorder.postprocessing.DeleteTooShort;
import ctbrec.recorder.postprocessing.Move;
import ctbrec.recorder.postprocessing.PostProcessor;
import ctbrec.recorder.postprocessing.Remux;
import ctbrec.recorder.postprocessing.Rename;
import ctbrec.recorder.postprocessing.Script;
import ctbrec.ui.controls.Dialogs;
import ctbrec.ui.settings.api.Preferences;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.layout.Region;
public class PostProcessingDialogFactory { public class PostProcessingDialogFactory {
static Map<Class<?>, Class<?>> ppToDialogMap = new HashMap<>(); static Map<Class<?>, Class<?>> ppToDialogMap = new HashMap<>();
@ -35,19 +28,19 @@ public class PostProcessingDialogFactory {
private PostProcessingDialogFactory() { private PostProcessingDialogFactory() {
} }
public static void openNewDialog(PostProcessor pp, Config config, Scene scene, ObservableList<PostProcessor> stepList) { public static void openNewDialog(PostProcessor pp, Scene scene, ObservableList<PostProcessor> stepList) {
openDialog(pp, config, scene, stepList, true); openDialog(pp, scene, stepList, true);
} }
public static void openEditDialog(PostProcessor pp, Config config, Scene scene, ObservableList<PostProcessor> stepList) { public static void openEditDialog(PostProcessor pp, Scene scene, ObservableList<PostProcessor> stepList) {
openDialog(pp, config, scene, stepList, false); openDialog(pp, scene, stepList, false);
} }
private static void openDialog(PostProcessor pp, Config config, Scene scene, ObservableList<PostProcessor> stepList, boolean newEntry) { private static void openDialog(PostProcessor pp, Scene scene, ObservableList<PostProcessor> stepList, boolean newEntry) {
boolean ok; boolean ok;
try { try {
Optional<Preferences> preferences = createPreferences(pp); Optional<Preferences> preferences = createPreferences(pp);
if(preferences.isPresent()) { if (preferences.isPresent()) {
Region view = preferences.get().getView(false); Region view = preferences.get().getView(false);
view.setMinWidth(600); view.setMinWidth(600);
ok = Dialogs.showCustomInput(scene, "Configure " + pp.getName(), view); ok = Dialogs.showCustomInput(scene, "Configure " + pp.getName(), view);
@ -62,12 +55,12 @@ public class PostProcessingDialogFactory {
} }
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| InstantiationException | IOException e) { | InstantiationException | IOException e) {
Dialogs.showError("New post-processing step", "Couldn't create dialog for " + pp.getName(), e); Dialogs.showError(scene, "New post-processing step", "Couldn't create dialog for " + pp.getName(), e);
} }
} }
private static Optional<Preferences> createPreferences(PostProcessor pp) throws InstantiationException, IllegalAccessException, IllegalArgumentException, private static Optional<Preferences> createPreferences(PostProcessor pp) throws InstantiationException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException, SecurityException { InvocationTargetException, NoSuchMethodException {
Class<?> paneFactoryClass = ppToDialogMap.get(pp.getClass()); Class<?> paneFactoryClass = ppToDialogMap.get(pp.getClass());
if (paneFactoryClass != null) { if (paneFactoryClass != null) {
AbstractPostProcessingPaneFactory factory = (AbstractPostProcessingPaneFactory) paneFactoryClass.getDeclaredConstructor().newInstance(); AbstractPostProcessingPaneFactory factory = (AbstractPostProcessingPaneFactory) paneFactoryClass.getDeclaredConstructor().newInstance();

View File

@ -1,21 +1,7 @@
package ctbrec.ui.settings; package ctbrec.ui.settings;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
import ctbrec.Config; import ctbrec.Config;
import ctbrec.recorder.postprocessing.Copy; import ctbrec.recorder.postprocessing.*;
import ctbrec.recorder.postprocessing.CreateContactSheet;
import ctbrec.recorder.postprocessing.DeleteOriginal;
import ctbrec.recorder.postprocessing.DeleteTooShort;
import ctbrec.recorder.postprocessing.Move;
import ctbrec.recorder.postprocessing.PostProcessor;
import ctbrec.recorder.postprocessing.RemoveKeepFile;
import ctbrec.recorder.postprocessing.Remux;
import ctbrec.recorder.postprocessing.Rename;
import ctbrec.recorder.postprocessing.Script;
import ctbrec.ui.controls.Dialogs; import ctbrec.ui.controls.Dialogs;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener; import javafx.collections.ListChangeListener;
@ -30,12 +16,16 @@ import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.Stage; import javafx.stage.Stage;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
public class PostProcessingStepPanel extends GridPane { public class PostProcessingStepPanel extends GridPane {
private Config config; private final Config config;
private static final Class<?>[] POST_PROCESSOR_CLASSES = new Class<?>[]{ // @formatter: off
private static final Class<?>[] POST_PROCESSOR_CLASSES = new Class<?>[] { // @formatter: off
Copy.class, Copy.class,
Rename.class, Rename.class,
Move.class, Move.class,
@ -98,33 +88,33 @@ public class PostProcessingStepPanel extends GridPane {
} }
private Button createUpButton() { private Button createUpButton() {
Button up = createButton("\u25B4", "Move step up"); Button button = createButton("\u25B4", "Move step up");
up.setOnAction(evt -> { button.setOnAction(evt -> {
int idx = stepListView.getSelectionModel().getSelectedIndex(); int idx = stepListView.getSelectionModel().getSelectedIndex();
PostProcessor selectedItem = stepListView.getSelectionModel().getSelectedItem(); PostProcessor selectedItem = stepListView.getSelectionModel().getSelectedItem();
stepList.remove(idx); stepList.remove(idx);
stepList.add(idx - 1, selectedItem); stepList.add(idx - 1, selectedItem);
stepListView.getSelectionModel().select(idx - 1); stepListView.getSelectionModel().select(idx - 1);
}); });
return up; return button;
} }
private Button createDownButton() { private Button createDownButton() {
Button down = createButton("\u25BE", "Move step down"); Button button = createButton("\u25BE", "Move step down");
down.setOnAction(evt -> { button.setOnAction(evt -> {
int idx = stepListView.getSelectionModel().getSelectedIndex(); int idx = stepListView.getSelectionModel().getSelectedIndex();
PostProcessor selectedItem = stepListView.getSelectionModel().getSelectedItem(); PostProcessor selectedItem = stepListView.getSelectionModel().getSelectedItem();
stepList.remove(idx); stepList.remove(idx);
stepList.add(idx + 1, selectedItem); stepList.add(idx + 1, selectedItem);
stepListView.getSelectionModel().select(idx + 1); stepListView.getSelectionModel().select(idx + 1);
}); });
return down; return button;
} }
private Button createAddButton() { private Button createAddButton() {
Button add = createButton("+", "Add a new step"); Button button = createButton("+", "Add a new step");
add.setDisable(false); button.setDisable(false);
add.setOnAction(evt -> { button.setOnAction(evt -> {
PostProcessor[] options = createOptions(); PostProcessor[] options = createOptions();
ChoiceDialog<PostProcessor> choice = new ChoiceDialog<>(options[0], options); ChoiceDialog<PostProcessor> choice = new ChoiceDialog<>(options[0], options);
choice.setTitle("New Post-Processing Step"); choice.setTitle("New Post-Processing Step");
@ -138,17 +128,17 @@ public class PostProcessingStepPanel extends GridPane {
stage.getIcons().add(new Image(icon)); stage.getIcons().add(new Image(icon));
Optional<PostProcessor> result = choice.showAndWait(); Optional<PostProcessor> result = choice.showAndWait();
result.ifPresent(pp -> PostProcessingDialogFactory.openNewDialog(pp, config, getScene(), stepList)); result.ifPresent(pp -> PostProcessingDialogFactory.openNewDialog(pp, getScene(), stepList));
saveConfig(); saveConfig();
}); });
return add; return button;
} }
private void saveConfig() { private void saveConfig() {
try { try {
config.save(); config.save();
} catch (IOException e) { } catch (IOException e) {
Dialogs.showError("Post-Processing", "Couldn't save post-processing step", e); Dialogs.showError(getScene(), "Post-Processing", "Couldn't save post-processing step", e);
} }
} }
@ -170,25 +160,25 @@ public class PostProcessingStepPanel extends GridPane {
} }
private Button createRemoveButton() { private Button createRemoveButton() {
Button remove = createButton("-", "Remove selected step"); Button button = createButton("-", "Remove selected step");
remove.setOnAction(evt -> { button.setOnAction(evt -> {
PostProcessor selectedItem = stepListView.getSelectionModel().getSelectedItem(); PostProcessor selectedItem = stepListView.getSelectionModel().getSelectedItem();
if (selectedItem != null) { if (selectedItem != null) {
stepList.remove(selectedItem); stepList.remove(selectedItem);
} }
}); });
return remove; return button;
} }
private Button createEditButton() { private Button createEditButton() {
Button edit = createButton("\u270E", "Edit selected step"); Button button = createButton("\u270E", "Edit selected step");
edit.setOnAction(evt -> { button.setOnAction(evt -> {
PostProcessor selectedItem = stepListView.getSelectionModel().getSelectedItem(); PostProcessor selectedItem = stepListView.getSelectionModel().getSelectedItem();
PostProcessingDialogFactory.openEditDialog(selectedItem, config, getScene(), stepList); PostProcessingDialogFactory.openEditDialog(selectedItem, getScene(), stepList);
stepListView.refresh(); stepListView.refresh();
saveConfig(); saveConfig();
}); });
return edit; return button;
} }
private Button createButton(String text, String tooltip) { private Button createButton(String text, String tooltip) {

View File

@ -1,25 +1,24 @@
package ctbrec.ui.sites.bonga; package ctbrec.ui.sites.bonga;
import java.io.IOException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.sites.bonga.BongaCams; import ctbrec.sites.bonga.BongaCams;
import ctbrec.sites.bonga.BongaCamsHttpClient; import ctbrec.sites.bonga.BongaCamsHttpClient;
import ctbrec.ui.controls.Dialogs; import ctbrec.ui.controls.Dialogs;
import ctbrec.ui.sites.AbstractSiteUi; import ctbrec.ui.sites.AbstractSiteUi;
import ctbrec.ui.sites.ConfigUI; import ctbrec.ui.sites.ConfigUI;
import ctbrec.ui.tabs.TabProvider; import ctbrec.ui.tabs.TabProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
public class BongaCamsSiteUi extends AbstractSiteUi { public class BongaCamsSiteUi extends AbstractSiteUi {
private static final transient Logger LOG = LoggerFactory.getLogger(BongaCamsSiteUi.class); private static final Logger LOG = LoggerFactory.getLogger(BongaCamsSiteUi.class);
private BongaCamsTabProvider tabProvider; private final BongaCamsTabProvider tabProvider;
private BongaCamsConfigUI configUi; private final BongaCamsConfigUI configUi;
private BongaCams bongaCams; private final BongaCams bongaCams;
public BongaCamsSiteUi(BongaCams bongaCams) { public BongaCamsSiteUi(BongaCams bongaCams) {
this.bongaCams = bongaCams; this.bongaCams = bongaCams;
@ -57,11 +56,13 @@ public class BongaCamsSiteUi extends AbstractSiteUi {
try { try {
queue.put(true); queue.put(true);
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOG.error("Error while signaling termination", e); LOG.error("Error while signaling termination", e);
} }
}).start(); }).start();
queue.take(); queue.take();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOG.error("Error while waiting for login dialog to close", e); LOG.error("Error while waiting for login dialog to close", e);
throw new IOException(e); throw new IOException(e);
} }

View File

@ -0,0 +1,44 @@
package ctbrec.ui.tabs;
import javafx.animation.Transition;
import javafx.scene.control.Tab;
import javafx.scene.paint.Color;
import javafx.util.Duration;
public class FollowTabBlinkTransition extends Transition {
private final String normalStyle;
private final Tab followedTab;
private final Color normal;
private final Color highlight;
FollowTabBlinkTransition(Tab followedTab) {
this.followedTab = followedTab;
normalStyle = followedTab.getStyle();
normal = Color.web("#f4f4f4");
highlight = Color.web("#2b8513");
setCycleDuration(Duration.millis(500));
setCycleCount(6);
setAutoReverse(true);
setOnFinished(evt -> followedTab.setStyle(normalStyle));
}
@Override
protected void interpolate(double fraction) {
double rh = highlight.getRed();
double rn = normal.getRed();
double diff = rh - rn;
double r = (rn + diff * fraction) * 255;
double gh = highlight.getGreen();
double gn = normal.getGreen();
diff = gh - gn;
double g = (gn + diff * fraction) * 255;
double bh = highlight.getBlue();
double bn = normal.getBlue();
diff = bh - bn;
double b = (bn + diff * fraction) * 255;
String style = "-fx-background-color: rgb(" + r + "," + g + "," + b + ")";
followedTab.setStyle(style);
}
}

View File

@ -1,31 +1,5 @@
package ctbrec.ui.tabs; package ctbrec.ui.tabs;
import static ctbrec.ui.controls.Dialogs.*;
import java.io.IOException;
import java.net.SocketTimeoutException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.Config; import ctbrec.Config;
import ctbrec.Model; import ctbrec.Model;
import ctbrec.event.EventBusHolder; import ctbrec.event.EventBusHolder;
@ -33,22 +7,13 @@ import ctbrec.recorder.Recorder;
import ctbrec.sites.Site; import ctbrec.sites.Site;
import ctbrec.sites.mfc.MyFreeCamsClient; import ctbrec.sites.mfc.MyFreeCamsClient;
import ctbrec.sites.mfc.MyFreeCamsModel; import ctbrec.sites.mfc.MyFreeCamsModel;
import ctbrec.ui.AutosizeAlert; import ctbrec.ui.*;
import ctbrec.ui.DesktopIntegration;
import ctbrec.ui.SiteUiFactory;
import ctbrec.ui.TipDialog;
import ctbrec.ui.TokenLabel;
import ctbrec.ui.action.OpenRecordingsDir; import ctbrec.ui.action.OpenRecordingsDir;
import ctbrec.ui.controls.FasterVerticalScrollPaneSkin; import ctbrec.ui.controls.FasterVerticalScrollPaneSkin;
import ctbrec.ui.controls.SearchBox; import ctbrec.ui.controls.SearchBox;
import ctbrec.ui.controls.SearchPopover; import ctbrec.ui.controls.SearchPopover;
import ctbrec.ui.controls.SearchPopoverTreeList; import ctbrec.ui.controls.SearchPopoverTreeList;
import javafx.animation.FadeTransition; import javafx.animation.*;
import javafx.animation.Interpolator;
import javafx.animation.ParallelTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.Transition;
import javafx.animation.TranslateTransition;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.property.BooleanProperty; import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
@ -64,33 +29,24 @@ import javafx.geometry.Insets;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.control.Alert; import javafx.scene.control.*;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.input.Clipboard; import javafx.scene.input.*;
import javafx.scene.input.ClipboardContent; import javafx.scene.layout.*;
import javafx.scene.input.ContextMenuEvent;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.transform.Transform; import javafx.scene.transform.Transform;
import javafx.util.Duration; import javafx.util.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.SocketTimeoutException;
import java.text.DecimalFormat;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import static ctbrec.ui.controls.Dialogs.showError;
public class ThumbOverviewTab extends Tab implements TabSelectionListener { public class ThumbOverviewTab extends Tab implements TabSelectionListener {
private static final Logger LOG = LoggerFactory.getLogger(ThumbOverviewTab.class); private static final Logger LOG = LoggerFactory.getLogger(ThumbOverviewTab.class);
@ -108,7 +64,6 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
private String filter; private String filter;
ReentrantLock gridLock = new ReentrantLock(); ReentrantLock gridLock = new ReentrantLock();
ScrollPane scrollPane = new ScrollPane(); ScrollPane scrollPane = new ScrollPane();
boolean loginRequired;
TextField pageInput = new TextField(Integer.toString(1)); TextField pageInput = new TextField(Integer.toString(1));
Button pageFirst = new Button("1"); Button pageFirst = new Button("1");
Button pagePrev = new Button(""); Button pagePrev = new Button("");
@ -119,9 +74,9 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
StackPane root = new StackPane(); StackPane root = new StackPane();
Task<List<Model>> searchTask; Task<List<Model>> searchTask;
SearchPopover popover; SearchPopover popover;
SearchPopoverTreeList popoverTreelist = new SearchPopoverTreeList(); SearchPopoverTreeList popoverTreeList = new SearchPopoverTreeList();
double imageAspectRatio = 3.0 / 4.0; double imageAspectRatio = 3.0 / 4.0;
private SimpleBooleanProperty preserveAspectRatio = new SimpleBooleanProperty(true); private final SimpleBooleanProperty preserveAspectRatio = new SimpleBooleanProperty(true);
private ComboBox<Integer> thumbWidth; private ComboBox<Integer> thumbWidth;
@ -174,7 +129,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
popover.maxHeightProperty().bind(popover.minHeightProperty()); popover.maxHeightProperty().bind(popover.minHeightProperty());
popover.prefHeightProperty().bind(popover.minHeightProperty()); popover.prefHeightProperty().bind(popover.minHeightProperty());
popover.setMinHeight(450); popover.setMinHeight(450);
popover.pushPage(popoverTreelist); popover.pushPage(popoverTreeList);
StackPane.setAlignment(popover, Pos.TOP_RIGHT); StackPane.setAlignment(popover, Pos.TOP_RIGHT);
StackPane.setMargin(popover, new Insets(35, 50, 0, 0)); StackPane.setMargin(popover, new Insets(35, 50, 0, 0));
@ -209,7 +164,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
pagination.getChildren().add(pageInput); pagination.getChildren().add(pageInput);
BorderPane.setMargin(pagination, new Insets(5)); BorderPane.setMargin(pagination, new Insets(5));
pageInput.setPrefWidth(50); pageInput.setPrefWidth(50);
pageInput.setOnAction(e -> handlePageNumberInput(e)); pageInput.setOnAction(this::handlePageNumberInput);
pageFirst.setTooltip(new Tooltip("First Page")); pageFirst.setTooltip(new Tooltip("First Page"));
pageFirst.setOnAction(e -> changePageTo(1)); pageFirst.setOnAction(e -> changePageTo(1));
pagePrev.setTooltip(new Tooltip("Previous Page")); pagePrev.setTooltip(new Tooltip("Previous Page"));
@ -230,8 +185,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
thumbWidth = new ComboBox<>(FXCollections.observableList(thumbWidths)); thumbWidth = new ComboBox<>(FXCollections.observableList(thumbWidths));
thumbWidth.getSelectionModel().select(Integer.valueOf(Config.getInstance().getSettings().thumbWidth)); thumbWidth.getSelectionModel().select(Integer.valueOf(Config.getInstance().getSettings().thumbWidth));
thumbWidth.setOnAction(e -> { thumbWidth.setOnAction(e -> {
int width = thumbWidth.getSelectionModel().getSelectedItem(); Config.getInstance().getSettings().thumbWidth = thumbWidth.getSelectionModel().getSelectedItem();
Config.getInstance().getSettings().thumbWidth = width;
updateThumbSize(); updateThumbSize();
}); });
thumbSizeSelector.getChildren().add(thumbWidth); thumbSizeSelector.getChildren().add(thumbWidth);
@ -252,20 +206,14 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
root.getChildren().add(popover); root.getChildren().add(popover);
setContent(root); setContent(root);
scrollPane.setOnKeyReleased(new EventHandler<KeyEvent>() { scrollPane.setOnKeyReleased(event -> {
@Override
public void handle(KeyEvent event) {
if (event.getCode() == KeyCode.RIGHT) { if (event.getCode() == KeyCode.RIGHT) {
System.out.println(event.getSource());
nextPage(); nextPage();
} else if (event.getCode() == KeyCode.LEFT) { } else if (event.getCode() == KeyCode.LEFT) {
System.out.println(event.getSource());
previousPage(); previousPage();
} else if (event.getCode().getCode() >= KeyCode.DIGIT1.getCode() && event.getCode().getCode() <= KeyCode.DIGIT9.getCode()) { } else if (event.getCode().getCode() >= KeyCode.DIGIT1.getCode() && event.getCode().getCode() <= KeyCode.DIGIT9.getCode()) {
System.out.println(event.getSource());
changePageTo(event.getCode().getCode() - 48); changePageTo(event.getCode().getCode() - 48);
} }
}
}); });
} }
@ -296,7 +244,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
if(newValue.length() < 2) { if(newValue.length() < 2) {
return; return;
} }
searchTask = new ThumbOverviewTabSearchTask(site, popover, popoverTreelist, newValue); searchTask = new ThumbOverviewTabSearchTask(site, popover, popoverTreeList, newValue);
new Thread(searchTask).start(); new Thread(searchTask).start();
}; };
} }
@ -448,11 +396,10 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
if(popup != null) { if(popup != null) {
popup.hide(); popup.hide();
popup = null; popup = null;
return;
} }
}); });
newCell.selectionProperty().addListener((obs, oldValue, newValue) -> { newCell.selectionProperty().addListener((obs, oldValue, newValue) -> {
if(newValue.booleanValue()) { if (Boolean.TRUE.equals(newValue)) {
selectedThumbCells.add(newCell); selectedThumbCells.add(newCell);
} else { } else {
selectedThumbCells.remove(newCell); selectedThumbCells.remove(newCell);
@ -577,10 +524,10 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
event.put("amount", tokens.doubleValue()); event.put("amount", tokens.doubleValue());
EventBusHolder.BUS.post(event); EventBusHolder.BUS.post(event);
} catch (IOException ex) { } catch (IOException ex) {
LOG.error("An error occured while sending tip", ex); LOG.error("An error occurred while sending tip", ex);
showError("Couldn't send tip", "An error occured while sending tip:", ex); showError(getTabPane().getScene(), "Couldn't send tip", "An error occurred while sending tip:", ex);
} catch (Exception ex) { } catch (Exception ex) {
showError("Couldn't send tip", "You entered an invalid amount of tokens", ex); showError(getTabPane().getScene(), "Couldn't send tip", "You entered an invalid amount of tokens", ex);
} }
} }
}); });
@ -599,7 +546,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
protected void follow(List<ThumbCell> selection, boolean follow) { protected void follow(List<ThumbCell> selection, boolean follow) {
for (ThumbCell thumbCell : selection) { for (ThumbCell thumbCell : selection) {
thumbCell.follow(follow).thenAccept(success -> { thumbCell.follow(follow).thenAccept(success -> {
if(follow && success.booleanValue()) { if (follow && Boolean.TRUE.equals(success)) {
showAddToFollowedAnimation(thumbCell); showAddToFollowedAnimation(thumbCell);
} }
}); });
@ -647,35 +594,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
ParallelTransition pt = new ParallelTransition(translate, scale); ParallelTransition pt = new ParallelTransition(translate, scale);
pt.play(); pt.play();
pt.setOnFinished(evt -> root.getChildren().remove(iv)); pt.setOnFinished(evt -> root.getChildren().remove(iv));
FollowTabBlinkTransition blink = new FollowTabBlinkTransition(followedTab);
String normalStyle = followedTab.getStyle();
Color normal = Color.web("#f4f4f4");
Color highlight = Color.web("#2b8513");
Transition blink = new Transition() {
{
setCycleDuration(Duration.millis(500));
}
@Override
protected void interpolate(double frac) {
double rh = highlight.getRed();
double rn = normal.getRed();
double diff = rh - rn;
double r = (rn + diff * frac) * 255;
double gh = highlight.getGreen();
double gn = normal.getGreen();
diff = gh - gn;
double g = (gn + diff * frac) * 255;
double bh = highlight.getBlue();
double bn = normal.getBlue();
diff = bh - bn;
double b = (bn + diff * frac) * 255;
String style = "-fx-background-color: rgb(" + r + "," + g + "," + b + ")";
followedTab.setStyle(style);
}
};
blink.setCycleCount(6);
blink.setAutoReverse(true);
blink.setOnFinished(evt -> followedTab.setStyle(normalStyle));
blink.play(); blink.play();
}); });
} }
@ -714,13 +633,13 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
} }
} }
private EventHandler<MouseEvent> mouseClickListener = e -> { private final EventHandler<MouseEvent> mouseClickListener = e -> {
ThumbCell cell = (ThumbCell) e.getSource(); ThumbCell cell = (ThumbCell) e.getSource();
if (e.getButton() == MouseButton.PRIMARY && e.getClickCount() == 2) { if (e.getButton() == MouseButton.PRIMARY && e.getClickCount() == 2) {
cell.setSelected(false); cell.setSelected(false);
cell.startPlayer(); cell.startPlayer();
} else if (e.getButton() == MouseButton.PRIMARY && e.isControlDown()) { } else if (e.getButton() == MouseButton.PRIMARY && e.isControlDown()) {
if(popup == null) { if (popup == null) {
cell.setSelected(!cell.isSelected()); cell.setSelected(!cell.isSelected());
} }
} else if (e.getButton() == MouseButton.PRIMARY) { } else if (e.getButton() == MouseButton.PRIMARY) {
@ -750,12 +669,9 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
} }
void filter() { void filter() {
Collections.sort(filteredThumbCells, (o1, o2) -> { filteredThumbCells.sort((c1, c2) -> {
ThumbCell c1 = o1; if (c1.getIndex() < c2.getIndex()) return -1;
ThumbCell c2 = o2; if (c1.getIndex() > c2.getIndex()) return 1;
if(c1.getIndex() < c2.getIndex()) return -1;
if(c1.getIndex() > c2.getIndex()) return 1;
return c1.getModel().getName().compareTo(c2.getModel().getName()); return c1.getModel().getName().compareTo(c2.getModel().getName());
}); });
@ -861,7 +777,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
return !tokensMissing; return !tokensMissing;
} }
private String createSearchText(Model m) throws ExecutionException { private String createSearchText(Model m) {
StringBuilder searchTextBuilder = new StringBuilder(m.getName()); StringBuilder searchTextBuilder = new StringBuilder(m.getName());
searchTextBuilder.append(' '); searchTextBuilder.append(' ');
searchTextBuilder.append(m.getDisplayName()); searchTextBuilder.append(m.getDisplayName());
@ -878,7 +794,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
public void setRecorder(Recorder recorder) { public void setRecorder(Recorder recorder) {
this.recorder = recorder; this.recorder = recorder;
popoverTreelist.setRecorder(recorder); popoverTreeList.setRecorder(recorder);
} }
@Override @Override

View File

@ -1,13 +1,5 @@
package ctbrec.ui.tabs; package ctbrec.ui.tabs;
import static ctbrec.ui.controls.Dialogs.*;
import java.io.IOException;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.Model; import ctbrec.Model;
import ctbrec.sites.Site; import ctbrec.sites.Site;
import ctbrec.ui.SiteUiFactory; import ctbrec.ui.SiteUiFactory;
@ -15,20 +7,27 @@ import ctbrec.ui.controls.SearchPopover;
import ctbrec.ui.controls.SearchPopoverTreeList; import ctbrec.ui.controls.SearchPopoverTreeList;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.List;
import static ctbrec.ui.controls.Dialogs.showError;
public class ThumbOverviewTabSearchTask extends Task<List<Model>> { public class ThumbOverviewTabSearchTask extends Task<List<Model>> {
private static final Logger LOG = LoggerFactory.getLogger(ThumbOverviewTabSearchTask.class); private static final Logger LOG = LoggerFactory.getLogger(ThumbOverviewTabSearchTask.class);
private Site site; private final Site site;
private SearchPopover popover; private final SearchPopover popover;
private SearchPopoverTreeList popoverTreelist; private final SearchPopoverTreeList popoverTreeList;
private String query; private final String query;
public ThumbOverviewTabSearchTask(Site site, SearchPopover popover, SearchPopoverTreeList popoverTreelist, String query) { public ThumbOverviewTabSearchTask(Site site, SearchPopover popover, SearchPopoverTreeList popoverTreeList, String query) {
this.site = site; this.site = site;
this.popover = popover; this.popover = popover;
this.popoverTreelist = popoverTreelist; this.popoverTreeList = popoverTreeList;
this.query = query; this.query = query;
} }
@ -39,10 +38,10 @@ public class ThumbOverviewTabSearchTask extends Task<List<Model>> {
try { try {
loggedin = SiteUiFactory.getUi(site).login(); loggedin = SiteUiFactory.getUi(site).login();
} catch (IOException e) { } catch (IOException e) {
loggedin = false; // nothing to do
} }
if(!loggedin) { if(!loggedin) {
showError("Login failed", "Search won't work correctly without login", null); showError(popover.getScene(), "Login failed", "Search won't work correctly without login", null);
} }
} }
return site.search(query); return site.search(query);
@ -61,9 +60,9 @@ public class ThumbOverviewTabSearchTask extends Task<List<Model>> {
if(models.isEmpty()) { if(models.isEmpty()) {
popover.hide(); popover.hide();
} else { } else {
popoverTreelist.getItems().clear(); popoverTreeList.getItems().clear();
for (Model model : getValue()) { for (Model model : getValue()) {
popoverTreelist.getItems().add(model); popoverTreeList.getItems().add(model);
} }
popover.show(); popover.show();
} }

View File

@ -1,8 +1,5 @@
package ctbrec.ui.tabs; package ctbrec.ui.tabs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.io.HttpException; import ctbrec.io.HttpException;
import ctbrec.ui.CamrecApplication; import ctbrec.ui.CamrecApplication;
import ctbrec.ui.CamrecApplication.Release; import ctbrec.ui.CamrecApplication.Release;
@ -18,12 +15,14 @@ import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class UpdateTab extends Tab { public class UpdateTab extends Tab {
private static final Logger LOG = LoggerFactory.getLogger(UpdateTab.class); private static final Logger LOG = LoggerFactory.getLogger(UpdateTab.class);
private TextArea changelog; private final TextArea changelog;
public UpdateTab(Release latest) { public UpdateTab(Release latest) {
setText("Update Available"); setText("Update Available");
@ -52,7 +51,7 @@ public class UpdateTab extends Tab {
} }
} catch (Exception e1) { } catch (Exception e1) {
LOG.error("Couldn't download the changelog", e1); LOG.error("Couldn't download the changelog", e1);
Dialogs.showError("Communication error", "Couldn't download the changelog", e1); Dialogs.showError(getTabPane().getScene(), "Communication error", "Couldn't download the changelog", e1);
} }
}).start(); }).start();
} }