forked from j62/ctbrec
Save column order in tables
This commit is contained in:
parent
dc30f7da51
commit
915be1d4fc
|
@ -34,6 +34,7 @@ import com.iheartradio.m3u8.PlaylistException;
|
|||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.Settings;
|
||||
import ctbrec.StringUtil;
|
||||
import ctbrec.recorder.download.StreamSource;
|
||||
import ctbrec.sites.mfc.MyFreeCams;
|
||||
|
@ -106,9 +107,9 @@ public class MyFreeCamsTableTab extends Tab implements TabSelectionListener {
|
|||
setText("Tabular");
|
||||
setClosable(false);
|
||||
createGui();
|
||||
restoreState();
|
||||
loadData();
|
||||
initUpdateService();
|
||||
restoreState();
|
||||
filter(filterInput.getText());
|
||||
}
|
||||
|
||||
|
@ -212,38 +213,47 @@ public class MyFreeCamsTableTab extends Tab implements TabSelectionListener {
|
|||
popup.hide();
|
||||
}
|
||||
});
|
||||
table.getColumns().addListener((ListChangeListener<TableColumn<?, ?>>)(e -> saveState()));
|
||||
|
||||
int idx = 0;
|
||||
TableColumn<ModelTableRow, Number> uid = createTableColumn("UID", 65, idx++);
|
||||
uid.setId("uid");
|
||||
uid.setCellValueFactory(cdf -> cdf.getValue().uidProperty());
|
||||
addTableColumnIfEnabled(uid);
|
||||
|
||||
TableColumn<ModelTableRow, String> name = createTableColumn("Name", 200, idx++);
|
||||
name.setId("name");
|
||||
name.setCellValueFactory(cdf -> cdf.getValue().nameProperty());
|
||||
addTableColumnIfEnabled(name);
|
||||
|
||||
TableColumn<ModelTableRow, String> state = createTableColumn("State", 130, idx++);
|
||||
state.setId("state");
|
||||
state.setCellValueFactory(cdf -> cdf.getValue().stateProperty());
|
||||
addTableColumnIfEnabled(state);
|
||||
|
||||
TableColumn<ModelTableRow, Boolean> hd = createTableColumn("HD", 130, idx++);
|
||||
hd.setId("hd");
|
||||
hd.setCellValueFactory(cdf -> cdf.getValue().hdProperty());
|
||||
addTableColumnIfEnabled(hd);
|
||||
|
||||
TableColumn<ModelTableRow, Boolean> webrtc = createTableColumn("webrtc", 130, idx++);
|
||||
webrtc.setId("webrtc");
|
||||
webrtc.setCellValueFactory(cdf -> cdf.getValue().webrtcProperty());
|
||||
addTableColumnIfEnabled(webrtc);
|
||||
|
||||
TableColumn<ModelTableRow, Number> flags = createTableColumn("Flags", 75, idx++);
|
||||
flags.setId("flags");
|
||||
flags.setCellValueFactory(cdf -> cdf.getValue().flagsProperty());
|
||||
addTableColumnIfEnabled(flags);
|
||||
|
||||
TableColumn<ModelTableRow, Number> camscore = createTableColumn("Score", 75, idx++);
|
||||
camscore.setId("camscore");
|
||||
camscore.setCellValueFactory(cdf -> cdf.getValue().camScoreProperty());
|
||||
addTableColumnIfEnabled(camscore);
|
||||
|
||||
// this is always 0, use https://api.myfreecams.com/missmfc and https://api.myfreecams.com/missmfc/online
|
||||
// TableColumn<SessionState, Number> missMfc = createTableColumn("Miss MFC", 75, idx++);
|
||||
// missMfc.setId("missMfc");
|
||||
// missMfc.setCellValueFactory(cdf -> {
|
||||
// Integer mmfc = Optional.ofNullable(cdf.getValue().getM()).map(m -> m.getMissmfc()).orElse(-1);
|
||||
// return new SimpleIntegerProperty(mmfc);
|
||||
|
@ -251,34 +261,42 @@ public class MyFreeCamsTableTab extends Tab implements TabSelectionListener {
|
|||
// addTableColumnIfEnabled(missMfc);
|
||||
|
||||
TableColumn<ModelTableRow, String> newModel = createTableColumn("New", 60, idx++);
|
||||
newModel.setId("newModel");
|
||||
newModel.setCellValueFactory(cdf -> cdf.getValue().newModelProperty());
|
||||
addTableColumnIfEnabled(newModel);
|
||||
|
||||
TableColumn<ModelTableRow, String> ethnic = createTableColumn("Ethnicity", 130, idx++);
|
||||
ethnic.setId("ethnic");
|
||||
ethnic.setCellValueFactory(cdf -> cdf.getValue().ethnicityProperty());
|
||||
addTableColumnIfEnabled(ethnic);
|
||||
|
||||
TableColumn<ModelTableRow, String> country = createTableColumn("Country", 160, idx++);
|
||||
country.setId("country");
|
||||
country.setCellValueFactory(cdf -> cdf.getValue().countryProperty());
|
||||
addTableColumnIfEnabled(country);
|
||||
|
||||
TableColumn<ModelTableRow, String> continent = createTableColumn("Continent", 100, idx++);
|
||||
continent.setId("continent");
|
||||
continent.setCellValueFactory(cdf -> cdf.getValue().continentProperty());
|
||||
addTableColumnIfEnabled(continent);
|
||||
|
||||
TableColumn<ModelTableRow, String> occupation = createTableColumn("Occupation", 160, idx++);
|
||||
occupation.setId("occupation");
|
||||
occupation.setCellValueFactory(cdf -> cdf.getValue().occupationProperty());
|
||||
addTableColumnIfEnabled(occupation);
|
||||
|
||||
TableColumn<ModelTableRow, String> tags = createTableColumn("Tags", 300, idx++);
|
||||
tags.setId("tags");
|
||||
tags.setCellValueFactory(cdf -> cdf.getValue().tagsProperty());
|
||||
addTableColumnIfEnabled(tags);
|
||||
|
||||
TableColumn<ModelTableRow, String> blurp = createTableColumn("Blurp", 300, idx++);
|
||||
blurp.setId("blurp");
|
||||
blurp.setCellValueFactory(cdf -> cdf.getValue().blurpProperty());
|
||||
addTableColumnIfEnabled(blurp);
|
||||
|
||||
TableColumn<ModelTableRow, String> topic = createTableColumn("Topic", 600, idx);
|
||||
topic.setId("topic");
|
||||
topic.setCellValueFactory(cdf -> cdf.getValue().topicProperty());
|
||||
addTableColumnIfEnabled(topic);
|
||||
|
||||
|
@ -534,6 +552,7 @@ public class MyFreeCamsTableTab extends Tab implements TabSelectionListener {
|
|||
}
|
||||
File file = new File(Config.getInstance().getConfigDir(), "mfc-models.json");
|
||||
Files.write(file.toPath(), data.toString(2).getBytes(UTF_8), CREATE, WRITE);
|
||||
saveState();
|
||||
} catch (Exception e) {
|
||||
LOG.debug("Couldn't write mfc models table data: {}", e.getMessage());
|
||||
}
|
||||
|
@ -574,19 +593,32 @@ public class MyFreeCamsTableTab extends Tab implements TabSelectionListener {
|
|||
}
|
||||
|
||||
private void saveState() {
|
||||
Settings settings = Config.getInstance().getSettings();
|
||||
if (!table.getSortOrder().isEmpty()) {
|
||||
TableColumn<ModelTableRow, ?> col = table.getSortOrder().get(0);
|
||||
Config.getInstance().getSettings().mfcModelsTableSortColumn = col.getText();
|
||||
Config.getInstance().getSettings().mfcModelsTableSortType = col.getSortType().toString();
|
||||
settings.mfcModelsTableSortColumn = col.getText();
|
||||
settings.mfcModelsTableSortType = col.getSortType().toString();
|
||||
}
|
||||
double[] columnWidths = new double[table.getColumns().size()];
|
||||
int size = table.getColumns().size();
|
||||
double[] columnWidths = new double[size];
|
||||
String[] columnIds = new String[size];
|
||||
for (int i = 0; i < columnWidths.length; i++) {
|
||||
columnWidths[i] = table.getColumns().get(i).getWidth();
|
||||
columnIds[i] = table.getColumns().get(i).getId();
|
||||
}
|
||||
Config.getInstance().getSettings().mfcModelsTableColumnWidths = columnWidths;
|
||||
settings.mfcModelsTableColumnWidths = columnWidths;
|
||||
settings.mfcModelsTableColumnIds = columnIds;
|
||||
}
|
||||
|
||||
private void restoreState() {
|
||||
restoreColumnOrder();
|
||||
restoreColumnWidths();
|
||||
restoreSorting();
|
||||
|
||||
filterInput.setText(Config.getInstance().getSettings().mfcModelsTableFilter);
|
||||
}
|
||||
|
||||
private void restoreSorting() {
|
||||
String sortCol = Config.getInstance().getSettings().mfcModelsTableSortColumn;
|
||||
if (StringUtil.isNotBlank(sortCol)) {
|
||||
for (TableColumn<ModelTableRow, ?> col : table.getColumns()) {
|
||||
|
@ -598,15 +630,29 @@ public class MyFreeCamsTableTab extends Tab implements TabSelectionListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreColumnOrder() {
|
||||
String[] columnIds = Config.getInstance().getSettings().mfcModelsTableColumnIds;
|
||||
ObservableList<TableColumn<ModelTableRow,?>> tableColumns = table.getColumns();
|
||||
for (int i = 0; i < columnIds.length; i++) {
|
||||
for (int j = 0; j < table.getColumns().size(); j++) {
|
||||
if(Objects.equals(columnIds[i], tableColumns.get(j).getId())) {
|
||||
TableColumn<ModelTableRow, ?> col = tableColumns.get(j);
|
||||
tableColumns.remove(j); // NOSONAR
|
||||
tableColumns.add(i, col);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreColumnWidths() {
|
||||
double[] columnWidths = Config.getInstance().getSettings().mfcModelsTableColumnWidths;
|
||||
if (columnWidths != null && columnWidths.length == table.getColumns().size()) {
|
||||
for (int i = 0; i < columnWidths.length; i++) {
|
||||
table.getColumns().get(i).setPrefWidth(columnWidths[i]);
|
||||
}
|
||||
}
|
||||
|
||||
filterInput.setText(Config.getInstance().getSettings().mfcModelsTableFilter);
|
||||
}
|
||||
|
||||
private ListChangeListener<TableColumn<ModelTableRow, ?>> createSortOrderChangedListener() {
|
||||
|
|
|
@ -155,26 +155,31 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
|
|||
name.setCellValueFactory(new PropertyValueFactory<JavaFxModel, String>("displayName"));
|
||||
name.setCellFactory(new ClickableCellFactory<>());
|
||||
name.setEditable(false);
|
||||
name.setId("name");
|
||||
TableColumn<JavaFxModel, String> url = new TableColumn<>("URL");
|
||||
url.setCellValueFactory(new PropertyValueFactory<JavaFxModel, String>("url"));
|
||||
url.setCellFactory(new ClickableCellFactory<>());
|
||||
url.setPrefWidth(400);
|
||||
url.setEditable(false);
|
||||
url.setId("url");
|
||||
TableColumn<JavaFxModel, Boolean> online = new TableColumn<>("Online");
|
||||
online.setCellValueFactory(cdf -> cdf.getValue().getOnlineProperty());
|
||||
online.setCellFactory(CheckBoxTableCell.forTableColumn(online));
|
||||
online.setPrefWidth(100);
|
||||
online.setEditable(false);
|
||||
online.setId("online");
|
||||
TableColumn<JavaFxModel, Boolean> recording = new TableColumn<>("Recording");
|
||||
recording.setCellValueFactory(cdf -> cdf.getValue().getRecordingProperty());
|
||||
recording.setCellFactory(CheckBoxTableCell.forTableColumn(recording));
|
||||
recording.setPrefWidth(100);
|
||||
recording.setEditable(false);
|
||||
recording.setId("recording");
|
||||
TableColumn<JavaFxModel, Boolean> paused = new TableColumn<>("Paused");
|
||||
paused.setCellValueFactory(cdf -> cdf.getValue().getPausedProperty());
|
||||
paused.setCellFactory(CheckBoxTableCell.forTableColumn(paused));
|
||||
paused.setPrefWidth(100);
|
||||
paused.setEditable(true);
|
||||
paused.setId("paused");
|
||||
TableColumn<JavaFxModel, Number> priority = new TableColumn<>("Priority");
|
||||
priority.setCellValueFactory(param -> param.getValue().getPriorityProperty());
|
||||
priority.setCellFactory(new PriorityCellFactory());
|
||||
|
@ -183,16 +188,19 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
|
|||
priority.setOnEditStart(e -> cellEditing = true);
|
||||
priority.setOnEditCommit(this::onUpdatePriority);
|
||||
priority.setOnEditCancel(e -> cellEditing = false);
|
||||
priority.setId("priority");
|
||||
TableColumn<JavaFxModel, Instant> lastSeen = new TableColumn<>("last seen");
|
||||
lastSeen.setCellValueFactory(cdf -> cdf.getValue().lastSeenProperty());
|
||||
lastSeen.setCellFactory(new DateTimeCellFactory<JavaFxModel>());
|
||||
lastSeen.setPrefWidth(150);
|
||||
lastSeen.setEditable(false);
|
||||
lastSeen.setId("lastSeen");
|
||||
TableColumn<JavaFxModel, Instant> lastRecorded = new TableColumn<>("last recorded");
|
||||
lastRecorded.setCellValueFactory(cdf -> cdf.getValue().lastRecordedProperty());
|
||||
lastRecorded.setCellFactory(new DateTimeCellFactory<JavaFxModel>());
|
||||
lastRecorded.setPrefWidth(150);
|
||||
lastRecorded.setEditable(false);
|
||||
lastRecorded.setId("lastRecorded");
|
||||
TableColumn<JavaFxModel, String> notes = new TableColumn<>("Notes");
|
||||
notes.setCellValueFactory(cdf -> {
|
||||
JavaFxModel m = cdf.getValue();
|
||||
|
@ -216,6 +224,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
|
|||
});
|
||||
notes.setPrefWidth(400);
|
||||
notes.setEditable(false);
|
||||
notes.setId("notes");
|
||||
table.getColumns().addAll(preview, name, url, online, recording, paused, priority, lastSeen, lastRecorded, notes);
|
||||
table.setItems(observableModels);
|
||||
table.addEventHandler(ContextMenuEvent.CONTEXT_MENU_REQUESTED, event -> {
|
||||
|
@ -729,14 +738,24 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
|
|||
Config.getInstance().getSettings().recordedModelsSortColumn = col.getText();
|
||||
Config.getInstance().getSettings().recordedModelsSortType = col.getSortType().toString();
|
||||
}
|
||||
double[] columnWidths = new double[table.getColumns().size()];
|
||||
int columns = table.getColumns().size();
|
||||
double[] columnWidths = new double[columns];
|
||||
String[] columnIds = new String[columns];
|
||||
for (int i = 0; i < columnWidths.length; i++) {
|
||||
columnWidths[i] = table.getColumns().get(i).getWidth();
|
||||
columnIds[i] = table.getColumns().get(i).getId();
|
||||
}
|
||||
Config.getInstance().getSettings().recordedModelsColumnWidths = columnWidths;
|
||||
Config.getInstance().getSettings().recordedModelsColumnIds = columnIds;
|
||||
}
|
||||
|
||||
private void restoreState() {
|
||||
restoreColumnOrder();
|
||||
restoreColumnWidths();
|
||||
restoreSorting();
|
||||
}
|
||||
|
||||
private void restoreSorting() {
|
||||
String sortCol = Config.getInstance().getSettings().recordedModelsSortColumn;
|
||||
if (StringUtil.isNotBlank(sortCol)) {
|
||||
for (TableColumn<JavaFxModel, ?> col : table.getColumns()) {
|
||||
|
@ -748,7 +767,23 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreColumnOrder() {
|
||||
String[] columnIds = Config.getInstance().getSettings().recordedModelsColumnIds;
|
||||
ObservableList<TableColumn<JavaFxModel,?>> columns = table.getColumns();
|
||||
for (int i = 0; i < columnIds.length; i++) {
|
||||
for (int j = 0; j < table.getColumns().size(); j++) {
|
||||
if(Objects.equals(columnIds[i], columns.get(j).getId())) {
|
||||
TableColumn<JavaFxModel, ?> col = columns.get(j);
|
||||
columns.remove(j); // NOSONAR
|
||||
columns.add(i, col);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreColumnWidths() {
|
||||
double[] columnWidths = Config.getInstance().getSettings().recordedModelsColumnWidths;
|
||||
if (columnWidths != null && columnWidths.length == table.getColumns().size()) {
|
||||
for (int i = 0; i < columnWidths.length; i++) {
|
||||
|
|
|
@ -125,9 +125,11 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
|||
table.setEditable(false);
|
||||
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
||||
TableColumn<JavaFxRecording, String> name = new TableColumn<>("Model");
|
||||
name.setId("name");
|
||||
name.setPrefWidth(200);
|
||||
name.setCellValueFactory(cdf -> new SimpleStringProperty(cdf.getValue().getModel().getName()));
|
||||
TableColumn<JavaFxRecording, Instant> date = new TableColumn<>("Date");
|
||||
date.setId("date");
|
||||
date.setCellValueFactory(cdf -> {
|
||||
Instant instant = cdf.getValue().getStartDate();
|
||||
return new SimpleObjectProperty<Instant>(instant);
|
||||
|
@ -135,12 +137,15 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
|||
date.setCellFactory(new DateTimeCellFactory<JavaFxRecording>());
|
||||
date.setPrefWidth(200);
|
||||
TableColumn<JavaFxRecording, String> status = new TableColumn<>("Status");
|
||||
status.setId("status");
|
||||
status.setCellValueFactory(cdf -> cdf.getValue().getStatusProperty());
|
||||
status.setPrefWidth(300);
|
||||
TableColumn<JavaFxRecording, String> progress = new TableColumn<>("Progress");
|
||||
progress.setId("progress");
|
||||
progress.setCellValueFactory(cdf -> cdf.getValue().getProgressProperty());
|
||||
progress.setPrefWidth(100);
|
||||
TableColumn<JavaFxRecording, Number> size = new TableColumn<>("Size");
|
||||
size.setId("size");
|
||||
size.setStyle("-fx-alignment: CENTER-RIGHT;");
|
||||
size.setPrefWidth(100);
|
||||
size.setCellValueFactory(cdf -> cdf.getValue().getSizeProperty());
|
||||
|
@ -696,14 +701,24 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
|||
Config.getInstance().getSettings().recordingsSortColumn = col.getText();
|
||||
Config.getInstance().getSettings().recordingsSortType = col.getSortType().toString();
|
||||
}
|
||||
double[] columnWidths = new double[table.getColumns().size()];
|
||||
int columns = table.getColumns().size();
|
||||
double[] columnWidths = new double[columns];
|
||||
String[] columnIds = new String[columns];
|
||||
for (int i = 0; i < columnWidths.length; i++) {
|
||||
columnWidths[i] = table.getColumns().get(i).getWidth();
|
||||
columnIds[i] = table.getColumns().get(i).getId();
|
||||
}
|
||||
Config.getInstance().getSettings().recordingsColumnWidths = columnWidths;
|
||||
Config.getInstance().getSettings().recordingsColumnIds = columnIds;
|
||||
}
|
||||
|
||||
private void restoreState() {
|
||||
restoreColumnOrder();
|
||||
restoreColumnWidths();
|
||||
restoreSorting();
|
||||
}
|
||||
|
||||
private void restoreSorting() {
|
||||
String sortCol = Config.getInstance().getSettings().recordingsSortColumn;
|
||||
if(StringUtil.isNotBlank(sortCol)) {
|
||||
for (TableColumn<JavaFxRecording, ?> col : table.getColumns()) {
|
||||
|
@ -715,7 +730,23 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreColumnOrder() {
|
||||
String[] columnIds = Config.getInstance().getSettings().recordingsColumnIds;
|
||||
ObservableList<TableColumn<JavaFxRecording,?>> columns = table.getColumns();
|
||||
for (int i = 0; i < columnIds.length; i++) {
|
||||
for (int j = 0; j < table.getColumns().size(); j++) {
|
||||
if(Objects.equals(columnIds[i], columns.get(j).getId())) {
|
||||
TableColumn<JavaFxRecording, ?> col = columns.get(j);
|
||||
columns.remove(j); // NOSONAR
|
||||
columns.add(i, col);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreColumnWidths() {
|
||||
double[] columnWidths = Config.getInstance().getSettings().recordingsColumnWidths;
|
||||
if(columnWidths != null && columnWidths.length == table.getColumns().size()) {
|
||||
for (int i = 0; i < columnWidths.length; i++) {
|
||||
|
|
|
@ -75,6 +75,7 @@ public class Settings {
|
|||
public String mfcBaseUrl = "https://www.myfreecams.com";
|
||||
public List<String> mfcDisabledModelsTableColumns = new ArrayList<>();
|
||||
public boolean mfcIgnoreUpscaled = false;
|
||||
public String[] mfcModelsTableColumnIds = new String[0];
|
||||
public double[] mfcModelsTableColumnWidths = new double[0];
|
||||
public String mfcModelsTableFilter = "";
|
||||
public String mfcModelsTableSortColumn = "";
|
||||
|
@ -98,9 +99,11 @@ public class Settings {
|
|||
public ProxyType proxyType = ProxyType.DIRECT;
|
||||
public String proxyUser;
|
||||
public double[] recordedModelsColumnWidths = new double[0];
|
||||
public String[] recordedModelsColumnIds = new String[0];
|
||||
public String recordedModelsSortColumn = "";
|
||||
public String recordedModelsSortType = "";
|
||||
public double[] recordingsColumnWidths = new double[0];
|
||||
public String[] recordingsColumnIds = new String[0];
|
||||
public String recordingsDir = System.getProperty("user.home") + File.separator + "ctbrec";
|
||||
public DirectoryStructure recordingsDirStructure = DirectoryStructure.FLAT;
|
||||
public String recordingsSortColumn = "";
|
||||
|
|
Loading…
Reference in New Issue