Search in sources :

Example 1 with Theme

use of org.springframework.ui.context.Theme in project spring-framework by spring-projects.

the class ResourceBundleThemeSource method getTheme.

/**
	 * This implementation returns a SimpleTheme instance, holding a
	 * ResourceBundle-based MessageSource whose basename corresponds to
	 * the given theme name (prefixed by the configured "basenamePrefix").
	 * <p>SimpleTheme instances are cached per theme name. Use a reloadable
	 * MessageSource if themes should reflect changes to the underlying files.
	 * @see #setBasenamePrefix
	 * @see #createMessageSource
	 */
@Override
public Theme getTheme(String themeName) {
    if (themeName == null) {
        return null;
    }
    Theme theme = this.themeCache.get(themeName);
    if (theme == null) {
        synchronized (this.themeCache) {
            theme = this.themeCache.get(themeName);
            if (theme == null) {
                String basename = this.basenamePrefix + themeName;
                MessageSource messageSource = createMessageSource(basename);
                theme = new SimpleTheme(themeName, messageSource);
                initParent(theme);
                this.themeCache.put(themeName, theme);
                if (logger.isDebugEnabled()) {
                    logger.debug("Theme created: name '" + themeName + "', basename [" + basename + "]");
                }
            }
        }
    }
    return theme;
}
Also used : Theme(org.springframework.ui.context.Theme) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) HierarchicalMessageSource(org.springframework.context.HierarchicalMessageSource) MessageSource(org.springframework.context.MessageSource)

Example 2 with Theme

use of org.springframework.ui.context.Theme in project spring-framework by spring-projects.

the class RequestContext method getFallbackTheme.

/**
	 * Determine the fallback theme for this context.
	 * <p>The default implementation returns the default theme (with name "theme").
	 * @return the fallback theme (never {@code null})
	 */
protected Theme getFallbackTheme() {
    ThemeSource themeSource = RequestContextUtils.getThemeSource(getRequest());
    if (themeSource == null) {
        themeSource = new ResourceBundleThemeSource();
    }
    Theme theme = themeSource.getTheme(DEFAULT_THEME_NAME);
    if (theme == null) {
        throw new IllegalStateException("No theme defined and no fallback theme found");
    }
    return theme;
}
Also used : ResourceBundleThemeSource(org.springframework.ui.context.support.ResourceBundleThemeSource) Theme(org.springframework.ui.context.Theme) ThemeSource(org.springframework.ui.context.ThemeSource) ResourceBundleThemeSource(org.springframework.ui.context.support.ResourceBundleThemeSource)

Example 3 with Theme

use of org.springframework.ui.context.Theme in project libresonic by Libresonic.

the class AbstractChartController method getColor.

private Color getColor(String code, HttpServletRequest request) {
    Theme theme = RequestContextUtils.getTheme(request);
    Locale locale = RequestContextUtils.getLocale(request);
    String colorHex = theme.getMessageSource().getMessage(code, new Object[0], locale);
    return new Color(Integer.parseInt(colorHex, 16));
}
Also used : Locale(java.util.Locale) Theme(org.springframework.ui.context.Theme)

Aggregations

Theme (org.springframework.ui.context.Theme)3 Locale (java.util.Locale)1 HierarchicalMessageSource (org.springframework.context.HierarchicalMessageSource)1 MessageSource (org.springframework.context.MessageSource)1 ResourceBundleMessageSource (org.springframework.context.support.ResourceBundleMessageSource)1 ThemeSource (org.springframework.ui.context.ThemeSource)1 ResourceBundleThemeSource (org.springframework.ui.context.support.ResourceBundleThemeSource)1