Code cleanup
This commit is contained in:
parent
267e3394b5
commit
cc277022f0
|
@ -1,30 +1,28 @@
|
|||
package ctbrec.ui.controls;
|
||||
|
||||
import static javafx.scene.control.ButtonType.*;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Optional;
|
||||
|
||||
import ctbrec.ui.AutosizeAlert;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.*;
|
||||
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.layout.GridPane;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Optional;
|
||||
|
||||
import static javafx.scene.control.ButtonType.*;
|
||||
|
||||
public class Dialogs {
|
||||
|
||||
private Dialogs() {}
|
||||
|
||||
// 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) {
|
||||
showError(null, header, text, t);
|
||||
}
|
||||
|
|
|
@ -1,15 +1,7 @@
|
|||
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.Moshi;
|
||||
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.ui.CamrecApplication;
|
||||
import ctbrec.ui.controls.Dialogs;
|
||||
|
@ -22,10 +14,15 @@ import javafx.scene.control.Tab;
|
|||
import javafx.scene.layout.VBox;
|
||||
import okhttp3.Request;
|
||||
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 {
|
||||
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 VBox layout = new VBox();
|
||||
|
@ -64,7 +61,7 @@ public class NewsTab extends Tab implements TabSelectionListener {
|
|||
}
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,25 +1,18 @@
|
|||
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.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
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 {
|
||||
|
||||
static Map<Class<?>, Class<?>> ppToDialogMap = new HashMap<>();
|
||||
|
@ -35,19 +28,19 @@ public class PostProcessingDialogFactory {
|
|||
private PostProcessingDialogFactory() {
|
||||
}
|
||||
|
||||
public static void openNewDialog(PostProcessor pp, Config config, Scene scene, ObservableList<PostProcessor> stepList) {
|
||||
openDialog(pp, config, scene, stepList, true);
|
||||
public static void openNewDialog(PostProcessor pp, Scene scene, ObservableList<PostProcessor> stepList) {
|
||||
openDialog(pp, scene, stepList, true);
|
||||
}
|
||||
|
||||
public static void openEditDialog(PostProcessor pp, Config config, Scene scene, ObservableList<PostProcessor> stepList) {
|
||||
openDialog(pp, config, scene, stepList, false);
|
||||
public static void openEditDialog(PostProcessor pp, Scene scene, ObservableList<PostProcessor> stepList) {
|
||||
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;
|
||||
try {
|
||||
Optional<Preferences> preferences = createPreferences(pp);
|
||||
if(preferences.isPresent()) {
|
||||
if (preferences.isPresent()) {
|
||||
Region view = preferences.get().getView(false);
|
||||
view.setMinWidth(600);
|
||||
ok = Dialogs.showCustomInput(scene, "Configure " + pp.getName(), view);
|
||||
|
@ -62,12 +55,12 @@ public class PostProcessingDialogFactory {
|
|||
}
|
||||
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||
| 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,
|
||||
InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
private static Optional<Preferences> createPreferences(PostProcessor pp) throws InstantiationException, IllegalAccessException,
|
||||
InvocationTargetException, NoSuchMethodException {
|
||||
Class<?> paneFactoryClass = ppToDialogMap.get(pp.getClass());
|
||||
if (paneFactoryClass != null) {
|
||||
AbstractPostProcessingPaneFactory factory = (AbstractPostProcessingPaneFactory) paneFactoryClass.getDeclaredConstructor().newInstance();
|
||||
|
|
|
@ -1,21 +1,7 @@
|
|||
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.recorder.postprocessing.Copy;
|
||||
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.recorder.postprocessing.*;
|
||||
import ctbrec.ui.controls.Dialogs;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
|
@ -30,21 +16,25 @@ import javafx.scene.layout.Priority;
|
|||
import javafx.scene.layout.VBox;
|
||||
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 {
|
||||
|
||||
private Config config;
|
||||
private final Config config;
|
||||
|
||||
|
||||
private static final Class<?>[] POST_PROCESSOR_CLASSES = new Class<?>[] { // @formatter: off
|
||||
Copy.class,
|
||||
Rename.class,
|
||||
Move.class,
|
||||
Remux.class,
|
||||
Script.class,
|
||||
DeleteOriginal.class,
|
||||
DeleteTooShort.class,
|
||||
RemoveKeepFile.class,
|
||||
CreateContactSheet.class
|
||||
private static final Class<?>[] POST_PROCESSOR_CLASSES = new Class<?>[]{ // @formatter: off
|
||||
Copy.class,
|
||||
Rename.class,
|
||||
Move.class,
|
||||
Remux.class,
|
||||
Script.class,
|
||||
DeleteOriginal.class,
|
||||
DeleteTooShort.class,
|
||||
RemoveKeepFile.class,
|
||||
CreateContactSheet.class
|
||||
}; // @formatter: on
|
||||
|
||||
ListView<PostProcessor> stepListView;
|
||||
|
@ -98,33 +88,33 @@ public class PostProcessingStepPanel extends GridPane {
|
|||
}
|
||||
|
||||
private Button createUpButton() {
|
||||
Button up = createButton("\u25B4", "Move step up");
|
||||
up.setOnAction(evt -> {
|
||||
Button button = createButton("\u25B4", "Move step up");
|
||||
button.setOnAction(evt -> {
|
||||
int idx = stepListView.getSelectionModel().getSelectedIndex();
|
||||
PostProcessor selectedItem = stepListView.getSelectionModel().getSelectedItem();
|
||||
stepList.remove(idx);
|
||||
stepList.add(idx - 1, selectedItem);
|
||||
stepListView.getSelectionModel().select(idx - 1);
|
||||
});
|
||||
return up;
|
||||
return button;
|
||||
}
|
||||
|
||||
private Button createDownButton() {
|
||||
Button down = createButton("\u25BE", "Move step down");
|
||||
down.setOnAction(evt -> {
|
||||
Button button = createButton("\u25BE", "Move step down");
|
||||
button.setOnAction(evt -> {
|
||||
int idx = stepListView.getSelectionModel().getSelectedIndex();
|
||||
PostProcessor selectedItem = stepListView.getSelectionModel().getSelectedItem();
|
||||
stepList.remove(idx);
|
||||
stepList.add(idx + 1, selectedItem);
|
||||
stepListView.getSelectionModel().select(idx + 1);
|
||||
});
|
||||
return down;
|
||||
return button;
|
||||
}
|
||||
|
||||
private Button createAddButton() {
|
||||
Button add = createButton("+", "Add a new step");
|
||||
add.setDisable(false);
|
||||
add.setOnAction(evt -> {
|
||||
Button button = createButton("+", "Add a new step");
|
||||
button.setDisable(false);
|
||||
button.setOnAction(evt -> {
|
||||
PostProcessor[] options = createOptions();
|
||||
ChoiceDialog<PostProcessor> choice = new ChoiceDialog<>(options[0], options);
|
||||
choice.setTitle("New Post-Processing Step");
|
||||
|
@ -138,17 +128,17 @@ public class PostProcessingStepPanel extends GridPane {
|
|||
stage.getIcons().add(new Image(icon));
|
||||
|
||||
Optional<PostProcessor> result = choice.showAndWait();
|
||||
result.ifPresent(pp -> PostProcessingDialogFactory.openNewDialog(pp, config, getScene(), stepList));
|
||||
result.ifPresent(pp -> PostProcessingDialogFactory.openNewDialog(pp, getScene(), stepList));
|
||||
saveConfig();
|
||||
});
|
||||
return add;
|
||||
return button;
|
||||
}
|
||||
|
||||
private void saveConfig() {
|
||||
try {
|
||||
config.save();
|
||||
} 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() {
|
||||
Button remove = createButton("-", "Remove selected step");
|
||||
remove.setOnAction(evt -> {
|
||||
Button button = createButton("-", "Remove selected step");
|
||||
button.setOnAction(evt -> {
|
||||
PostProcessor selectedItem = stepListView.getSelectionModel().getSelectedItem();
|
||||
if (selectedItem != null) {
|
||||
stepList.remove(selectedItem);
|
||||
}
|
||||
});
|
||||
return remove;
|
||||
return button;
|
||||
}
|
||||
|
||||
private Button createEditButton() {
|
||||
Button edit = createButton("\u270E", "Edit selected step");
|
||||
edit.setOnAction(evt -> {
|
||||
Button button = createButton("\u270E", "Edit selected step");
|
||||
button.setOnAction(evt -> {
|
||||
PostProcessor selectedItem = stepListView.getSelectionModel().getSelectedItem();
|
||||
PostProcessingDialogFactory.openEditDialog(selectedItem, config, getScene(), stepList);
|
||||
PostProcessingDialogFactory.openEditDialog(selectedItem, getScene(), stepList);
|
||||
stepListView.refresh();
|
||||
saveConfig();
|
||||
});
|
||||
return edit;
|
||||
return button;
|
||||
}
|
||||
|
||||
private Button createButton(String text, String tooltip) {
|
||||
|
|
|
@ -1,25 +1,24 @@
|
|||
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.BongaCamsHttpClient;
|
||||
import ctbrec.ui.controls.Dialogs;
|
||||
import ctbrec.ui.sites.AbstractSiteUi;
|
||||
import ctbrec.ui.sites.ConfigUI;
|
||||
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 {
|
||||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(BongaCamsSiteUi.class);
|
||||
private BongaCamsTabProvider tabProvider;
|
||||
private BongaCamsConfigUI configUi;
|
||||
private BongaCams bongaCams;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(BongaCamsSiteUi.class);
|
||||
private final BongaCamsTabProvider tabProvider;
|
||||
private final BongaCamsConfigUI configUi;
|
||||
private final BongaCams bongaCams;
|
||||
|
||||
public BongaCamsSiteUi(BongaCams bongaCams) {
|
||||
this.bongaCams = bongaCams;
|
||||
|
@ -57,11 +56,13 @@ public class BongaCamsSiteUi extends AbstractSiteUi {
|
|||
try {
|
||||
queue.put(true);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
LOG.error("Error while signaling termination", e);
|
||||
}
|
||||
}).start();
|
||||
queue.take();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
LOG.error("Error while waiting for login dialog to close", e);
|
||||
throw new IOException(e);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -1,31 +1,5 @@
|
|||
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.Model;
|
||||
import ctbrec.event.EventBusHolder;
|
||||
|
@ -33,22 +7,13 @@ import ctbrec.recorder.Recorder;
|
|||
import ctbrec.sites.Site;
|
||||
import ctbrec.sites.mfc.MyFreeCamsClient;
|
||||
import ctbrec.sites.mfc.MyFreeCamsModel;
|
||||
import ctbrec.ui.AutosizeAlert;
|
||||
import ctbrec.ui.DesktopIntegration;
|
||||
import ctbrec.ui.SiteUiFactory;
|
||||
import ctbrec.ui.TipDialog;
|
||||
import ctbrec.ui.TokenLabel;
|
||||
import ctbrec.ui.*;
|
||||
import ctbrec.ui.action.OpenRecordingsDir;
|
||||
import ctbrec.ui.controls.FasterVerticalScrollPaneSkin;
|
||||
import ctbrec.ui.controls.SearchBox;
|
||||
import ctbrec.ui.controls.SearchPopover;
|
||||
import ctbrec.ui.controls.SearchPopoverTreeList;
|
||||
import javafx.animation.FadeTransition;
|
||||
import javafx.animation.Interpolator;
|
||||
import javafx.animation.ParallelTransition;
|
||||
import javafx.animation.ScaleTransition;
|
||||
import javafx.animation.Transition;
|
||||
import javafx.animation.TranslateTransition;
|
||||
import javafx.animation.*;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
|
@ -64,33 +29,24 @@ import javafx.geometry.Insets;
|
|||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.Alert;
|
||||
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.control.*;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.input.Clipboard;
|
||||
import javafx.scene.input.ClipboardContent;
|
||||
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.input.*;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.scene.transform.Transform;
|
||||
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 {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ThumbOverviewTab.class);
|
||||
|
@ -108,7 +64,6 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
private String filter;
|
||||
ReentrantLock gridLock = new ReentrantLock();
|
||||
ScrollPane scrollPane = new ScrollPane();
|
||||
boolean loginRequired;
|
||||
TextField pageInput = new TextField(Integer.toString(1));
|
||||
Button pageFirst = new Button("1");
|
||||
Button pagePrev = new Button("◀");
|
||||
|
@ -119,9 +74,9 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
StackPane root = new StackPane();
|
||||
Task<List<Model>> searchTask;
|
||||
SearchPopover popover;
|
||||
SearchPopoverTreeList popoverTreelist = new SearchPopoverTreeList();
|
||||
SearchPopoverTreeList popoverTreeList = new SearchPopoverTreeList();
|
||||
double imageAspectRatio = 3.0 / 4.0;
|
||||
private SimpleBooleanProperty preserveAspectRatio = new SimpleBooleanProperty(true);
|
||||
private final SimpleBooleanProperty preserveAspectRatio = new SimpleBooleanProperty(true);
|
||||
|
||||
private ComboBox<Integer> thumbWidth;
|
||||
|
||||
|
@ -174,7 +129,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
popover.maxHeightProperty().bind(popover.minHeightProperty());
|
||||
popover.prefHeightProperty().bind(popover.minHeightProperty());
|
||||
popover.setMinHeight(450);
|
||||
popover.pushPage(popoverTreelist);
|
||||
popover.pushPage(popoverTreeList);
|
||||
StackPane.setAlignment(popover, Pos.TOP_RIGHT);
|
||||
StackPane.setMargin(popover, new Insets(35, 50, 0, 0));
|
||||
|
||||
|
@ -209,7 +164,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
pagination.getChildren().add(pageInput);
|
||||
BorderPane.setMargin(pagination, new Insets(5));
|
||||
pageInput.setPrefWidth(50);
|
||||
pageInput.setOnAction(e -> handlePageNumberInput(e));
|
||||
pageInput.setOnAction(this::handlePageNumberInput);
|
||||
pageFirst.setTooltip(new Tooltip("First Page"));
|
||||
pageFirst.setOnAction(e -> changePageTo(1));
|
||||
pagePrev.setTooltip(new Tooltip("Previous Page"));
|
||||
|
@ -230,8 +185,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
thumbWidth = new ComboBox<>(FXCollections.observableList(thumbWidths));
|
||||
thumbWidth.getSelectionModel().select(Integer.valueOf(Config.getInstance().getSettings().thumbWidth));
|
||||
thumbWidth.setOnAction(e -> {
|
||||
int width = thumbWidth.getSelectionModel().getSelectedItem();
|
||||
Config.getInstance().getSettings().thumbWidth = width;
|
||||
Config.getInstance().getSettings().thumbWidth = thumbWidth.getSelectionModel().getSelectedItem();
|
||||
updateThumbSize();
|
||||
});
|
||||
thumbSizeSelector.getChildren().add(thumbWidth);
|
||||
|
@ -252,19 +206,13 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
root.getChildren().add(popover);
|
||||
setContent(root);
|
||||
|
||||
scrollPane.setOnKeyReleased(new EventHandler<KeyEvent>() {
|
||||
@Override
|
||||
public void handle(KeyEvent event) {
|
||||
if (event.getCode() == KeyCode.RIGHT) {
|
||||
System.out.println(event.getSource());
|
||||
nextPage();
|
||||
} else if (event.getCode() == KeyCode.LEFT) {
|
||||
System.out.println(event.getSource());
|
||||
previousPage();
|
||||
} else if (event.getCode().getCode() >= KeyCode.DIGIT1.getCode() && event.getCode().getCode() <= KeyCode.DIGIT9.getCode()) {
|
||||
System.out.println(event.getSource());
|
||||
changePageTo(event.getCode().getCode() - 48);
|
||||
}
|
||||
scrollPane.setOnKeyReleased(event -> {
|
||||
if (event.getCode() == KeyCode.RIGHT) {
|
||||
nextPage();
|
||||
} else if (event.getCode() == KeyCode.LEFT) {
|
||||
previousPage();
|
||||
} else if (event.getCode().getCode() >= KeyCode.DIGIT1.getCode() && event.getCode().getCode() <= KeyCode.DIGIT9.getCode()) {
|
||||
changePageTo(event.getCode().getCode() - 48);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -296,7 +244,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
if(newValue.length() < 2) {
|
||||
return;
|
||||
}
|
||||
searchTask = new ThumbOverviewTabSearchTask(site, popover, popoverTreelist, newValue);
|
||||
searchTask = new ThumbOverviewTabSearchTask(site, popover, popoverTreeList, newValue);
|
||||
new Thread(searchTask).start();
|
||||
};
|
||||
}
|
||||
|
@ -448,11 +396,10 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
if(popup != null) {
|
||||
popup.hide();
|
||||
popup = null;
|
||||
return;
|
||||
}
|
||||
});
|
||||
newCell.selectionProperty().addListener((obs, oldValue, newValue) -> {
|
||||
if(newValue.booleanValue()) {
|
||||
if (Boolean.TRUE.equals(newValue)) {
|
||||
selectedThumbCells.add(newCell);
|
||||
} else {
|
||||
selectedThumbCells.remove(newCell);
|
||||
|
@ -577,10 +524,10 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
event.put("amount", tokens.doubleValue());
|
||||
EventBusHolder.BUS.post(event);
|
||||
} catch (IOException ex) {
|
||||
LOG.error("An error occured while sending tip", ex);
|
||||
showError("Couldn't send tip", "An error occured while sending tip:", ex);
|
||||
LOG.error("An error occurred while sending tip", ex);
|
||||
showError(getTabPane().getScene(), "Couldn't send tip", "An error occurred while sending tip:", 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) {
|
||||
for (ThumbCell thumbCell : selection) {
|
||||
thumbCell.follow(follow).thenAccept(success -> {
|
||||
if(follow && success.booleanValue()) {
|
||||
if (follow && Boolean.TRUE.equals(success)) {
|
||||
showAddToFollowedAnimation(thumbCell);
|
||||
}
|
||||
});
|
||||
|
@ -647,35 +594,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
ParallelTransition pt = new ParallelTransition(translate, scale);
|
||||
pt.play();
|
||||
pt.setOnFinished(evt -> root.getChildren().remove(iv));
|
||||
|
||||
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));
|
||||
FollowTabBlinkTransition blink = new FollowTabBlinkTransition(followedTab);
|
||||
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();
|
||||
if (e.getButton() == MouseButton.PRIMARY && e.getClickCount() == 2) {
|
||||
cell.setSelected(false);
|
||||
cell.startPlayer();
|
||||
} else if (e.getButton() == MouseButton.PRIMARY && e.isControlDown()) {
|
||||
if(popup == null) {
|
||||
if (popup == null) {
|
||||
cell.setSelected(!cell.isSelected());
|
||||
}
|
||||
} else if (e.getButton() == MouseButton.PRIMARY) {
|
||||
|
@ -750,12 +669,9 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
}
|
||||
|
||||
void filter() {
|
||||
Collections.sort(filteredThumbCells, (o1, o2) -> {
|
||||
ThumbCell c1 = o1;
|
||||
ThumbCell c2 = o2;
|
||||
|
||||
if(c1.getIndex() < c2.getIndex()) return -1;
|
||||
if(c1.getIndex() > c2.getIndex()) return 1;
|
||||
filteredThumbCells.sort((c1, c2) -> {
|
||||
if (c1.getIndex() < c2.getIndex()) return -1;
|
||||
if (c1.getIndex() > c2.getIndex()) return 1;
|
||||
return c1.getModel().getName().compareTo(c2.getModel().getName());
|
||||
});
|
||||
|
||||
|
@ -861,7 +777,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
return !tokensMissing;
|
||||
}
|
||||
|
||||
private String createSearchText(Model m) throws ExecutionException {
|
||||
private String createSearchText(Model m) {
|
||||
StringBuilder searchTextBuilder = new StringBuilder(m.getName());
|
||||
searchTextBuilder.append(' ');
|
||||
searchTextBuilder.append(m.getDisplayName());
|
||||
|
@ -878,7 +794,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
|
||||
public void setRecorder(Recorder recorder) {
|
||||
this.recorder = recorder;
|
||||
popoverTreelist.setRecorder(recorder);
|
||||
popoverTreeList.setRecorder(recorder);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
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.sites.Site;
|
||||
import ctbrec.ui.SiteUiFactory;
|
||||
|
@ -15,20 +7,27 @@ import ctbrec.ui.controls.SearchPopover;
|
|||
import ctbrec.ui.controls.SearchPopoverTreeList;
|
||||
import javafx.application.Platform;
|
||||
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>> {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ThumbOverviewTabSearchTask.class);
|
||||
|
||||
private Site site;
|
||||
private SearchPopover popover;
|
||||
private SearchPopoverTreeList popoverTreelist;
|
||||
private String query;
|
||||
private final Site site;
|
||||
private final SearchPopover popover;
|
||||
private final SearchPopoverTreeList popoverTreeList;
|
||||
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.popover = popover;
|
||||
this.popoverTreelist = popoverTreelist;
|
||||
this.popoverTreeList = popoverTreeList;
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
|
@ -39,10 +38,10 @@ public class ThumbOverviewTabSearchTask extends Task<List<Model>> {
|
|||
try {
|
||||
loggedin = SiteUiFactory.getUi(site).login();
|
||||
} catch (IOException e) {
|
||||
loggedin = false;
|
||||
// nothing to do
|
||||
}
|
||||
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);
|
||||
|
@ -61,9 +60,9 @@ public class ThumbOverviewTabSearchTask extends Task<List<Model>> {
|
|||
if(models.isEmpty()) {
|
||||
popover.hide();
|
||||
} else {
|
||||
popoverTreelist.getItems().clear();
|
||||
popoverTreeList.getItems().clear();
|
||||
for (Model model : getValue()) {
|
||||
popoverTreelist.getItems().add(model);
|
||||
popoverTreeList.getItems().add(model);
|
||||
}
|
||||
popover.show();
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package ctbrec.ui.tabs;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.ui.CamrecApplication;
|
||||
import ctbrec.ui.CamrecApplication.Release;
|
||||
|
@ -18,12 +15,14 @@ import javafx.scene.layout.Priority;
|
|||
import javafx.scene.layout.VBox;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class UpdateTab extends Tab {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(UpdateTab.class);
|
||||
|
||||
private TextArea changelog;
|
||||
private final TextArea changelog;
|
||||
|
||||
public UpdateTab(Release latest) {
|
||||
setText("Update Available");
|
||||
|
@ -52,7 +51,7 @@ public class UpdateTab extends Tab {
|
|||
}
|
||||
} catch (Exception 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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue