Skip to content

Commit

Permalink
Theming
Browse files Browse the repository at this point in the history
Fixes #1792
  • Loading branch information
1-alex98 committed Jun 20, 2020
1 parent a4beb20 commit 2f98cdd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class AutoJoinChannelsController implements Controller<Node> {
public Button addChannelButton;
public ListView<String> channelListView;
public GridPane autoJoinChannelsSettingsRoot;
public ListView<String> removeListView;
public Button removeButton;

public AutoJoinChannelsController(PreferencesService preferencesService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public void initialize() {
configureTimeSetting(preferences);
configureChatSetting(preferences);
configureLanguageSelection();
configureThemeSelection(preferences);
configureThemeSelection();
configureToastScreen(preferences);
configureStartTab(preferences);

Expand Down Expand Up @@ -392,13 +392,10 @@ private void setSelectedColorMode(ChatColorMode newValue) {
}
}

private void configureThemeSelection(Preferences preferences) {
private void configureThemeSelection() {
themeComboBox.setItems(FXCollections.observableArrayList(uiService.getAvailableThemes()));

Theme currentTheme = themeComboBox.getItems().stream()
.filter(theme -> theme.getDisplayName().equals(preferences.getThemeName()))
.findFirst().orElse(UiService.DEFAULT_THEME);
themeComboBox.getSelectionModel().select(currentTheme);
themeComboBox.getSelectionModel().select(uiService.getCurrentTheme());

themeComboBox.getSelectionModel().selectedItemProperty().addListener(selectedThemeChangeListener);
JavaFxUtil.addListener(uiService.currentThemeProperty(), new WeakChangeListener<>(currentThemeChangeListener));
Expand Down
32 changes: 19 additions & 13 deletions src/main/java/com/faforever/client/theme/UiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ public class UiService implements InitializingBean, DisposableBean {
private final I18n i18n;

private WatchService watchService;
private ObservableMap<String, Theme> themesByFolderName;
private Map<Theme, String> folderNamesByTheme;
private Map<Path, WatchKey> watchKeys;
private ObjectProperty<Theme> currentTheme;
private final ObservableMap<String, Theme> themesByFolderName;
private final Map<Theme, String> folderNamesByTheme;
private final Map<Path, WatchKey> watchKeys;
private final ObjectProperty<Theme> currentTheme;
private Path currentTempStyleSheet;
private MessageSourceResourceBundle resources;

Expand Down Expand Up @@ -178,7 +178,12 @@ public void afterPropertiesSet() throws IOException {
loadThemes();

String storedTheme = preferencesService.getPreferences().getThemeName();
setTheme(themesByFolderName.get(storedTheme));
if (themesByFolderName.containsKey(storedTheme)) {
setTheme(themesByFolderName.get(storedTheme));
} else {
logger.warn("Selected theme was not found in folder {}, falling back to default.", storedTheme);
setTheme(DEFAULT_THEME);
}

loadWebViewsStyleSheet(getWebViewStyleSheet());
}
Expand Down Expand Up @@ -235,11 +240,9 @@ public void destroy() throws IOException {
deleteStylesheetsCacheDirectory();
}

private void stopWatchingTheme(Theme theme) {
Path path = getThemeDirectory(theme);
if (watchKeys.containsKey(path)) {
watchKeys.remove(path).cancel();
}
private void stopWatchingOldThemes() {
watchKeys.values().forEach(WatchKey::cancel);
watchKeys.clear();
}

/**
Expand Down Expand Up @@ -317,7 +320,7 @@ public URL getThemeFileUrl(String relativeFile) {


public void setTheme(Theme theme) {
stopWatchingTheme(theme);
stopWatchingOldThemes();

if (theme == DEFAULT_THEME) {
preferencesService.getPreferences().setThemeName(DEFAULT_THEME_NAME);
Expand Down Expand Up @@ -367,7 +370,8 @@ public String[] getStylesheets() {
JFoenixResources.load("css/jfoenix-fonts.css").toExternalForm(),
JFoenixResources.load("css/jfoenix-design.css").toExternalForm(),
getThemeFile("theme/jfoenix.css"),
getSceneStyleSheet()
getSceneStyleSheet(),
getThemeFile("theme/style_extension.css")
};
}

Expand All @@ -390,11 +394,13 @@ public void loadThemes() {
});
}


public Collection<Theme> getAvailableThemes() {
return new ArrayList<>(themesByFolderName.values());
}

public Theme getCurrentTheme() {
return currentTheme.get();
}

public ReadOnlyObjectProperty<Theme> currentThemeProperty() {
return currentTheme;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/theme/settings/settings.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@
<children>
<Label styleClass="h3" text="%settings.general.theme"
GridPane.columnSpan="2147483647"/>
<JFXComboBox fx:id="themeComboBox" disable="true"
<JFXComboBox fx:id="themeComboBox"
maxWidth="1.7976931348623157E308" GridPane.columnSpan="2147483647"
GridPane.rowIndex="1"/>
<Label styleClass="h3" text="%settings.appearance.backgoundImage"
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/theme/style_extension.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*
To be overwritten by theme
*/

0 comments on commit 2f98cdd

Please sign in to comment.