diff --git a/client/src/main/java/ctbrec/ui/CamrecApplication.java b/client/src/main/java/ctbrec/ui/CamrecApplication.java index 51249043..bf9bc55b 100644 --- a/client/src/main/java/ctbrec/ui/CamrecApplication.java +++ b/client/src/main/java/ctbrec/ui/CamrecApplication.java @@ -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()); } } diff --git a/client/src/main/java/ctbrec/ui/ColorSettingsPane.css b/client/src/main/java/ctbrec/ui/ColorSettingsPane.css new file mode 100644 index 00000000..5b29c0fc --- /dev/null +++ b/client/src/main/java/ctbrec/ui/ColorSettingsPane.css @@ -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; +} +*/ \ No newline at end of file diff --git a/client/src/main/java/ctbrec/ui/ColorSettingsPane.java b/client/src/main/java/ctbrec/ui/ColorSettingsPane.java new file mode 100644 index 00000000..073152ec --- /dev/null +++ b/client/src/main/java/ctbrec/ui/ColorSettingsPane.java @@ -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); + } +} diff --git a/client/src/main/java/ctbrec/ui/SettingsTab.java b/client/src/main/java/ctbrec/ui/SettingsTab.java index 11287e82..7e3a6459 100644 --- a/client/src/main/java/ctbrec/ui/SettingsTab.java +++ b/client/src/main/java/ctbrec/ui/SettingsTab.java @@ -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()); diff --git a/common/src/main/java/ctbrec/Settings.java b/common/src/main/java/ctbrec/Settings.java index 5937bee3..4772116b 100644 --- a/common/src/main/java/ctbrec/Settings.java +++ b/common/src/main/java/ctbrec/Settings.java @@ -72,5 +72,6 @@ public class Settings { public int windowY; public int splitRecordings = 0; public List disabledSites = new ArrayList<>(); - public long onlineCheckIntervalInSecs = 60; + public String colorBase = "#FFFFFF"; + public String colorAccent = "#FFFFFF"; }