Add action to set the recording stop date
This commit is contained in:
parent
f9b09775e3
commit
b76a67ac7d
|
@ -0,0 +1,95 @@
|
||||||
|
package ctbrec.ui.action;
|
||||||
|
|
||||||
|
import static ctbrec.SubsequentAction.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import ctbrec.Model;
|
||||||
|
import ctbrec.SubsequentAction;
|
||||||
|
import ctbrec.recorder.Recorder;
|
||||||
|
import ctbrec.ui.controls.Dialogs;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.Cursor;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.control.DatePicker;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.RadioButton;
|
||||||
|
import javafx.scene.control.ToggleGroup;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
|
||||||
|
public class SetStopDateAction {
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(SetStopDateAction.class);
|
||||||
|
|
||||||
|
private Node source;
|
||||||
|
private Model model;
|
||||||
|
private Recorder recorder;
|
||||||
|
|
||||||
|
public SetStopDateAction(Node source, Model model, Recorder recorder) {
|
||||||
|
this.source = source;
|
||||||
|
this.model = model;
|
||||||
|
this.recorder = recorder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<Boolean> execute() {
|
||||||
|
source.setCursor(Cursor.WAIT);
|
||||||
|
DatePicker datePicker = new DatePicker();
|
||||||
|
GridPane gridPane = new GridPane();
|
||||||
|
gridPane.setHgap(10);
|
||||||
|
gridPane.setVgap(10);
|
||||||
|
gridPane.setPadding(new Insets(20, 150, 10, 10));
|
||||||
|
gridPane.add(new Label("Stop at"), 0, 0);
|
||||||
|
gridPane.add(datePicker, 1, 0);
|
||||||
|
gridPane.add(new Label("And then"), 0, 1);
|
||||||
|
ToggleGroup toggleGroup = new ToggleGroup();
|
||||||
|
RadioButton pauseButton = new RadioButton("pause recording");
|
||||||
|
pauseButton.setSelected(model.getRecordUntilSubsequentAction() == PAUSE);
|
||||||
|
pauseButton.setToggleGroup(toggleGroup);
|
||||||
|
RadioButton removeButton = new RadioButton("remove model");
|
||||||
|
removeButton.setSelected(model.getRecordUntilSubsequentAction() == REMOVE);
|
||||||
|
removeButton.setToggleGroup(toggleGroup);
|
||||||
|
HBox row = new HBox();
|
||||||
|
row.getChildren().addAll(pauseButton, removeButton);
|
||||||
|
HBox.setMargin(pauseButton, new Insets(5));
|
||||||
|
HBox.setMargin(removeButton, new Insets(5));
|
||||||
|
gridPane.add(row, 1, 1);
|
||||||
|
if (model.isRecordingTimeLimited()) {
|
||||||
|
LocalDate localDate = LocalDate.ofInstant(model.getRecordUntil(), ZoneId.systemDefault());
|
||||||
|
datePicker.setValue(localDate);
|
||||||
|
}
|
||||||
|
boolean userClickedOk = Dialogs.showCustomInput(source.getScene(), "Stop Recording at", gridPane);
|
||||||
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
if (userClickedOk) {
|
||||||
|
SubsequentAction action = pauseButton.isSelected() ? PAUSE : REMOVE;
|
||||||
|
LOG.info("Stop at {} and {}", datePicker.getValue(), action);
|
||||||
|
Instant stopAt = Instant.from(datePicker.getValue().atStartOfDay().atZone(ZoneId.systemDefault()));
|
||||||
|
model.setRecordUntil(stopAt);
|
||||||
|
model.setRecordUntilSubsequentAction(action);
|
||||||
|
try {
|
||||||
|
recorder.stopRecordingAt(model);
|
||||||
|
} catch (InvalidKeyException | NoSuchAlgorithmException | IOException e) {
|
||||||
|
Dialogs.showError(source.getScene(), "Error", "Couln't set stop date", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}).whenComplete((r, e) -> {
|
||||||
|
source.setCursor(Cursor.DEFAULT);
|
||||||
|
if (e != null) {
|
||||||
|
LOG.error("Error", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,14 +1,12 @@
|
||||||
package ctbrec.ui.tabs;
|
package ctbrec.ui.tabs;
|
||||||
|
|
||||||
import static ctbrec.Recording.State.*;
|
import static ctbrec.Recording.State.*;
|
||||||
import static ctbrec.SubsequentAction.*;
|
|
||||||
import static ctbrec.ui.UnicodeEmoji.*;
|
import static ctbrec.ui.UnicodeEmoji.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
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.time.LocalDate;
|
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
@ -34,7 +32,6 @@ import ctbrec.Config;
|
||||||
import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
import ctbrec.Recording;
|
import ctbrec.Recording;
|
||||||
import ctbrec.StringUtil;
|
import ctbrec.StringUtil;
|
||||||
import ctbrec.SubsequentAction;
|
|
||||||
import ctbrec.recorder.Recorder;
|
import ctbrec.recorder.Recorder;
|
||||||
import ctbrec.sites.Site;
|
import ctbrec.sites.Site;
|
||||||
import ctbrec.ui.AutosizeAlert;
|
import ctbrec.ui.AutosizeAlert;
|
||||||
|
@ -50,6 +47,7 @@ import ctbrec.ui.action.PauseAction;
|
||||||
import ctbrec.ui.action.PlayAction;
|
import ctbrec.ui.action.PlayAction;
|
||||||
import ctbrec.ui.action.RemoveTimeLimitAction;
|
import ctbrec.ui.action.RemoveTimeLimitAction;
|
||||||
import ctbrec.ui.action.ResumeAction;
|
import ctbrec.ui.action.ResumeAction;
|
||||||
|
import ctbrec.ui.action.SetStopDateAction;
|
||||||
import ctbrec.ui.action.StopRecordingAction;
|
import ctbrec.ui.action.StopRecordingAction;
|
||||||
import ctbrec.ui.action.ToggleRecordingAction;
|
import ctbrec.ui.action.ToggleRecordingAction;
|
||||||
import ctbrec.ui.controls.DateTimeCellFactory;
|
import ctbrec.ui.controls.DateTimeCellFactory;
|
||||||
|
@ -72,10 +70,8 @@ import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.ContextMenu;
|
import javafx.scene.control.ContextMenu;
|
||||||
import javafx.scene.control.DatePicker;
|
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.MenuItem;
|
import javafx.scene.control.MenuItem;
|
||||||
import javafx.scene.control.RadioButton;
|
|
||||||
import javafx.scene.control.ScrollPane;
|
import javafx.scene.control.ScrollPane;
|
||||||
import javafx.scene.control.SelectionMode;
|
import javafx.scene.control.SelectionMode;
|
||||||
import javafx.scene.control.Tab;
|
import javafx.scene.control.Tab;
|
||||||
|
@ -87,7 +83,6 @@ import javafx.scene.control.TableRow;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.control.ToggleButton;
|
import javafx.scene.control.ToggleButton;
|
||||||
import javafx.scene.control.ToggleGroup;
|
|
||||||
import javafx.scene.control.Tooltip;
|
import javafx.scene.control.Tooltip;
|
||||||
import javafx.scene.control.cell.CheckBoxTableCell;
|
import javafx.scene.control.cell.CheckBoxTableCell;
|
||||||
import javafx.scene.control.cell.PropertyValueFactory;
|
import javafx.scene.control.cell.PropertyValueFactory;
|
||||||
|
@ -101,7 +96,6 @@ import javafx.scene.input.MouseButton;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
import javafx.scene.layout.FlowPane;
|
import javafx.scene.layout.FlowPane;
|
||||||
import javafx.scene.layout.GridPane;
|
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.Priority;
|
import javafx.scene.layout.Priority;
|
||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
|
@ -703,44 +697,9 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setStopDate(JavaFxModel model) {
|
private void setStopDate(JavaFxModel model) {
|
||||||
DatePicker datePicker = new DatePicker();
|
new SetStopDateAction(table, model.getDelegate(), recorder) //
|
||||||
GridPane gridPane = new GridPane();
|
.execute() //
|
||||||
gridPane.setHgap(10);
|
.whenComplete((result, exception) -> table.refresh());
|
||||||
gridPane.setVgap(10);
|
|
||||||
gridPane.setPadding(new Insets(20, 150, 10, 10));
|
|
||||||
gridPane.add(new Label("Stop at"), 0, 0);
|
|
||||||
gridPane.add(datePicker, 1, 0);
|
|
||||||
gridPane.add(new Label("And then"), 0, 1);
|
|
||||||
ToggleGroup toggleGroup = new ToggleGroup();
|
|
||||||
RadioButton pauseButton = new RadioButton("pause recording");
|
|
||||||
pauseButton.setSelected(model.getRecordUntilSubsequentAction() == PAUSE);
|
|
||||||
pauseButton.setToggleGroup(toggleGroup);
|
|
||||||
RadioButton removeButton = new RadioButton("remove model");
|
|
||||||
removeButton.setSelected(model.getRecordUntilSubsequentAction() == REMOVE);
|
|
||||||
removeButton.setToggleGroup(toggleGroup);
|
|
||||||
HBox row = new HBox();
|
|
||||||
row.getChildren().addAll(pauseButton, removeButton);
|
|
||||||
HBox.setMargin(pauseButton, new Insets(5));
|
|
||||||
HBox.setMargin(removeButton, new Insets(5));
|
|
||||||
gridPane.add(row, 1, 1);
|
|
||||||
if (model.isRecordingTimeLimited()) {
|
|
||||||
LocalDate localDate = LocalDate.ofInstant(model.getRecordUntil(), ZoneId.systemDefault());
|
|
||||||
datePicker.setValue(localDate);
|
|
||||||
}
|
|
||||||
boolean userClickedOk = Dialogs.showCustomInput(getTabPane().getScene(), "Stop Recording at", gridPane);
|
|
||||||
if (userClickedOk) {
|
|
||||||
SubsequentAction action = pauseButton.isSelected() ? PAUSE : REMOVE;
|
|
||||||
LOG.info("Stop at {} and {}", datePicker.getValue(), action);
|
|
||||||
Instant stopAt = Instant.from(datePicker.getValue().atStartOfDay().atZone(ZoneId.systemDefault()));
|
|
||||||
model.setRecordUntil(stopAt);
|
|
||||||
model.setRecordUntilSubsequentAction(action);
|
|
||||||
table.refresh();
|
|
||||||
try {
|
|
||||||
recorder.stopRecordingAt(model.getDelegate());
|
|
||||||
} catch (InvalidKeyException | NoSuchAlgorithmException | IOException e) {
|
|
||||||
Dialogs.showError(getTabPane().getScene(), "Error", "Couln't set stop date", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeTimeLimit(JavaFxModel selectedModel) {
|
private void removeTimeLimit(JavaFxModel selectedModel) {
|
||||||
|
|
Loading…
Reference in New Issue