diff --git a/client/src/main/java/ctbrec/ui/settings/SettingsTab.java b/client/src/main/java/ctbrec/ui/settings/SettingsTab.java index 61059384..42303518 100644 --- a/client/src/main/java/ctbrec/ui/settings/SettingsTab.java +++ b/client/src/main/java/ctbrec/ui/settings/SettingsTab.java @@ -44,25 +44,22 @@ import javafx.scene.layout.GridPane; import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; -import javafx.scene.text.Font;; +import javafx.scene.text.Font; public class SettingsTab extends Tab implements TabSelectionListener { - private static final transient Logger LOG = LoggerFactory.getLogger(SettingsTab.class); - private static final int ONE_GiB_IN_BYTES = 1024 * 1024 * 1024; + private static final String PATTERN_NOT_A_DIGIT = "[^\\d]"; + private static final Logger LOG = LoggerFactory.getLogger(SettingsTab.class); + private static final int ONE_GIB_IN_BYTES = 1024 * 1024 * 1024; public static final int CHECKBOX_MARGIN = 6; private DirectorySelectionBox recordingsDirectory; - private ProgramSelectionBox mediaPlayer; private ProgramSelectionBox postProcessing; private TextField server; private TextField port; private TextField onlineCheckIntervalInSecs; - private TextField overviewUpdateIntervalInSecs; private TextField leaveSpaceOnDevice; private TextField minimumLengthInSecs; - private TextField servletContext; - private CheckBox loadResolution; private CheckBox useAuthentication = new CheckBox(); private CheckBox useTLS = new CheckBox(); private CheckBox chooseStreamQuality = new CheckBox(); @@ -71,8 +68,6 @@ public class SettingsTab extends Tab implements TabSelectionListener { private CheckBox livePreviews = new CheckBox(); private CheckBox showPlayerStarting = new CheckBox(); private RadioButton recordLocal; - private RadioButton recordRemote; - private ToggleGroup recordLocation; private ProxySettingsPane proxySettingsPane; private TextField maxResolution; private TextField concurrentRecordings; @@ -156,16 +151,16 @@ public class SettingsTab extends Tab implements TabSelectionListener { Label l = new Label("Record Location"); int row = 0; layout.add(l, 0, row); - recordLocation = new ToggleGroup(); + ToggleGroup recordLocationToggleGroup = new ToggleGroup(); recordLocal = new RadioButton("Local"); - recordRemote = new RadioButton("Remote"); - recordLocal.setToggleGroup(recordLocation); - recordRemote.setToggleGroup(recordLocation); + RadioButton recordRemote = new RadioButton("Remote"); + recordLocal.setToggleGroup(recordLocationToggleGroup); + recordRemote.setToggleGroup(recordLocationToggleGroup); recordLocal.setSelected(Config.getInstance().getSettings().localRecording); recordRemote.setSelected(!recordLocal.isSelected()); layout.add(recordLocal, 1, row); layout.add(recordRemote, 2, row++); - recordLocation.selectedToggleProperty().addListener((e) -> { + recordLocationToggleGroup.selectedToggleProperty().addListener(e -> { Config.getInstance().getSettings().localRecording = recordLocal.isSelected(); setRecordingMode(recordLocal.isSelected()); showRestartRequired(); @@ -192,7 +187,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { port = new TextField(Integer.toString(Config.getInstance().getSettings().httpPort)); port.textProperty().addListener((observable, oldValue, newValue) -> { if (!newValue.matches("\\d*")) { - port.setText(newValue.replaceAll("[^\\d]", "")); + port.setText(newValue.replaceAll(PATTERN_NOT_A_DIGIT, "")); } if(!port.getText().isEmpty()) { Config.getInstance().getSettings().httpPort = Integer.parseInt(port.getText()); @@ -205,7 +200,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { layout.add(port, 1, row++); layout.add(new Label("Path"), 0, row); - servletContext = new TextField(Config.getInstance().getSettings().servletContext); + TextField servletContext = new TextField(Config.getInstance().getSettings().servletContext); servletContext.setPromptText("e.g. /ctbrec"); servletContext.setTooltip(new Tooltip("Leave empty, if you didn't change the servletContext in the server config")); servletContext.textProperty().addListener((observable, oldValue, newValue) -> { @@ -220,7 +215,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { l = new Label("Require authentication"); layout.add(l, 0, row); useAuthentication.setSelected(Config.getInstance().getSettings().requireAuthentication); - useAuthentication.setOnAction((e) -> { + useAuthentication.setOnAction(e -> { Config.getInstance().getSettings().requireAuthentication = useAuthentication.isSelected(); if(useAuthentication.isSelected()) { byte[] key = Config.getInstance().getSettings().key; @@ -248,13 +243,13 @@ public class SettingsTab extends Tab implements TabSelectionListener { l = new Label("Use Secure Communication (TLS)"); layout.add(l, 0, row); useTLS.setSelected(Config.getInstance().getSettings().transportLayerSecurity); - useTLS.setOnAction((e) -> { + useTLS.setOnAction(e -> { Config.getInstance().getSettings().transportLayerSecurity = useTLS.isSelected(); saveConfig(); }); GridPane.setMargin(l, new Insets(4, CHECKBOX_MARGIN, 0, 0)); GridPane.setMargin(useTLS, new Insets(4, 0, 0, 0)); - layout.add(useTLS, 1, row++); + layout.add(useTLS, 1, row); TitledPane recordLocation = new TitledPane("Record Location", layout); recordLocation.setCollapsible(false); @@ -287,7 +282,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { options.add(ONE_PER_RECORDING); directoryStructure = new ComboBox<>(FXCollections.observableList(options)); directoryStructure.setValue(Config.getInstance().getSettings().recordingsDirStructure); - directoryStructure.setOnAction((evt) -> { + directoryStructure.setOnAction(evt -> { Config.getInstance().getSettings().recordingsDirStructure = directoryStructure.getValue(); saveConfig(); }); @@ -312,7 +307,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { splitAfter = new ComboBox<>(FXCollections.observableList(splitOptions)); layout.add(splitAfter, 1, row++); setSplitAfterValue(); - splitAfter.setOnAction((e) -> { + splitAfter.setOnAction(e -> { Config.getInstance().getSettings().splitRecordings = splitAfter.getSelectionModel().getSelectedItem().getValue(); saveConfig(); }); @@ -328,7 +323,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { maxResolution.setTooltip(tt); maxResolution.textProperty().addListener((observable, oldValue, newValue) -> { if (!newValue.matches("\\d*")) { - maxResolution.setText(newValue.replaceAll("[^\\d]", "")); + maxResolution.setText(newValue.replaceAll(PATTERN_NOT_A_DIGIT, "")); } if (!maxResolution.getText().isEmpty()) { int newRes = Integer.parseInt(maxResolution.getText()); @@ -348,7 +343,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { concurrentRecordings = new TextField(Integer.toString(Config.getInstance().getSettings().concurrentRecordings)); concurrentRecordings.textProperty().addListener((observable, oldValue, newValue) -> { if (!newValue.matches("\\d*")) { - concurrentRecordings.setText(newValue.replaceAll("[^\\d]", "")); + concurrentRecordings.setText(newValue.replaceAll(PATTERN_NOT_A_DIGIT, "")); } if (!concurrentRecordings.getText().isEmpty()) { int newConcurrentRecordings = Integer.parseInt(concurrentRecordings.getText()); @@ -386,7 +381,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { onlineCheckIntervalInSecs.setTooltip(tt); onlineCheckIntervalInSecs.textProperty().addListener((observable, oldValue, newValue) -> { if (!newValue.matches("\\d*")) { - onlineCheckIntervalInSecs.setText(newValue.replaceAll("[^\\d]", "")); + onlineCheckIntervalInSecs.setText(newValue.replaceAll(PATTERN_NOT_A_DIGIT, "")); } if(!onlineCheckIntervalInSecs.getText().isEmpty()) { Config.getInstance().getSettings().onlineCheckIntervalInSecs = Integer.parseInt(onlineCheckIntervalInSecs.getText()); @@ -401,16 +396,16 @@ public class SettingsTab extends Tab implements TabSelectionListener { l.setTooltip(tt); layout.add(l, 0, row); long minimumSpaceLeftInBytes = Config.getInstance().getSettings().minimumSpaceLeftInBytes; - int minimumSpaceLeftInGiB = (int) (minimumSpaceLeftInBytes / ONE_GiB_IN_BYTES); + int minimumSpaceLeftInGiB = (int) (minimumSpaceLeftInBytes / ONE_GIB_IN_BYTES); leaveSpaceOnDevice = new TextField(Integer.toString(minimumSpaceLeftInGiB)); leaveSpaceOnDevice.setTooltip(tt); leaveSpaceOnDevice.textProperty().addListener((observable, oldValue, newValue) -> { if (!newValue.matches("\\d*")) { - leaveSpaceOnDevice.setText(newValue.replaceAll("[^\\d]", "")); + leaveSpaceOnDevice.setText(newValue.replaceAll(PATTERN_NOT_A_DIGIT, "")); } if(!leaveSpaceOnDevice.getText().isEmpty()) { long spaceLeftInGiB = Long.parseLong(leaveSpaceOnDevice.getText()); - Config.getInstance().getSettings().minimumSpaceLeftInBytes = spaceLeftInGiB * ONE_GiB_IN_BYTES; + Config.getInstance().getSettings().minimumSpaceLeftInBytes = spaceLeftInGiB * ONE_GIB_IN_BYTES; saveConfig(); } }); @@ -426,7 +421,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { minimumLengthInSecs.setTooltip(tt); minimumLengthInSecs.textProperty().addListener((observable, oldValue, newValue) -> { if (!newValue.matches("\\d*")) { - minimumLengthInSecs.setText(newValue.replaceAll("[^\\d]", "")); + minimumLengthInSecs.setText(newValue.replaceAll(PATTERN_NOT_A_DIGIT, "")); } if(!minimumLengthInSecs.getText().isEmpty()) { int minimumLength = Integer.parseInt(minimumLengthInSecs.getText()); @@ -435,7 +430,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { } }); GridPane.setMargin(minimumLengthInSecs, new Insets(0, 0, 0, CHECKBOX_MARGIN)); - layout.add(minimumLengthInSecs, 1, row++); + layout.add(minimumLengthInSecs, 1, row); TitledPane locations = new TitledPane("Recorder", layout); locations.setCollapsible(false); @@ -457,7 +452,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { int row = 0; layout.add(new Label("Player"), 0, row); - mediaPlayer = new ProgramSelectionBox(Config.getInstance().getSettings().mediaPlayer); + ProgramSelectionBox mediaPlayer = new ProgramSelectionBox(Config.getInstance().getSettings().mediaPlayer); mediaPlayer.fileProperty().addListener((obs, o, n) -> { String path = n; if (!Objects.equals(path, Config.getInstance().getSettings().mediaPlayer)) { @@ -473,7 +468,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { Label l = new Label("Allow multiple players"); layout.add(l, 0, row); multiplePlayers.setSelected(!Config.getInstance().getSettings().singlePlayer); - multiplePlayers.setOnAction((e) -> { + multiplePlayers.setOnAction(e -> { Config.getInstance().getSettings().singlePlayer = !multiplePlayers.isSelected(); saveConfig(); }); @@ -484,7 +479,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { l = new Label("Show \"Player Starting\" Message"); layout.add(l, 0, row); showPlayerStarting.setSelected(Config.getInstance().getSettings().showPlayerStarting); - showPlayerStarting.setOnAction((e) -> { + showPlayerStarting.setOnAction(e -> { Config.getInstance().getSettings().showPlayerStarting = showPlayerStarting.isSelected(); saveConfig(); }); @@ -494,9 +489,9 @@ public class SettingsTab extends Tab implements TabSelectionListener { l = new Label("Display stream resolution in overview"); layout.add(l, 0, row); - loadResolution = new CheckBox(); + CheckBox loadResolution = new CheckBox(); loadResolution.setSelected(Config.getInstance().getSettings().determineResolution); - loadResolution.setOnAction((e) -> { + loadResolution.setOnAction(e -> { Config.getInstance().getSettings().determineResolution = loadResolution.isSelected(); saveConfig(); }); @@ -507,7 +502,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { l = new Label("Manually select stream quality"); layout.add(l, 0, row); chooseStreamQuality.setSelected(Config.getInstance().getSettings().chooseStreamQuality); - chooseStreamQuality.setOnAction((e) -> { + chooseStreamQuality.setOnAction(e -> { Config.getInstance().getSettings().chooseStreamQuality = chooseStreamQuality.isSelected(); saveConfig(); }); @@ -518,7 +513,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { l = new Label("Enable live previews (experimental)"); layout.add(l, 0, row); livePreviews.setSelected(Config.getInstance().getSettings().livePreviews); - livePreviews.setOnAction((e) -> { + livePreviews.setOnAction(e -> { Config.getInstance().getSettings().livePreviews = livePreviews.isSelected(); saveConfig(); showRestartRequired(); @@ -533,7 +528,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { layout.add(l, 0, row); updateThumbnails.setTooltip(tt); updateThumbnails.setSelected(Config.getInstance().getSettings().updateThumbnails); - updateThumbnails.setOnAction((e) -> { + updateThumbnails.setOnAction(e -> { Config.getInstance().getSettings().updateThumbnails = updateThumbnails.isSelected(); saveConfig(); }); @@ -545,11 +540,11 @@ public class SettingsTab extends Tab implements TabSelectionListener { l = new Label("Update overview interval (seconds)"); l.setTooltip(tt); layout.add(l, 0, row); - overviewUpdateIntervalInSecs = new TextField(Integer.toString(Config.getInstance().getSettings().overviewUpdateIntervalInSecs)); + TextField overviewUpdateIntervalInSecs = new TextField(Integer.toString(Config.getInstance().getSettings().overviewUpdateIntervalInSecs)); overviewUpdateIntervalInSecs.setTooltip(tt); overviewUpdateIntervalInSecs.textProperty().addListener((observable, oldValue, newValue) -> { if (!newValue.matches("\\d*")) { - overviewUpdateIntervalInSecs.setText(newValue.replaceAll("[^\\d]", "")); + overviewUpdateIntervalInSecs.setText(newValue.replaceAll(PATTERN_NOT_A_DIGIT, "")); } if(!overviewUpdateIntervalInSecs.getText().isEmpty()) { Config.getInstance().getSettings().overviewUpdateIntervalInSecs = Integer.parseInt(overviewUpdateIntervalInSecs.getText()); @@ -564,7 +559,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { l = new Label("Start Tab"); layout.add(l, 0, row); startTab = new ComboBox<>(); - startTab.setOnAction((e) -> { + startTab.setOnAction(e -> { Config.getInstance().getSettings().startTab = startTab.getSelectionModel().getSelectedItem(); saveConfig(); }); @@ -576,7 +571,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { l = new Label("Colors (Base / Accent)"); layout.add(l, 0, row); ColorSettingsPane colorSettingsPane = new ColorSettingsPane(this); - layout.add(colorSettingsPane, 1, row++); + layout.add(colorSettingsPane, 1, row); GridPane.setMargin(l, new Insets(0, 0, 0, 0)); GridPane.setMargin(colorSettingsPane, new Insets(0, 0, 0, CHECKBOX_MARGIN));