forked from j62/ctbrec
1
0
Fork 0

Add setting to SettingsTab to define the color scheme of the app

This commit is contained in:
0xboobface 2018-11-25 19:11:15 +01:00
parent 240e5e0d92
commit 84dfeb9484
5 changed files with 123 additions and 9 deletions

View File

@ -2,6 +2,7 @@ package ctbrec.ui;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -44,6 +45,7 @@ import javafx.scene.control.Alert;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import okhttp3.Request;
import okhttp3.Response;
@ -122,8 +124,13 @@ public class CamrecApplication extends Application {
rootPane.getTabs().add(new DonateTabFx());
switchToStartTab();
loadUserStyleSheet(primaryStage);
writeColorSchemeStyleSheet(primaryStage);
Color base = Color.web(Config.getInstance().getSettings().colorBase);
if(!base.equals(Color.WHITE)) {
loadStyleSheet(primaryStage, "color.css");
}
loadStyleSheet(primaryStage, "style.css");
primaryStage.getScene().getStylesheets().add("/ctbrec/ui/ColorSettingsPane.css");
primaryStage.getScene().getStylesheets().add("/ctbrec/ui/ThumbCell.css");
primaryStage.getScene().getStylesheets().add("/ctbrec/ui/controls/SearchBox.css");
primaryStage.getScene().getStylesheets().add("/ctbrec/ui/controls/Popover.css");
@ -188,10 +195,26 @@ public class CamrecApplication extends Application {
});
}
private void loadUserStyleSheet(Stage primaryStage) {
File userCss = new File(Config.getInstance().getConfigDir(), "style.css");
if(userCss.exists() && userCss.isFile()) {
primaryStage.getScene().getStylesheets().add(userCss.toURI().toString());
private void writeColorSchemeStyleSheet(Stage primaryStage) {
File colorCss = new File(Config.getInstance().getConfigDir(), "color.css");
try(FileOutputStream fos = new FileOutputStream(colorCss)) {
String content = ".root {\n" +
" -fx-base: "+Config.getInstance().getSettings().colorBase+";\n" +
" -fx-accent: "+Config.getInstance().getSettings().colorAccent+";\n" +
" -fx-default-button: -fx-accent;\n" +
" -fx-focus-color: -fx-accent;\n" +
" -fx-control-inner-background-alt: derive(-fx-base, 95%);\n" +
"}";
fos.write(content.getBytes("utf-8"));
} catch(Exception e) {
LOG.error("Couldn't write stylesheet for user defined color theme");
}
}
private void loadStyleSheet(Stage primaryStage, String filename) {
File css = new File(Config.getInstance().getConfigDir(), filename);
if(css.exists() && css.isFile()) {
primaryStage.getScene().getStylesheets().add(css.toURI().toString());
}
}

View File

@ -0,0 +1,10 @@
ColorSettingsPane .color-picker .color-picker-label .text {
visibility: false;
}
/*
ColorSettingsPane .color-picker > .arrow-button,
ColorSettingsPane .color-picker > .arrow-button:hover
{
visibility: false;
}
*/

View File

@ -0,0 +1,73 @@
package ctbrec.ui;
import ctbrec.Config;
import javafx.scene.control.Button;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
public class ColorSettingsPane extends Pane {
Label labelBaseColor = new Label("Base");
ColorPicker baseColor = new ColorPicker();
Label labelAccentColor = new Label("Accent");
ColorPicker accentColor = new ColorPicker();
Button reset = new Button("Reset");
Pane foobar = new Pane();
public ColorSettingsPane() {
getChildren().add(labelBaseColor);
getChildren().add(baseColor);
getChildren().add(labelAccentColor);
getChildren().add(accentColor);
getChildren().add(reset);
baseColor.setValue(Color.web(Config.getInstance().getSettings().colorBase));
accentColor.setValue(Color.web(Config.getInstance().getSettings().colorAccent));
baseColor.setOnAction(evt -> Config.getInstance().getSettings().colorBase = toWeb(baseColor.getValue()));
accentColor.setOnAction(evt -> Config.getInstance().getSettings().colorAccent = toWeb(accentColor.getValue()));
reset.setOnAction(evt -> {
baseColor.setValue(Color.WHITE);
Config.getInstance().getSettings().colorBase = toWeb(Color.WHITE);
accentColor.setValue(Color.WHITE);
Config.getInstance().getSettings().colorAccent = toWeb(Color.WHITE);
});
}
private String toWeb(Color value) {
StringBuilder sb = new StringBuilder("#");
sb.append(toHex((int) (value.getRed() * 255)));
sb.append(toHex((int) (value.getGreen() * 255)));
sb.append(toHex((int) (value.getBlue() * 255)));
if(!value.isOpaque()) {
sb.append(toHex((int) (value.getOpacity() * 255)));
}
return sb.toString();
}
private CharSequence toHex(int v) {
StringBuilder sb = new StringBuilder();
if(v < 16) {
sb.append('0');
}
sb.append(Integer.toHexString(v));
return sb;
}
@Override
protected void layoutChildren() {
labelBaseColor.resize(32, 25);
baseColor.resize(44, 25);
labelAccentColor.resize(46, 25);
accentColor.resize(44, 25);
reset.resize(60, 25);
labelBaseColor.setTranslateX(0);
baseColor.setTranslateX(labelBaseColor.getWidth() + 10);
labelAccentColor.setTranslateX(baseColor.getTranslateX() + baseColor.getWidth() + 15);
accentColor.setTranslateX(labelAccentColor.getTranslateX() + labelAccentColor.getWidth() + 10);
reset.setTranslateX(accentColor.getTranslateX() + accentColor.getWidth() + 50);
}
}

View File

@ -121,12 +121,12 @@ public class SettingsTab extends Tab implements TabSelectionListener {
leftSide.getChildren().add(createGeneralPanel());
leftSide.getChildren().add(createLocationsPanel());
leftSide.getChildren().add(createRecordLocationPanel());
proxySettingsPane = new ProxySettingsPane(this);
leftSide.getChildren().add(proxySettingsPane);
//right side
rightSide.getChildren().add(createSiteSelectionPanel());
rightSide.getChildren().add(credentialsAccordion);
proxySettingsPane = new ProxySettingsPane(this);
rightSide.getChildren().add(proxySettingsPane);
for (int i = 0; i < sites.size(); i++) {
Site site = sites.get(i);
ConfigUI siteConfig = SiteUiFactory.getUi(site).getConfigUI();
@ -384,6 +384,13 @@ public class SettingsTab extends Tab implements TabSelectionListener {
GridPane.setMargin(l, new Insets(0, 0, 0, 0));
GridPane.setMargin(startTab, new Insets(0, 0, 0, CHECKBOX_MARGIN));
l = new Label("Colors");
layout.add(l, 0, row);
ColorSettingsPane colorSettingsPane = new ColorSettingsPane();
layout.add(colorSettingsPane, 1, row++);
GridPane.setMargin(l, new Insets(0, 0, 0, 0));
GridPane.setMargin(colorSettingsPane, new Insets(CHECKBOX_MARGIN, 0, 0, CHECKBOX_MARGIN));
splitAfter.prefWidthProperty().bind(startTab.widthProperty());
maxResolution.prefWidthProperty().bind(startTab.widthProperty());

View File

@ -72,5 +72,6 @@ public class Settings {
public int windowY;
public int splitRecordings = 0;
public List<String> disabledSites = new ArrayList<>();
public long onlineCheckIntervalInSecs = 60;
public String colorBase = "#FFFFFF";
public String colorAccent = "#FFFFFF";
}