Add more settings
This commit is contained in:
parent
ec1a0826e0
commit
90300473bc
|
@ -190,8 +190,8 @@ public class CamrecApplication extends Application {
|
||||||
recordingsTab = new RecordingsTab("Recordings", recorder, config, sites);
|
recordingsTab = new RecordingsTab("Recordings", recorder, config, sites);
|
||||||
tabPane.getTabs().add(recordingsTab);
|
tabPane.getTabs().add(recordingsTab);
|
||||||
settingsTab = new SettingsTab(sites, recorder);
|
settingsTab = new SettingsTab(sites, recorder);
|
||||||
tabPane.getTabs().add(settingsTab);
|
|
||||||
tabPane.getTabs().add(new SettingsTab2(sites, recorder));
|
tabPane.getTabs().add(new SettingsTab2(sites, recorder));
|
||||||
|
tabPane.getTabs().add(settingsTab);
|
||||||
tabPane.getTabs().add(new NewsTab());
|
tabPane.getTabs().add(new NewsTab());
|
||||||
tabPane.getTabs().add(new DonateTabFx());
|
tabPane.getTabs().add(new DonateTabFx());
|
||||||
tabPane.getTabs().add(new HelpTab());
|
tabPane.getTabs().add(new HelpTab());
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package ctbrec.ui.settings;
|
package ctbrec.ui.settings;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
|
import ctbrec.ui.controls.Dialogs;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.ColorPicker;
|
import javafx.scene.control.ColorPicker;
|
||||||
import javafx.scene.control.Tooltip;
|
import javafx.scene.control.Tooltip;
|
||||||
|
@ -14,41 +17,49 @@ public class ColorSettingsPane extends HBox {
|
||||||
ColorPicker accentColor = new ColorPicker();
|
ColorPicker accentColor = new ColorPicker();
|
||||||
Button reset = new Button("Reset");
|
Button reset = new Button("Reset");
|
||||||
Pane foobar = new Pane();
|
Pane foobar = new Pane();
|
||||||
|
private Config config;
|
||||||
|
|
||||||
public ColorSettingsPane(SettingsTab settingsTab) {
|
public ColorSettingsPane(Config config) {
|
||||||
super(5);
|
super(5);
|
||||||
|
this.config = config;
|
||||||
getChildren().add(baseColor);
|
getChildren().add(baseColor);
|
||||||
getChildren().add(accentColor);
|
getChildren().add(accentColor);
|
||||||
getChildren().add(reset);
|
getChildren().add(reset);
|
||||||
|
|
||||||
baseColor.setValue(Color.web(Config.getInstance().getSettings().colorBase));
|
baseColor.setValue(Color.web(config.getSettings().colorBase));
|
||||||
baseColor.setTooltip(new Tooltip("Base Color"));
|
baseColor.setTooltip(new Tooltip("Base Color"));
|
||||||
baseColor.setMaxSize(44, 25);
|
baseColor.setMaxSize(44, 25);
|
||||||
accentColor.setValue(Color.web(Config.getInstance().getSettings().colorAccent));
|
accentColor.setValue(Color.web(config.getSettings().colorAccent));
|
||||||
accentColor.setTooltip(new Tooltip("Accent Color"));
|
accentColor.setTooltip(new Tooltip("Accent Color"));
|
||||||
accentColor.setMaxSize(44, 25);
|
accentColor.setMaxSize(44, 25);
|
||||||
|
reset.setMinSize(60, 25);
|
||||||
reset.setMaxSize(60, 25);
|
reset.setMaxSize(60, 25);
|
||||||
|
|
||||||
baseColor.setOnAction(evt -> {
|
baseColor.setOnAction(evt -> {
|
||||||
Config.getInstance().getSettings().colorBase = toWeb(baseColor.getValue());
|
config.getSettings().colorBase = toWeb(baseColor.getValue());
|
||||||
settingsTab.showRestartRequired();
|
save();
|
||||||
settingsTab.saveConfig();
|
|
||||||
});
|
});
|
||||||
accentColor.setOnAction(evt -> {
|
accentColor.setOnAction(evt -> {
|
||||||
Config.getInstance().getSettings().colorAccent = toWeb(accentColor.getValue());
|
config.getSettings().colorAccent = toWeb(accentColor.getValue());
|
||||||
settingsTab.showRestartRequired();
|
save();
|
||||||
settingsTab.saveConfig();
|
|
||||||
});
|
});
|
||||||
reset.setOnAction(evt -> {
|
reset.setOnAction(evt -> {
|
||||||
baseColor.setValue(Color.WHITE);
|
baseColor.setValue(Color.WHITE);
|
||||||
Config.getInstance().getSettings().colorBase = toWeb(Color.WHITE);
|
config.getSettings().colorBase = toWeb(Color.WHITE);
|
||||||
accentColor.setValue(Color.WHITE);
|
accentColor.setValue(Color.WHITE);
|
||||||
Config.getInstance().getSettings().colorAccent = toWeb(Color.WHITE);
|
config.getSettings().colorAccent = toWeb(Color.WHITE);
|
||||||
settingsTab.showRestartRequired();
|
save();
|
||||||
settingsTab.saveConfig();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void save() {
|
||||||
|
try {
|
||||||
|
config.save();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Dialogs.showError(getScene(), "Save Settings", "Couldn't save color settings", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String toWeb(Color value) {
|
private String toWeb(Color value) {
|
||||||
StringBuilder sb = new StringBuilder("#");
|
StringBuilder sb = new StringBuilder("#");
|
||||||
sb.append(toHex((int) (value.getRed() * 255)));
|
sb.append(toHex((int) (value.getRed() * 255)));
|
||||||
|
|
|
@ -2,16 +2,22 @@ package ctbrec.ui.settings;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Settings;
|
import ctbrec.Settings;
|
||||||
|
import ctbrec.StringUtil;
|
||||||
import ctbrec.ui.settings.api.Preferences;
|
import ctbrec.ui.settings.api.Preferences;
|
||||||
import ctbrec.ui.settings.api.PreferencesStorage;
|
import ctbrec.ui.settings.api.PreferencesStorage;
|
||||||
|
import ctbrec.ui.settings.api.SelectionSetting;
|
||||||
|
import ctbrec.ui.settings.api.Setting;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.CheckBox;
|
import javafx.scene.control.CheckBox;
|
||||||
|
import javafx.scene.control.ComboBox;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
|
|
||||||
|
@ -40,11 +46,14 @@ public class CtbrecPreferencesStorage implements PreferencesStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Node createGui(String key) throws Exception {
|
public Node createGui(Setting setting) throws Exception {
|
||||||
|
String key = setting.getKey();
|
||||||
Field field = Settings.class.getField(key);
|
Field field = Settings.class.getField(key);
|
||||||
Class<?> t = field.getType();
|
Class<?> t = field.getType();
|
||||||
Object value = field.get(settings);
|
Object value = field.get(settings);
|
||||||
if (t == String.class) {
|
if(setting instanceof SelectionSetting) {
|
||||||
|
return createComboBox(key, ((SelectionSetting) setting).getOptions());
|
||||||
|
} else if (t == String.class) {
|
||||||
return createStringProperty(key, (String) value);
|
return createStringProperty(key, (String) value);
|
||||||
} else if (t == int.class || t == Integer.class) {
|
} else if (t == int.class || t == Integer.class) {
|
||||||
return createIntegerProperty(key, (Integer) value);
|
return createIntegerProperty(key, (Integer) value);
|
||||||
|
@ -91,6 +100,21 @@ public class CtbrecPreferencesStorage implements PreferencesStorage {
|
||||||
return ctrl;
|
return ctrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Node createComboBox(String key, Object[] options) throws NoSuchFieldException, IllegalAccessException {
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
ComboBox<Object> comboBox = new ComboBox(FXCollections.observableList(Arrays.asList(options)));
|
||||||
|
Field field = Settings.class.getField(key);
|
||||||
|
Object value = field.get(settings);
|
||||||
|
if(StringUtil.isNotBlank(value.toString())) {
|
||||||
|
comboBox.getSelectionModel().select(value);
|
||||||
|
}
|
||||||
|
comboBox.valueProperty().addListener((obs, oldV, newV) -> saveValue(() -> {
|
||||||
|
field.set(settings, newV);
|
||||||
|
config.save();
|
||||||
|
}));
|
||||||
|
return comboBox;
|
||||||
|
}
|
||||||
|
|
||||||
private void saveValue(Exec exe) {
|
private void saveValue(Exec exe) {
|
||||||
try {
|
try {
|
||||||
exe.run();
|
exe.run();
|
||||||
|
|
|
@ -745,7 +745,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
||||||
|
|
||||||
l = new Label("Colors (Base / Accent)");
|
l = new Label("Colors (Base / Accent)");
|
||||||
layout.add(l, 0, row);
|
layout.add(l, 0, row);
|
||||||
ColorSettingsPane colorSettingsPane = new ColorSettingsPane(this);
|
ColorSettingsPane colorSettingsPane = new ColorSettingsPane(Config.getInstance());
|
||||||
layout.add(colorSettingsPane, 1, row++);
|
layout.add(colorSettingsPane, 1, row++);
|
||||||
GridPane.setMargin(l, new Insets(0, 0, 0, 0));
|
GridPane.setMargin(l, new Insets(0, 0, 0, 0));
|
||||||
GridPane.setMargin(colorSettingsPane, new Insets(0, 0, 0, CHECKBOX_MARGIN));
|
GridPane.setMargin(colorSettingsPane, new Insets(0, 0, 0, CHECKBOX_MARGIN));
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package ctbrec.ui.settings;
|
package ctbrec.ui.settings;
|
||||||
|
|
||||||
|
import static ctbrec.Settings.ProxyType.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -18,13 +20,15 @@ public class SettingsTab2 extends Tab implements TabSelectionListener {
|
||||||
|
|
||||||
private List<Site> sites;
|
private List<Site> sites;
|
||||||
private Recorder recorder;
|
private Recorder recorder;
|
||||||
|
private Preferences prefs;
|
||||||
|
private boolean initialized = false;
|
||||||
|
|
||||||
public SettingsTab2(List<Site> sites, Recorder recorder) {
|
public SettingsTab2(List<Site> sites, Recorder recorder) {
|
||||||
this.sites = sites;
|
this.sites = sites;
|
||||||
this.recorder = recorder;
|
this.recorder = recorder;
|
||||||
setText("Settings");
|
setText("Settings");
|
||||||
createGui();
|
|
||||||
setClosable(false);
|
setClosable(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createGui() {
|
private void createGui() {
|
||||||
|
@ -33,33 +37,60 @@ public class SettingsTab2 extends Tab implements TabSelectionListener {
|
||||||
siteCategories.add(Category.of(site.getName(), SiteUiFactory.getUi(site).getConfigUI().createConfigPanel()));
|
siteCategories.add(Category.of(site.getName(), SiteUiFactory.getUi(site).getConfigUI().createConfigPanel()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Preferences prefs = Preferences.of(new CtbrecPreferencesStorage(Config.getInstance()),
|
prefs = Preferences.of(new CtbrecPreferencesStorage(Config.getInstance()),
|
||||||
Category.of("General",
|
Category.of("General",
|
||||||
Group.of("General",
|
Group.of("General",
|
||||||
Setting.of("Player", "mediaPlayer"),
|
Setting.of("User-Agent", "httpUserAgent"),
|
||||||
Setting.of("Start parameters", "mediaPlayerParams"),
|
Setting.of("User-Agent mobile", "httpUserAgentMobile"),
|
||||||
Setting.of("Maximum resolution (0 = unlimited)", "maximumResolutionPlayer", "video height, e.g. 720 or 1080")),
|
Setting.of("Update overview interval (seconds)", "overviewUpdateIntervalInSecs", "Update the thumbnail overviews every x seconds"),
|
||||||
|
Setting.of("Update thumbnails", "updateThumbnails", "The overviews will still be updated, but the thumbnails won't be changed. This is useful for less powerful systems."),
|
||||||
|
Setting.of("Display stream resolution in overview", "determineResolution"),
|
||||||
|
Setting.of("Manually select stream quality", "chooseStreamQuality", "Opens a dialog to select the video resolution before recording"),
|
||||||
|
Setting.of("Enable live previews (experimental)", "livePreviews"),
|
||||||
|
Setting.of("Start Tab", "startTab", getTabNames()),
|
||||||
|
Setting.of("Colors (Base / Accent)", null, new ColorSettingsPane(Config.getInstance()))
|
||||||
|
),
|
||||||
Group.of("Player",
|
Group.of("Player",
|
||||||
Setting.of("Player", "mediaPlayer"),
|
Setting.of("Player", "mediaPlayer"),
|
||||||
Setting.of("Start parameters", "mediaPlayerParams"),
|
Setting.of("Start parameters", "mediaPlayerParams"),
|
||||||
Setting.of("Maximum resolution (0 = unlimited)", "maximumResolutionPlayer", "video height, e.g. 720 or 1080"),
|
Setting.of("Maximum resolution (0 = unlimited)", "maximumResolutionPlayer", "video height, e.g. 720 or 1080"),
|
||||||
Setting.of("Show \"Player Starting\" Message", "showPlayerStarting"))
|
Setting.of("Show \"Player Starting\" Message", "showPlayerStarting"),
|
||||||
|
Setting.of("Start only one player at a time", "singlePlayer")
|
||||||
|
)
|
||||||
),
|
),
|
||||||
Category.of("Sites", siteCategories.toArray(new Category[0]))
|
Category.of("Sites", siteCategories.toArray(new Category[0])),
|
||||||
|
Category.of("Proxy",
|
||||||
|
Group.of("Proxy",
|
||||||
|
Setting.of("Type", "proxyType", DIRECT, HTTP, SOCKS4, SOCKS5),
|
||||||
|
Setting.of("Host", "proxyHost"),
|
||||||
|
Setting.of("Port", "proxyPort"),
|
||||||
|
Setting.of("Username", "proxyUser"),
|
||||||
|
Setting.of("Password", "proxyPassword")
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
setContent(prefs.getView());
|
setContent(prefs.getView());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object[] getTabNames() {
|
||||||
|
List<String> tabNames = new ArrayList<>();
|
||||||
|
for (Tab tab : getTabPane().getTabs()) {
|
||||||
|
tabNames.add(tab.getText());
|
||||||
|
}
|
||||||
|
return tabNames.toArray(new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selected() {
|
public void selected() {
|
||||||
// TODO Auto-generated method stub
|
if (!initialized) {
|
||||||
|
createGui();
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deselected() {
|
public void deselected() {
|
||||||
// TODO Auto-generated method stub
|
// TODO maybe save the config ?!?
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import ctbrec.ui.controls.SearchBox;
|
import ctbrec.ui.controls.SearchBox;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.geometry.VPos;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.Tooltip;
|
import javafx.scene.control.Tooltip;
|
||||||
|
@ -83,7 +84,7 @@ public class Preferences {
|
||||||
main.setCenter(gui);
|
main.setCenter(gui);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
categoryTree.getSelectionModel().select(0);
|
||||||
return main;
|
return main;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,12 +151,14 @@ public class Preferences {
|
||||||
for (Setting setting : settings) {
|
for (Setting setting : settings) {
|
||||||
Node node = setting.getGui();
|
Node node = setting.getGui();
|
||||||
Label label = new Label(setting.getName());
|
Label label = new Label(setting.getName());
|
||||||
|
label.setMinHeight(34);
|
||||||
label.labelForProperty().set(node);
|
label.labelForProperty().set(node);
|
||||||
if (setting.getTooltip() != null) {
|
label.setTooltip(new Tooltip(setting.getName()));
|
||||||
label.setTooltip(new Tooltip(setting.getTooltip()));
|
|
||||||
}
|
|
||||||
pane.addRow(row++, label, node);
|
pane.addRow(row++, label, node);
|
||||||
|
GridPane.setVgrow(label, Priority.ALWAYS);
|
||||||
|
GridPane.setValignment(label, VPos.CENTER);
|
||||||
GridPane.setMargin(node, new Insets(5, 0, 5, 10));
|
GridPane.setMargin(node, new Insets(5, 0, 5, 10));
|
||||||
|
GridPane.setValignment(node, VPos.CENTER);
|
||||||
GridPane.setHgrow(node, Priority.ALWAYS);
|
GridPane.setHgrow(node, Priority.ALWAYS);
|
||||||
}
|
}
|
||||||
return pane;
|
return pane;
|
||||||
|
|
|
@ -9,5 +9,5 @@ public interface PreferencesStorage {
|
||||||
void save(Preferences preferences) throws IOException;
|
void save(Preferences preferences) throws IOException;
|
||||||
void load(Preferences preferences);
|
void load(Preferences preferences);
|
||||||
|
|
||||||
Node createGui(String key) throws Exception;
|
Node createGui(Setting setting) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package ctbrec.ui.settings.api;
|
||||||
|
|
||||||
|
public class SelectionSetting extends Setting {
|
||||||
|
|
||||||
|
private Object[] options;
|
||||||
|
|
||||||
|
public SelectionSetting(String name, String key, Object[] options) {
|
||||||
|
super(name, key);
|
||||||
|
this.options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] getOptions() {
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,8 +16,9 @@ public class Setting {
|
||||||
private Property<?> property;
|
private Property<?> property;
|
||||||
private Node gui;
|
private Node gui;
|
||||||
private PreferencesStorage preferencesStorage;
|
private PreferencesStorage preferencesStorage;
|
||||||
|
private boolean needsRestart = false;
|
||||||
|
|
||||||
private Setting(String name, String key) {
|
protected Setting(String name, String key) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
@ -32,18 +33,37 @@ public class Setting {
|
||||||
return setting;
|
return setting;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getName() {
|
public static Setting of(String name, String key, Object...options) {
|
||||||
|
return new SelectionSetting(name, key, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Setting of(String name, String key, Node gui) {
|
||||||
|
Setting setting = new Setting(name, key);
|
||||||
|
setting.gui = gui;
|
||||||
|
return setting;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getKey() {
|
public String getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getTooltip() {
|
public String getTooltip() {
|
||||||
return tooltip;
|
return tooltip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Setting needsRestart() {
|
||||||
|
needsRestart = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean doesNeedRestart() {
|
||||||
|
return needsRestart;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
Property getProperty() {
|
Property getProperty() {
|
||||||
return property;
|
return property;
|
||||||
|
@ -51,7 +71,7 @@ public class Setting {
|
||||||
|
|
||||||
Node getGui() throws Exception {
|
Node getGui() throws Exception {
|
||||||
if (gui == null) {
|
if (gui == null) {
|
||||||
gui = preferencesStorage.createGui(key);
|
gui = preferencesStorage.createGui(this);
|
||||||
if (gui instanceof Control && StringUtil.isNotBlank(tooltip)) {
|
if (gui instanceof Control && StringUtil.isNotBlank(tooltip)) {
|
||||||
Control control = (Control) gui;
|
Control control = (Control) gui;
|
||||||
control.setTooltip(new Tooltip(tooltip));
|
control.setTooltip(new Tooltip(tooltip));
|
||||||
|
|
Loading…
Reference in New Issue