From 9df466f0ea462a68152400b16998fec0d4c5807c Mon Sep 17 00:00:00 2001 From: 0xb00bface <0xboobface@gmail.com> Date: Sun, 19 Feb 2023 20:11:25 +0100 Subject: [PATCH] Add checkbox to post-processing steps to disable them --- .../settings/PostProcessingDialogFactory.java | 19 ++- .../ui/settings/PostProcessingStepPanel.java | 113 ++++++++++-------- .../ctbrec/ui/settings/api/Preferences.java | 1 + 3 files changed, 81 insertions(+), 52 deletions(-) diff --git a/client/src/main/java/ctbrec/ui/settings/PostProcessingDialogFactory.java b/client/src/main/java/ctbrec/ui/settings/PostProcessingDialogFactory.java index dd6e8bb9..95f3c52c 100644 --- a/client/src/main/java/ctbrec/ui/settings/PostProcessingDialogFactory.java +++ b/client/src/main/java/ctbrec/ui/settings/PostProcessingDialogFactory.java @@ -4,7 +4,12 @@ import ctbrec.recorder.postprocessing.*; import ctbrec.ui.controls.Dialogs; import ctbrec.ui.settings.api.Preferences; import javafx.collections.ObservableList; +import javafx.geometry.HPos; +import javafx.geometry.Insets; +import javafx.geometry.VPos; import javafx.scene.Scene; +import javafx.scene.control.CheckBox; +import javafx.scene.layout.GridPane; import javafx.scene.layout.Region; import java.io.IOException; @@ -16,6 +21,7 @@ import java.util.Optional; public class PostProcessingDialogFactory { static Map, Class> ppToDialogMap = new HashMap<>(); + static { ppToDialogMap.put(Remux.class, RemuxerPaneFactory.class); ppToDialogMap.put(Script.class, ScriptPaneFactory.class); @@ -43,7 +49,16 @@ public class PostProcessingDialogFactory { if (preferences.isPresent()) { Region view = preferences.get().getView(false); view.setMinWidth(600); - ok = Dialogs.showCustomInput(scene, "Configure " + pp.getName(), view); + CheckBox enabledCheckbox = new CheckBox("Enabled"); + enabledCheckbox.setSelected(pp.isEnabled()); + enabledCheckbox.selectedProperty().addListener((src, oldV, newV) -> pp.setEnabled(newV)); + GridPane container = new GridPane(); + container.add(enabledCheckbox, 0, 0); + container.add(view, 0, 1); + GridPane.setMargin(enabledCheckbox, new Insets(0, 0, 10, 0)); + GridPane.setValignment(view, VPos.CENTER); + GridPane.setHalignment(view, HPos.CENTER); + ok = Dialogs.showCustomInput(scene, "Configure " + pp.getName(), container); if (ok) { preferences.get().save(); if (newEntry) { @@ -54,7 +69,7 @@ public class PostProcessingDialogFactory { stepList.add(pp); } } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException - | InstantiationException | IOException e) { + | InstantiationException | IOException e) { Dialogs.showError(scene, "New post-processing step", "Couldn't create dialog for " + pp.getName(), e); } } diff --git a/client/src/main/java/ctbrec/ui/settings/PostProcessingStepPanel.java b/client/src/main/java/ctbrec/ui/settings/PostProcessingStepPanel.java index 70c7d124..7776b1ae 100644 --- a/client/src/main/java/ctbrec/ui/settings/PostProcessingStepPanel.java +++ b/client/src/main/java/ctbrec/ui/settings/PostProcessingStepPanel.java @@ -1,53 +1,44 @@ 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.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; import javafx.geometry.Insets; -import javafx.scene.control.Button; -import javafx.scene.control.ChoiceDialog; -import javafx.scene.control.ListView; -import javafx.scene.control.Tooltip; +import javafx.scene.control.*; +import javafx.scene.control.cell.CheckBoxTableCell; import javafx.scene.image.Image; import javafx.scene.layout.GridPane; 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 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 + Copy.class, + Rename.class, + Move.class, + Remux.class, + Script.class, + DeleteOriginal.class, + DeleteTooShort.class, + RemoveKeepFile.class, + CreateContactSheet.class }; // @formatter: on - ListView stepListView; + TableView stepView; ObservableList stepList; Button up; @@ -74,21 +65,35 @@ public class PostProcessingStepPanel extends GridPane { var buttons = new VBox(5, add, edit, up, down, remove); stepList = FXCollections.observableList(config.getSettings().postProcessors); - stepList.addListener((ListChangeListener) change -> { - try { - config.save(); - } catch (IOException e) { - Dialogs.showError(getScene(), "Couldn't save configuration", "An error occurred while saving the configuration", e); - } + stepList.addListener((ListChangeListener) change -> safelySaveConfig()); + stepView = new TableView<>(stepList); + stepView.setEditable(true); + stepView.setStyle("-fx-table-cell-border-color: transparent;"); + var postProcessorColumn = new TableColumn("Step"); + postProcessorColumn.setCellValueFactory(cdf -> new SimpleStringProperty(cdf.getValue().getName())); + postProcessorColumn.setStyle("-fx-alignment: CENTER-LEFT;"); + var enabledColumn = new TableColumn("Enabled"); + enabledColumn.setCellValueFactory(cdf -> { + var prop = new SimpleBooleanProperty(cdf.getValue().isEnabled()); + prop.addListener((src, oldV, newV) -> { + cdf.getValue().setEnabled(newV); + safelySaveConfig(); + }); + return prop; }); - stepListView = new ListView<>(stepList); - GridPane.setHgrow(stepListView, Priority.ALWAYS); - GridPane.setFillWidth(stepListView, true); + enabledColumn.setCellFactory(CheckBoxTableCell.forTableColumn(enabledColumn)); + enabledColumn.setEditable(true); + enabledColumn.setStyle("-fx-alignment: CENTER;"); + postProcessorColumn.prefWidthProperty().bind(stepView.widthProperty().subtract(enabledColumn.widthProperty()).subtract(5)); + stepView.getColumns().add(enabledColumn); + stepView.getColumns().add(postProcessorColumn); + GridPane.setHgrow(stepView, Priority.ALWAYS); + GridPane.setFillWidth(stepView, true); - add(stepListView, 0, 0); + add(stepView, 0, 0); add(buttons, 1, 0); - stepListView.getSelectionModel().selectedIndexProperty().addListener((obs, oldV, newV) -> { + stepView.getSelectionModel().selectedIndexProperty().addListener((obs, oldV, newV) -> { var idx = newV.intValue(); boolean noSelection = idx == -1; up.setDisable(noSelection || idx == 0); @@ -100,14 +105,22 @@ public class PostProcessingStepPanel extends GridPane { setPadding(new Insets(10)); } + private void safelySaveConfig() { + try { + config.save(); + } catch (IOException e) { + Dialogs.showError(getScene(), "Couldn't save configuration", "An error occurred while saving the configuration", e); + } + } + private Button createUpButton() { var button = createButton("\u25B4", "Move step up"); button.setOnAction(evt -> { - int idx = stepListView.getSelectionModel().getSelectedIndex(); - PostProcessor selectedItem = stepListView.getSelectionModel().getSelectedItem(); + int idx = stepView.getSelectionModel().getSelectedIndex(); + PostProcessor selectedItem = stepView.getSelectionModel().getSelectedItem(); stepList.remove(idx); stepList.add(idx - 1, selectedItem); - stepListView.getSelectionModel().select(idx - 1); + stepView.getSelectionModel().select(idx - 1); }); return button; } @@ -115,11 +128,11 @@ public class PostProcessingStepPanel extends GridPane { private Button createDownButton() { var button = createButton("\u25BE", "Move step down"); button.setOnAction(evt -> { - int idx = stepListView.getSelectionModel().getSelectedIndex(); - PostProcessor selectedItem = stepListView.getSelectionModel().getSelectedItem(); + int idx = stepView.getSelectionModel().getSelectedIndex(); + PostProcessor selectedItem = stepView.getSelectionModel().getSelectedItem(); stepList.remove(idx); stepList.add(idx + 1, selectedItem); - stepListView.getSelectionModel().select(idx + 1); + stepView.getSelectionModel().select(idx + 1); }); return button; } @@ -166,7 +179,7 @@ public class PostProcessingStepPanel extends GridPane { } return options; } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException - | SecurityException e) { + | SecurityException e) { Dialogs.showError(getScene(), "Create post-processor selection", "Error while reaing in post-processing options", e); return new PostProcessor[0]; } @@ -175,7 +188,7 @@ public class PostProcessingStepPanel extends GridPane { private Button createRemoveButton() { var button = createButton("-", "Remove selected step"); button.setOnAction(evt -> { - PostProcessor selectedItem = stepListView.getSelectionModel().getSelectedItem(); + PostProcessor selectedItem = stepView.getSelectionModel().getSelectedItem(); if (selectedItem != null) { stepList.remove(selectedItem); } @@ -186,9 +199,9 @@ public class PostProcessingStepPanel extends GridPane { private Button createEditButton() { var button = createButton("\u270E", "Edit selected step"); button.setOnAction(evt -> { - PostProcessor selectedItem = stepListView.getSelectionModel().getSelectedItem(); + PostProcessor selectedItem = stepView.getSelectionModel().getSelectedItem(); PostProcessingDialogFactory.openEditDialog(selectedItem, getScene(), stepList); - stepListView.refresh(); + stepView.refresh(); saveConfig(); }); return button; diff --git a/client/src/main/java/ctbrec/ui/settings/api/Preferences.java b/client/src/main/java/ctbrec/ui/settings/api/Preferences.java index 23782325..92c2409a 100644 --- a/client/src/main/java/ctbrec/ui/settings/api/Preferences.java +++ b/client/src/main/java/ctbrec/ui/settings/api/Preferences.java @@ -91,6 +91,7 @@ public class Preferences { } }); categoryTree.getSelectionModel().select(0); + main.setBorder(Border.EMPTY); return main; }