Enum Class DynamicTheme
- All Implemented Interfaces:
Serializable,Comparable<DynamicTheme>,Constable
This enum facilitates switching between themes (e.g., Lumo, Aura) at runtime.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionvoidapply(HasElement component) Applies this theme to the view.static DynamicThemeReturn the current dynamic theme.voidinitialize(AppShellSettings settings) Initializes the theme settings into the providedAppShellSettings.voidinitialize(IndexHtmlResponse response) Initializes the theme settings into the providedIndexHtmlResponse.static booleanChecks if the dynamic theme feature has been initialized for the current session.static booleanChecks if the dynamic theme feature is supported.static voidPrepares the component for dynamic theme switching by preloading stylesheets.static DynamicThemeReturns the enum constant of this class with the specified name.static DynamicTheme[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
LUMO
The standard Lumo theme. -
AURA
The standard Aura theme. -
BASE
A base theme without specific styling.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
isFeatureSupported
public static boolean isFeatureSupported()Checks if the dynamic theme feature is supported. The feature is supported in Vaadin 25.- Returns:
trueif the feature is supported and initialized;falseotherwise.
-
isFeatureInitialized
public static boolean isFeatureInitialized()Checks if the dynamic theme feature has been initialized for the current session.- Returns:
trueif the feature is supported and initialized;falseotherwise.
-
getCurrent
Return the current dynamic theme.- Returns:
- the current dynamic theme, or
nullif the feature has not been initialized. - Throws:
UnsupportedOperationException- if the runtime Vaadin version is older than 25.
-
initialize
Initializes the theme settings into the providedAppShellSettings.This method performs a lazy initialization of the
DynamicThemewithin the currentVaadinSession. If no theme is present, it registers this instance as the session default. Subsequently, it injects the corresponding CSS stylesheet link into the document head.- Parameters:
settings- the application shell settings to be modified- Throws:
UnsupportedOperationException- if the runtime Vaadin version is older than 25IllegalStateException- if theAppShellConfiguratoris configured with the legacyThemeannotation
-
initialize
Initializes the theme settings into the providedIndexHtmlResponse.This method performs a lazy initialization of the
DynamicThemewithin the currentVaadinSession. If no theme is present, it registers this instance as the session default. Subsequently, it injects the corresponding CSS stylesheet link into the document head.- Parameters:
response- the index HTML response to be modified- Throws:
UnsupportedOperationException- if the runtime Vaadin version is older than 25IllegalStateException- if theAppShellConfiguratoris configured with the legacyThemeannotation
-
prepare
Prepares the component for dynamic theme switching by preloading stylesheets.Adds a client-side listener to the component that detects mouseover events. When triggered, it preloads the theme stylesheets (Lumo and Aura) to ensure they can be applied immediately when needed.
- Parameters:
component- the component to attach the listener to- Throws:
IllegalStateException- if the dynamic theme feature has not been initialized
-
apply
Applies this theme to the view.- Parameters:
component- a component in the view- Throws:
IllegalStateException- if the dynamic theme feature has not been initialized
-