forked from j62/ctbrec
1
0
Fork 0

Make columns in recorded tab configurable

This commit is contained in:
0xb00bface 2021-08-15 15:38:20 +02:00
parent 985ded70a8
commit 7b85114164
3 changed files with 108 additions and 4 deletions

View File

@ -459,15 +459,21 @@ public class MyFreeCamsTableTab extends Tab implements TabSelectionListener {
item.setOnAction(e -> { item.setOnAction(e -> {
if (item.isSelected()) { if (item.isSelected()) {
Config.getInstance().getSettings().mfcDisabledModelsTableColumns.remove(tc.getText()); Config.getInstance().getSettings().mfcDisabledModelsTableColumns.remove(tc.getText());
boolean added = false;
for (int i = table.getColumns().size() - 1; i >= 0; i--) { for (int i = table.getColumns().size() - 1; i >= 0; i--) {
TableColumn<ModelTableRow, ?> other = table.getColumns().get(i); TableColumn<ModelTableRow, ?> other = table.getColumns().get(i);
LOG.debug("Adding column {}", tc.getText());
int idx = (int) tc.getUserData(); int idx = (int) tc.getUserData();
int otherIdx = (int) other.getUserData(); int otherIdx = (int) other.getUserData();
if (otherIdx < idx) { if (otherIdx < idx) {
table.getColumns().add(i + 1, tc); table.getColumns().add(i + 1, tc);
added = true;
break; break;
} }
} }
if (!added) {
table.getColumns().add(0, tc);
}
} else { } else {
Config.getInstance().getSettings().mfcDisabledModelsTableColumns.add(tc.getText()); Config.getInstance().getSettings().mfcDisabledModelsTableColumns.add(tc.getText());
table.getColumns().remove(tc); table.getColumns().remove(tc);

View File

@ -9,6 +9,7 @@ import java.io.IOException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -66,10 +67,12 @@ import javafx.concurrent.Task;
import javafx.concurrent.WorkerStateEvent; import javafx.concurrent.WorkerStateEvent;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.geometry.Point2D;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Cursor; import javafx.scene.Cursor;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.ContextMenu; import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane; import javafx.scene.control.ScrollPane;
@ -116,6 +119,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
FlowPane grid = new FlowPane(); FlowPane grid = new FlowPane();
ScrollPane scrollPane = new ScrollPane(); ScrollPane scrollPane = new ScrollPane();
TableView<JavaFxModel> table = new TableView<>(); TableView<JavaFxModel> table = new TableView<>();
private List<TableColumn<JavaFxModel, ?>> columns = new ArrayList<>();
ObservableList<JavaFxModel> observableModels = FXCollections.observableArrayList(); ObservableList<JavaFxModel> observableModels = FXCollections.observableArrayList();
ObservableList<JavaFxModel> filteredModels = FXCollections.observableArrayList(); ObservableList<JavaFxModel> filteredModels = FXCollections.observableArrayList();
ContextMenu popup; ContextMenu popup;
@ -143,7 +147,6 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
initializeUpdateService(); initializeUpdateService();
} }
@SuppressWarnings("unchecked")
private void createGui() { private void createGui() {
grid.setPadding(new Insets(5)); grid.setPadding(new Insets(5));
grid.setHgap(5); grid.setHgap(5);
@ -154,6 +157,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
scrollPane.setFitToWidth(true); scrollPane.setFitToWidth(true);
BorderPane.setMargin(scrollPane, new Insets(5)); BorderPane.setMargin(scrollPane, new Insets(5));
int idx = 0;
table.setEditable(true); table.setEditable(true);
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
var previewPopupHandler = new PreviewPopupHandler(table); var previewPopupHandler = new PreviewPopupHandler(table);
@ -167,6 +171,9 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
preview.setCellValueFactory(cdf -> new SimpleStringProperty("")); preview.setCellValueFactory(cdf -> new SimpleStringProperty(""));
preview.setEditable(false); preview.setEditable(false);
preview.setId("preview"); preview.setId("preview");
preview.setUserData(idx++);
columns.add(preview);
addTableColumnIfEnabled(preview);
if (!Config.getInstance().getSettings().livePreviews) { if (!Config.getInstance().getSettings().livePreviews) {
preview.setVisible(false); preview.setVisible(false);
} }
@ -186,6 +193,9 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
portrait.setCellFactory(param -> new ImageTableCell()); portrait.setCellFactory(param -> new ImageTableCell());
portrait.setEditable(false); portrait.setEditable(false);
portrait.setId("portrait"); portrait.setId("portrait");
portrait.setUserData(idx++);
columns.add(portrait);
addTableColumnIfEnabled(portrait);
TableColumn<JavaFxModel, ModelName> name = new TableColumn<>("Model"); TableColumn<JavaFxModel, ModelName> name = new TableColumn<>("Model");
name.setPrefWidth(200); name.setPrefWidth(200);
@ -196,32 +206,47 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
name.setCellFactory(param -> new ModelNameTableCell(recorder)); name.setCellFactory(param -> new ModelNameTableCell(recorder));
name.setEditable(false); name.setEditable(false);
name.setId("name"); name.setId("name");
name.setUserData(idx++);
columns.add(name);
addTableColumnIfEnabled(name);
TableColumn<JavaFxModel, String> url = new TableColumn<>("URL"); TableColumn<JavaFxModel, String> url = new TableColumn<>("URL");
url.setCellValueFactory(new PropertyValueFactory<>("url")); url.setCellValueFactory(new PropertyValueFactory<>("url"));
url.setCellFactory(new ClickableCellFactory<>()); url.setCellFactory(new ClickableCellFactory<>());
url.setPrefWidth(400); url.setPrefWidth(400);
url.setEditable(false); url.setEditable(false);
url.setId("url"); url.setId("url");
url.setUserData(idx++);
columns.add(url);
addTableColumnIfEnabled(url);
TableColumn<JavaFxModel, Boolean> online = new TableColumn<>("Online"); TableColumn<JavaFxModel, Boolean> online = new TableColumn<>("Online");
online.setCellValueFactory(cdf -> cdf.getValue().getOnlineProperty()); online.setCellValueFactory(cdf -> cdf.getValue().getOnlineProperty());
online.setCellFactory(param -> new OnlineTableCell()); online.setCellFactory(param -> new OnlineTableCell());
online.setPrefWidth(100); online.setPrefWidth(100);
online.setEditable(false); online.setEditable(false);
online.setId("online"); online.setId("online");
online.setUserData(idx++);
online.setStyle(STYLE_ALIGN_CENTER); online.setStyle(STYLE_ALIGN_CENTER);
columns.add(online);
addTableColumnIfEnabled(online);
TableColumn<JavaFxModel, Boolean> recording = new TableColumn<>("Recording"); TableColumn<JavaFxModel, Boolean> recording = new TableColumn<>("Recording");
recording.setCellValueFactory(cdf -> cdf.getValue().getRecordingProperty()); recording.setCellValueFactory(cdf -> cdf.getValue().getRecordingProperty());
recording.setCellFactory(tc -> new RecordingTableCell()); recording.setCellFactory(tc -> new RecordingTableCell());
recording.setPrefWidth(100); recording.setPrefWidth(100);
recording.setEditable(false); recording.setEditable(false);
recording.setId("recording"); recording.setId("recording");
recording.setUserData(idx++);
recording.setStyle(STYLE_ALIGN_CENTER); recording.setStyle(STYLE_ALIGN_CENTER);
columns.add(recording);
addTableColumnIfEnabled(recording);
TableColumn<JavaFxModel, Boolean> paused = new TableColumn<>("Paused"); TableColumn<JavaFxModel, Boolean> paused = new TableColumn<>("Paused");
paused.setCellValueFactory(cdf -> cdf.getValue().getPausedProperty()); paused.setCellValueFactory(cdf -> cdf.getValue().getPausedProperty());
paused.setCellFactory(CheckBoxTableCell.forTableColumn(paused)); paused.setCellFactory(CheckBoxTableCell.forTableColumn(paused));
paused.setPrefWidth(100); paused.setPrefWidth(100);
paused.setEditable(true); paused.setEditable(true);
paused.setId("paused"); paused.setId("paused");
paused.setUserData(idx++);
columns.add(paused);
addTableColumnIfEnabled(paused);
TableColumn<JavaFxModel, Number> priority = new TableColumn<>("Priority"); TableColumn<JavaFxModel, Number> priority = new TableColumn<>("Priority");
priority.setCellValueFactory(param -> param.getValue().getPriorityProperty()); priority.setCellValueFactory(param -> param.getValue().getPriorityProperty());
priority.setCellFactory(new PriorityCellFactory()); priority.setCellFactory(new PriorityCellFactory());
@ -231,18 +256,27 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
priority.setOnEditCommit(this::onUpdatePriority); priority.setOnEditCommit(this::onUpdatePriority);
priority.setOnEditCancel(e -> cellEditing = false); priority.setOnEditCancel(e -> cellEditing = false);
priority.setId("priority"); priority.setId("priority");
priority.setUserData(idx++);
columns.add(priority);
addTableColumnIfEnabled(priority);
TableColumn<JavaFxModel, Instant> lastSeen = new TableColumn<>("last seen"); TableColumn<JavaFxModel, Instant> lastSeen = new TableColumn<>("last seen");
lastSeen.setCellValueFactory(cdf -> cdf.getValue().lastSeenProperty()); lastSeen.setCellValueFactory(cdf -> cdf.getValue().lastSeenProperty());
lastSeen.setCellFactory(new DateTimeCellFactory<>()); lastSeen.setCellFactory(new DateTimeCellFactory<>());
lastSeen.setPrefWidth(150); lastSeen.setPrefWidth(150);
lastSeen.setEditable(false); lastSeen.setEditable(false);
lastSeen.setId("lastSeen"); lastSeen.setId("lastSeen");
lastSeen.setUserData(idx++);
columns.add(lastSeen);
addTableColumnIfEnabled(lastSeen);
TableColumn<JavaFxModel, Instant> lastRecorded = new TableColumn<>("last recorded"); TableColumn<JavaFxModel, Instant> lastRecorded = new TableColumn<>("last recorded");
lastRecorded.setCellValueFactory(cdf -> cdf.getValue().lastRecordedProperty()); lastRecorded.setCellValueFactory(cdf -> cdf.getValue().lastRecordedProperty());
lastRecorded.setCellFactory(new DateTimeCellFactory<>()); lastRecorded.setCellFactory(new DateTimeCellFactory<>());
lastRecorded.setPrefWidth(150); lastRecorded.setPrefWidth(150);
lastRecorded.setEditable(false); lastRecorded.setEditable(false);
lastRecorded.setId("lastRecorded"); lastRecorded.setId("lastRecorded");
lastRecorded.setUserData(idx++);
columns.add(lastRecorded);
addTableColumnIfEnabled(lastRecorded);
TableColumn<JavaFxModel, String> notes = new TableColumn<>("Notes"); TableColumn<JavaFxModel, String> notes = new TableColumn<>("Notes");
notes.setCellValueFactory(cdf -> { notes.setCellValueFactory(cdf -> {
JavaFxModel m = cdf.getValue(); JavaFxModel m = cdf.getValue();
@ -267,7 +301,10 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
notes.setPrefWidth(400); notes.setPrefWidth(400);
notes.setEditable(false); notes.setEditable(false);
notes.setId("notes"); notes.setId("notes");
table.getColumns().addAll(preview, portrait, name, url, online, recording, paused, priority, lastSeen, lastRecorded, notes); notes.setUserData(idx);
columns.add(notes);
addTableColumnIfEnabled(notes);
table.setItems(observableModels); table.setItems(observableModels);
table.addEventHandler(ContextMenuEvent.CONTEXT_MENU_REQUESTED, event -> { table.addEventHandler(ContextMenuEvent.CONTEXT_MENU_REQUESTED, event -> {
popup = createContextMenu(); popup = createContextMenu();
@ -321,8 +358,9 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
checkModelAccountExistance checkModelAccountExistance
.setOnAction(evt -> new CheckModelAccountAction(checkModelAccountExistance, recorder).execute(Predicate.not(Model::isMarkedForLaterRecording))); .setOnAction(evt -> new CheckModelAccountAction(checkModelAccountExistance, recorder).execute(Predicate.not(Model::isMarkedForLaterRecording)));
var filterContainer = new HBox(); var filterContainer = new HBox();
filterContainer.setSpacing(0); filterContainer.setSpacing(5);
filterContainer.setPadding(new Insets(0)); filterContainer.setPadding(new Insets(0));
filterContainer.setAlignment(Pos.CENTER_RIGHT); filterContainer.setAlignment(Pos.CENTER_RIGHT);
filterContainer.minWidth(100); filterContainer.minWidth(100);
@ -342,7 +380,14 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
} }
}); });
filter.getStyleClass().remove("search-box-icon"); filter.getStyleClass().remove("search-box-icon");
filterContainer.getChildren().add(filter);
var columnSelection = new Button("");
columnSelection.setOnAction(this::showColumnSelection);
columnSelection.setTooltip(new Tooltip("Select columns"));
columnSelection.prefHeightProperty().bind(filter.prefHeightProperty());
columnSelection.prefWidthProperty().bind(columnSelection.prefHeightProperty());
filterContainer.getChildren().addAll(columnSelection, filter);
addModelBox.getChildren().add(filterContainer); addModelBox.getChildren().add(filterContainer);
var root = new BorderPane(); var root = new BorderPane();
@ -354,6 +399,12 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
restoreState(); restoreState();
} }
private void addTableColumnIfEnabled(TableColumn<JavaFxModel, ?> tc) {
if(isColumnEnabled(tc)) {
table.getColumns().add(tc);
}
}
private void jumpToNextModel(KeyCode code) { private void jumpToNextModel(KeyCode code) {
if (!table.getItems().isEmpty() && (code.isLetterKey() || code.isDigitKey())) { if (!table.getItems().isEmpty() && (code.isLetterKey() || code.isDigitKey())) {
// determine where to start looking for the next model // determine where to start looking for the next model
@ -847,4 +898,50 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
} }
return new Image(RecordedModelsTab.class.getResourceAsStream("/silhouette_256.png")); return new Image(RecordedModelsTab.class.getResourceAsStream("/silhouette_256.png"));
} }
private void showColumnSelection(ActionEvent evt) {
ContextMenu menu = new CustomMouseBehaviorContextMenu();
for (TableColumn<JavaFxModel, ?> tc : columns) {
var item = new CheckMenuItem(tc.getText());
item.setSelected(isColumnEnabled(tc));
menu.getItems().add(item);
item.setOnAction(e -> {
try {
if (item.isSelected()) {
Config.getInstance().getSettings().disabledRecordedModelsTableColumns.remove(tc.getText());
boolean added = false;
for (int i = table.getColumns().size() - 1; i >= 0; i--) {
TableColumn<JavaFxModel, ?> other = table.getColumns().get(i);
if (!other.isVisible()) {
continue;
}
int idx = (int) tc.getUserData();
LOG.debug("otherIdx {}", other.getText());
int otherIdx = (int) other.getUserData();
if (otherIdx < idx) {
table.getColumns().add(i + 1, tc);
added = true;
break;
}
}
if (!added) {
table.getColumns().add(0, tc);
}
} else {
Config.getInstance().getSettings().disabledRecordedModelsTableColumns.add(tc.getText());
table.getColumns().remove(tc);
}
} catch (Exception ex) {
LOG.error("Couldn't activate column {}", tc, ex);
}
});
}
Button src = (Button) evt.getSource();
Point2D location = src.localToScreen(src.getTranslateX(), src.getTranslateY());
menu.show(getTabPane().getScene().getWindow(), location.getX(), location.getY() + src.getHeight() + 5);
}
private boolean isColumnEnabled(TableColumn<JavaFxModel, ?> tc) {
return !Config.getInstance().getSettings().disabledRecordedModelsTableColumns.contains(tc.getText());
}
} }

View File

@ -64,6 +64,7 @@ public class Settings {
public boolean confirmationForDangerousActions = false; public boolean confirmationForDangerousActions = false;
public String contactsheetTimestampLook = "font=sans-serif:fontcolor=white:fontsize=60:box=1:boxcolor=black@0.5:boxborderw=5"; public String contactsheetTimestampLook = "font=sans-serif:fontcolor=white:fontsize=60:box=1:boxcolor=black@0.5:boxborderw=5";
public boolean determineResolution = false; public boolean determineResolution = false;
public List<String> disabledRecordedModelsTableColumns = new ArrayList<>();
public List<String> disabledSites = new ArrayList<>(); public List<String> disabledSites = new ArrayList<>();
public String downloadFilename = "${modelSanitizedName}-${localDateTime}"; public String downloadFilename = "${modelSanitizedName}-${localDateTime}";
public List<EventHandlerConfiguration> eventHandlers = new ArrayList<>(); public List<EventHandlerConfiguration> eventHandlers = new ArrayList<>();