Add button to suspend events
This commit is contained in:
parent
92fa017b6b
commit
bf9e23bdfa
|
@ -1,6 +1,7 @@
|
||||||
package ctbrec.ui.settings;
|
package ctbrec.ui.settings;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
@ -8,7 +9,9 @@ import java.time.format.FormatStyle;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import javafx.scene.control.*;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -42,15 +45,6 @@ import javafx.geometry.Orientation;
|
||||||
import javafx.geometry.VPos;
|
import javafx.geometry.VPos;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Button;
|
|
||||||
import javafx.scene.control.CheckBox;
|
|
||||||
import javafx.scene.control.ComboBox;
|
|
||||||
import javafx.scene.control.Label;
|
|
||||||
import javafx.scene.control.ListView;
|
|
||||||
import javafx.scene.control.ScrollPane;
|
|
||||||
import javafx.scene.control.SelectionMode;
|
|
||||||
import javafx.scene.control.Separator;
|
|
||||||
import javafx.scene.control.TextField;
|
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
|
@ -64,20 +58,21 @@ public class ActionSettingsPanel extends GridPane {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ActionSettingsPanel.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ActionSettingsPanel.class);
|
||||||
private ListView<EventHandlerConfiguration> actionTable;
|
private ListView<EventHandlerConfiguration> actionTable;
|
||||||
|
|
||||||
private TextField name = new TextField();
|
private final TextField name = new TextField();
|
||||||
private ComboBox<Event.Type> event = new ComboBox<>();
|
private final ComboBox<Event.Type> event = new ComboBox<>();
|
||||||
private ComboBox<Model.State> modelState = new ComboBox<>();
|
private final ComboBox<Model.State> modelState = new ComboBox<>();
|
||||||
private ComboBox<Recording.State> recordingState = new ComboBox<>();
|
private final ComboBox<Recording.State> recordingState = new ComboBox<>();
|
||||||
|
|
||||||
private CheckBox playSound = new CheckBox("Play sound");
|
private final CheckBox playSound = new CheckBox("Play sound");
|
||||||
private FileSelectionBox sound = new FileSelectionBox();
|
private final FileSelectionBox sound = new FileSelectionBox();
|
||||||
private CheckBox showNotification = new CheckBox("Notify me");
|
private final CheckBox showNotification = new CheckBox("Notify me");
|
||||||
private Button testNotification = new Button("Test");
|
private final Button testNotification = new Button("Test");
|
||||||
private CheckBox executeProgram = new CheckBox("Execute program");
|
private final ToggleButton toggleEvents = new ToggleButton();
|
||||||
private ProgramSelectionBox program = new ProgramSelectionBox();
|
private final CheckBox executeProgram = new CheckBox("Execute program");
|
||||||
|
private final ProgramSelectionBox program = new ProgramSelectionBox();
|
||||||
private ListSelectionPane<Model> modelSelectionPane;
|
private ListSelectionPane<Model> modelSelectionPane;
|
||||||
|
|
||||||
private Recorder recorder;
|
private final Recorder recorder;
|
||||||
|
|
||||||
public ActionSettingsPanel(Recorder recorder) {
|
public ActionSettingsPanel(Recorder recorder) {
|
||||||
this.recorder = recorder;
|
this.recorder = recorder;
|
||||||
|
@ -111,20 +106,35 @@ public class ActionSettingsPanel extends GridPane {
|
||||||
var delete = new Button("Delete");
|
var delete = new Button("Delete");
|
||||||
delete.setOnAction(this::delete);
|
delete.setOnAction(this::delete);
|
||||||
delete.setDisable(true);
|
delete.setDisable(true);
|
||||||
var buttons = new HBox(5, add, delete);
|
toggleEvents.setOnAction(this::toggleEvents);
|
||||||
|
toggleEvents.setSelected(Config.getInstance().getSettings().eventsSuspended);
|
||||||
|
toggleEvents.setText(toggleEvents.isSelected() ? "Resume Events" : "Suspend Events");
|
||||||
|
toggleEvents.setTooltip(new Tooltip(toggleEvents.isSelected() ? "Events are currently suspended" : "Events are currently active"));
|
||||||
|
var buttons = new HBox(5, add, delete, toggleEvents);
|
||||||
buttons.setStyle("-fx-background-color: -fx-background"); // workaround so that the buttons don't shrink
|
buttons.setStyle("-fx-background-color: -fx-background"); // workaround so that the buttons don't shrink
|
||||||
add(buttons, 0, 2);
|
add(buttons, 0, 2);
|
||||||
|
|
||||||
actionTable.getSelectionModel().getSelectedItems().addListener((ListChangeListener<EventHandlerConfiguration>) change -> delete.setDisable(change.getList().isEmpty()));
|
actionTable.getSelectionModel().getSelectedItems().addListener((ListChangeListener<EventHandlerConfiguration>) change -> delete.setDisable(change.getList().isEmpty()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void toggleEvents(ActionEvent actionEvent) {
|
||||||
|
Config.getInstance().getSettings().eventsSuspended = toggleEvents.isSelected();
|
||||||
|
toggleEvents.setText(toggleEvents.isSelected() ? "Resume Events" : "Suspend Events");
|
||||||
|
toggleEvents.setTooltip(new Tooltip(toggleEvents.isSelected() ? "Events are currently suspended" : "Events are currently active"));
|
||||||
|
try {
|
||||||
|
Config.getInstance().save();
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.error("Couldn't save config", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void add(ActionEvent evt) {
|
private void add(ActionEvent evt) {
|
||||||
var actionPane = createActionPane();
|
var actionPane = createActionPane();
|
||||||
var dialog = new Stage();
|
var dialog = new Stage();
|
||||||
dialog.initModality(Modality.APPLICATION_MODAL);
|
dialog.initModality(Modality.APPLICATION_MODAL);
|
||||||
dialog.initOwner(getScene().getWindow());
|
dialog.initOwner(getScene().getWindow());
|
||||||
dialog.setTitle("New Action");
|
dialog.setTitle("New Action");
|
||||||
InputStream icon = getClass().getResourceAsStream("/icon.png");
|
InputStream icon = Objects.requireNonNull(getClass().getResourceAsStream("/icon.png"), "/icon.png not found in classpath");
|
||||||
dialog.getIcons().add(new Image(icon));
|
dialog.getIcons().add(new Image(icon));
|
||||||
var root = new Wizard(dialog, this::validateSettings, actionPane);
|
var root = new Wizard(dialog, this::validateSettings, actionPane);
|
||||||
var scene = new Scene(root, 800, 540);
|
var scene = new Scene(root, 800, 540);
|
||||||
|
|
|
@ -71,6 +71,7 @@ public class Settings {
|
||||||
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<>();
|
||||||
|
public boolean eventsSuspended = false;
|
||||||
public boolean fastScrollSpeed = true;
|
public boolean fastScrollSpeed = true;
|
||||||
public String fc2livePassword = "";
|
public String fc2livePassword = "";
|
||||||
public String fc2liveUsername = "";
|
public String fc2liveUsername = "";
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import ctbrec.Config;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -17,16 +18,15 @@ import ctbrec.event.EventHandlerConfiguration.ActionConfiguration;
|
||||||
import ctbrec.event.EventHandlerConfiguration.PredicateConfiguration;
|
import ctbrec.event.EventHandlerConfiguration.PredicateConfiguration;
|
||||||
|
|
||||||
public class EventHandler {
|
public class EventHandler {
|
||||||
private static final transient Logger LOG = LoggerFactory.getLogger(EventHandler.class);
|
private static final Logger LOG = LoggerFactory.getLogger(EventHandler.class);
|
||||||
|
|
||||||
private List<EventPredicate> predicates = new ArrayList<>();
|
private List<EventPredicate> predicates = new ArrayList<>();
|
||||||
private List<Action> actions;
|
private final List<Action> actions;
|
||||||
private Type event;
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
public EventHandler(EventHandlerConfiguration config) {
|
public EventHandler(EventHandlerConfiguration config) {
|
||||||
id = config.getId();
|
id = config.getId();
|
||||||
event = config.getEvent();
|
Type event = config.getEvent();
|
||||||
actions = createActions(config);
|
actions = createActions(config);
|
||||||
predicates = createPredicates(config);
|
predicates = createPredicates(config);
|
||||||
predicates.add(new EventTypePredicate(event));
|
predicates.add(new EventTypePredicate(event));
|
||||||
|
@ -51,6 +51,11 @@ public class EventHandler {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void reactToEvent(Event evt) {
|
public void reactToEvent(Event evt) {
|
||||||
|
if (Config.getInstance().getSettings().eventsSuspended) {
|
||||||
|
LOG.debug("Events are suspended. Ignoring {}", evt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
boolean matches = true;
|
boolean matches = true;
|
||||||
for (Predicate<Event> predicate : predicates) {
|
for (Predicate<Event> predicate : predicates) {
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
package ctbrec.event;
|
package ctbrec.event;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
public class EventHandlerConfiguration {
|
public class EventHandlerConfiguration {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
@ -154,10 +150,7 @@ public class EventHandlerConfiguration {
|
||||||
return false;
|
return false;
|
||||||
EventHandlerConfiguration other = (EventHandlerConfiguration) obj;
|
EventHandlerConfiguration other = (EventHandlerConfiguration) obj;
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
if (other.id != null)
|
return other.id == null;
|
||||||
return false;
|
} else return id.equals(other.id);
|
||||||
} else if (!id.equals(other.id))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue