forked from j62/ctbrec
1
0
Fork 0

Add notes column to recorded models tab

This commit is contained in:
0xboobface 2019-04-07 18:11:27 +02:00
parent fb7953e045
commit 458e05d2b4
4 changed files with 119 additions and 2 deletions

View File

@ -26,6 +26,7 @@ import ctbrec.Recording;
import ctbrec.StringUtil; import ctbrec.StringUtil;
import ctbrec.recorder.Recorder; import ctbrec.recorder.Recorder;
import ctbrec.sites.Site; import ctbrec.sites.Site;
import ctbrec.ui.action.EditNotesAction;
import ctbrec.ui.action.FollowAction; import ctbrec.ui.action.FollowAction;
import ctbrec.ui.action.PauseAction; import ctbrec.ui.action.PauseAction;
import ctbrec.ui.action.PlayAction; import ctbrec.ui.action.PlayAction;
@ -34,6 +35,7 @@ import ctbrec.ui.action.StopRecordingAction;
import ctbrec.ui.controls.AutoFillTextField; import ctbrec.ui.controls.AutoFillTextField;
import ctbrec.ui.controls.SearchBox; import ctbrec.ui.controls.SearchBox;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringPropertyBase;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.concurrent.ScheduledService; import javafx.concurrent.ScheduledService;
@ -152,7 +154,30 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
paused.setCellFactory(CheckBoxTableCell.forTableColumn(paused)); paused.setCellFactory(CheckBoxTableCell.forTableColumn(paused));
paused.setPrefWidth(100); paused.setPrefWidth(100);
paused.setEditable(true); paused.setEditable(true);
table.getColumns().addAll(preview, name, url, online, recording, paused); TableColumn<JavaFxModel, String> notes = new TableColumn<>("Notes");
notes.setCellValueFactory(cdf -> {
JavaFxModel m = cdf.getValue();
return new StringPropertyBase() {
@Override
public String getName() {
return "Model Notes";
}
@Override
public Object getBean() {
return null;
};
@Override
public String get() {
String modelNotes = Config.getInstance().getSettings().modelNotes.getOrDefault(m.getUrl(), "");
return modelNotes;
}
};
});
notes.setPrefWidth(400);
notes.setEditable(false);
table.getColumns().addAll(preview, name, url, online, recording, paused, 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();
@ -502,6 +527,8 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
switchStreamSource.setOnAction((e) -> switchStreamSource(selectedModels.get(0))); switchStreamSource.setOnAction((e) -> switchStreamSource(selectedModels.get(0)));
MenuItem follow = new MenuItem("Follow"); MenuItem follow = new MenuItem("Follow");
follow.setOnAction((e) -> follow(selectedModels)); follow.setOnAction((e) -> follow(selectedModels));
MenuItem notes = new MenuItem("Notes");
notes.setOnAction((e) -> notes(selectedModels));
ContextMenu menu = new ContextMenu(stop); ContextMenu menu = new ContextMenu(stop);
if (selectedModels.size() == 1) { if (selectedModels.size() == 1) {
@ -509,13 +536,14 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
} else { } else {
menu.getItems().addAll(resumeRecording, pauseRecording); menu.getItems().addAll(resumeRecording, pauseRecording);
} }
menu.getItems().addAll(copyUrl, openInPlayer, openInBrowser, switchStreamSource, follow); menu.getItems().addAll(copyUrl, openInPlayer, openInBrowser, switchStreamSource, follow, notes);
if (selectedModels.size() > 1) { if (selectedModels.size() > 1) {
copyUrl.setDisable(true); copyUrl.setDisable(true);
openInPlayer.setDisable(true); openInPlayer.setDisable(true);
openInBrowser.setDisable(true); openInBrowser.setDisable(true);
switchStreamSource.setDisable(true); switchStreamSource.setDisable(true);
notes.setDisable(true);
} }
return menu; return menu;
@ -525,6 +553,10 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
new FollowAction(getTabPane(), new ArrayList<JavaFxModel>(selectedModels)).execute(); new FollowAction(getTabPane(), new ArrayList<JavaFxModel>(selectedModels)).execute();
} }
private void notes(ObservableList<JavaFxModel> selectedModels) {
new EditNotesAction(getTabPane(), selectedModels.get(0), table).execute();
}
private void openInPlayer(JavaFxModel selectedModel) { private void openInPlayer(JavaFxModel selectedModel) {
new PlayAction(getTabPane(), selectedModel).execute(); new PlayAction(getTabPane(), selectedModel).execute();
} }

View File

@ -0,0 +1,38 @@
package ctbrec.ui.action;
import java.util.Optional;
import ctbrec.Config;
import ctbrec.Model;
import ctbrec.ui.JavaFxModel;
import ctbrec.ui.controls.Dialogs;
import javafx.application.Platform;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.TableView;
public class EditNotesAction {
private Node source;
private Model model;
private TableView<JavaFxModel> table;
public EditNotesAction(Node source, Model selectedModel, TableView<JavaFxModel> table) {
this.source = source;
this.model = selectedModel;
this.table = table;
}
public void execute() {
source.setCursor(Cursor.WAIT);
new Thread(() -> {
Platform.runLater(() -> {
String notes = Config.getInstance().getSettings().modelNotes.getOrDefault(model.getUrl(), "");
Optional<String> newNotes = Dialogs.showTextInput("Model Notes", "Notes for " + model.getName(), notes);
newNotes.ifPresent(n -> Config.getInstance().getSettings().modelNotes.put(model.getUrl(), n));
table.refresh();
source.setCursor(Cursor.DEFAULT);
});
}).start();
}
}

View File

@ -1,8 +1,19 @@
package ctbrec.ui.controls; package ctbrec.ui.controls;
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.scene.control.Alert; import javafx.scene.control.Alert;
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.stage.Modality;
import javafx.stage.Stage;
public class Dialogs { public class Dialogs {
public static void showError(String header, String text, Throwable t) { public static void showError(String header, String text, Throwable t) {
@ -24,4 +35,37 @@ public class Dialogs {
Platform.runLater(r); Platform.runLater(r);
} }
} }
public static Optional<String> showTextInput(String title, String header, String text) {
Dialog<String> dialog = new Dialog<>();
dialog.setTitle(title);
dialog.setHeaderText(header);
dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
dialog.initModality(Modality.APPLICATION_MODAL);
dialog.setResizable(true);
InputStream icon = Dialogs.class.getResourceAsStream("/icon.png");
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
stage.getIcons().add(new Image(icon));
GridPane grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(20, 150, 10, 10));
TextArea notes = new TextArea(text);
notes.setPrefRowCount(3);
grid.add(notes, 0, 0);
dialog.getDialogPane().setContent(grid);
Platform.runLater(() -> notes.requestFocus());
dialog.setResultConverter(dialogButton -> {
if (dialogButton == ButtonType.OK) {
return notes.getText();
}
return null;
});
return dialog.showAndWait();
}
} }

View File

@ -2,7 +2,9 @@ package ctbrec;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import ctbrec.event.EventHandlerConfiguration; import ctbrec.event.EventHandlerConfiguration;
@ -109,4 +111,5 @@ public class Settings {
public String recordingsSortType = ""; public String recordingsSortType = "";
public double[] recordingsColumnWidths = new double[0]; public double[] recordingsColumnWidths = new double[0];
public boolean generatePlaylist = true; public boolean generatePlaylist = true;
public Map<String, String> modelNotes = new HashMap<>();
} }